pass texture to plugin so it doesn't have to grab from title bar.
[wmaker-crm.git] / src / defaults.c
blobba96530e0cd6a000bf1b6cc9a9347db3699ece58
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
25 #include "plugin.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
45 #ifndef PATH_MAX
46 #define PATH_MAX DEFAULT_PATH_MAX
47 #endif
49 #include <X11/Xlib.h>
50 #include <X11/Xutil.h>
51 #include <X11/keysym.h>
53 #include <wraster.h>
56 #include "WindowMaker.h"
57 #include "wcore.h"
58 #include "framewin.h"
59 #include "window.h"
60 #include "texture.h"
61 #include "screen.h"
62 #include "resources.h"
63 #include "defaults.h"
64 #include "keybind.h"
65 #include "xmodifier.h"
66 #include "icon.h"
67 #include "funcs.h"
68 #include "actions.h"
69 #include "dock.h"
70 #include "workspace.h"
71 #include "properties.h"
75 * Our own proplist reader parser. This one will not accept any
76 * syntax errors and is more descriptive in the error messages.
77 * It also doesn't seem to crash.
79 extern proplist_t ReadProplistFromFile(char *file);
82 /***** Global *****/
84 extern WDDomain *WDWindowMaker;
85 extern WDDomain *WDWindowAttributes;
86 extern WDDomain *WDRootMenu;
88 extern int wScreenCount;
90 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
91 extern Atom _XA_WINDOWMAKER_ICON_TILE;
94 extern proplist_t wDomainName;
95 extern proplist_t wAttributeDomainName;
97 extern WPreferences wPreferences;
99 extern WShortKey wKeyBindings[WKBD_LAST];
101 typedef struct {
102 char *key;
103 char *default_value;
104 void *extra_data;
105 void *addr;
106 int (*convert)();
107 int (*update)();
108 proplist_t plkey;
109 proplist_t plvalue; /* default value */
110 } WDefaultEntry;
113 /* used to map strings to integers */
114 typedef struct {
115 char *string;
116 short value;
117 char is_alias;
118 } WOptionEnumeration;
121 /* type converters */
122 static int getBool();
123 static int getInt();
124 static int getCoord();
125 #if 0
126 /* this is not used yet */
127 static int getString();
128 #endif
129 static int getPathList();
130 static int getEnum();
131 static int getTexture();
132 #ifdef DRAWSTRING_PLUGIN
133 static int getTextRenderer();
134 #endif
135 static int getWSBackground();
136 static int getWSSpecificBackground();
137 static int getFont();
138 static int getColor();
139 static int getKeybind();
140 static int getModMask();
141 #ifdef NEWSTUFF
142 static int getRImage();
143 #endif
146 /* value setting functions */
147 static int setJustify();
148 static int setClearance();
149 static int setIfDockPresent();
150 static int setStickyIcons();
152 static int setPositive();
154 static int setWidgetColor();
155 static int setIconTile();
156 static int setWinTitleFont();
157 static int setMenuTitleFont();
158 static int setMenuTextFont();
159 static int setIconTitleFont();
160 static int setIconTitleColor();
161 static int setIconTitleBack();
162 static int setLargeDisplayFont();
163 static int setWTitleColor();
164 static int setFTitleBack();
165 static int setPTitleBack();
166 static int setUTitleBack();
167 static int setResizebarBack();
168 static int setWorkspaceBack();
169 static int setWorkspaceSpecificBack();
170 static int setMenuTitleColor();
171 static int setMenuTextColor();
172 static int setMenuDisabledColor();
173 static int setMenuTitleBack();
174 static int setMenuTextBack();
175 static int setHightlight();
176 static int setHightlightText();
177 static int setKeyGrab();
178 static int setDoubleClick();
179 static int setIconPosition();
181 static int setClipTitleFont();
182 static int setClipTitleColor();
184 static int setMenuStyle();
185 #if 0
186 static int setMultiByte();
187 #endif
188 static int updateUsableArea();
190 #ifdef DEFINABLE_CURSOR
191 extern Cursor wCursor[WCUR_LAST];
192 static int getCursor();
193 static int setCursor();
194 #endif
198 * Tables to convert strings to enumeration values.
199 * Values stored are char
203 /* WARNING: sum of length of all value strings must not exceed
204 * this value */
205 #define TOTAL_VALUES_LENGTH 80
210 #define REFRESH_WINDOW_TEXTURES (1<<0)
211 #define REFRESH_MENU_TEXTURE (1<<1)
212 #define REFRESH_MENU_FONT (1<<2)
213 #define REFRESH_MENU_COLOR (1<<3)
214 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
215 #define REFRESH_MENU_TITLE_FONT (1<<5)
216 #define REFRESH_MENU_TITLE_COLOR (1<<6)
217 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
218 #define REFRESH_WINDOW_FONT (1<<8)
219 #define REFRESH_ICON_TILE (1<<9)
220 #define REFRESH_ICON_FONT (1<<10)
221 #define REFRESH_WORKSPACE_BACK (1<<11)
223 #define REFRESH_BUTTON_IMAGES (1<<12)
225 #define REFRESH_ICON_TITLE_COLOR (1<<13)
226 #define REFRESH_ICON_TITLE_BACK (1<<14)
230 static WOptionEnumeration seFocusModes[] = {
231 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
232 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
233 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
234 {NULL, 0, 0}
237 static WOptionEnumeration seColormapModes[] = {
238 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
239 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
240 {NULL, 0, 0}
243 static WOptionEnumeration sePlacements[] = {
244 {"Auto", WPM_AUTO, 0},
245 {"Smart", WPM_SMART, 0},
246 {"Cascade", WPM_CASCADE, 0},
247 {"Random", WPM_RANDOM, 0},
248 {"Manual", WPM_MANUAL, 0},
249 {NULL, 0, 0}
252 static WOptionEnumeration seGeomDisplays[] = {
253 {"Center", WDIS_CENTER, 0},
254 {"Corner", WDIS_TOPLEFT, 0},
255 {"Floating", WDIS_FRAME_CENTER, 0},
256 {"Line", WDIS_NEW, 0},
257 {NULL, 0, 0}
260 static WOptionEnumeration seSpeeds[] = {
261 {"UltraFast", SPEED_ULTRAFAST, 0},
262 {"Fast", SPEED_FAST, 0},
263 {"Medium", SPEED_MEDIUM, 0},
264 {"Slow", SPEED_SLOW, 0},
265 {"UltraSlow", SPEED_ULTRASLOW, 0},
266 {NULL, 0, 0}
269 static WOptionEnumeration seMouseButtons[] = {
270 {"None", -1, 0},
271 {"Left", Button1, 0}, {"Button1", Button1, 1},
272 {"Middle", Button2, 0}, {"Button2", Button2, 1},
273 {"Right", Button3, 0}, {"Button3", Button3, 1},
274 {"Button4", Button4, 0},
275 {"Button5", Button5, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seIconificationStyles[] = {
280 {"Zoom", WIS_ZOOM, 0},
281 {"Twist", WIS_TWIST, 0},
282 {"Flip", WIS_FLIP, 0},
283 {"None", WIS_NONE, 0},
284 {"random", WIS_RANDOM, 0},
285 {NULL, 0, 0}
288 static WOptionEnumeration seJustifications[] = {
289 {"Left", WTJ_LEFT, 0},
290 {"Center", WTJ_CENTER, 0},
291 {"Right", WTJ_RIGHT, 0},
292 {NULL, 0, 0}
295 static WOptionEnumeration seIconPositions[] = {
296 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
297 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
298 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
299 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
300 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
301 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
302 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
303 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
304 {NULL, 0, 0}
307 static WOptionEnumeration seMenuStyles[] = {
308 {"normal", MS_NORMAL, 0},
309 {"singletexture", MS_SINGLE_TEXTURE, 0},
310 {"flat", MS_FLAT, 0},
311 {NULL, 0, 0}
315 static WOptionEnumeration seDisplayPositions[] = {
316 {"none", WD_NONE, 0},
317 {"center", WD_CENTER, 0},
318 {"top", WD_TOP, 0},
319 {"bottom", WD_BOTTOM, 0},
320 {"topleft", WD_TOPLEFT, 0},
321 {"topright", WD_TOPRIGHT, 0},
322 {"bottomleft", WD_BOTTOMLEFT, 0},
323 {"bottomright", WD_BOTTOMRIGHT, 0},
324 {NULL, 0, 0}
327 static WOptionEnumeration seWorkspaceBorder[] = {
328 {"None", WB_NONE, 0},
329 {"LeftRight", WB_LEFTRIGHT, 0},
330 {"TopBottom", WB_TOPBOTTOM, 0},
331 {"AllDirections", WB_ALLDIRS, 0},
332 {NULL, 0, 0}
337 * ALL entries in the tables bellow, NEED to have a default value
338 * defined, and this value needs to be correct.
341 /* these options will only affect the window manager on startup
343 * static defaults can't access the screen data, because it is
344 * created after these defaults are read
346 WDefaultEntry staticOptionList[] = {
348 {"ColormapSize", "4", NULL,
349 &wPreferences.cmap_size, getInt, NULL
351 {"DisableDithering", "NO", NULL,
352 &wPreferences.no_dithering, getBool, NULL
354 /* static by laziness */
355 {"IconSize", "64", NULL,
356 &wPreferences.icon_size, getInt, NULL
358 {"ModifierKey", "Mod1", NULL,
359 &wPreferences.modifier_mask, getModMask, NULL
361 {"DisableWSMouseActions", "NO", NULL,
362 &wPreferences.disable_root_mouse, getBool, NULL
364 {"FocusMode", "manual", seFocusModes,
365 &wPreferences.focus_mode, getEnum, NULL
366 }, /* have a problem when switching from manual to sloppy without restart */
367 {"NewStyle", "NO", NULL,
368 &wPreferences.new_style, getBool, NULL
370 {"DisableDock", "NO", (void*) WM_DOCK,
371 NULL, getBool, setIfDockPresent
373 {"DisableClip", "NO", (void*) WM_CLIP,
374 NULL, getBool, setIfDockPresent
376 {"DisableMiniwindows", "NO", NULL,
377 &wPreferences.disable_miniwindows, getBool, NULL
379 #if 0
380 ,{"MultiByteText", "NO", NULL,
381 &wPreferences.multi_byte_text, getBool, setMultiByte
383 #endif
388 WDefaultEntry optionList[] = {
389 /* dynamic options */
390 {"IconPosition", "blh", seIconPositions,
391 &wPreferences.icon_yard, getEnum, setIconPosition
393 {"IconificationStyle", "Zoom", seIconificationStyles,
394 &wPreferences.iconification_style, getEnum, NULL
396 {"SelectWindowsMouseButton", "Left", seMouseButtons,
397 &wPreferences.select_button, getEnum, NULL
399 {"WindowListMouseButton", "Middle", seMouseButtons,
400 &wPreferences.windowl_button, getEnum, NULL
402 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
403 &wPreferences.menu_button, getEnum, NULL
405 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
406 &wPreferences.pixmap_path, getPathList, NULL
408 {"IconPath", DEF_ICON_PATHS, NULL,
409 &wPreferences.icon_path, getPathList, NULL
411 {"ColormapMode", "auto", seColormapModes,
412 &wPreferences.colormap_mode, getEnum, NULL
414 {"AutoFocus", "NO", NULL,
415 &wPreferences.auto_focus, getBool, NULL
417 {"RaiseDelay", "0", NULL,
418 &wPreferences.raise_delay, getInt, NULL
420 {"WindozeCycling", "YES", NULL,
421 &wPreferences.windows_cycling,getBool, NULL
423 {"CirculateRaise", "NO", NULL,
424 &wPreferences.circ_raise, getBool, NULL
426 {"Superfluous", "NO", NULL,
427 &wPreferences.superfluous, getBool, NULL
429 {"AdvanceToNewWorkspace", "NO", NULL,
430 &wPreferences.ws_advance, getBool, NULL
432 {"CycleWorkspaces", "NO", NULL,
433 &wPreferences.ws_cycle, getBool, NULL
435 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
436 &wPreferences.workspace_name_display_position, getEnum, NULL
438 {"WorkspaceBorder", "None", seWorkspaceBorder,
439 &wPreferences.workspace_border_position, getEnum, updateUsableArea
441 {"WorkspaceBorderSize", "0", NULL,
442 &wPreferences.workspace_border_size, getInt, updateUsableArea
444 #ifdef VIRTUAL_DESKTOP
445 {"VirtualEdgeThickness", "1", NULL,
446 &wPreferences.vedge_thickness, getInt, NULL
448 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
449 &wPreferences.vedge_hscrollspeed, getInt, NULL
451 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
452 &wPreferences.vedge_vscrollspeed, getInt, NULL
454 {"VirtualEdgeMaximumWidth", "3000", NULL,
455 &wPreferences.vedge_maxwidth, getInt, NULL
457 {"VirtualEdgeMaximumHeight", "3000", NULL,
458 &wPreferences.vedge_maxheight, getInt, NULL
460 #endif
461 {"StickyIcons", "NO", NULL,
462 &wPreferences.sticky_icons, getBool, setStickyIcons
464 {"SaveSessionOnExit", "NO", NULL,
465 &wPreferences.save_session_on_exit, getBool, NULL
467 {"WrapMenus", "NO", NULL,
468 &wPreferences.wrap_menus, getBool, NULL
470 {"ScrollableMenus", "NO", NULL,
471 &wPreferences.scrollable_menus, getBool, NULL
473 {"MenuScrollSpeed", "medium", seSpeeds,
474 &wPreferences.menu_scroll_speed, getEnum, NULL
476 {"IconSlideSpeed", "medium", seSpeeds,
477 &wPreferences.icon_slide_speed, getEnum, NULL
479 {"ShadeSpeed", "medium", seSpeeds,
480 &wPreferences.shade_speed, getEnum, NULL
482 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
483 &wPreferences.dblclick_time, getInt, setDoubleClick,
485 {"AlignSubmenus", "NO", NULL,
486 &wPreferences.align_menus, getBool, NULL
488 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
489 &wPreferences.open_transients_with_parent, getBool, NULL
491 {"WindowPlacement", "auto", sePlacements,
492 &wPreferences.window_placement, getEnum, NULL
494 {"IgnoreFocusClick","NO", NULL,
495 &wPreferences.ignore_focus_click, getBool, NULL
497 {"UseSaveUnders", "NO", NULL,
498 &wPreferences.use_saveunders, getBool, NULL
500 {"OpaqueMove", "NO", NULL,
501 &wPreferences.opaque_move, getBool, NULL
503 {"DisableSound", "NO", NULL,
504 &wPreferences.no_sound, getBool, NULL
506 {"DisableAnimations", "NO", NULL,
507 &wPreferences.no_animations, getBool, NULL
509 {"DontLinkWorkspaces","NO", NULL,
510 &wPreferences.no_autowrap, getBool, NULL
512 {"AutoArrangeIcons", "NO", NULL,
513 &wPreferences.auto_arrange_icons, getBool, NULL
515 {"NoWindowOverDock", "NO", NULL,
516 &wPreferences.no_window_over_dock, getBool, updateUsableArea
518 {"NoWindowOverIcons", "NO", NULL,
519 &wPreferences.no_window_over_icons, getBool, updateUsableArea
521 {"WindowPlaceOrigin", "(0, 0)", NULL,
522 &wPreferences.window_place_origin, getCoord, NULL
524 {"ResizeDisplay", "corner", seGeomDisplays,
525 &wPreferences.size_display, getEnum, NULL
527 {"MoveDisplay", "corner", seGeomDisplays,
528 &wPreferences.move_display, getEnum, NULL
530 {"DontConfirmKill", "NO", NULL,
531 &wPreferences.dont_confirm_kill, getBool,NULL
533 {"WindowTitleBalloons", "NO", NULL,
534 &wPreferences.window_balloon, getBool, NULL
536 {"MiniwindowTitleBalloons", "NO", NULL,
537 &wPreferences.miniwin_balloon,getBool, NULL
539 {"AppIconBalloons", "NO", NULL,
540 &wPreferences.appicon_balloon,getBool, NULL
542 {"HelpBalloons", "NO", NULL,
543 &wPreferences.help_balloon, getBool, NULL
545 {"EdgeResistance", "30", NULL,
546 &wPreferences.edge_resistance,getInt, NULL
548 {"Attraction", "NO", NULL,
549 &wPreferences.attract, getBool, NULL
551 {"DisableBlinking", "NO", NULL,
552 &wPreferences.dont_blink, getBool, NULL
554 /* style options */
555 {"MenuStyle", "normal", seMenuStyles,
556 &wPreferences.menu_style, getEnum, setMenuStyle
558 {"WidgetColor", "(solid, gray)", NULL,
559 NULL, getTexture, setWidgetColor,
561 {"WorkspaceSpecificBack","()", NULL,
562 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
564 /* WorkspaceBack must come after WorkspaceSpecificBack or
565 * WorkspaceBack wont know WorkspaceSpecificBack was also
566 * specified and 2 copies of wmsetbg will be launched */
567 {"WorkspaceBack", "(solid, black)", NULL,
568 NULL, getWSBackground,setWorkspaceBack
570 {"SmoothWorkspaceBack", "NO", NULL,
571 NULL, getBool, NULL
573 {"IconBack", "(solid, gray)", NULL,
574 NULL, getTexture, setIconTile
576 {"TitleJustify", "center", seJustifications,
577 &wPreferences.title_justification, getEnum, setJustify
579 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
580 NULL, getFont, setWinTitleFont,
582 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
583 &wPreferences.window_title_clearance, getInt, setClearance
585 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
586 &wPreferences.menu_title_clearance, getInt, setClearance
588 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
589 &wPreferences.menu_text_clearance, getInt, setClearance
591 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
592 NULL, getFont, setMenuTitleFont
594 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
595 NULL, getFont, setMenuTextFont
597 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
598 NULL, getFont, setIconTitleFont
600 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
601 NULL, getFont, setClipTitleFont
603 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
604 NULL, getFont, setLargeDisplayFont
606 {"HighlightColor", "white", NULL,
607 NULL, getColor, setHightlight
609 {"HighlightTextColor", "black", NULL,
610 NULL, getColor, setHightlightText
612 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
613 NULL, getColor, setClipTitleColor
615 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
616 NULL, getColor, setClipTitleColor
618 #ifdef DRAWSTRING_PLUGIN
619 {"FTitleColor", "white", (void*)WS_FOCUSED,
620 NULL, getTextRenderer, setWTitleColor
622 {"PTitleColor", "white", (void*)WS_PFOCUSED,
623 NULL, getTextRenderer, setWTitleColor
625 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
626 NULL, getTextRenderer, setWTitleColor
628 #else
629 {"FTitleColor", "white", (void*)WS_FOCUSED,
630 NULL, getColor, setWTitleColor
632 {"PTitleColor", "white", (void*)WS_PFOCUSED,
633 NULL, getColor, setWTitleColor
635 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
636 NULL, getColor, setWTitleColor
638 #endif
639 {"FTitleBack", "(solid, black)", NULL,
640 NULL, getTexture, setFTitleBack
642 {"PTitleBack", "(solid, \"#616161\")", NULL,
643 NULL, getTexture, setPTitleBack
645 {"UTitleBack", "(solid, gray)", NULL,
646 NULL, getTexture, setUTitleBack
648 {"ResizebarBack", "(solid, gray)", NULL,
649 NULL, getTexture, setResizebarBack
651 #ifdef DRAWSTRING_PLUGIN
652 {"MenuTitleColor", "white", NULL,
653 NULL, getTextRenderer, setMenuTitleColor
655 {"MenuTextColor", "black", NULL,
656 NULL, getTextRenderer, setMenuTextColor
658 #else
659 {"MenuTitleColor", "white", NULL,
660 NULL, getColor, setMenuTitleColor
662 {"MenuTextColor", "black", NULL,
663 NULL, getColor, setMenuTextColor
665 #endif
666 {"MenuDisabledColor", "\"#616161\"", NULL,
667 NULL, getColor, setMenuDisabledColor
669 {"MenuTitleBack", "(solid, black)", NULL,
670 NULL, getTexture, setMenuTitleBack
672 {"MenuTextBack", "(solid, gray)", NULL,
673 NULL, getTexture, setMenuTextBack
675 {"IconTitleColor", "white", NULL,
676 NULL, getColor, setIconTitleColor
678 {"IconTitleBack", "black", NULL,
679 NULL, getColor, setIconTitleBack
681 /* keybindings */
682 #ifndef LITE
683 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
684 NULL, getKeybind, setKeyGrab
686 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
687 NULL, getKeybind, setKeyGrab
689 #endif /* LITE */
690 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
691 NULL, getKeybind, setKeyGrab
693 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
694 NULL, getKeybind, setKeyGrab
696 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
697 NULL, getKeybind, setKeyGrab
699 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
700 NULL, getKeybind, setKeyGrab
702 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
703 NULL, getKeybind, setKeyGrab
705 {"HideKey", "None", (void*)WKBD_HIDE,
706 NULL, getKeybind, setKeyGrab
708 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
709 NULL, getKeybind, setKeyGrab
711 {"CloseKey", "None", (void*)WKBD_CLOSE,
712 NULL, getKeybind, setKeyGrab
714 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
715 NULL, getKeybind, setKeyGrab
717 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
718 NULL, getKeybind, setKeyGrab
720 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
721 NULL, getKeybind, setKeyGrab
723 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
724 NULL, getKeybind, setKeyGrab
726 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
727 NULL, getKeybind, setKeyGrab
729 {"ShadeKey", "None", (void*)WKBD_SHADE,
730 NULL, getKeybind, setKeyGrab
732 {"SelectKey", "None", (void*)WKBD_SELECT,
733 NULL, getKeybind, setKeyGrab
735 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
736 NULL, getKeybind, setKeyGrab
738 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
739 NULL, getKeybind, setKeyGrab
741 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
742 NULL, getKeybind, setKeyGrab
744 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
745 NULL, getKeybind, setKeyGrab
747 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
748 NULL, getKeybind, setKeyGrab
750 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
766 NULL, getKeybind, setKeyGrab
768 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
769 NULL, getKeybind, setKeyGrab
771 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
772 NULL, getKeybind, setKeyGrab
774 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
775 NULL, getKeybind, setKeyGrab
777 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
778 NULL, getKeybind, setKeyGrab
780 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
790 NULL, getKeybind, setKeyGrab
792 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
793 NULL, getKeybind, setKeyGrab
795 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
796 NULL, getKeybind, setKeyGrab
798 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
799 NULL, getKeybind, setKeyGrab
801 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
802 NULL, getKeybind, setKeyGrab
804 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
805 NULL, getKeybind, setKeyGrab
807 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
808 NULL, getKeybind, setKeyGrab
810 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
811 NULL, getKeybind, setKeyGrab
813 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
814 NULL, getKeybind, setKeyGrab
817 #ifdef KEEP_XKB_LOCK_STATUS
818 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
819 NULL, getKeybind, setKeyGrab
821 {"KbdModeLock", "NO", NULL,
822 &wPreferences.modelock, getBool, NULL
824 #endif /* KEEP_XKB_LOCK_STATUS */
825 #ifdef DEFINABLE_CURSOR
826 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
827 NULL, getCursor, setCursor
829 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
830 NULL, getCursor, setCursor
832 #if 0
833 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
834 NULL, getCursor, setCursor
836 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
837 NULL, getCursor, setCursor
839 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
840 NULL, getCursor, setCursor
842 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
843 NULL, getCursor, setCursor
845 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
846 NULL, getCursor, setCursor
848 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
849 NULL, getCursor, setCursor
851 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
852 NULL, getCursor, setCursor
854 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
855 NULL, getCursor, setCursor
857 #endif
858 #endif /* DEFINABLE_CURSOR */
862 #if 0
863 static void rereadDefaults(void);
864 #endif
866 #if 0
867 static void
868 rereadDefaults(void)
870 /* must defer the update because accessing X data from a
871 * signal handler can mess up Xlib */
874 #endif
876 static void
877 initDefaults()
879 int i;
880 WDefaultEntry *entry;
882 PLSetStringCmpHook(StringCompareHook);
884 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
885 entry = &optionList[i];
887 entry->plkey = PLMakeString(entry->key);
888 if (entry->default_value)
889 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
890 else
891 entry->plvalue = NULL;
894 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
895 entry = &staticOptionList[i];
897 entry->plkey = PLMakeString(entry->key);
898 if (entry->default_value)
899 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
900 else
901 entry->plvalue = NULL;
905 wDomainName = PLMakeString(WMDOMAIN_NAME);
906 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
908 PLRegister(wDomainName, rereadDefaults);
909 PLRegister(wAttributeDomainName, rereadDefaults);
916 #if 0
917 proplist_t
918 wDefaultsInit(int screen_number)
920 static int defaults_inited = 0;
921 proplist_t dict;
923 if (!defaults_inited) {
924 initDefaults();
927 dict = PLGetDomain(wDomainName);
928 if (!dict) {
929 wwarning(_("could not read domain \"%s\" from defaults database"),
930 PLGetString(wDomainName));
933 return dict;
935 #endif
938 void
939 wDefaultsDestroyDomain(WDDomain *domain)
941 if (domain->dictionary)
942 PLRelease(domain->dictionary);
943 wfree(domain->path);
944 wfree(domain);
948 WDDomain*
949 wDefaultsInitDomain(char *domain, Bool requireDictionary)
951 WDDomain *db;
952 struct stat stbuf;
953 static int inited = 0;
954 char path[PATH_MAX];
955 char *the_path;
956 proplist_t shared_dict=NULL;
958 if (!inited) {
959 inited = 1;
960 initDefaults();
963 db = wmalloc(sizeof(WDDomain));
964 memset(db, 0, sizeof(WDDomain));
965 db->domain_name = domain;
966 db->path = wdefaultspathfordomain(domain);
967 the_path = db->path;
969 if (the_path && stat(the_path, &stbuf)>=0) {
970 db->dictionary = ReadProplistFromFile(the_path);
971 if (db->dictionary) {
972 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
973 PLRelease(db->dictionary);
974 db->dictionary = NULL;
975 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
976 domain, the_path);
978 db->timestamp = stbuf.st_mtime;
979 } else {
980 wwarning(_("could not load domain %s from user defaults database"),
981 domain);
985 /* global system dictionary */
986 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
987 if (stat(path, &stbuf)>=0) {
988 shared_dict = ReadProplistFromFile(path);
989 if (shared_dict) {
990 if (requireDictionary && !PLIsDictionary(shared_dict)) {
991 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
992 domain, path);
993 PLRelease(shared_dict);
994 shared_dict = NULL;
995 } else {
996 if (db->dictionary && PLIsDictionary(shared_dict) &&
997 PLIsDictionary(db->dictionary)) {
998 PLMergeDictionaries(shared_dict, db->dictionary);
999 PLRelease(db->dictionary);
1000 db->dictionary = shared_dict;
1001 if (stbuf.st_mtime > db->timestamp)
1002 db->timestamp = stbuf.st_mtime;
1003 } else if (!db->dictionary) {
1004 db->dictionary = shared_dict;
1005 if (stbuf.st_mtime > db->timestamp)
1006 db->timestamp = stbuf.st_mtime;
1009 } else {
1010 wwarning(_("could not load domain %s from global defaults database (%s)"),
1011 domain, path);
1015 /* set to save it in user's directory, no matter from where it was read */
1016 if (db->dictionary) {
1017 proplist_t tmp = PLMakeString(db->path);
1019 PLSetFilename(db->dictionary, tmp);
1020 PLRelease(tmp);
1023 return db;
1027 void
1028 wReadStaticDefaults(proplist_t dict)
1030 proplist_t plvalue;
1031 WDefaultEntry *entry;
1032 int i;
1033 void *tdata;
1036 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1037 entry = &staticOptionList[i];
1039 if (dict)
1040 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1041 else
1042 plvalue = NULL;
1044 if (!plvalue) {
1045 /* no default in the DB. Use builtin default */
1046 plvalue = entry->plvalue;
1049 if (plvalue) {
1050 /* convert data */
1051 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1052 if (entry->update) {
1053 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1060 void
1061 wDefaultsCheckDomains(void *foo)
1063 WScreen *scr;
1064 struct stat stbuf;
1065 proplist_t dict;
1066 int i;
1067 char path[PATH_MAX];
1069 #ifdef HEARTBEAT
1070 puts("Checking domains...");
1071 #endif
1072 if (stat(WDWindowMaker->path, &stbuf)>=0
1073 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1074 proplist_t shared_dict = NULL;
1075 #ifdef HEARTBEAT
1076 puts("Checking WindowMaker domain");
1077 #endif
1078 WDWindowMaker->timestamp = stbuf.st_mtime;
1080 /* global dictionary */
1081 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1082 if (stat(path, &stbuf)>=0) {
1083 shared_dict = ReadProplistFromFile(path);
1084 if (shared_dict && !PLIsDictionary(shared_dict)) {
1085 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1086 "WindowMaker", path);
1087 PLRelease(shared_dict);
1088 shared_dict = NULL;
1089 } else if (!shared_dict) {
1090 wwarning(_("could not load domain %s from global defaults database"),
1091 "WindowMaker");
1094 /* user dictionary */
1095 dict = ReadProplistFromFile(WDWindowMaker->path);
1096 if (dict) {
1097 if (!PLIsDictionary(dict)) {
1098 PLRelease(dict);
1099 dict = NULL;
1100 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1101 "WindowMaker", WDWindowMaker->path);
1102 } else {
1103 if (shared_dict) {
1104 PLSetFilename(shared_dict, PLGetFilename(dict));
1105 PLMergeDictionaries(shared_dict, dict);
1106 PLRelease(dict);
1107 dict = shared_dict;
1108 shared_dict = NULL;
1110 for (i=0; i<wScreenCount; i++) {
1111 scr = wScreenWithNumber(i);
1112 if (scr)
1113 wReadDefaults(scr, dict);
1115 if (WDWindowMaker->dictionary) {
1116 PLRelease(WDWindowMaker->dictionary);
1118 WDWindowMaker->dictionary = dict;
1120 } else {
1121 wwarning(_("could not load domain %s from user defaults database"),
1122 "WindowMaker");
1124 if (shared_dict) {
1125 PLRelease(shared_dict);
1129 if (stat(WDWindowAttributes->path, &stbuf)>=0
1130 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1131 #ifdef HEARTBEAT
1132 puts("Checking WMWindowAttributes domain");
1133 #endif
1134 dict = ReadProplistFromFile(WDWindowAttributes->path);
1135 if (dict) {
1136 if (!PLIsDictionary(dict)) {
1137 PLRelease(dict);
1138 dict = NULL;
1139 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1140 "WMWindowAttributes", WDWindowAttributes->path);
1141 } else {
1142 if (WDWindowAttributes->dictionary)
1143 PLRelease(WDWindowAttributes->dictionary);
1144 WDWindowAttributes->dictionary = dict;
1145 for (i=0; i<wScreenCount; i++) {
1146 scr = wScreenWithNumber(i);
1147 if (scr)
1148 wDefaultUpdateIcons(scr);
1151 } else {
1152 wwarning(_("could not load domain %s from user defaults database"),
1153 "WMWindowAttributes");
1155 WDWindowAttributes->timestamp = stbuf.st_mtime;
1158 #ifndef LITE
1159 if (stat(WDRootMenu->path, &stbuf)>=0
1160 && WDRootMenu->timestamp < stbuf.st_mtime) {
1161 dict = ReadProplistFromFile(WDRootMenu->path);
1162 #ifdef HEARTBEAT
1163 puts("Checking WMRootMenu domain");
1164 #endif
1165 if (dict) {
1166 if (!PLIsArray(dict) && !PLIsString(dict)) {
1167 PLRelease(dict);
1168 dict = NULL;
1169 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1170 "WMRootMenu", WDRootMenu->path);
1171 } else {
1172 if (WDRootMenu->dictionary) {
1173 PLRelease(WDRootMenu->dictionary);
1175 WDRootMenu->dictionary = dict;
1177 } else {
1178 wwarning(_("could not load domain %s from user defaults database"),
1179 "WMRootMenu");
1181 WDRootMenu->timestamp = stbuf.st_mtime;
1183 #endif /* !LITE */
1185 if (!foo)
1186 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1190 void
1191 wReadDefaults(WScreen *scr, proplist_t new_dict)
1193 proplist_t plvalue, old_value;
1194 WDefaultEntry *entry;
1195 int i, must_update;
1196 int update_workspace_back = 0; /* kluge :/ */
1197 int needs_refresh;
1198 void *tdata;
1199 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1200 ? WDWindowMaker->dictionary : NULL);
1202 must_update = 0;
1204 needs_refresh = 0;
1206 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1207 entry = &optionList[i];
1209 if (new_dict)
1210 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1211 else
1212 plvalue = NULL;
1214 if (!old_dict)
1215 old_value = NULL;
1216 else
1217 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1220 if (!plvalue && !old_value) {
1221 /* no default in the DB. Use builtin default */
1222 plvalue = entry->plvalue;
1223 if (plvalue && new_dict) {
1224 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1225 must_update = 1;
1227 } else if (!plvalue) {
1228 /* value was deleted from DB. Keep current value */
1229 continue;
1230 } else if (!old_value) {
1231 /* set value for the 1st time */
1232 } else if (!PLIsEqual(plvalue, old_value)) {
1233 /* value has changed */
1234 } else {
1236 if (strcmp(entry->key, "WorkspaceBack") == 0
1237 && update_workspace_back
1238 && scr->flags.backimage_helper_launched) {
1239 } else {
1240 /* value was not changed since last time */
1241 continue;
1245 if (plvalue) {
1246 #ifdef DEBUG
1247 printf("Updating %s to %s\n", entry->key,
1248 PLGetDescription(plvalue));
1249 #endif
1250 /* convert data */
1251 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1253 * If the WorkspaceSpecificBack data has been changed
1254 * so that the helper will be launched now, we must be
1255 * sure to send the default background texture config
1256 * to the helper.
1258 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1259 && !scr->flags.backimage_helper_launched) {
1260 update_workspace_back = 1;
1262 if (entry->update) {
1263 needs_refresh |=
1264 (*entry->update)(scr, entry, tdata, entry->extra_data);
1270 if (needs_refresh!=0 && !scr->flags.startup) {
1271 int foo;
1273 foo = 0;
1274 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1275 foo |= WTextureSettings;
1276 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1277 foo |= WFontSettings;
1278 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1279 foo |= WColorSettings;
1280 if (foo)
1281 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1282 (void*)foo);
1284 foo = 0;
1285 if (needs_refresh & REFRESH_MENU_TEXTURE)
1286 foo |= WTextureSettings;
1287 if (needs_refresh & REFRESH_MENU_FONT)
1288 foo |= WFontSettings;
1289 if (needs_refresh & REFRESH_MENU_COLOR)
1290 foo |= WColorSettings;
1291 if (foo)
1292 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1293 (void*)foo);
1295 foo = 0;
1296 if (needs_refresh & REFRESH_WINDOW_FONT) {
1297 foo |= WFontSettings;
1299 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1300 foo |= WTextureSettings;
1302 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1303 foo |= WColorSettings;
1305 if (foo)
1306 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1307 (void*)foo);
1309 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1310 foo = 0;
1311 if (needs_refresh & REFRESH_ICON_FONT) {
1312 foo |= WFontSettings;
1314 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1315 foo |= WTextureSettings;
1317 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1318 foo |= WTextureSettings;
1320 if (foo)
1321 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1322 (void*)foo);
1324 if (needs_refresh & REFRESH_ICON_TILE)
1325 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1330 void
1331 wDefaultUpdateIcons(WScreen *scr)
1333 WAppIcon *aicon = scr->app_icon_list;
1334 WWindow *wwin = scr->focused_window;
1335 char *file;
1337 while(aicon) {
1338 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1339 False);
1340 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1341 || (file && !aicon->icon->file)) {
1342 RImage *new_image;
1344 if (aicon->icon->file)
1345 wfree(aicon->icon->file);
1346 aicon->icon->file = wstrdup(file);
1348 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1349 aicon->wm_class);
1350 if (new_image) {
1351 wIconChangeImage(aicon->icon, new_image);
1352 wAppIconPaint(aicon);
1355 aicon = aicon->next;
1358 if (!wPreferences.flags.noclip)
1359 wClipIconPaint(scr->clip_icon);
1361 while (wwin) {
1362 if (wwin->icon && wwin->flags.miniaturized) {
1363 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1364 False);
1365 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1366 || (file && !wwin->icon->file)) {
1367 RImage *new_image;
1369 if (wwin->icon->file)
1370 wfree(wwin->icon->file);
1371 wwin->icon->file = wstrdup(file);
1373 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1374 wwin->wm_class);
1375 if (new_image)
1376 wIconChangeImage(wwin->icon, new_image);
1379 wwin = wwin->prev;
1384 /* --------------------------- Local ----------------------- */
1386 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1387 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1388 entry->key, x); \
1389 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1390 var = entry->default_value;\
1391 } else var = PLGetString(value)\
1397 static int
1398 string2index(proplist_t key, proplist_t val, proplist_t def,
1399 WOptionEnumeration *values)
1401 char *str;
1402 WOptionEnumeration *v;
1403 char buffer[TOTAL_VALUES_LENGTH];
1405 if (PLIsString(val) && (str = PLGetString(val))) {
1406 for (v=values; v->string!=NULL; v++) {
1407 if (strcasecmp(v->string, str)==0)
1408 return v->value;
1412 buffer[0] = 0;
1413 for (v=values; v->string!=NULL; v++) {
1414 if (!v->is_alias) {
1415 if (buffer[0]!=0)
1416 strcat(buffer, ", ");
1417 strcat(buffer, v->string);
1420 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1421 PLGetString(key), buffer);
1423 if (def) {
1424 return string2index(key, val, NULL, values);
1427 return -1;
1434 * value - is the value in the defaults DB
1435 * addr - is the address to store the data
1436 * ret - is the address to store a pointer to a temporary buffer. ret
1437 * must not be freed and is used by the set functions
1439 static int
1440 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1441 void **ret)
1443 static char data;
1444 char *val;
1445 int second_pass=0;
1447 GET_STRING_OR_DEFAULT("Boolean", val);
1449 again:
1450 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1451 || strcasecmp(val, "YES")==0) {
1453 data = 1;
1454 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1455 || strcasecmp(val, "NO")==0) {
1456 data = 0;
1457 } else {
1458 int i;
1459 if (sscanf(val, "%i", &i)==1) {
1460 if (i!=0)
1461 data = 1;
1462 else
1463 data = 0;
1464 } else {
1465 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1466 val, entry->key);
1467 if (second_pass==0) {
1468 val = PLGetString(entry->plvalue);
1469 second_pass = 1;
1470 wwarning(_("using default \"%s\" instead"), val);
1471 goto again;
1473 return False;
1477 if (ret)
1478 *ret = &data;
1480 if (addr) {
1481 *(char*)addr = data;
1484 return True;
1488 static int
1489 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1490 void **ret)
1492 static int data;
1493 char *val;
1496 GET_STRING_OR_DEFAULT("Integer", val);
1498 if (sscanf(val, "%i", &data)!=1) {
1499 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1500 val, entry->key);
1501 val = PLGetString(entry->plvalue);
1502 wwarning(_("using default \"%s\" instead"), val);
1503 if (sscanf(val, "%i", &data)!=1) {
1504 return False;
1508 if (ret)
1509 *ret = &data;
1511 if (addr) {
1512 *(int*)addr = data;
1514 return True;
1518 static int
1519 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1520 void **ret)
1522 static WCoord data;
1523 char *val_x, *val_y;
1524 int nelem, changed=0;
1525 proplist_t elem_x, elem_y;
1527 again:
1528 if (!PLIsArray(value)) {
1529 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1530 entry->key, "Coordinate");
1531 if (changed==0) {
1532 value = entry->plvalue;
1533 changed = 1;
1534 wwarning(_("using default \"%s\" instead"), entry->default_value);
1535 goto again;
1537 return False;
1540 nelem = PLGetNumberOfElements(value);
1541 if (nelem != 2) {
1542 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1543 entry->key);
1544 if (changed==0) {
1545 value = entry->plvalue;
1546 changed = 1;
1547 wwarning(_("using default \"%s\" instead"), entry->default_value);
1548 goto again;
1550 return False;
1553 elem_x = PLGetArrayElement(value, 0);
1554 elem_y = PLGetArrayElement(value, 1);
1556 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1557 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1558 entry->key);
1559 if (changed==0) {
1560 value = entry->plvalue;
1561 changed = 1;
1562 wwarning(_("using default \"%s\" instead"), entry->default_value);
1563 goto again;
1565 return False;
1568 val_x = PLGetString(elem_x);
1569 val_y = PLGetString(elem_y);
1571 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1572 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1573 if (changed==0) {
1574 value = entry->plvalue;
1575 changed = 1;
1576 wwarning(_("using default \"%s\" instead"), entry->default_value);
1577 goto again;
1579 return False;
1582 if (data.x < 0)
1583 data.x = 0;
1584 else if (data.x > scr->scr_width/3)
1585 data.x = scr->scr_width/3;
1586 if (data.y < 0)
1587 data.y = 0;
1588 else if (data.y > scr->scr_height/3)
1589 data.y = scr->scr_height/3;
1591 if (ret)
1592 *ret = &data;
1594 if (addr) {
1595 *(WCoord*)addr = data;
1598 return True;
1602 #if 0
1603 /* This function is not used at the moment. */
1604 static int
1605 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1606 void **ret)
1608 static char *data;
1610 GET_STRING_OR_DEFAULT("String", data);
1612 if (!data) {
1613 data = PLGetString(entry->plvalue);
1614 if (!data)
1615 return False;
1618 if (ret)
1619 *ret = &data;
1621 if (addr)
1622 *(char**)addr = wstrdup(data);
1624 return True;
1626 #endif
1629 static int
1630 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1631 void **ret)
1633 static char *data;
1634 int i, count, len;
1635 char *ptr;
1636 proplist_t d;
1637 int changed=0;
1639 again:
1640 if (!PLIsArray(value)) {
1641 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1642 entry->key, "an array of paths");
1643 if (changed==0) {
1644 value = entry->plvalue;
1645 changed = 1;
1646 wwarning(_("using default \"%s\" instead"), entry->default_value);
1647 goto again;
1649 return False;
1652 i = 0;
1653 count = PLGetNumberOfElements(value);
1654 if (count < 1) {
1655 if (changed==0) {
1656 value = entry->plvalue;
1657 changed = 1;
1658 wwarning(_("using default \"%s\" instead"), entry->default_value);
1659 goto again;
1661 return False;
1664 len = 0;
1665 for (i=0; i<count; i++) {
1666 d = PLGetArrayElement(value, i);
1667 if (!d || !PLIsString(d)) {
1668 count = i;
1669 break;
1671 len += strlen(PLGetString(d))+1;
1674 ptr = data = wmalloc(len+1);
1676 for (i=0; i<count; i++) {
1677 d = PLGetArrayElement(value, i);
1678 if (!d || !PLIsString(d)) {
1679 break;
1681 strcpy(ptr, PLGetString(d));
1682 ptr += strlen(PLGetString(d));
1683 *ptr = ':';
1684 ptr++;
1686 ptr--; *(ptr--) = 0;
1688 if (*(char**)addr!=NULL) {
1689 wfree(*(char**)addr);
1691 *(char**)addr = data;
1693 return True;
1697 static int
1698 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1699 void **ret)
1701 static signed char data;
1703 data = string2index(entry->plkey, value, entry->default_value,
1704 (WOptionEnumeration*)entry->extra_data);
1705 if (data < 0)
1706 return False;
1708 if (ret)
1709 *ret = &data;
1711 if (addr)
1712 *(signed char*)addr = data;
1714 return True;
1720 * (solid <color>)
1721 * (hgradient <color> <color>)
1722 * (vgradient <color> <color>)
1723 * (dgradient <color> <color>)
1724 * (mhgradient <color> <color> ...)
1725 * (mvgradient <color> <color> ...)
1726 * (mdgradient <color> <color> ...)
1727 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1728 * (tpixmap <file> <color>)
1729 * (spixmap <file> <color>)
1730 * (cpixmap <file> <color>)
1731 * (thgradient <file> <opaqueness> <color> <color>)
1732 * (tvgradient <file> <opaqueness> <color> <color>)
1733 * (tdgradient <file> <opaqueness> <color> <color>)
1734 * (function <lib> <function> ...)
1737 static WTexture*
1738 parse_texture(WScreen *scr, proplist_t pl)
1740 proplist_t elem;
1741 char *val;
1742 int nelem;
1743 WTexture *texture=NULL;
1745 nelem = PLGetNumberOfElements(pl);
1746 if (nelem < 1)
1747 return NULL;
1750 elem = PLGetArrayElement(pl, 0);
1751 if (!elem || !PLIsString(elem))
1752 return NULL;
1753 val = PLGetString(elem);
1756 if (strcasecmp(val, "solid")==0) {
1757 XColor color;
1759 if (nelem != 2)
1760 return NULL;
1762 /* get color */
1764 elem = PLGetArrayElement(pl, 1);
1765 if (!elem || !PLIsString(elem))
1766 return NULL;
1767 val = PLGetString(elem);
1769 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1770 wwarning(_("\"%s\" is not a valid color name"), val);
1771 return NULL;
1774 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1775 } else if (strcasecmp(val, "dgradient")==0
1776 || strcasecmp(val, "vgradient")==0
1777 || strcasecmp(val, "hgradient")==0) {
1778 RColor color1, color2;
1779 XColor xcolor;
1780 int type;
1782 if (nelem != 3) {
1783 wwarning(_("bad number of arguments in gradient specification"));
1784 return NULL;
1787 if (val[0]=='d' || val[0]=='D')
1788 type = WTEX_DGRADIENT;
1789 else if (val[0]=='h' || val[0]=='H')
1790 type = WTEX_HGRADIENT;
1791 else
1792 type = WTEX_VGRADIENT;
1795 /* get from color */
1796 elem = PLGetArrayElement(pl, 1);
1797 if (!elem || !PLIsString(elem))
1798 return NULL;
1799 val = PLGetString(elem);
1801 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1802 wwarning(_("\"%s\" is not a valid color name"), val);
1803 return NULL;
1805 color1.alpha = 255;
1806 color1.red = xcolor.red >> 8;
1807 color1.green = xcolor.green >> 8;
1808 color1.blue = xcolor.blue >> 8;
1810 /* get to color */
1811 elem = PLGetArrayElement(pl, 2);
1812 if (!elem || !PLIsString(elem)) {
1813 return NULL;
1815 val = PLGetString(elem);
1817 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1818 wwarning(_("\"%s\" is not a valid color name"), val);
1819 return NULL;
1821 color2.alpha = 255;
1822 color2.red = xcolor.red >> 8;
1823 color2.green = xcolor.green >> 8;
1824 color2.blue = xcolor.blue >> 8;
1826 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1828 } else if (strcasecmp(val, "igradient")==0) {
1829 RColor colors1[2], colors2[2];
1830 int th1, th2;
1831 XColor xcolor;
1832 int i;
1834 if (nelem != 7) {
1835 wwarning(_("bad number of arguments in gradient specification"));
1836 return NULL;
1839 /* get from color */
1840 for (i = 0; i < 2; i++) {
1841 elem = PLGetArrayElement(pl, 1+i);
1842 if (!elem || !PLIsString(elem))
1843 return NULL;
1844 val = PLGetString(elem);
1846 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1847 wwarning(_("\"%s\" is not a valid color name"), val);
1848 return NULL;
1850 colors1[i].alpha = 255;
1851 colors1[i].red = xcolor.red >> 8;
1852 colors1[i].green = xcolor.green >> 8;
1853 colors1[i].blue = xcolor.blue >> 8;
1855 elem = PLGetArrayElement(pl, 3);
1856 if (!elem || !PLIsString(elem))
1857 return NULL;
1858 val = PLGetString(elem);
1859 th1 = atoi(val);
1862 /* get from color */
1863 for (i = 0; i < 2; i++) {
1864 elem = PLGetArrayElement(pl, 4+i);
1865 if (!elem || !PLIsString(elem))
1866 return NULL;
1867 val = PLGetString(elem);
1869 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1870 wwarning(_("\"%s\" is not a valid color name"), val);
1871 return NULL;
1873 colors2[i].alpha = 255;
1874 colors2[i].red = xcolor.red >> 8;
1875 colors2[i].green = xcolor.green >> 8;
1876 colors2[i].blue = xcolor.blue >> 8;
1878 elem = PLGetArrayElement(pl, 6);
1879 if (!elem || !PLIsString(elem))
1880 return NULL;
1881 val = PLGetString(elem);
1882 th2 = atoi(val);
1884 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1885 th2, colors2);
1887 } else if (strcasecmp(val, "mhgradient")==0
1888 || strcasecmp(val, "mvgradient")==0
1889 || strcasecmp(val, "mdgradient")==0) {
1890 XColor color;
1891 RColor **colors;
1892 int i, count;
1893 int type;
1895 if (nelem < 3) {
1896 wwarning(_("too few arguments in multicolor gradient specification"));
1897 return NULL;
1900 if (val[1]=='h' || val[1]=='H')
1901 type = WTEX_MHGRADIENT;
1902 else if (val[1]=='v' || val[1]=='V')
1903 type = WTEX_MVGRADIENT;
1904 else
1905 type = WTEX_MDGRADIENT;
1907 count = nelem-1;
1909 colors = wmalloc(sizeof(RColor*)*(count+1));
1911 for (i=0; i<count; i++) {
1912 elem = PLGetArrayElement(pl, i+1);
1913 if (!elem || !PLIsString(elem)) {
1914 for (--i; i>=0; --i) {
1915 wfree(colors[i]);
1917 wfree(colors);
1918 return NULL;
1920 val = PLGetString(elem);
1922 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1923 wwarning(_("\"%s\" is not a valid color name"), val);
1924 for (--i; i>=0; --i) {
1925 wfree(colors[i]);
1927 wfree(colors);
1928 return NULL;
1929 } else {
1930 colors[i] = wmalloc(sizeof(RColor));
1931 colors[i]->red = color.red >> 8;
1932 colors[i]->green = color.green >> 8;
1933 colors[i]->blue = color.blue >> 8;
1936 colors[i] = NULL;
1938 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1939 } else if (strcasecmp(val, "spixmap")==0 ||
1940 strcasecmp(val, "cpixmap")==0 ||
1941 strcasecmp(val, "tpixmap")==0) {
1942 XColor color;
1943 int type;
1945 if (nelem != 3)
1946 return NULL;
1948 if (val[0] == 's' || val[0] == 'S')
1949 type = WTP_SCALE;
1950 else if (val[0] == 'c' || val[0] == 'C')
1951 type = WTP_CENTER;
1952 else
1953 type = WTP_TILE;
1955 /* get color */
1956 elem = PLGetArrayElement(pl, 2);
1957 if (!elem || !PLIsString(elem)) {
1958 return NULL;
1960 val = PLGetString(elem);
1962 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1963 wwarning(_("\"%s\" is not a valid color name"), val);
1964 return NULL;
1967 /* file name */
1968 elem = PLGetArrayElement(pl, 1);
1969 if (!elem || !PLIsString(elem))
1970 return NULL;
1971 val = PLGetString(elem);
1973 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1974 } else if (strcasecmp(val, "thgradient")==0
1975 || strcasecmp(val, "tvgradient")==0
1976 || strcasecmp(val, "tdgradient")==0) {
1977 RColor color1, color2;
1978 XColor xcolor;
1979 int opacity;
1980 int style;
1982 if (val[1]=='h' || val[1]=='H')
1983 style = WTEX_THGRADIENT;
1984 else if (val[1]=='v' || val[1]=='V')
1985 style = WTEX_TVGRADIENT;
1986 else
1987 style = WTEX_TDGRADIENT;
1989 if (nelem != 5) {
1990 wwarning(_("bad number of arguments in textured gradient specification"));
1991 return NULL;
1994 /* get from color */
1995 elem = PLGetArrayElement(pl, 3);
1996 if (!elem || !PLIsString(elem))
1997 return NULL;
1998 val = PLGetString(elem);
2000 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2001 wwarning(_("\"%s\" is not a valid color name"), val);
2002 return NULL;
2004 color1.alpha = 255;
2005 color1.red = xcolor.red >> 8;
2006 color1.green = xcolor.green >> 8;
2007 color1.blue = xcolor.blue >> 8;
2009 /* get to color */
2010 elem = PLGetArrayElement(pl, 4);
2011 if (!elem || !PLIsString(elem)) {
2012 return NULL;
2014 val = PLGetString(elem);
2016 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2017 wwarning(_("\"%s\" is not a valid color name"), val);
2018 return NULL;
2020 color2.alpha = 255;
2021 color2.red = xcolor.red >> 8;
2022 color2.green = xcolor.green >> 8;
2023 color2.blue = xcolor.blue >> 8;
2025 /* get opacity */
2026 elem = PLGetArrayElement(pl, 2);
2027 if (!elem || !PLIsString(elem))
2028 opacity = 128;
2029 else
2030 val = PLGetString(elem);
2032 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2033 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2034 opacity = 128;
2037 /* get file name */
2038 elem = PLGetArrayElement(pl, 1);
2039 if (!elem || !PLIsString(elem))
2040 return NULL;
2041 val = PLGetString(elem);
2043 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2044 val, opacity);
2046 #ifdef TEXTURE_PLUGIN
2047 else if (strcasecmp(val, "function")==0) {
2048 WTexFunction *function;
2049 void (*initFunc) (Display *, Colormap);
2050 char *lib, *func, **argv;
2051 int i, argc;
2053 if (nelem < 3)
2054 return NULL;
2056 /* get the library name */
2057 elem = PLGetArrayElement(pl, 1);
2058 if (!elem || !PLIsString(elem)) {
2059 return NULL;
2061 lib = PLGetString(elem);
2063 /* get the function name */
2064 elem = PLGetArrayElement(pl, 2);
2065 if (!elem || !PLIsString(elem)) {
2066 return NULL;
2068 func = PLGetString(elem);
2070 argc = nelem - 2;
2071 argv = (char **)wmalloc(argc * sizeof(char *));
2073 /* get the parameters */
2074 argv[0] = wstrdup(func);
2075 for (i = 0; i < argc - 1; i++) {
2076 elem = PLGetArrayElement(pl, 3 + i);
2077 if (!elem || !PLIsString(elem)) {
2078 wfree(argv);
2080 return NULL;
2082 argv[i+1] = wstrdup(PLGetString(elem));
2085 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2087 #ifdef HAVE_DLFCN_H
2088 if (function) {
2089 initFunc = dlsym(function->handle, "initWindowMaker");
2090 if (initFunc) {
2091 initFunc(dpy, scr->w_colormap);
2092 } else {
2093 wwarning(_("could not initialize library %s"), lib);
2095 } else {
2096 wwarning(_("could not find function %s::%s"), lib, func);
2098 #endif /* HAVE_DLFCN_H */
2099 texture = (WTexture*)function;
2101 #endif /* TEXTURE_PLUGIN */
2102 else {
2103 wwarning(_("invalid texture type %s"), val);
2104 return NULL;
2106 return texture;
2111 static int
2112 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2113 void **ret)
2115 static WTexture *texture;
2116 int changed=0;
2118 again:
2119 if (!PLIsArray(value)) {
2120 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2121 entry->key, "Texture");
2122 if (changed==0) {
2123 value = entry->plvalue;
2124 changed = 1;
2125 wwarning(_("using default \"%s\" instead"), entry->default_value);
2126 goto again;
2128 return False;
2131 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2132 proplist_t pl;
2134 pl = PLGetArrayElement(value, 0);
2135 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2136 || strcasecmp(PLGetString(pl), "solid")!=0) {
2137 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2138 entry->key, "Solid Texture");
2140 value = entry->plvalue;
2141 changed = 1;
2142 wwarning(_("using default \"%s\" instead"), entry->default_value);
2143 goto again;
2147 texture = parse_texture(scr, value);
2149 if (!texture) {
2150 wwarning(_("Error in texture specification for key \"%s\""),
2151 entry->key);
2152 if (changed==0) {
2153 value = entry->plvalue;
2154 changed = 1;
2155 wwarning(_("using default \"%s\" instead"), entry->default_value);
2156 goto again;
2158 return False;
2161 if (ret)
2162 *ret = &texture;
2164 if (addr)
2165 *(WTexture**)addr = texture;
2167 return True;
2172 #ifdef DRAWSTRING_PLUGIN
2173 static int
2174 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2175 void *addr, void **ret)
2177 proplist_t elem;
2178 char *val, *lib, *func, **argv;
2179 int argc, changed;
2181 /* Destroying functions if they are already loaded. */
2182 /* The function will auto-check NULL, does this break any ethic? */
2183 if (strcmp(entry->key, "FTitleColor")==0) {
2184 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2185 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2186 } else if (strcmp(entry->key, "UTitleColor")==0) {
2187 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2188 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2189 } else if (strcmp(entry->key, "PTitleColor")==0) {
2190 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2191 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2192 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2193 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2194 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2195 } else if (strcmp(entry->key, "MenuTextColor")==0) { /* problemssss */
2196 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2197 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2200 if (PLIsArray(value)) {
2201 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2202 argc -= 2;
2203 argv = (char **)wmalloc(argc * sizeof(char *));
2205 elem = PLGetArrayElement(value,0);
2206 if (!elem || !PLIsString(elem)) return False;
2207 val = PLGetString(elem);
2208 if (strcasecmp(val, "function")==0) {
2209 elem = PLGetArrayElement(value, 1); /* library name */
2210 if (!elem || !PLIsString(elem)) return False;
2211 lib = PLGetString(elem);
2212 elem = PLGetArrayElement(value, 2); /* function name */
2213 if (!elem || !PLIsString(elem)) return False;
2214 func = PLGetString(elem);
2215 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2216 lib, "initDrawString", func, "destroyDrawString", value,
2217 wPluginPackData(3, dpy, scr->w_colormap,"-DATA-"));
2220 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2221 } else if (PLIsString(value)) {
2222 return getColor(scr, entry, value, addr, ret);
2225 return False;
2227 #endif /* DRAWSTRING_PLUGIN */
2231 static int
2232 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2233 void *addr, void **ret)
2235 proplist_t elem;
2236 int changed = 0;
2237 char *val;
2238 int nelem;
2240 again:
2241 if (!PLIsArray(value)) {
2242 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2243 "WorkspaceBack", "Texture or None");
2244 if (changed==0) {
2245 value = entry->plvalue;
2246 changed = 1;
2247 wwarning(_("using default \"%s\" instead"), entry->default_value);
2248 goto again;
2250 return False;
2253 /* only do basic error checking and verify for None texture */
2255 nelem = PLGetNumberOfElements(value);
2256 if (nelem > 0) {
2257 elem = PLGetArrayElement(value, 0);
2258 if (!elem || !PLIsString(elem)) {
2259 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2260 if (changed==0) {
2261 value = entry->plvalue;
2262 changed = 1;
2263 wwarning(_("using default \"%s\" instead"), entry->default_value);
2264 goto again;
2266 return False;
2268 val = PLGetString(elem);
2270 if (strcasecmp(val, "None")==0)
2271 return True;
2273 *ret = PLRetain(value);
2275 return True;
2279 static int
2280 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2281 void *addr, void **ret)
2283 proplist_t elem;
2284 int nelem;
2285 int changed = 0;
2287 again:
2288 if (!PLIsArray(value)) {
2289 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2290 "WorkspaceSpecificBack", "an array of textures");
2291 if (changed==0) {
2292 value = entry->plvalue;
2293 changed = 1;
2294 wwarning(_("using default \"%s\" instead"), entry->default_value);
2295 goto again;
2297 return False;
2300 /* only do basic error checking and verify for None texture */
2302 nelem = PLGetNumberOfElements(value);
2303 if (nelem > 0) {
2304 while (nelem--) {
2305 elem = PLGetArrayElement(value, nelem);
2306 if (!elem || !PLIsArray(elem)) {
2307 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2308 nelem);
2313 *ret = PLRetain(value);
2315 #ifdef notworking
2317 * Kluge to force wmsetbg helper to set the default background.
2318 * If the WorkspaceSpecificBack is changed once wmaker has started,
2319 * the WorkspaceBack won't be sent to the helper, unless the user
2320 * changes it's value too. So, we must force this by removing the
2321 * value from the defaults DB.
2323 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2324 proplist_t key = PLMakeString("WorkspaceBack");
2326 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2328 PLRelease(key);
2330 #endif
2331 return True;
2335 static int
2336 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2337 void **ret)
2339 static WMFont *font;
2340 char *val;
2342 GET_STRING_OR_DEFAULT("Font", val);
2344 font = WMCreateFont(scr->wmscreen, val);
2345 if (!font)
2346 font = WMCreateFont(scr->wmscreen, "fixed");
2348 if (!font) {
2349 wfatal(_("could not load any usable font!!!"));
2350 exit(1);
2353 if (ret)
2354 *ret = font;
2356 /* can't assign font value outside update function */
2357 wassertrv(addr == NULL, True);
2359 return True;
2363 static int
2364 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2365 void **ret)
2367 static XColor color;
2368 char *val;
2369 int second_pass=0;
2371 GET_STRING_OR_DEFAULT("Color", val);
2374 again:
2375 if (!wGetColor(scr, val, &color)) {
2376 wwarning(_("could not get color for key \"%s\""),
2377 entry->key);
2378 if (second_pass==0) {
2379 val = PLGetString(entry->plvalue);
2380 second_pass = 1;
2381 wwarning(_("using default \"%s\" instead"), val);
2382 goto again;
2384 return False;
2387 if (ret)
2388 *ret = &color;
2390 assert(addr==NULL);
2392 if (addr)
2393 *(unsigned long*)addr = pixel;
2396 return True;
2401 static int
2402 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2403 void **ret)
2405 static WShortKey shortcut;
2406 KeySym ksym;
2407 char *val;
2408 char *k;
2409 char buf[128], *b;
2412 GET_STRING_OR_DEFAULT("Key spec", val);
2414 if (!val || strcasecmp(val, "NONE")==0) {
2415 shortcut.keycode = 0;
2416 shortcut.modifier = 0;
2417 if (ret)
2418 *ret = &shortcut;
2419 return True;
2422 strcpy(buf, val);
2424 b = (char*)buf;
2426 /* get modifiers */
2427 shortcut.modifier = 0;
2428 while ((k = strchr(b, '+'))!=NULL) {
2429 int mod;
2431 *k = 0;
2432 mod = wXModifierFromKey(b);
2433 if (mod<0) {
2434 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2435 return False;
2437 shortcut.modifier |= mod;
2439 b = k+1;
2442 /* get key */
2443 ksym = XStringToKeysym(b);
2445 if (ksym==NoSymbol) {
2446 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2447 val);
2448 return False;
2451 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2452 if (shortcut.keycode==0) {
2453 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2454 return False;
2457 if (ret)
2458 *ret = &shortcut;
2460 return True;
2464 static int
2465 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2466 void **ret)
2468 static unsigned int mask;
2469 char *str;
2471 GET_STRING_OR_DEFAULT("Modifier Key", str);
2473 if (!str)
2474 return False;
2476 mask = wXModifierFromKey(str);
2477 if (mask < 0) {
2478 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2479 mask = 0;
2480 return False;
2483 if (addr)
2484 *(unsigned int*)addr = mask;
2486 if (ret)
2487 *ret = &mask;
2489 return True;
2493 #ifdef NEWSTUFF
2494 static int
2495 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2496 void *addr, void **ret)
2498 unsigned int mask;
2499 char *str;
2500 RImage *image;
2501 int i, n;
2502 int w, h;
2504 GET_STRING_OR_DEFAULT("Image File Path", str);
2505 if (!str)
2506 return False;
2508 image = RLoadImage(scr->rcontext, str, 0);
2509 if (!image) {
2510 wwarning(_("could not load image in option %s: %s"), entry->key,
2511 RMessageForError(RErrorCode));
2512 return False;
2515 if (*(RImage**)addr) {
2516 RDestroyImage(*(RImage**)addr);
2518 if (addr)
2519 *(RImage**)addr = image;
2521 assert(ret == NULL);
2523 if (ret)
2524 *(RImage**)ret = image;
2527 return True;
2529 #endif
2531 #ifdef DEFINABLE_CURSOR
2533 # include <X11/cursorfont.h>
2534 typedef struct
2536 char *name;
2537 int id;
2538 } WCursorLookup;
2540 #define CURSOR_ID_NONE (XC_num_glyphs)
2542 static WCursorLookup cursor_table[] =
2544 { "X_cursor", XC_X_cursor },
2545 { "arrow", XC_arrow },
2546 { "based_arrow_down", XC_based_arrow_down },
2547 { "based_arrow_up", XC_based_arrow_up },
2548 { "boat", XC_boat },
2549 { "bogosity", XC_bogosity },
2550 { "bottom_left_corner", XC_bottom_left_corner },
2551 { "bottom_right_corner", XC_bottom_right_corner },
2552 { "bottom_side", XC_bottom_side },
2553 { "bottom_tee", XC_bottom_tee },
2554 { "box_spiral", XC_box_spiral },
2555 { "center_ptr", XC_center_ptr },
2556 { "circle", XC_circle },
2557 { "clock", XC_clock },
2558 { "coffee_mug", XC_coffee_mug },
2559 { "cross", XC_cross },
2560 { "cross_reverse", XC_cross_reverse },
2561 { "crosshair", XC_crosshair },
2562 { "diamond_cross", XC_diamond_cross },
2563 { "dot", XC_dot },
2564 { "dotbox", XC_dotbox },
2565 { "double_arrow", XC_double_arrow },
2566 { "draft_large", XC_draft_large },
2567 { "draft_small", XC_draft_small },
2568 { "draped_box", XC_draped_box },
2569 { "exchange", XC_exchange },
2570 { "fleur", XC_fleur },
2571 { "gobbler", XC_gobbler },
2572 { "gumby", XC_gumby },
2573 { "hand1", XC_hand1 },
2574 { "hand2", XC_hand2 },
2575 { "heart", XC_heart },
2576 { "icon", XC_icon },
2577 { "iron_cross", XC_iron_cross },
2578 { "left_ptr", XC_left_ptr },
2579 { "left_side", XC_left_side },
2580 { "left_tee", XC_left_tee },
2581 { "leftbutton", XC_leftbutton },
2582 { "ll_angle", XC_ll_angle },
2583 { "lr_angle", XC_lr_angle },
2584 { "man", XC_man },
2585 { "middlebutton", XC_middlebutton },
2586 { "mouse", XC_mouse },
2587 { "pencil", XC_pencil },
2588 { "pirate", XC_pirate },
2589 { "plus", XC_plus },
2590 { "question_arrow", XC_question_arrow },
2591 { "right_ptr", XC_right_ptr },
2592 { "right_side", XC_right_side },
2593 { "right_tee", XC_right_tee },
2594 { "rightbutton", XC_rightbutton },
2595 { "rtl_logo", XC_rtl_logo },
2596 { "sailboat", XC_sailboat },
2597 { "sb_down_arrow", XC_sb_down_arrow },
2598 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2599 { "sb_left_arrow", XC_sb_left_arrow },
2600 { "sb_right_arrow", XC_sb_right_arrow },
2601 { "sb_up_arrow", XC_sb_up_arrow },
2602 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2603 { "shuttle", XC_shuttle },
2604 { "sizing", XC_sizing },
2605 { "spider", XC_spider },
2606 { "spraycan", XC_spraycan },
2607 { "star", XC_star },
2608 { "target", XC_target },
2609 { "tcross", XC_tcross },
2610 { "top_left_arrow", XC_top_left_arrow },
2611 { "top_left_corner", XC_top_left_corner },
2612 { "top_right_corner", XC_top_right_corner },
2613 { "top_side", XC_top_side },
2614 { "top_tee", XC_top_tee },
2615 { "trek", XC_trek },
2616 { "ul_angle", XC_ul_angle },
2617 { "umbrella", XC_umbrella },
2618 { "ur_angle", XC_ur_angle },
2619 { "watch", XC_watch },
2620 { "xterm", XC_xterm },
2621 { NULL, CURSOR_ID_NONE }
2624 static void
2625 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2627 switch(status) {
2628 case BitmapOpenFailed:
2629 wwarning(_("failed to open bitmap file \"%s\""), filename);
2630 break;
2631 case BitmapFileInvalid:
2632 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2633 break;
2634 case BitmapNoMemory:
2635 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2636 break;
2637 case BitmapSuccess:
2638 XFreePixmap(dpy, bitmap);
2639 break;
2644 * (none)
2645 * (builtin, <cursor_name>)
2646 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2648 static int
2649 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2651 proplist_t elem;
2652 char *val;
2653 int nelem;
2654 int status = 0;
2656 nelem = PLGetNumberOfElements(pl);
2657 if (nelem < 1) {
2658 return(status);
2660 elem = PLGetArrayElement(pl, 0);
2661 if (!elem || !PLIsString(elem)) {
2662 return(status);
2664 val = PLGetString(elem);
2666 if (0 == strcasecmp(val, "none")) {
2667 status = 1;
2668 *cursor = None;
2669 } else if (0 == strcasecmp(val, "builtin")) {
2670 int i;
2671 int cursor_id = CURSOR_ID_NONE;
2673 if (2 != nelem) {
2674 wwarning(_("bad number of arguments in cursor specification"));
2675 return(status);
2677 elem = PLGetArrayElement(pl, 1);
2678 if (!elem || !PLIsString(elem)) {
2679 return(status);
2681 val = PLGetString(elem);
2683 for (i = 0; NULL != cursor_table[i].name; i++) {
2684 if (0 == strcasecmp(val, cursor_table[i].name)) {
2685 cursor_id = cursor_table[i].id;
2686 break;
2689 if (CURSOR_ID_NONE == cursor_id) {
2690 wwarning(_("unknown builtin cursor name \"%s\""), val);
2691 } else {
2692 *cursor = XCreateFontCursor(dpy, cursor_id);
2693 status = 1;
2695 } else if (0 == strcasecmp(val, "bitmap")) {
2696 char *bitmap_name;
2697 char *mask_name;
2698 int bitmap_status;
2699 int mask_status;
2700 Pixmap bitmap;
2701 Pixmap mask;
2702 unsigned int w, h;
2703 int x, y;
2704 XColor fg, bg;
2706 if (3 != nelem) {
2707 wwarning(_("bad number of arguments in cursor specification"));
2708 return(status);
2710 elem = PLGetArrayElement(pl, 1);
2711 if (!elem || !PLIsString(elem)) {
2712 return(status);
2714 val = PLGetString(elem);
2715 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2716 if (!bitmap_name) {
2717 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2718 return(status);
2720 elem = PLGetArrayElement(pl, 2);
2721 if (!elem || !PLIsString(elem)) {
2722 wfree(bitmap_name);
2723 return(status);
2725 val = PLGetString(elem);
2726 mask_name = FindImage(wPreferences.pixmap_path, val);
2727 if (!mask_name) {
2728 wfree(bitmap_name);
2729 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2730 return(status);
2732 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2733 &mask, &x, &y);
2734 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2735 &bitmap, &x, &y);
2736 if ((BitmapSuccess == bitmap_status) &&
2737 (BitmapSuccess == mask_status)) {
2738 fg.pixel = scr->black_pixel;
2739 bg.pixel = scr->white_pixel;
2740 XQueryColor(dpy, scr->w_colormap, &fg);
2741 XQueryColor(dpy, scr->w_colormap, &bg);
2742 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2743 status = 1;
2745 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2746 check_bitmap_status(mask_status, mask_name, mask);
2747 wfree(bitmap_name);
2748 wfree(mask_name);
2750 return(status);
2754 static int
2755 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2756 void **ret)
2758 static Cursor cursor;
2759 int status;
2760 int changed = 0;
2762 again:
2763 if (!PLIsArray(value)) {
2764 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2765 entry->key, "cursor specification");
2766 if (!changed) {
2767 value = entry->plvalue;
2768 changed = 1;
2769 wwarning(_("using default \"%s\" instead"), entry->default_value);
2770 goto again;
2772 return(False);
2774 status = parse_cursor(scr, value, &cursor);
2775 if (!status) {
2776 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2777 if (!changed) {
2778 value = entry->plvalue;
2779 changed = 1;
2780 wwarning(_("using default \"%s\" instead"), entry->default_value);
2781 goto again;
2783 return(False);
2785 if (ret) {
2786 *ret = &cursor;
2788 if (addr) {
2789 *(Cursor *)addr = cursor;
2791 return(True);
2793 #undef CURSOR_ID_NONE
2795 #endif /* DEFINABLE_CURSOR */
2798 /* ---------------- value setting functions --------------- */
2799 static int
2800 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2802 return REFRESH_WINDOW_TITLE_COLOR;
2805 static int
2806 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2808 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2811 static int
2812 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2814 switch (which) {
2815 case WM_DOCK:
2816 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2817 break;
2818 case WM_CLIP:
2819 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2820 break;
2821 default:
2822 break;
2824 return 0;
2828 static int
2829 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2831 if (scr->workspaces) {
2832 wWorkspaceForceChange(scr, scr->current_workspace);
2833 wArrangeIcons(scr, False);
2835 return 0;
2838 #if not_used
2839 static int
2840 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2842 if (*value <= 0)
2843 *(int*)foo = 1;
2845 return 0;
2847 #endif
2851 static int
2852 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2854 Pixmap pixmap;
2855 RImage *img;
2856 int reset = 0;
2858 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2859 wPreferences.icon_size,
2860 ((*texture)->any.type & WREL_BORDER_MASK)
2861 ? WREL_ICON : WREL_FLAT);
2862 if (!img) {
2863 wwarning(_("could not render texture for icon background"));
2864 if (!entry->addr)
2865 wTextureDestroy(scr, *texture);
2866 return 0;
2868 RConvertImage(scr->rcontext, img, &pixmap);
2870 if (scr->icon_tile) {
2871 reset = 1;
2872 RDestroyImage(scr->icon_tile);
2873 XFreePixmap(dpy, scr->icon_tile_pixmap);
2876 scr->icon_tile = img;
2879 /* put the icon in the noticeboard hint */
2880 PropSetIconTileHint(scr, img);
2883 if (!wPreferences.flags.noclip) {
2884 if (scr->clip_tile) {
2885 RDestroyImage(scr->clip_tile);
2887 scr->clip_tile = wClipMakeTile(scr, img);
2890 scr->icon_tile_pixmap = pixmap;
2892 if (scr->def_icon_pixmap) {
2893 XFreePixmap(dpy, scr->def_icon_pixmap);
2894 scr->def_icon_pixmap = None;
2896 if (scr->def_ticon_pixmap) {
2897 XFreePixmap(dpy, scr->def_ticon_pixmap);
2898 scr->def_ticon_pixmap = None;
2901 if (scr->icon_back_texture) {
2902 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2904 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2906 if (scr->clip_balloon)
2907 XSetWindowBackground(dpy, scr->clip_balloon,
2908 (*texture)->any.color.pixel);
2911 * Free the texture as nobody else will use it, nor refer to it.
2913 if (!entry->addr)
2914 wTextureDestroy(scr, *texture);
2916 return (reset ? REFRESH_ICON_TILE : 0);
2921 static int
2922 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2924 if (scr->title_font) {
2925 WMReleaseFont(scr->title_font);
2927 scr->title_font = font;
2929 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2933 static int
2934 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2936 if (scr->menu_title_font) {
2937 WMReleaseFont(scr->menu_title_font);
2940 scr->menu_title_font = font;
2942 return REFRESH_MENU_TITLE_FONT;
2946 static int
2947 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2949 if (scr->menu_entry_font) {
2950 WMReleaseFont(scr->menu_entry_font);
2952 scr->menu_entry_font = font;
2954 return REFRESH_MENU_FONT;
2959 static int
2960 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2962 if (scr->icon_title_font) {
2963 WMReleaseFont(scr->icon_title_font);
2966 scr->icon_title_font = font;
2968 return REFRESH_ICON_FONT;
2972 static int
2973 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2975 if (scr->clip_title_font) {
2976 WMReleaseFont(scr->clip_title_font);
2979 scr->clip_title_font = font;
2981 return REFRESH_ICON_FONT;
2985 static int
2986 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2988 if (scr->workspace_name_font) {
2989 WMReleaseFont(scr->workspace_name_font);
2992 scr->workspace_name_font = font;
2994 return 0;
2998 static int
2999 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3001 if (scr->select_pixel!=scr->white_pixel &&
3002 scr->select_pixel!=scr->black_pixel) {
3003 wFreeColor(scr, scr->select_pixel);
3006 scr->select_pixel = color->pixel;
3008 return REFRESH_MENU_COLOR;
3012 static int
3013 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3015 if (scr->select_text_pixel!=scr->white_pixel &&
3016 scr->select_text_pixel!=scr->black_pixel) {
3017 wFreeColor(scr, scr->select_text_pixel);
3020 scr->select_text_pixel = color->pixel;
3022 return REFRESH_MENU_COLOR;
3026 static int
3027 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3029 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
3030 scr->clip_title_pixel[index]!=scr->black_pixel) {
3031 wFreeColor(scr, scr->clip_title_pixel[index]);
3033 scr->clip_title_pixel[index] = color->pixel;
3035 #ifdef GRADIENT_CLIP_ARROW
3036 if (index == CLIP_NORMAL) {
3037 RImage *image;
3038 RColor color1, color2;
3039 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3040 int as = pt - 15; /* 15 = 5+5+5 */
3042 FREE_PIXMAP(scr->clip_arrow_gradient);
3044 color1.red = (color->red >> 8)*6/10;
3045 color1.green = (color->green >> 8)*6/10;
3046 color1.blue = (color->blue >> 8)*6/10;
3048 color2.red = WMIN((color->red >> 8)*20/10, 255);
3049 color2.green = WMIN((color->green >> 8)*20/10, 255);
3050 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3052 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3053 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3054 RDestroyImage(image);
3056 #endif /* GRADIENT_CLIP_ARROW */
3058 return REFRESH_ICON_TITLE_COLOR;
3062 static int
3063 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3065 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3066 scr->window_title_pixel[index]!=scr->black_pixel) {
3067 wFreeColor(scr, scr->window_title_pixel[index]);
3070 scr->window_title_pixel[index] = color->pixel;
3072 if (index == WS_UNFOCUSED)
3073 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3075 return REFRESH_WINDOW_TITLE_COLOR;
3079 static int
3080 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3082 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3083 scr->menu_title_pixel[0]!=scr->black_pixel) {
3084 #ifdef DRAWSTRING_PLUGIN
3085 if(!scr->drawstring_func[W_STRING_MTITLE])
3086 #endif
3087 wFreeColor(scr, scr->menu_title_pixel[0]);
3090 scr->menu_title_pixel[0] = color->pixel;
3091 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3093 return REFRESH_MENU_TITLE_COLOR;
3097 static int
3098 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3100 XGCValues gcv;
3101 #define gcm (GCForeground|GCBackground|GCFillStyle)
3103 if (scr->mtext_pixel!=scr->white_pixel &&
3104 scr->mtext_pixel!=scr->black_pixel) {
3105 wFreeColor(scr, scr->mtext_pixel);
3108 scr->mtext_pixel = color->pixel;
3110 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3113 if (scr->dtext_pixel == scr->mtext_pixel) {
3114 gcv.foreground = scr->white_pixel;
3115 gcv.background = scr->black_pixel;
3116 gcv.fill_style = FillStippled;
3117 } else {
3118 gcv.foreground = scr->dtext_pixel;
3119 gcv.fill_style = FillSolid;
3121 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3123 return REFRESH_MENU_COLOR;
3124 #undef gcm
3128 static int
3129 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3131 XGCValues gcv;
3132 #define gcm (GCForeground|GCBackground|GCFillStyle)
3134 if (scr->dtext_pixel!=scr->white_pixel &&
3135 scr->dtext_pixel!=scr->black_pixel) {
3136 wFreeColor(scr, scr->dtext_pixel);
3139 scr->dtext_pixel = color->pixel;
3141 if (scr->dtext_pixel == scr->mtext_pixel) {
3142 gcv.foreground = scr->white_pixel;
3143 gcv.background = scr->black_pixel;
3144 gcv.fill_style = FillStippled;
3145 } else {
3146 gcv.foreground = scr->dtext_pixel;
3147 gcv.fill_style = FillSolid;
3149 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3151 return REFRESH_MENU_COLOR;
3152 #undef gcm
3155 static int
3156 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3158 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3160 return REFRESH_ICON_TITLE_COLOR;
3164 static int
3165 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3167 if (scr->icon_title_texture) {
3168 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3170 XQueryColor (dpy, scr->w_colormap, color);
3171 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3173 return REFRESH_ICON_TITLE_BACK;
3177 static void
3178 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3180 close(scr->helper_fd);
3181 scr->helper_fd = 0;
3182 scr->helper_pid = 0;
3183 scr->flags.backimage_helper_launched = 0;
3187 static int
3188 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3189 void *bar)
3191 int i;
3192 proplist_t val;
3193 char *str;
3195 if (scr->flags.backimage_helper_launched) {
3196 if (PLGetNumberOfElements(value)==0) {
3197 SendHelperMessage(scr, 'C', 0, NULL);
3198 SendHelperMessage(scr, 'K', 0, NULL);
3200 PLRelease(value);
3201 return 0;
3203 } else {
3204 pid_t pid;
3205 int filedes[2];
3207 if (PLGetNumberOfElements(value) == 0)
3208 return 0;
3210 if (pipe(filedes) < 0) {
3211 wsyserror("pipe() failed:can't set workspace specific background image");
3213 PLRelease(value);
3214 return 0;
3217 pid = fork();
3218 if (pid < 0) {
3219 wsyserror("fork() failed:can't set workspace specific background image");
3220 if (close(filedes[0]) < 0)
3221 wsyserror("could not close pipe");
3222 if (close(filedes[1]) < 0)
3223 wsyserror("could not close pipe");
3225 } else if (pid == 0) {
3226 SetupEnvironment(scr);
3228 if (close(0) < 0)
3229 wsyserror("could not close pipe");
3230 if (dup(filedes[0]) < 0) {
3231 wsyserror("dup() failed:can't set workspace specific background image");
3233 if (wPreferences.smooth_workspace_back)
3234 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3235 else
3236 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3237 wsyserror("could not execute wmsetbg");
3238 exit(1);
3239 } else {
3241 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3242 wsyserror("error setting close-on-exec flag");
3244 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3245 wsyserror("error setting close-on-exec flag");
3248 scr->helper_fd = filedes[1];
3249 scr->helper_pid = pid;
3250 scr->flags.backimage_helper_launched = 1;
3252 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3254 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3259 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3260 val = PLGetArrayElement(value, i);
3261 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3262 str = PLGetDescription(val);
3264 SendHelperMessage(scr, 'S', i+1, str);
3266 wfree(str);
3267 } else {
3268 SendHelperMessage(scr, 'U', i+1, NULL);
3271 sleep(1);
3273 PLRelease(value);
3274 return 0;
3278 static int
3279 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3280 void *bar)
3282 if (scr->flags.backimage_helper_launched) {
3283 char *str;
3285 if (PLGetNumberOfElements(value)==0) {
3286 SendHelperMessage(scr, 'U', 0, NULL);
3287 } else {
3288 /* set the default workspace background to this one */
3289 str = PLGetDescription(value);
3290 if (str) {
3291 SendHelperMessage(scr, 'S', 0, str);
3292 wfree(str);
3293 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3294 } else {
3295 SendHelperMessage(scr, 'U', 0, NULL);
3298 } else if (PLGetNumberOfElements(value) > 0) {
3299 char *command;
3300 char *text;
3302 SetupEnvironment(scr);
3303 text = PLGetDescription(value);
3304 command = wmalloc(strlen(text)+40);
3305 if (wPreferences.smooth_workspace_back)
3306 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3307 else
3308 sprintf(command, "wmsetbg -d -p '%s' &", text);
3309 wfree(text);
3310 system(command);
3311 wfree(command);
3313 PLRelease(value);
3315 return 0;
3319 static int
3320 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3322 if (scr->widget_texture) {
3323 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3325 scr->widget_texture = *(WTexSolid**)texture;
3327 return 0;
3331 static int
3332 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3334 if (scr->window_title_texture[WS_FOCUSED]) {
3335 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3337 scr->window_title_texture[WS_FOCUSED] = *texture;
3339 return REFRESH_WINDOW_TEXTURES;
3343 static int
3344 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3346 if (scr->window_title_texture[WS_PFOCUSED]) {
3347 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3349 scr->window_title_texture[WS_PFOCUSED] = *texture;
3351 return REFRESH_WINDOW_TEXTURES;
3355 static int
3356 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3358 if (scr->window_title_texture[WS_UNFOCUSED]) {
3359 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3361 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3363 return REFRESH_WINDOW_TEXTURES;
3367 static int
3368 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3370 if (scr->resizebar_texture[0]) {
3371 wTextureDestroy(scr, scr->resizebar_texture[0]);
3373 scr->resizebar_texture[0] = *texture;
3375 return REFRESH_WINDOW_TEXTURES;
3379 static int
3380 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3382 if (scr->menu_title_texture[0]) {
3383 wTextureDestroy(scr, scr->menu_title_texture[0]);
3385 scr->menu_title_texture[0] = *texture;
3387 return REFRESH_MENU_TITLE_TEXTURE;
3391 static int
3392 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3394 if (scr->menu_item_texture) {
3395 wTextureDestroy(scr, scr->menu_item_texture);
3396 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3398 scr->menu_item_texture = *texture;
3400 scr->menu_item_auxtexture
3401 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3403 return REFRESH_MENU_TEXTURE;
3407 static int
3408 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3410 WWindow *wwin;
3411 wKeyBindings[index] = *shortcut;
3413 wwin = scr->focused_window;
3415 while (wwin!=NULL) {
3416 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3418 if (!WFLAGP(wwin, no_bind_keys)) {
3419 wWindowSetKeyGrabs(wwin);
3421 wwin = wwin->prev;
3424 return 0;
3428 static int
3429 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3431 wArrangeIcons(scr, True);
3433 return 0;
3437 static int
3438 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3440 wScreenUpdateUsableArea(scr);
3442 return 0;
3446 static int
3447 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3449 return REFRESH_MENU_TEXTURE;
3454 static int
3455 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3457 return REFRESH_BUTTON_IMAGES;
3462 * Very ugly kluge.
3463 * Need access to the double click variables, so that all widgets in
3464 * wmaker panels will have the same dbl-click values.
3465 * TODO: figure a better way of dealing with it.
3467 #include "WINGsP.h"
3469 static int
3470 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3472 extern _WINGsConfiguration WINGsConfiguration;
3474 if (*value <= 0)
3475 *(int*)foo = 1;
3477 WINGsConfiguration.doubleClickDelay = *value;
3479 return 0;
3483 #if 0
3484 static int
3485 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3487 extern _WINGsConfiguration WINGsConfiguration;
3489 WINGsConfiguration.useMultiByte = *value;
3491 return 0;
3493 #endif
3495 #ifdef DEFINABLE_CURSOR
3496 static int
3497 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3499 if (None != wCursor[index])
3501 XFreeCursor(dpy, wCursor[index]);
3504 wCursor[index] = *cursor;
3506 if ((WCUR_ROOT == index) && (None != *cursor))
3508 XDefineCursor(dpy, scr->root_win, *cursor);
3511 return 0;
3513 #endif /* DEFINABLE_CURSOR*/