- made deiconification not automatically focus window in sloppy focus
[wmaker-crm.git] / src / defaults.c
blob1bcd4be4e96986147e309c096b2a8ffbac2c5b7e
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"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
55 #include "WindowMaker.h"
56 #include "wcore.h"
57 #include "framewin.h"
58 #include "window.h"
59 #include "texture.h"
60 #include "screen.h"
61 #include "resources.h"
62 #include "defaults.h"
63 #include "keybind.h"
64 #include "xmodifier.h"
65 #include "icon.h"
66 #include "funcs.h"
67 #include "actions.h"
68 #include "dock.h"
69 #include "workspace.h"
73 * Our own proplist reader parser. This one will not accept any
74 * syntax errors and is more descriptive in the error messages.
75 * It also doesn't seem to crash.
77 extern proplist_t ReadProplistFromFile(char *file);
80 /***** Global *****/
82 extern WDDomain *WDWindowMaker;
83 extern WDDomain *WDWindowAttributes;
84 extern WDDomain *WDRootMenu;
86 extern int wScreenCount;
89 extern proplist_t wDomainName;
90 extern proplist_t wAttributeDomainName;
92 extern WPreferences wPreferences;
94 extern WShortKey wKeyBindings[WKBD_LAST];
96 typedef struct {
97 char *key;
98 char *default_value;
99 void *extra_data;
100 void *addr;
101 int (*convert)();
102 int (*update)();
103 proplist_t plkey;
104 proplist_t plvalue; /* default value */
105 } WDefaultEntry;
108 /* used to map strings to integers */
109 typedef struct {
110 char *string;
111 short value;
112 char is_alias;
113 } WOptionEnumeration;
116 /* type converters */
117 static int getBool();
118 static int getInt();
119 static int getCoord();
120 #if 0
121 /* this is not used yet */
122 static int getString();
123 #endif
124 static int getPathList();
125 static int getEnum();
126 static int getTexture();
127 static int getWSBackground();
128 static int getWSSpecificBackground();
129 static int getFont();
130 static int getColor();
131 static int getKeybind();
132 static int getModMask();
133 #ifdef NEWSTUFF
134 static int getRImage();
135 #endif
138 /* value setting functions */
139 static int setJustify();
140 static int setIfDockPresent();
141 static int setStickyIcons();
143 static int setPositive();
145 static int setWidgetColor();
146 static int setIconTile();
147 static int setWinTitleFont();
148 static int setMenuTitleFont();
149 static int setMenuTextFont();
150 static int setIconTitleFont();
151 static int setIconTitleColor();
152 static int setIconTitleBack();
153 static int setDisplayFont();
154 static int setLargeDisplayFont();
155 static int setWTitleColor();
156 static int setFTitleBack();
157 static int setPTitleBack();
158 static int setUTitleBack();
159 static int setResizebarBack();
160 static int setWorkspaceBack();
161 static int setWorkspaceSpecificBack();
162 static int setMenuTitleColor();
163 static int setMenuTextColor();
164 static int setMenuDisabledColor();
165 static int setMenuTitleBack();
166 static int setMenuTextBack();
167 static int setHightlight();
168 static int setHightlightText();
169 static int setKeyGrab();
170 static int setDoubleClick();
171 static int setIconPosition();
173 static int setClipTitleFont();
174 static int setClipTitleColor();
176 static int setMenuStyle();
179 static int updateUsableArea();
184 * Tables to convert strings to enumeration values.
185 * Values stored are char
189 /* WARNING: sum of length of all value strings must not exceed
190 * this value */
191 #define TOTAL_VALUES_LENGTH 80
196 #define REFRESH_WINDOW_TEXTURES (1<<0)
197 #define REFRESH_MENU_TEXTURE (1<<1)
198 #define REFRESH_MENU_FONT (1<<2)
199 #define REFRESH_MENU_COLOR (1<<3)
200 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
201 #define REFRESH_MENU_TITLE_FONT (1<<5)
202 #define REFRESH_MENU_TITLE_COLOR (1<<6)
203 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
204 #define REFRESH_WINDOW_FONT (1<<8)
205 #define REFRESH_ICON_TILE (1<<9)
206 #define REFRESH_ICON_FONT (1<<10)
207 #define REFRESH_WORKSPACE_BACK (1<<11)
209 #define REFRESH_BUTTON_IMAGES (1<<12)
211 #define REFRESH_ICON_TITLE_COLOR (1<<13)
212 #define REFRESH_ICON_TITLE_BACK (1<<14)
216 static WOptionEnumeration seFocusModes[] = {
217 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
218 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
219 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
220 {NULL, 0, 0}
223 static WOptionEnumeration seColormapModes[] = {
224 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
225 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
226 {NULL, 0, 0}
229 static WOptionEnumeration sePlacements[] = {
230 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
231 {"Cascade", WPM_CASCADE, 0},
232 {"Random", WPM_RANDOM, 0},
233 {"Manual", WPM_MANUAL, 0},
234 {NULL, 0, 0}
237 static WOptionEnumeration seGeomDisplays[] = {
238 {"Center", WDIS_CENTER, 0},
239 {"Corner", WDIS_TOPLEFT, 0},
240 {"Floating", WDIS_FRAME_CENTER, 0},
241 {"Line", WDIS_NEW, 0},
242 {NULL, 0, 0}
245 static WOptionEnumeration seSpeeds[] = {
246 {"UltraFast", SPEED_ULTRAFAST, 0},
247 {"Fast", SPEED_FAST, 0},
248 {"Medium", SPEED_MEDIUM, 0},
249 {"Slow", SPEED_SLOW, 0},
250 {"UltraSlow", SPEED_ULTRASLOW, 0},
251 {NULL, 0, 0}
254 static WOptionEnumeration seMouseButtons[] = {
255 {"Left", Button1, 0}, {"Button1", Button1, 1},
256 {"Middle", Button2, 0}, {"Button2", Button2, 1},
257 {"Right", Button3, 0}, {"Button3", Button3, 1},
258 {"Button4", Button4, 0},
259 {"Button5", Button5, 0},
260 {NULL, 0, 0}
263 static WOptionEnumeration seIconificationStyles[] = {
264 {"Zoom", WIS_ZOOM, 0},
265 {"Twist", WIS_TWIST, 0},
266 {"Flip", WIS_FLIP, 0},
267 {"None", WIS_NONE, 0},
268 {"random", WIS_RANDOM, 0},
269 {NULL, 0, 0}
272 static WOptionEnumeration seJustifications[] = {
273 {"Left", WTJ_LEFT, 0},
274 {"Center", WTJ_CENTER, 0},
275 {"Right", WTJ_RIGHT, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seIconPositions[] = {
280 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
281 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
282 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
283 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
284 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
285 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
286 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
287 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
288 {NULL, 0, 0}
291 static WOptionEnumeration seMenuStyles[] = {
292 {"normal", MS_NORMAL, 0},
293 {"singletexture", MS_SINGLE_TEXTURE, 0},
294 {"flat", MS_FLAT, 0},
295 {NULL, 0, 0}
300 * ALL entries in the tables bellow, NEED to have a default value
301 * defined, and this value needs to be correct.
304 /* these options will only affect the window manager on startup
306 * static defaults can't access the screen data, because it is
307 * created after these defaults are read
309 WDefaultEntry staticOptionList[] = {
311 {"DisableDithering", "NO", NULL,
312 &wPreferences.no_dithering, getBool, NULL
314 {"ColormapSize", "4", NULL,
315 &wPreferences.cmap_size, getInt, NULL
317 /* static by laziness */
318 {"IconSize", "64", NULL,
319 &wPreferences.icon_size, getInt, NULL
321 {"ModifierKey", "Mod1", NULL,
322 &wPreferences.modifier_mask, getModMask, NULL
324 {"DisableWSMouseActions", "NO", NULL,
325 &wPreferences.disable_root_mouse, getBool, NULL
327 {"FocusMode", "manual", seFocusModes,
328 &wPreferences.focus_mode, getEnum, NULL
329 }, /* have a problem when switching from manual to sloppy without restart */
330 {"NewStyle", "NO", NULL,
331 &wPreferences.new_style, getBool, NULL
333 {"DisableDock", "NO", (void*) WM_DOCK,
334 NULL, getBool, setIfDockPresent
336 {"DisableClip", "NO", (void*) WM_CLIP,
337 NULL, getBool, setIfDockPresent
339 {"DisableMiniwindows", "NO", NULL,
340 &wPreferences.disable_miniwindows, getBool, NULL
346 WDefaultEntry optionList[] = {
347 /* dynamic options */
348 {"IconPosition", "blh", seIconPositions,
349 &wPreferences.icon_yard, getEnum, setIconPosition
351 {"IconificationStyle", "Zoom", seIconificationStyles,
352 &wPreferences.iconification_style, getEnum, NULL
354 {"SelectWindowsMouseButton", "Left", seMouseButtons,
355 &wPreferences.select_button, getEnum, NULL
357 {"WindowListMouseButton", "Middle", seMouseButtons,
358 &wPreferences.windowl_button, getEnum, NULL
360 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
361 &wPreferences.menu_button, getEnum, NULL
363 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
364 &wPreferences.pixmap_path, getPathList, NULL
366 {"IconPath", DEF_ICON_PATHS, NULL,
367 &wPreferences.icon_path, getPathList, NULL
369 {"ColormapMode", "auto", seColormapModes,
370 &wPreferences.colormap_mode, getEnum, NULL
372 {"AutoFocus", "NO", NULL,
373 &wPreferences.auto_focus, getBool, NULL
375 {"RaiseDelay", "0", NULL,
376 &wPreferences.raise_delay, getInt, NULL
378 {"CirculateRaise", "NO", NULL,
379 &wPreferences.circ_raise, getBool, NULL
381 {"Superfluous", "NO", NULL,
382 &wPreferences.superfluous, getBool, NULL
384 {"AdvanceToNewWorkspace", "NO", NULL,
385 &wPreferences.ws_advance, getBool, NULL
387 {"CycleWorkspaces", "NO", NULL,
388 &wPreferences.ws_cycle, getBool, NULL
390 {"IAmAnnoyingAndDontWantWorkspaceNameDisplay", "NO",NULL,
391 &wPreferences.no_workspace_name_display, getBool, NULL
393 {"StickyIcons", "NO", NULL,
394 &wPreferences.sticky_icons, getBool, setStickyIcons
396 {"SaveSessionOnExit", "NO", NULL,
397 &wPreferences.save_session_on_exit, getBool, NULL
399 {"WrapMenus", "NO", NULL,
400 &wPreferences.wrap_menus, getBool, NULL
402 {"ScrollableMenus", "NO", NULL,
403 &wPreferences.scrollable_menus, getBool, NULL
405 {"MenuScrollSpeed", "medium", seSpeeds,
406 &wPreferences.menu_scroll_speed, getEnum, NULL
408 {"IconSlideSpeed", "medium", seSpeeds,
409 &wPreferences.icon_slide_speed, getEnum, NULL
411 {"ShadeSpeed", "medium", seSpeeds,
412 &wPreferences.shade_speed, getEnum, NULL
414 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
415 &wPreferences.dblclick_time, getInt, setDoubleClick,
417 {"AlignSubmenus", "NO", NULL,
418 &wPreferences.align_menus, getBool, NULL
420 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
421 &wPreferences.open_transients_with_parent, getBool, NULL
423 {"WindowPlacement", "auto", sePlacements,
424 &wPreferences.window_placement, getEnum, NULL
426 {"IgnoreFocusClick","NO", NULL,
427 &wPreferences.ignore_focus_click, getBool, NULL
429 {"UseSaveUnders", "NO", NULL,
430 &wPreferences.use_saveunders, getBool, NULL
432 {"OpaqueMove", "NO", NULL,
433 &wPreferences.opaque_move, getBool, NULL
435 {"DisableSound", "NO", NULL,
436 &wPreferences.no_sound, getBool, NULL
438 {"DisableAnimations", "NO", NULL,
439 &wPreferences.no_animations, getBool, NULL
441 {"DontLinkWorkspaces","NO", NULL,
442 &wPreferences.no_autowrap, getBool, NULL
444 {"AutoArrangeIcons", "NO", NULL,
445 &wPreferences.auto_arrange_icons, getBool, NULL
447 {"NoWindowOverDock", "NO", NULL,
448 &wPreferences.no_window_over_dock, getBool, updateUsableArea
450 {"NoWindowOverIcons", "NO", NULL,
451 &wPreferences.no_window_over_icons, getBool, updateUsableArea
453 {"WindowPlaceOrigin", "(0, 0)", NULL,
454 &wPreferences.window_place_origin, getCoord, NULL
456 {"ResizeDisplay", "corner", seGeomDisplays,
457 &wPreferences.size_display, getEnum, NULL
459 {"MoveDisplay", "corner", seGeomDisplays,
460 &wPreferences.move_display, getEnum, NULL
462 {"DontConfirmKill", "NO", NULL,
463 &wPreferences.dont_confirm_kill, getBool,NULL
465 {"WindowTitleBalloons", "NO", NULL,
466 &wPreferences.window_balloon, getBool, NULL
468 {"MiniwindowTitleBalloons", "NO", NULL,
469 &wPreferences.miniwin_balloon,getBool, NULL
471 {"AppIconBalloons", "NO", NULL,
472 &wPreferences.appicon_balloon,getBool, NULL
474 {"EdgeResistance", "30", NULL,
475 &wPreferences.edge_resistance,getInt, NULL
477 {"DisableBlinking", "NO", NULL,
478 &wPreferences.dont_blink, getBool, NULL
480 #ifdef WEENDOZE_CYCLE
481 {"WindozeCycling","NO", NULL,
482 &wPreferences.windoze_cycling, getBool, NULL
484 {"PopupSwitchMenu","YES", NULL,
485 &wPreferences.popup_switchmenu, getBool, NULL
487 #endif /* WEENDOZE_CYCLE */
488 /* style options */
489 {"MenuStyle", "normal", seMenuStyles,
490 &wPreferences.menu_style, getEnum, setMenuStyle
492 {"WidgetColor", "(solid, gray)", NULL,
493 NULL, getTexture, setWidgetColor,
495 {"WorkspaceSpecificBack","()", NULL,
496 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
498 /* WorkspaceBack must come after WorkspaceSpecificBack or
499 * WorkspaceBack wont know WorkspaceSpecificBack was also
500 * specified and 2 copies of wmsetbg will be launched */
501 {"WorkspaceBack", "(solid, black)", NULL,
502 NULL, getWSBackground,setWorkspaceBack
504 {"IconBack", "(solid, gray)", NULL,
505 NULL, getTexture, setIconTile
507 {"TitleJustify", "center", seJustifications,
508 &wPreferences.title_justification, getEnum, setJustify
510 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
511 NULL, getFont, setWinTitleFont,
513 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
514 NULL, getFont, setMenuTitleFont
516 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
517 NULL, getFont, setMenuTextFont
519 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
520 NULL, getFont, setIconTitleFont
522 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
523 NULL, getFont, setClipTitleFont
525 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
526 NULL, getFont, setDisplayFont
528 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
529 NULL, getFont, setLargeDisplayFont
531 {"HighlightColor", "white", NULL,
532 NULL, getColor, setHightlight
534 {"HighlightTextColor", "black", NULL,
535 NULL, getColor, setHightlightText
537 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
538 NULL, getColor, setClipTitleColor
540 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
541 NULL, getColor, setClipTitleColor
543 {"FTitleColor", "white", (void*)WS_FOCUSED,
544 NULL, getColor, setWTitleColor
546 {"PTitleColor", "white", (void*)WS_PFOCUSED,
547 NULL, getColor, setWTitleColor
549 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
550 NULL, getColor, setWTitleColor
552 {"FTitleBack", "(solid, black)", NULL,
553 NULL, getTexture, setFTitleBack
555 {"PTitleBack", "(solid, \"#616161\")", NULL,
556 NULL, getTexture, setPTitleBack
558 {"UTitleBack", "(solid, gray)", NULL,
559 NULL, getTexture, setUTitleBack
561 {"ResizebarBack", "(solid, gray)", NULL,
562 NULL, getTexture, setResizebarBack
564 {"MenuTitleColor", "white", NULL,
565 NULL, getColor, setMenuTitleColor
567 {"MenuTextColor", "black", NULL,
568 NULL, getColor, setMenuTextColor
570 {"MenuDisabledColor", "\"#616161\"", NULL,
571 NULL, getColor, setMenuDisabledColor
573 {"MenuTitleBack", "(solid, black)", NULL,
574 NULL, getTexture, setMenuTitleBack
576 {"MenuTextBack", "(solid, gray)", NULL,
577 NULL, getTexture, setMenuTextBack
579 {"IconTitleColor", "white", NULL,
580 NULL, getColor, setIconTitleColor
582 {"IconTitleBack", "black", NULL,
583 NULL, getColor, setIconTitleBack
585 /* keybindings */
586 #ifndef LITE
587 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
588 NULL, getKeybind, setKeyGrab
590 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
591 NULL, getKeybind, setKeyGrab
593 #endif /* LITE */
594 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
595 NULL, getKeybind, setKeyGrab
597 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
598 NULL, getKeybind, setKeyGrab
600 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
601 NULL, getKeybind, setKeyGrab
603 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
604 NULL, getKeybind, setKeyGrab
606 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
607 NULL, getKeybind, setKeyGrab
609 {"HideKey", "None", (void*)WKBD_HIDE,
610 NULL, getKeybind, setKeyGrab
612 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
613 NULL, getKeybind, setKeyGrab
615 {"CloseKey", "None", (void*)WKBD_CLOSE,
616 NULL, getKeybind, setKeyGrab
618 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
619 NULL, getKeybind, setKeyGrab
621 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
622 NULL, getKeybind, setKeyGrab
624 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
625 NULL, getKeybind, setKeyGrab
627 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
628 NULL, getKeybind, setKeyGrab
630 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
631 NULL, getKeybind, setKeyGrab
633 {"ShadeKey", "None", (void*)WKBD_SHADE,
634 NULL, getKeybind, setKeyGrab
636 {"SelectKey", "None", (void*)WKBD_SELECT,
637 NULL, getKeybind, setKeyGrab
639 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
640 NULL, getKeybind, setKeyGrab
642 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
643 NULL, getKeybind, setKeyGrab
645 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
646 NULL, getKeybind, setKeyGrab
648 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
649 NULL, getKeybind, setKeyGrab
651 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
652 NULL, getKeybind, setKeyGrab
654 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
655 NULL, getKeybind, setKeyGrab
657 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
658 NULL, getKeybind, setKeyGrab
660 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
661 NULL, getKeybind, setKeyGrab
663 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
664 NULL, getKeybind, setKeyGrab
666 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
667 NULL, getKeybind, setKeyGrab
669 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
670 NULL, getKeybind, setKeyGrab
672 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
673 NULL, getKeybind, setKeyGrab
675 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
676 NULL, getKeybind, setKeyGrab
678 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
679 NULL, getKeybind, setKeyGrab
681 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
682 NULL, getKeybind, setKeyGrab
684 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
685 NULL, getKeybind, setKeyGrab
687 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
688 NULL, getKeybind, setKeyGrab
690 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
691 NULL, getKeybind, setKeyGrab
693 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
694 NULL, getKeybind, setKeyGrab
696 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
697 NULL, getKeybind, setKeyGrab
699 #ifdef EXTEND_WINDOWSHORTCUT
700 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
701 NULL, getKeybind, setKeyGrab
703 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
704 NULL, getKeybind, setKeyGrab
706 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
707 NULL, getKeybind, setKeyGrab
709 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
710 NULL, getKeybind, setKeyGrab
712 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
713 NULL, getKeybind, setKeyGrab
715 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
716 NULL, getKeybind, setKeyGrab
718 #endif /* EXTEND_WINDOWSHORTCUT */
720 #ifdef KEEP_XKB_LOCK_STATUS
721 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
722 NULL, getKeybind, setKeyGrab
724 {"KbdModeLock", "NO", NULL,
725 &wPreferences.modelock, getBool, NULL
727 #endif /* KEEP_XKB_LOCK_STATUS */
728 #ifdef TITLE_TEXT_SHADOW
729 ,{"FShadowColor", "black", (void*)WS_SFOCUSED,
730 NULL, getColor, setWTitleColor
732 {"PShadowColor", "black", (void*)WS_SPFOCUSED,
733 NULL, getColor, setWTitleColor
735 {"UShadowColor", "grey50", (void*)WS_SUNFOCUSED,
736 NULL, getColor, setWTitleColor
738 {"MShadowColor", "black", (void*)WS_SMENU,
739 NULL, getColor, setMenuTitleColor
741 {"Shadow", "Yes", NULL,
742 &wPreferences.title_shadow, getBool, setJustify
744 #endif /* TITLE_TEXT_SHADOW */
748 #if 0
749 static void rereadDefaults(void);
750 #endif
752 #if 0
753 static void
754 rereadDefaults(void)
756 /* must defer the update because accessing X data from a
757 * signal handler can mess up Xlib */
760 #endif
762 static void
763 initDefaults()
765 int i;
766 WDefaultEntry *entry;
768 PLSetStringCmpHook(StringCompareHook);
770 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
771 entry = &optionList[i];
773 entry->plkey = PLMakeString(entry->key);
774 if (entry->default_value)
775 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
776 else
777 entry->plvalue = NULL;
780 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
781 entry = &staticOptionList[i];
783 entry->plkey = PLMakeString(entry->key);
784 if (entry->default_value)
785 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
786 else
787 entry->plvalue = NULL;
791 wDomainName = PLMakeString(WMDOMAIN_NAME);
792 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
794 PLRegister(wDomainName, rereadDefaults);
795 PLRegister(wAttributeDomainName, rereadDefaults);
802 #if 0
803 proplist_t
804 wDefaultsInit(int screen_number)
806 static int defaults_inited = 0;
807 proplist_t dict;
809 if (!defaults_inited) {
810 initDefaults();
813 dict = PLGetDomain(wDomainName);
814 if (!dict) {
815 wwarning(_("could not read domain \"%s\" from defaults database"),
816 PLGetString(wDomainName));
819 return dict;
821 #endif
824 void
825 wDefaultsDestroyDomain(WDDomain *domain)
827 if (domain->dictionary)
828 PLRelease(domain->dictionary);
829 free(domain->path);
830 free(domain);
834 WDDomain*
835 wDefaultsInitDomain(char *domain, Bool requireDictionary)
837 WDDomain *db;
838 struct stat stbuf;
839 static int inited = 0;
840 char path[PATH_MAX];
841 char *the_path;
842 proplist_t shared_dict=NULL;
844 if (!inited) {
845 inited = 1;
846 initDefaults();
849 db = wmalloc(sizeof(WDDomain));
850 memset(db, 0, sizeof(WDDomain));
851 db->domain_name = domain;
852 db->path = wdefaultspathfordomain(domain);
853 the_path = db->path;
855 if (the_path && stat(the_path, &stbuf)>=0) {
856 db->dictionary = ReadProplistFromFile(the_path);
857 if (db->dictionary) {
858 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
859 PLRelease(db->dictionary);
860 db->dictionary = NULL;
861 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
862 domain, the_path);
864 db->timestamp = stbuf.st_mtime;
865 } else {
866 wwarning(_("could not load domain %s from user defaults database"),
867 domain);
871 /* global system dictionary */
872 sprintf(path, "%s/%s", SYSCONFDIR, domain);
873 if (stat(path, &stbuf)>=0) {
874 shared_dict = ReadProplistFromFile(path);
875 if (shared_dict) {
876 if (requireDictionary && !PLIsDictionary(shared_dict)) {
877 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
878 domain, path);
879 PLRelease(shared_dict);
880 shared_dict = NULL;
881 } else {
882 if (db->dictionary && PLIsDictionary(shared_dict) &&
883 PLIsDictionary(db->dictionary)) {
884 PLMergeDictionaries(shared_dict, db->dictionary);
885 PLRelease(db->dictionary);
886 db->dictionary = shared_dict;
887 if (stbuf.st_mtime > db->timestamp)
888 db->timestamp = stbuf.st_mtime;
889 } else if (!db->dictionary) {
890 db->dictionary = shared_dict;
891 if (stbuf.st_mtime > db->timestamp)
892 db->timestamp = stbuf.st_mtime;
895 } else {
896 wwarning(_("could not load domain %s from global defaults database"),
897 domain);
901 /* set to save it in user's directory, no matter from where it was read */
902 if (db->dictionary) {
903 proplist_t tmp = PLMakeString(db->path);
905 PLSetFilename(db->dictionary, tmp);
906 PLRelease(tmp);
909 return db;
913 void
914 wReadStaticDefaults(proplist_t dict)
916 proplist_t plvalue;
917 WDefaultEntry *entry;
918 int i;
919 void *tdata;
922 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
923 entry = &staticOptionList[i];
925 if (dict)
926 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
927 else
928 plvalue = NULL;
930 if (!plvalue) {
931 /* no default in the DB. Use builtin default */
932 plvalue = entry->plvalue;
935 if (plvalue) {
936 /* convert data */
937 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
938 if (entry->update) {
939 (*entry->update)(NULL, entry, tdata, entry->extra_data);
946 void
947 wDefaultsCheckDomains(void *foo)
949 WScreen *scr;
950 struct stat stbuf;
951 proplist_t dict;
952 int i;
953 char path[PATH_MAX];
955 #ifdef HEARTBEAT
956 puts("Checking domains...");
957 #endif
958 if (stat(WDWindowMaker->path, &stbuf)>=0
959 && WDWindowMaker->timestamp < stbuf.st_mtime) {
960 proplist_t shared_dict = NULL;
961 #ifdef HEARTBEAT
962 puts("Checking WindowMaker domain");
963 #endif
964 WDWindowMaker->timestamp = stbuf.st_mtime;
966 /* global dictionary */
967 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
968 if (stat(path, &stbuf)>=0) {
969 shared_dict = ReadProplistFromFile(path);
970 if (shared_dict && !PLIsDictionary(shared_dict)) {
971 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
972 "WindowMaker", path);
973 PLRelease(shared_dict);
974 shared_dict = NULL;
975 } else if (!shared_dict) {
976 wwarning(_("could not load domain %s from global defaults database"),
977 "WindowMaker");
980 /* user dictionary */
981 dict = ReadProplistFromFile(WDWindowMaker->path);
982 if (dict) {
983 if (!PLIsDictionary(dict)) {
984 PLRelease(dict);
985 dict = NULL;
986 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
987 "WindowMaker", WDWindowMaker->path);
988 } else {
989 if (shared_dict) {
990 PLSetFilename(shared_dict, PLGetFilename(dict));
991 PLMergeDictionaries(shared_dict, dict);
992 PLRelease(dict);
993 dict = shared_dict;
994 shared_dict = NULL;
996 for (i=0; i<wScreenCount; i++) {
997 scr = wScreenWithNumber(i);
998 if (scr)
999 wReadDefaults(scr, dict);
1001 if (WDWindowMaker->dictionary) {
1002 PLRelease(WDWindowMaker->dictionary);
1004 WDWindowMaker->dictionary = dict;
1006 } else {
1007 wwarning(_("could not load domain %s from user defaults database"),
1008 "WindowMaker");
1010 if (shared_dict) {
1011 PLRelease(shared_dict);
1015 if (stat(WDWindowAttributes->path, &stbuf)>=0
1016 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1017 #ifdef HEARTBEAT
1018 puts("Checking WMWindowAttributes domain");
1019 #endif
1020 dict = ReadProplistFromFile(WDWindowAttributes->path);
1021 if (dict) {
1022 if (!PLIsDictionary(dict)) {
1023 PLRelease(dict);
1024 dict = NULL;
1025 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1026 "WMWindowAttributes", WDWindowAttributes->path);
1027 } else {
1028 if (WDWindowAttributes->dictionary)
1029 PLRelease(WDWindowAttributes->dictionary);
1030 WDWindowAttributes->dictionary = dict;
1031 for (i=0; i<wScreenCount; i++) {
1032 scr = wScreenWithNumber(i);
1033 if (scr)
1034 wDefaultUpdateIcons(scr);
1037 } else {
1038 wwarning(_("could not load domain %s from user defaults database"),
1039 "WMWindowAttributes");
1041 WDWindowAttributes->timestamp = stbuf.st_mtime;
1044 #ifndef LITE
1045 if (stat(WDRootMenu->path, &stbuf)>=0
1046 && WDRootMenu->timestamp < stbuf.st_mtime) {
1047 dict = ReadProplistFromFile(WDRootMenu->path);
1048 #ifdef HEARTBEAT
1049 puts("Checking WMRootMenu domain");
1050 #endif
1051 if (dict) {
1052 if (!PLIsArray(dict) && !PLIsString(dict)) {
1053 PLRelease(dict);
1054 dict = NULL;
1055 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1056 "WMRootMenu", WDRootMenu->path);
1057 } else {
1058 if (WDRootMenu->dictionary) {
1059 PLRelease(WDRootMenu->dictionary);
1061 WDRootMenu->dictionary = dict;
1063 } else {
1064 wwarning(_("could not load domain %s from user defaults database"),
1065 "WMRootMenu");
1067 WDRootMenu->timestamp = stbuf.st_mtime;
1069 #endif /* !LITE */
1071 if (!foo)
1072 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1076 void
1077 wReadDefaults(WScreen *scr, proplist_t new_dict)
1079 proplist_t plvalue, old_value;
1080 WDefaultEntry *entry;
1081 int i, must_update;
1082 int needs_refresh;
1083 void *tdata;
1084 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1085 ? WDWindowMaker->dictionary : NULL);
1087 must_update = 0;
1089 needs_refresh = 0;
1091 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1092 entry = &optionList[i];
1094 if (new_dict)
1095 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1096 else
1097 plvalue = NULL;
1099 if (!old_dict)
1100 old_value = NULL;
1101 else
1102 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1105 if (!plvalue && !old_value) {
1106 /* no default in the DB. Use builtin default */
1107 plvalue = entry->plvalue;
1108 if (plvalue && new_dict) {
1109 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1110 must_update = 1;
1112 } else if (!plvalue) {
1113 /* value was deleted from DB. Keep current value */
1114 continue;
1115 } else if (!old_value) {
1116 /* set value for the 1st time */
1117 } else if (!PLIsEqual(plvalue, old_value)) {
1118 /* value has changed */
1119 } else {
1120 /* value was not changed since last time */
1121 continue;
1124 if (plvalue) {
1125 #ifdef DEBUG
1126 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1127 #endif
1128 /* convert data */
1129 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1130 if (entry->update) {
1131 needs_refresh |=
1132 (*entry->update)(scr, entry, tdata, entry->extra_data);
1138 if (needs_refresh!=0 && !scr->flags.startup) {
1139 int foo;
1141 foo = 0;
1142 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1143 foo |= WTextureSettings;
1144 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1145 foo |= WFontSettings;
1146 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1147 foo |= WColorSettings;
1148 if (foo)
1149 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1150 (void*)foo);
1152 foo = 0;
1153 if (needs_refresh & REFRESH_MENU_TEXTURE)
1154 foo |= WTextureSettings;
1155 if (needs_refresh & REFRESH_MENU_FONT)
1156 foo |= WFontSettings;
1157 if (needs_refresh & REFRESH_MENU_COLOR)
1158 foo |= WColorSettings;
1159 if (foo)
1160 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1161 (void*)foo);
1163 foo = 0;
1164 if (needs_refresh & REFRESH_WINDOW_FONT) {
1165 foo |= WFontSettings;
1167 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1168 foo |= WTextureSettings;
1170 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1171 foo |= WColorSettings;
1173 if (foo)
1174 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1175 (void*)foo);
1177 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1178 foo = 0;
1179 if (needs_refresh & REFRESH_ICON_FONT) {
1180 foo |= WFontSettings;
1182 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1183 foo |= WTextureSettings;
1185 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1186 foo |= WTextureSettings;
1188 if (foo)
1189 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1190 (void*)foo);
1192 if (needs_refresh & REFRESH_ICON_TILE)
1193 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1198 void
1199 wDefaultUpdateIcons(WScreen *scr)
1201 WAppIcon *aicon = scr->app_icon_list;
1202 WWindow *wwin = scr->focused_window;
1203 char *file;
1205 while(aicon) {
1206 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1207 False);
1208 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1209 || (file && !aicon->icon->file)) {
1210 RImage *new_image;
1212 if (aicon->icon->file)
1213 free(aicon->icon->file);
1214 aicon->icon->file = wstrdup(file);
1216 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1217 aicon->wm_class);
1218 if (new_image) {
1219 wIconChangeImage(aicon->icon, new_image);
1220 wAppIconPaint(aicon);
1223 aicon = aicon->next;
1226 if (!wPreferences.flags.noclip)
1227 wClipIconPaint(scr->clip_icon);
1229 while (wwin) {
1230 if (wwin->icon && wwin->flags.miniaturized) {
1231 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1232 False);
1233 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1234 || (file && !wwin->icon->file)) {
1235 RImage *new_image;
1237 if (wwin->icon->file)
1238 free(wwin->icon->file);
1239 wwin->icon->file = wstrdup(file);
1241 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1242 wwin->wm_class);
1243 if (new_image)
1244 wIconChangeImage(wwin->icon, new_image);
1247 wwin = wwin->prev;
1252 /* --------------------------- Local ----------------------- */
1254 #define STRINGP(x) if (!PLIsString(value)) { \
1255 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1256 entry->key, x); \
1257 return False; }
1261 static int
1262 string2index(proplist_t key, proplist_t val, proplist_t def,
1263 WOptionEnumeration *values)
1265 char *str;
1266 WOptionEnumeration *v;
1267 char buffer[TOTAL_VALUES_LENGTH];
1269 if (PLIsString(val) && (str = PLGetString(val))) {
1270 for (v=values; v->string!=NULL; v++) {
1271 if (strcasecmp(v->string, str)==0)
1272 return v->value;
1276 buffer[0] = 0;
1277 for (v=values; v->string!=NULL; v++) {
1278 if (!v->is_alias) {
1279 if (buffer[0]!=0)
1280 strcat(buffer, ", ");
1281 strcat(buffer, v->string);
1284 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1285 PLGetString(key), buffer);
1287 if (def) {
1288 return string2index(key, val, NULL, values);
1291 return -1;
1298 * value - is the value in the defaults DB
1299 * addr - is the address to store the data
1300 * ret - is the address to store a pointer to a temporary buffer. ret
1301 * must not be freed and is used by the set functions
1303 static int
1304 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1305 void **ret)
1307 static char data;
1308 char *val;
1309 int second_pass=0;
1311 STRINGP("Boolean");
1313 val = PLGetString(value);
1315 again:
1316 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1317 || strcasecmp(val, "YES")==0) {
1319 data = 1;
1320 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1321 || strcasecmp(val, "NO")==0) {
1322 data = 0;
1323 } else {
1324 int i;
1325 if (sscanf(val, "%i", &i)==1) {
1326 if (i!=0)
1327 data = 1;
1328 else
1329 data = 0;
1330 } else {
1331 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1332 val, entry->key);
1333 if (second_pass==0) {
1334 val = PLGetString(entry->plvalue);
1335 second_pass = 1;
1336 wwarning(_("using default \"%s\" instead"), val);
1337 goto again;
1339 return False;
1343 if (ret)
1344 *ret = &data;
1346 if (addr) {
1347 *(char*)addr = data;
1350 return True;
1354 static int
1355 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1356 void **ret)
1358 static int data;
1359 char *val;
1362 STRINGP("Integer");
1364 val = PLGetString(value);
1366 if (sscanf(val, "%i", &data)!=1) {
1367 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1368 val, entry->key);
1369 val = PLGetString(entry->plvalue);
1370 wwarning(_("using default \"%s\" instead"), val);
1371 if (sscanf(val, "%i", &data)!=1) {
1372 return False;
1376 if (ret)
1377 *ret = &data;
1379 if (addr) {
1380 *(int*)addr = data;
1382 return True;
1386 static int
1387 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1388 void **ret)
1390 static WCoord data;
1391 char *val_x, *val_y;
1392 int nelem, changed=0;
1393 proplist_t elem_x, elem_y;
1395 again:
1396 if (!PLIsArray(value)) {
1397 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1398 entry->key, "Coordinate");
1399 if (changed==0) {
1400 value = entry->plvalue;
1401 changed = 1;
1402 wwarning(_("using default \"%s\" instead"), entry->default_value);
1403 goto again;
1405 return False;
1408 nelem = PLGetNumberOfElements(value);
1409 if (nelem != 2) {
1410 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1411 entry->key);
1412 if (changed==0) {
1413 value = entry->plvalue;
1414 changed = 1;
1415 wwarning(_("using default \"%s\" instead"), entry->default_value);
1416 goto again;
1418 return False;
1421 elem_x = PLGetArrayElement(value, 0);
1422 elem_y = PLGetArrayElement(value, 1);
1424 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1425 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1426 entry->key);
1427 if (changed==0) {
1428 value = entry->plvalue;
1429 changed = 1;
1430 wwarning(_("using default \"%s\" instead"), entry->default_value);
1431 goto again;
1433 return False;
1436 val_x = PLGetString(elem_x);
1437 val_y = PLGetString(elem_y);
1439 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1440 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1441 if (changed==0) {
1442 value = entry->plvalue;
1443 changed = 1;
1444 wwarning(_("using default \"%s\" instead"), entry->default_value);
1445 goto again;
1447 return False;
1450 if (data.x < 0)
1451 data.x = 0;
1452 else if (data.x > scr->scr_width/3)
1453 data.x = scr->scr_width/3;
1454 if (data.y < 0)
1455 data.y = 0;
1456 else if (data.y > scr->scr_height/3)
1457 data.y = scr->scr_height/3;
1459 if (ret)
1460 *ret = &data;
1462 if (addr) {
1463 *(WCoord*)addr = data;
1466 return True;
1470 #if 0
1471 /* This function is not used at the moment. */
1472 static int
1473 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1474 void **ret)
1476 static char *data;
1478 STRINGP("String");
1480 data = PLGetString(value);
1482 if (!data) {
1483 data = PLGetString(entry->plvalue);
1484 if (!data)
1485 return False;
1488 if (ret)
1489 *ret = &data;
1491 if (addr)
1492 *(char**)addr = wstrdup(data);
1494 return True;
1496 #endif
1499 static int
1500 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1501 void **ret)
1503 static char *data;
1504 int i, count, len;
1505 char *ptr;
1506 proplist_t d;
1507 int changed=0;
1509 again:
1510 if (!PLIsArray(value)) {
1511 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1512 entry->key, "an array of paths");
1513 if (changed==0) {
1514 value = entry->plvalue;
1515 changed = 1;
1516 wwarning(_("using default \"%s\" instead"), entry->default_value);
1517 goto again;
1519 return False;
1522 i = 0;
1523 count = PLGetNumberOfElements(value);
1524 if (count < 1) {
1525 if (changed==0) {
1526 value = entry->plvalue;
1527 changed = 1;
1528 wwarning(_("using default \"%s\" instead"), entry->default_value);
1529 goto again;
1531 return False;
1534 len = 0;
1535 for (i=0; i<count; i++) {
1536 d = PLGetArrayElement(value, i);
1537 if (!d || !PLIsString(d)) {
1538 count = i;
1539 break;
1541 len += strlen(PLGetString(d))+1;
1544 ptr = data = wmalloc(len+1);
1546 for (i=0; i<count; i++) {
1547 d = PLGetArrayElement(value, i);
1548 if (!d || !PLIsString(d)) {
1549 break;
1551 strcpy(ptr, PLGetString(d));
1552 ptr += strlen(PLGetString(d));
1553 *ptr = ':';
1554 ptr++;
1556 ptr--; *(ptr--) = 0;
1558 if (*(char**)addr!=NULL) {
1559 free(*(char**)addr);
1561 *(char**)addr = data;
1563 return True;
1567 static int
1568 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1569 void **ret)
1571 static signed char data;
1573 data = string2index(entry->plkey, value, entry->default_value,
1574 (WOptionEnumeration*)entry->extra_data);
1575 if (data < 0)
1576 return False;
1578 if (ret)
1579 *ret = &data;
1581 if (addr)
1582 *(signed char*)addr = data;
1584 return True;
1590 * (solid <color>)
1591 * (hgradient <color> <color>)
1592 * (vgradient <color> <color>)
1593 * (dgradient <color> <color>)
1594 * (mhgradient <color> <color> ...)
1595 * (mvgradient <color> <color> ...)
1596 * (tpixmap <file> <color>)
1597 * (spixmap <file> <color>)
1598 * (cpixmap <file> <color>)
1599 * (thgradient <file> <opaqueness> <color> <color>)
1600 * (tvgradient <file> <opaqueness> <color> <color>)
1601 * (tdgradient <file> <opaqueness> <color> <color>)
1602 * (function <lib> <function> ...)
1605 static WTexture*
1606 parse_texture(WScreen *scr, proplist_t pl)
1608 proplist_t elem;
1609 char *val;
1610 int nelem;
1611 WTexture *texture=NULL;
1613 nelem = PLGetNumberOfElements(pl);
1614 if (nelem < 1)
1615 return NULL;
1618 elem = PLGetArrayElement(pl, 0);
1619 if (!elem || !PLIsString(elem))
1620 return NULL;
1621 val = PLGetString(elem);
1624 if (strcasecmp(val, "solid")==0) {
1625 XColor color;
1627 if (nelem != 2)
1628 return NULL;
1630 /* get color */
1632 elem = PLGetArrayElement(pl, 1);
1633 if (!elem || !PLIsString(elem))
1634 return NULL;
1635 val = PLGetString(elem);
1637 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1638 wwarning(_("\"%s\" is not a valid color name"), val);
1639 return NULL;
1642 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1643 } else if (strcasecmp(val, "dgradient")==0
1644 || strcasecmp(val, "vgradient")==0
1645 || strcasecmp(val, "hgradient")==0) {
1646 RColor color1, color2;
1647 XColor xcolor;
1648 int type;
1650 if (nelem != 3) {
1651 wwarning(_("bad number of arguments in gradient specification"));
1652 return NULL;
1655 if (val[0]=='d' || val[0]=='D')
1656 type = WTEX_DGRADIENT;
1657 else if (val[0]=='h' || val[0]=='H')
1658 type = WTEX_HGRADIENT;
1659 else
1660 type = WTEX_VGRADIENT;
1663 /* get from color */
1664 elem = PLGetArrayElement(pl, 1);
1665 if (!elem || !PLIsString(elem))
1666 return NULL;
1667 val = PLGetString(elem);
1669 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1670 wwarning(_("\"%s\" is not a valid color name"), val);
1671 return NULL;
1673 color1.alpha = 255;
1674 color1.red = xcolor.red >> 8;
1675 color1.green = xcolor.green >> 8;
1676 color1.blue = xcolor.blue >> 8;
1678 /* get to color */
1679 elem = PLGetArrayElement(pl, 2);
1680 if (!elem || !PLIsString(elem)) {
1681 return NULL;
1683 val = PLGetString(elem);
1685 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1686 wwarning(_("\"%s\" is not a valid color name"), val);
1687 return NULL;
1689 color2.alpha = 255;
1690 color2.red = xcolor.red >> 8;
1691 color2.green = xcolor.green >> 8;
1692 color2.blue = xcolor.blue >> 8;
1694 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1696 } else if (strcasecmp(val, "mhgradient")==0
1697 || strcasecmp(val, "mvgradient")==0
1698 || strcasecmp(val, "mdgradient")==0) {
1699 XColor color;
1700 RColor **colors;
1701 int i, count;
1702 int type;
1704 if (nelem < 3) {
1705 wwarning(_("too few arguments in multicolor gradient specification"));
1706 return NULL;
1709 if (val[1]=='h' || val[1]=='H')
1710 type = WTEX_MHGRADIENT;
1711 else if (val[1]=='v' || val[1]=='V')
1712 type = WTEX_MVGRADIENT;
1713 else
1714 type = WTEX_MDGRADIENT;
1716 count = nelem-1;
1718 colors = wmalloc(sizeof(RColor*)*(count+1));
1720 for (i=0; i<count; i++) {
1721 elem = PLGetArrayElement(pl, i+1);
1722 if (!elem || !PLIsString(elem)) {
1723 for (--i; i>=0; --i) {
1724 free(colors[i]);
1726 free(colors);
1727 return NULL;
1729 val = PLGetString(elem);
1731 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1732 wwarning(_("\"%s\" is not a valid color name"), val);
1733 for (--i; i>=0; --i) {
1734 free(colors[i]);
1736 free(colors);
1737 return NULL;
1738 } else {
1739 colors[i] = wmalloc(sizeof(RColor));
1740 colors[i]->red = color.red >> 8;
1741 colors[i]->green = color.green >> 8;
1742 colors[i]->blue = color.blue >> 8;
1745 colors[i] = NULL;
1747 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1748 } else if (strcasecmp(val, "spixmap")==0 ||
1749 strcasecmp(val, "cpixmap")==0 ||
1750 strcasecmp(val, "tpixmap")==0) {
1751 XColor color;
1752 int type;
1754 if (nelem != 3)
1755 return NULL;
1757 if (val[0] == 's' || val[0] == 'S')
1758 type = WTP_SCALE;
1759 else if (val[0] == 'c' || val[0] == 'C')
1760 type = WTP_CENTER;
1761 else
1762 type = WTP_TILE;
1764 /* get color */
1765 elem = PLGetArrayElement(pl, 2);
1766 if (!elem || !PLIsString(elem)) {
1767 return NULL;
1769 val = PLGetString(elem);
1771 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1772 wwarning(_("\"%s\" is not a valid color name"), val);
1773 return NULL;
1776 /* file name */
1777 elem = PLGetArrayElement(pl, 1);
1778 if (!elem || !PLIsString(elem))
1779 return NULL;
1780 val = PLGetString(elem);
1782 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1783 } else if (strcasecmp(val, "thgradient")==0
1784 || strcasecmp(val, "tvgradient")==0
1785 || strcasecmp(val, "tdgradient")==0) {
1786 RColor color1, color2;
1787 XColor xcolor;
1788 int opacity;
1789 int style;
1791 if (val[1]=='h' || val[1]=='H')
1792 style = WTEX_THGRADIENT;
1793 else if (val[1]=='v' || val[1]=='V')
1794 style = WTEX_TVGRADIENT;
1795 else
1796 style = WTEX_TDGRADIENT;
1798 if (nelem != 5) {
1799 wwarning(_("bad number of arguments in textured gradient specification"));
1800 return NULL;
1803 /* get from color */
1804 elem = PLGetArrayElement(pl, 3);
1805 if (!elem || !PLIsString(elem))
1806 return NULL;
1807 val = PLGetString(elem);
1809 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1810 wwarning(_("\"%s\" is not a valid color name"), val);
1811 return NULL;
1813 color1.alpha = 255;
1814 color1.red = xcolor.red >> 8;
1815 color1.green = xcolor.green >> 8;
1816 color1.blue = xcolor.blue >> 8;
1818 /* get to color */
1819 elem = PLGetArrayElement(pl, 4);
1820 if (!elem || !PLIsString(elem)) {
1821 return NULL;
1823 val = PLGetString(elem);
1825 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1826 wwarning(_("\"%s\" is not a valid color name"), val);
1827 return NULL;
1829 color2.alpha = 255;
1830 color2.red = xcolor.red >> 8;
1831 color2.green = xcolor.green >> 8;
1832 color2.blue = xcolor.blue >> 8;
1834 /* get opacity */
1835 elem = PLGetArrayElement(pl, 2);
1836 if (!elem || !PLIsString(elem))
1837 opacity = 128;
1838 else
1839 val = PLGetString(elem);
1841 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1842 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1843 opacity = 128;
1846 /* get file name */
1847 elem = PLGetArrayElement(pl, 1);
1848 if (!elem || !PLIsString(elem))
1849 return NULL;
1850 val = PLGetString(elem);
1852 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1853 val, opacity);
1855 #ifdef TEXTURE_PLUGIN
1856 else if (strcasecmp(val, "function")==0) {
1857 WTexFunction *function;
1858 void (*initFunc) (Display *, Colormap);
1859 char *lib, *func, **argv;
1860 int i, argc;
1862 if (nelem < 3)
1863 return NULL;
1865 /* get the library name */
1866 elem = PLGetArrayElement(pl, 1);
1867 if (!elem || !PLIsString(elem)) {
1868 return NULL;
1870 lib = PLGetString(elem);
1872 /* get the function name */
1873 elem = PLGetArrayElement(pl, 2);
1874 if (!elem || !PLIsString(elem)) {
1875 return NULL;
1877 func = PLGetString(elem);
1879 argc = nelem - 2;
1880 argv = (char **)wmalloc(argc * sizeof(char *));
1882 /* get the parameters */
1883 argv[0] = wstrdup(func);
1884 for (i = 0; i < argc - 1; i++) {
1885 elem = PLGetArrayElement(pl, 3 + i);
1886 if (!elem || !PLIsString(elem)) {
1887 free(argv);
1889 return NULL;
1891 argv[i+1] = wstrdup(PLGetString(elem));
1894 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1896 #ifdef HAVE_DLFCN_H
1897 if (function) {
1898 initFunc = dlsym(function->handle, "initWindowMaker");
1899 if (initFunc) {
1900 initFunc(dpy, scr->w_colormap);
1901 } else {
1902 wwarning(_("could not initialize library %s"), lib);
1904 } else {
1905 wwarning(_("could not find function %s::%s"), lib, func);
1907 #endif /* HAVE_DLFCN_H */
1908 texture = (WTexture*)function;
1910 #endif /* TEXTURE_PLUGIN */
1911 else {
1912 wwarning(_("invalid texture type %s"), val);
1913 return NULL;
1915 return texture;
1920 static int
1921 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1922 void **ret)
1924 static WTexture *texture;
1925 int changed=0;
1927 again:
1928 if (!PLIsArray(value)) {
1929 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1930 entry->key, "Texture");
1931 if (changed==0) {
1932 value = entry->plvalue;
1933 changed = 1;
1934 wwarning(_("using default \"%s\" instead"), entry->default_value);
1935 goto again;
1937 return False;
1940 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1941 proplist_t pl;
1943 pl = PLGetArrayElement(value, 0);
1944 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1945 || strcasecmp(PLGetString(pl), "solid")!=0) {
1946 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1947 entry->key, "Solid Texture");
1949 value = entry->plvalue;
1950 changed = 1;
1951 wwarning(_("using default \"%s\" instead"), entry->default_value);
1952 goto again;
1956 texture = parse_texture(scr, value);
1958 if (!texture) {
1959 wwarning(_("Error in texture specification for key \"%s\""),
1960 entry->key);
1961 if (changed==0) {
1962 value = entry->plvalue;
1963 changed = 1;
1964 wwarning(_("using default \"%s\" instead"), entry->default_value);
1965 goto again;
1967 return False;
1970 if (ret)
1971 *ret = &texture;
1973 if (addr)
1974 *(WTexture**)addr = texture;
1976 return True;
1981 static int
1982 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
1983 void *addr, void **ret)
1985 proplist_t elem;
1986 int changed = 0;
1987 char *val;
1988 int nelem;
1990 again:
1991 if (!PLIsArray(value)) {
1992 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1993 "WorkspaceBack", "Texture or None");
1994 if (changed==0) {
1995 value = entry->plvalue;
1996 changed = 1;
1997 wwarning(_("using default \"%s\" instead"), entry->default_value);
1998 goto again;
2000 return False;
2003 /* only do basic error checking and verify for None texture */
2005 nelem = PLGetNumberOfElements(value);
2006 if (nelem > 0) {
2007 elem = PLGetArrayElement(value, 0);
2008 if (!elem || !PLIsString(elem)) {
2009 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2010 if (changed==0) {
2011 value = entry->plvalue;
2012 changed = 1;
2013 wwarning(_("using default \"%s\" instead"), entry->default_value);
2014 goto again;
2016 return False;
2018 val = PLGetString(elem);
2020 if (strcasecmp(val, "None")==0)
2021 return True;
2023 *ret = PLRetain(value);
2025 return True;
2029 static int
2030 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2031 void *addr, void **ret)
2033 proplist_t elem;
2034 int nelem;
2035 int changed = 0;
2037 again:
2038 if (!PLIsArray(value)) {
2039 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2040 "WorkspaceSpecificBack", "an array of textures");
2041 if (changed==0) {
2042 value = entry->plvalue;
2043 changed = 1;
2044 wwarning(_("using default \"%s\" instead"), entry->default_value);
2045 goto again;
2047 return False;
2050 /* only do basic error checking and verify for None texture */
2052 nelem = PLGetNumberOfElements(value);
2053 if (nelem > 0) {
2054 while (nelem--) {
2055 elem = PLGetArrayElement(value, nelem);
2056 if (!elem || !PLIsArray(elem)) {
2057 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2058 nelem);
2063 *ret = PLRetain(value);
2065 #ifdef notworking
2067 * Kluge to force wmsetbg helper to set the default background.
2068 * If the WorkspaceSpecificBack is changed once wmaker has started,
2069 * the WorkspaceBack won't be sent to the helper, unless the user
2070 * changes it's value too. So, we must force this by removing the
2071 * value from the defaults DB.
2073 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2074 proplist_t key = PLMakeString("WorkspaceBack");
2076 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2078 PLRelease(key);
2080 #endif
2081 return True;
2085 static int
2086 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2087 void **ret)
2089 static WFont *font;
2090 char *val;
2092 STRINGP("Font");
2094 val = PLGetString(value);
2096 font = wLoadFont(val);
2097 if (!font) {
2098 wfatal(_("could not load any usable font!!!"));
2099 exit(1);
2102 if (ret)
2103 *ret = font;
2105 /* can't assign font value outside update function */
2106 wassertrv(addr == NULL, True);
2108 return True;
2112 static int
2113 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2114 void **ret)
2116 static XColor color;
2117 char *val;
2118 int second_pass=0;
2120 STRINGP("Color");
2122 val = PLGetString(value);
2124 again:
2125 if (!wGetColor(scr, val, &color)) {
2126 wwarning(_("could not get color for key \"%s\""),
2127 entry->key);
2128 if (second_pass==0) {
2129 val = PLGetString(entry->plvalue);
2130 second_pass = 1;
2131 wwarning(_("using default \"%s\" instead"), val);
2132 goto again;
2134 return False;
2137 if (ret)
2138 *ret = &color;
2140 assert(addr==NULL);
2142 if (addr)
2143 *(unsigned long*)addr = pixel;
2146 return True;
2151 static int
2152 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2153 void **ret)
2155 static WShortKey shortcut;
2156 KeySym ksym;
2157 char *val;
2158 char *k;
2159 char buf[128], *b;
2162 STRINGP("Key spec");
2164 val = PLGetString(value);
2166 if (!val || strcasecmp(val, "NONE")==0) {
2167 shortcut.keycode = 0;
2168 shortcut.modifier = 0;
2169 if (ret)
2170 *ret = &shortcut;
2171 return True;
2174 strcpy(buf, val);
2176 b = (char*)buf;
2178 /* get modifiers */
2179 shortcut.modifier = 0;
2180 while ((k = strchr(b, '+'))!=NULL) {
2181 int mod;
2183 *k = 0;
2184 mod = wXModifierFromKey(b);
2185 if (mod<0) {
2186 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2187 return False;
2189 shortcut.modifier |= mod;
2191 b = k+1;
2194 /* get key */
2195 ksym = XStringToKeysym(b);
2197 if (ksym==NoSymbol) {
2198 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2199 val);
2200 return False;
2203 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2204 if (shortcut.keycode==0) {
2205 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2206 return False;
2209 if (ret)
2210 *ret = &shortcut;
2212 return True;
2216 static int
2217 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2218 void **ret)
2220 static unsigned int mask;
2221 char *str;
2223 STRINGP("Modifier Key");
2225 str = PLGetString(value);
2226 if (!str)
2227 return False;
2229 mask = wXModifierFromKey(str);
2230 if (mask < 0) {
2231 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2232 mask = 0;
2233 return False;
2236 if (addr)
2237 *(unsigned int*)addr = mask;
2239 if (ret)
2240 *ret = &mask;
2242 return True;
2246 #ifdef NEWSTUFF
2247 static int
2248 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2249 void *addr, void **ret)
2251 unsigned int mask;
2252 char *str;
2253 RImage *image;
2254 int i, n;
2255 int w, h;
2257 STRINGP("Image File Path");
2259 str = PLGetString(value);
2260 if (!str)
2261 return False;
2263 image = RLoadImage(scr->rcontext, str, 0);
2264 if (!image) {
2265 wwarning(_("could not load image in option %s: %s"), entry->key,
2266 RMessageForError(RErrorCode));
2267 return False;
2270 if (*(RImage**)addr) {
2271 RDestroyImage(*(RImage**)addr);
2273 if (addr)
2274 *(RImage**)addr = image;
2276 assert(ret == NULL);
2278 if (ret)
2279 *(RImage**)ret = image;
2282 return True;
2284 #endif
2287 /* ---------------- value setting functions --------------- */
2288 static int
2289 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2291 return REFRESH_WINDOW_TITLE_COLOR;
2295 static int
2296 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2298 switch (which) {
2299 case WM_DOCK:
2300 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2301 break;
2302 case WM_CLIP:
2303 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2304 break;
2305 default:
2306 break;
2308 return 0;
2312 static int
2313 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2315 if (scr->workspaces) {
2316 wWorkspaceForceChange(scr, scr->current_workspace);
2317 wArrangeIcons(scr, False);
2319 return 0;
2322 #if not_used
2323 static int
2324 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2326 if (*value <= 0)
2327 *(int*)foo = 1;
2329 return 0;
2331 #endif
2335 static int
2336 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2338 Pixmap pixmap;
2339 RImage *img;
2340 int reset = 0;
2342 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2343 wPreferences.icon_size,
2344 ((*texture)->any.type & WREL_BORDER_MASK)
2345 ? WREL_ICON : WREL_FLAT);
2346 if (!img) {
2347 wwarning(_("could not render texture for icon background"));
2348 if (!entry->addr)
2349 wTextureDestroy(scr, *texture);
2350 return 0;
2352 RConvertImage(scr->rcontext, img, &pixmap);
2354 if (scr->icon_tile) {
2355 reset = 1;
2356 RDestroyImage(scr->icon_tile);
2357 XFreePixmap(dpy, scr->icon_tile_pixmap);
2360 scr->icon_tile = img;
2362 if (!wPreferences.flags.noclip) {
2363 if (scr->clip_tile) {
2364 RDestroyImage(scr->clip_tile);
2366 scr->clip_tile = wClipMakeTile(scr, img);
2369 scr->icon_tile_pixmap = pixmap;
2371 if (scr->def_icon_pixmap) {
2372 XFreePixmap(dpy, scr->def_icon_pixmap);
2373 scr->def_icon_pixmap = None;
2375 if (scr->def_ticon_pixmap) {
2376 XFreePixmap(dpy, scr->def_ticon_pixmap);
2377 scr->def_ticon_pixmap = None;
2380 if (scr->icon_back_texture) {
2381 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2383 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2385 if (scr->clip_balloon)
2386 XSetWindowBackground(dpy, scr->clip_balloon,
2387 (*texture)->any.color.pixel);
2390 * Free the texture as nobody else will use it, nor refer to it.
2392 if (!entry->addr)
2393 wTextureDestroy(scr, *texture);
2395 return (reset ? REFRESH_ICON_TILE : 0);
2400 static int
2401 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2403 if (scr->title_font) {
2404 wFreeFont(scr->title_font);
2407 scr->title_font = font;
2409 #ifndef I18N_MB
2410 XSetFont(dpy, scr->window_title_gc, font->font->fid);
2411 #endif
2413 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2417 static int
2418 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2420 if (scr->menu_title_font) {
2421 wFreeFont(scr->menu_title_font);
2424 scr->menu_title_font = font;
2426 #ifndef I18N_MB
2427 XSetFont(dpy, scr->menu_title_gc, font->font->fid);
2428 #endif
2430 return REFRESH_MENU_TITLE_FONT;
2434 static int
2435 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2437 if (scr->menu_entry_font) {
2438 wFreeFont(scr->menu_entry_font);
2441 scr->menu_entry_font = font;
2443 #ifndef I18N_MB
2444 XSetFont(dpy, scr->menu_entry_gc, font->font->fid);
2445 XSetFont(dpy, scr->disabled_menu_entry_gc, font->font->fid);
2446 XSetFont(dpy, scr->select_menu_gc, font->font->fid);
2447 #endif
2449 return REFRESH_MENU_FONT;
2454 static int
2455 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2457 if (scr->icon_title_font) {
2458 wFreeFont(scr->icon_title_font);
2461 scr->icon_title_font = font;
2463 #ifndef I18N_MB
2464 XSetFont(dpy, scr->icon_title_gc, font->font->fid);
2465 #endif
2467 return REFRESH_ICON_FONT;
2471 static int
2472 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2474 if (scr->clip_title_font) {
2475 wFreeFont(scr->clip_title_font);
2478 scr->clip_title_font = font;
2480 #ifndef I18N_MB
2481 XSetFont(dpy, scr->clip_title_gc, font->font->fid);
2482 #endif
2484 return REFRESH_ICON_FONT;
2488 static int
2489 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2491 if (scr->info_text_font) {
2492 wFreeFont(scr->info_text_font);
2495 scr->info_text_font = font;
2497 #ifndef I18N_MB
2498 XSetFont(dpy, scr->info_text_gc, font->font->fid);
2499 XSetFont(dpy, scr->line_gc, font->font->fid);
2500 #endif
2502 /* This test works because the scr structure is initially zeroed out
2503 and None = 0. Any other time, the window should be valid. */
2504 if (scr->geometry_display != None) {
2505 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2506 &scr->geometry_display_height);
2507 XResizeWindow(dpy, scr->geometry_display,
2508 scr->geometry_display_width, scr->geometry_display_height);
2511 return 0;
2515 static int
2516 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WFont *font, void *foo)
2518 if (scr->workspace_name_font) {
2519 wFreeFont(scr->workspace_name_font);
2522 scr->workspace_name_font = font;
2524 return 0;
2528 static int
2529 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2531 if (scr->select_pixel!=scr->white_pixel &&
2532 scr->select_pixel!=scr->black_pixel) {
2533 wFreeColor(scr, scr->select_pixel);
2536 scr->select_pixel = color->pixel;
2538 return REFRESH_MENU_COLOR;
2542 static int
2543 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2545 if (scr->select_text_pixel!=scr->white_pixel &&
2546 scr->select_text_pixel!=scr->black_pixel) {
2547 wFreeColor(scr, scr->select_text_pixel);
2550 scr->select_text_pixel = color->pixel;
2552 return REFRESH_MENU_COLOR;
2556 static int
2557 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2559 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2560 scr->clip_title_pixel[index]!=scr->black_pixel) {
2561 wFreeColor(scr, scr->clip_title_pixel[index]);
2563 scr->clip_title_pixel[index] = color->pixel;
2565 #ifdef GRADIENT_CLIP_ARROW
2566 if (index == CLIP_NORMAL) {
2567 RImage *image;
2568 RColor color1, color2;
2569 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2570 int as = pt - 15; /* 15 = 5+5+5 */
2572 FREE_PIXMAP(scr->clip_arrow_gradient);
2574 color1.red = (color->red >> 8)*6/10;
2575 color1.green = (color->green >> 8)*6/10;
2576 color1.blue = (color->blue >> 8)*6/10;
2578 color2.red = WMIN((color->red >> 8)*20/10, 255);
2579 color2.green = WMIN((color->green >> 8)*20/10, 255);
2580 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2582 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2583 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2584 RDestroyImage(image);
2586 #endif /* GRADIENT_CLIP_ARROW */
2588 return REFRESH_ICON_TITLE_COLOR;
2592 static int
2593 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2595 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2596 scr->window_title_pixel[index]!=scr->black_pixel) {
2597 wFreeColor(scr, scr->window_title_pixel[index]);
2600 scr->window_title_pixel[index] = color->pixel;
2602 if (index == WS_UNFOCUSED)
2603 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2605 return REFRESH_WINDOW_TITLE_COLOR;
2609 static int
2610 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2612 #ifdef TITLE_TEXT_SHADOW
2613 if (index == WS_SMENU){
2614 if (scr->menu_title_pixel[WS_SMENU]!=scr->white_pixel &&
2615 scr->menu_title_pixel[WS_SMENU]!=scr->black_pixel) {
2616 wFreeColor(scr, scr->menu_title_pixel[WS_SMENU]);
2618 scr->menu_title_pixel[WS_SMENU] = color->pixel;
2620 else {
2621 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2622 scr->menu_title_pixel[0]!=scr->black_pixel) {
2623 wFreeColor(scr, scr->menu_title_pixel[0]);
2625 scr->menu_title_pixel[0] = color->pixel;
2627 #else /* !TITLE_TEXT_SHADOW */
2628 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2629 scr->menu_title_pixel[0]!=scr->black_pixel) {
2630 wFreeColor(scr, scr->menu_title_pixel[0]);
2633 scr->menu_title_pixel[0] = color->pixel;
2634 #endif /* !TITLE_TEXT_SHADOW */
2635 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2637 return REFRESH_MENU_TITLE_COLOR;
2641 static int
2642 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2644 XGCValues gcv;
2645 #define gcm (GCForeground|GCBackground|GCFillStyle)
2647 if (scr->mtext_pixel!=scr->white_pixel &&
2648 scr->mtext_pixel!=scr->black_pixel) {
2649 wFreeColor(scr, scr->mtext_pixel);
2652 scr->mtext_pixel = color->pixel;
2654 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2657 if (scr->dtext_pixel == scr->mtext_pixel) {
2658 gcv.foreground = scr->white_pixel;
2659 gcv.background = scr->black_pixel;
2660 gcv.fill_style = FillStippled;
2661 } else {
2662 gcv.foreground = scr->dtext_pixel;
2663 gcv.fill_style = FillSolid;
2665 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2667 return REFRESH_MENU_COLOR;
2668 #undef gcm
2672 static int
2673 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2675 XGCValues gcv;
2676 #define gcm (GCForeground|GCBackground|GCFillStyle)
2678 if (scr->dtext_pixel!=scr->white_pixel &&
2679 scr->dtext_pixel!=scr->black_pixel) {
2680 wFreeColor(scr, scr->dtext_pixel);
2683 scr->dtext_pixel = color->pixel;
2685 if (scr->dtext_pixel == scr->mtext_pixel) {
2686 gcv.foreground = scr->white_pixel;
2687 gcv.background = scr->black_pixel;
2688 gcv.fill_style = FillStippled;
2689 } else {
2690 gcv.foreground = scr->dtext_pixel;
2691 gcv.fill_style = FillSolid;
2693 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2695 return REFRESH_MENU_COLOR;
2696 #undef gcm
2699 static int
2700 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2702 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2704 return REFRESH_ICON_TITLE_COLOR;
2708 static int
2709 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2711 if (scr->icon_title_texture) {
2712 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2714 XQueryColor (dpy, scr->w_colormap, color);
2715 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2717 return REFRESH_ICON_TITLE_BACK;
2721 static void
2722 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2724 close(scr->helper_fd);
2725 scr->helper_fd = 0;
2726 scr->helper_pid = 0;
2727 scr->flags.backimage_helper_launched = 0;
2731 static int
2732 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2733 void *bar)
2735 int i;
2736 proplist_t val;
2737 char *str;
2739 if (scr->flags.backimage_helper_launched) {
2740 if (PLGetNumberOfElements(value)==0) {
2741 SendHelperMessage(scr, 'C', 0, NULL);
2742 SendHelperMessage(scr, 'K', 0, NULL);
2744 PLRelease(value);
2745 return 0;
2747 } else {
2748 pid_t pid;
2749 int filedes[2];
2751 if (PLGetNumberOfElements(value) == 0)
2752 return 0;
2754 if (pipe(filedes) < 0) {
2755 wsyserror("pipe() failed:can't set workspace specific background image");
2757 PLRelease(value);
2758 return 0;
2761 pid = fork();
2762 if (pid < 0) {
2763 wsyserror("fork() failed:can't set workspace specific background image");
2764 if (close(filedes[0]) < 0)
2765 wsyserror("could not close pipe");
2766 if (close(filedes[1]) < 0)
2767 wsyserror("could not close pipe");
2769 } else if (pid == 0) {
2770 SetupEnvironment(scr);
2772 if (close(0) < 0)
2773 wsyserror("could not close pipe");
2774 if (dup(filedes[0]) < 0) {
2775 wsyserror("dup() failed:can't set workspace specific background image");
2777 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2778 wsyserror("could not execute wmsetbg");
2779 exit(1);
2780 } else {
2782 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2783 wsyserror("error setting close-on-exec flag");
2785 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2786 wsyserror("error setting close-on-exec flag");
2789 scr->helper_fd = filedes[1];
2790 scr->helper_pid = pid;
2791 scr->flags.backimage_helper_launched = 1;
2793 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2795 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2799 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2800 val = PLGetArrayElement(value, i);
2801 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2802 str = PLGetDescription(val);
2804 SendHelperMessage(scr, 'S', i+1, str);
2806 free(str);
2807 } else {
2808 SendHelperMessage(scr, 'U', i+1, NULL);
2811 sleep(1);
2813 PLRelease(value);
2814 return 0;
2818 static int
2819 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2820 void *bar)
2822 if (scr->flags.backimage_helper_launched) {
2823 char *str;
2825 if (PLGetNumberOfElements(value)==0) {
2826 SendHelperMessage(scr, 'U', 0, NULL);
2827 } else {
2828 /* set the default workspace background to this one */
2829 str = PLGetDescription(value);
2830 if (str) {
2831 SendHelperMessage(scr, 'S', 0, str);
2832 free(str);
2833 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2834 } else {
2835 SendHelperMessage(scr, 'U', 0, NULL);
2838 } else {
2839 char *command;
2840 char *text;
2842 SetupEnvironment(scr);
2843 text = PLGetDescription(value);
2844 command = wmalloc(strlen(text)+40);
2845 sprintf(command, "wmsetbg -d -p '%s' &", text);
2846 free(text);
2847 system(command);
2848 free(command);
2850 PLRelease(value);
2852 return 0;
2856 static int
2857 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2859 if (scr->widget_texture) {
2860 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2862 scr->widget_texture = *(WTexSolid**)texture;
2864 if (scr->geometry_display != None)
2865 XSetWindowBackground(dpy, scr->geometry_display,
2866 scr->widget_texture->normal.pixel);
2868 return 0;
2872 static int
2873 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2875 if (scr->window_title_texture[WS_FOCUSED]) {
2876 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2878 scr->window_title_texture[WS_FOCUSED] = *texture;
2880 return REFRESH_WINDOW_TEXTURES;
2884 static int
2885 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2887 if (scr->window_title_texture[WS_PFOCUSED]) {
2888 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2890 scr->window_title_texture[WS_PFOCUSED] = *texture;
2892 return REFRESH_WINDOW_TEXTURES;
2896 static int
2897 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2899 if (scr->window_title_texture[WS_UNFOCUSED]) {
2900 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2902 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2904 return REFRESH_WINDOW_TEXTURES;
2908 static int
2909 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2911 if (scr->resizebar_texture[0]) {
2912 wTextureDestroy(scr, scr->resizebar_texture[0]);
2914 scr->resizebar_texture[0] = *texture;
2916 return REFRESH_WINDOW_TEXTURES;
2920 static int
2921 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2923 if (scr->menu_title_texture[0]) {
2924 wTextureDestroy(scr, scr->menu_title_texture[0]);
2926 scr->menu_title_texture[0] = *texture;
2928 return REFRESH_MENU_TITLE_TEXTURE;
2932 static int
2933 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2935 if (scr->menu_item_texture) {
2936 wTextureDestroy(scr, scr->menu_item_texture);
2937 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2939 scr->menu_item_texture = *texture;
2941 scr->menu_item_auxtexture
2942 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2944 return REFRESH_MENU_TEXTURE;
2948 static int
2949 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
2951 WWindow *wwin;
2952 wKeyBindings[index] = *shortcut;
2954 wwin = scr->focused_window;
2956 while (wwin!=NULL) {
2957 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2959 if (!WFLAGP(wwin, no_bind_keys)) {
2960 wWindowSetKeyGrabs(wwin);
2962 wwin = wwin->prev;
2965 return 0;
2969 static int
2970 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2972 wArrangeIcons(scr, True);
2974 return 0;
2978 static int
2979 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2981 wScreenUpdateUsableArea(scr);
2983 return 0;
2987 static int
2988 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2990 return REFRESH_MENU_TEXTURE;
2995 static int
2996 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2998 return REFRESH_BUTTON_IMAGES;
3003 * Very ugly kluge.
3004 * Need access to the double click variables, so that all widgets in
3005 * wmaker panels will have the same dbl-click values.
3006 * TODO: figure a better way of dealing with it.
3008 #include "WINGsP.h"
3010 static int
3011 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3013 extern _WINGsConfiguration WINGsConfiguration;
3015 if (*value <= 0)
3016 *(int*)foo = 1;
3018 WINGsConfiguration.doubleClickDelay = *value;
3020 return 0;