cleaning up plugin code.
[wmaker-crm.git] / src / defaults.c
blob35eec188731e6a2981381e0ad872a3252bf61c52
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"
74 * Our own proplist reader parser. This one will not accept any
75 * syntax errors and is more descriptive in the error messages.
76 * It also doesn't seem to crash.
78 extern proplist_t ReadProplistFromFile(char *file);
81 /***** Global *****/
83 extern WDDomain *WDWindowMaker;
84 extern WDDomain *WDWindowAttributes;
85 extern WDDomain *WDRootMenu;
87 extern int wScreenCount;
90 extern proplist_t wDomainName;
91 extern proplist_t wAttributeDomainName;
93 extern WPreferences wPreferences;
95 extern WShortKey wKeyBindings[WKBD_LAST];
97 typedef struct {
98 char *key;
99 char *default_value;
100 void *extra_data;
101 void *addr;
102 int (*convert)();
103 int (*update)();
104 proplist_t plkey;
105 proplist_t plvalue; /* default value */
106 } WDefaultEntry;
109 /* used to map strings to integers */
110 typedef struct {
111 char *string;
112 short value;
113 char is_alias;
114 } WOptionEnumeration;
117 /* type converters */
118 static int getBool();
119 static int getInt();
120 static int getCoord();
121 #if 0
122 /* this is not used yet */
123 static int getString();
124 #endif
125 static int getPathList();
126 static int getEnum();
127 static int getTexture();
128 #ifdef DRAWSTRING_PLUGIN
129 static int getTextRenderer();
130 #endif
131 static int getWSBackground();
132 static int getWSSpecificBackground();
133 static int getFont();
134 static int getColor();
135 static int getKeybind();
136 static int getModMask();
137 #ifdef NEWSTUFF
138 static int getRImage();
139 #endif
142 /* value setting functions */
143 static int setJustify();
144 static int setIfDockPresent();
145 static int setStickyIcons();
147 static int setPositive();
149 static int setWidgetColor();
150 static int setIconTile();
151 static int setWinTitleFont();
152 static int setMenuTitleFont();
153 static int setMenuTextFont();
154 static int setIconTitleFont();
155 static int setIconTitleColor();
156 static int setIconTitleBack();
157 static int setDisplayFont();
158 static int setLargeDisplayFont();
159 static int setWTitleColor();
160 static int setFTitleBack();
161 static int setPTitleBack();
162 static int setUTitleBack();
163 static int setResizebarBack();
164 static int setWorkspaceBack();
165 static int setWorkspaceSpecificBack();
166 static int setMenuTitleColor();
167 static int setMenuTextColor();
168 static int setMenuDisabledColor();
169 static int setMenuTitleBack();
170 static int setMenuTextBack();
171 static int setHightlight();
172 static int setHightlightText();
173 static int setKeyGrab();
174 static int setDoubleClick();
175 static int setIconPosition();
177 static int setClipTitleFont();
178 static int setClipTitleColor();
180 static int setMenuStyle();
181 static int setMultiByte();
183 static int updateUsableArea();
188 * Tables to convert strings to enumeration values.
189 * Values stored are char
193 /* WARNING: sum of length of all value strings must not exceed
194 * this value */
195 #define TOTAL_VALUES_LENGTH 80
200 #define REFRESH_WINDOW_TEXTURES (1<<0)
201 #define REFRESH_MENU_TEXTURE (1<<1)
202 #define REFRESH_MENU_FONT (1<<2)
203 #define REFRESH_MENU_COLOR (1<<3)
204 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
205 #define REFRESH_MENU_TITLE_FONT (1<<5)
206 #define REFRESH_MENU_TITLE_COLOR (1<<6)
207 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
208 #define REFRESH_WINDOW_FONT (1<<8)
209 #define REFRESH_ICON_TILE (1<<9)
210 #define REFRESH_ICON_FONT (1<<10)
211 #define REFRESH_WORKSPACE_BACK (1<<11)
213 #define REFRESH_BUTTON_IMAGES (1<<12)
215 #define REFRESH_ICON_TITLE_COLOR (1<<13)
216 #define REFRESH_ICON_TITLE_BACK (1<<14)
220 static WOptionEnumeration seFocusModes[] = {
221 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
222 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
223 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
224 {NULL, 0, 0}
227 static WOptionEnumeration seColormapModes[] = {
228 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
229 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
230 {NULL, 0, 0}
233 static WOptionEnumeration sePlacements[] = {
234 {"Auto", WPM_SMART, 0}, {"Smart", WPM_SMART, 1},
235 {"Cascade", WPM_CASCADE, 0},
236 {"Random", WPM_RANDOM, 0},
237 {"Manual", WPM_MANUAL, 0},
238 {NULL, 0, 0}
241 static WOptionEnumeration seGeomDisplays[] = {
242 {"Center", WDIS_CENTER, 0},
243 {"Corner", WDIS_TOPLEFT, 0},
244 {"Floating", WDIS_FRAME_CENTER, 0},
245 {"Line", WDIS_NEW, 0},
246 {NULL, 0, 0}
249 static WOptionEnumeration seSpeeds[] = {
250 {"UltraFast", SPEED_ULTRAFAST, 0},
251 {"Fast", SPEED_FAST, 0},
252 {"Medium", SPEED_MEDIUM, 0},
253 {"Slow", SPEED_SLOW, 0},
254 {"UltraSlow", SPEED_ULTRASLOW, 0},
255 {NULL, 0, 0}
258 static WOptionEnumeration seMouseButtons[] = {
259 {"Left", Button1, 0}, {"Button1", Button1, 1},
260 {"Middle", Button2, 0}, {"Button2", Button2, 1},
261 {"Right", Button3, 0}, {"Button3", Button3, 1},
262 {"Button4", Button4, 0},
263 {"Button5", Button5, 0},
264 {NULL, 0, 0}
267 static WOptionEnumeration seIconificationStyles[] = {
268 {"Zoom", WIS_ZOOM, 0},
269 {"Twist", WIS_TWIST, 0},
270 {"Flip", WIS_FLIP, 0},
271 {"None", WIS_NONE, 0},
272 {"random", WIS_RANDOM, 0},
273 {NULL, 0, 0}
276 static WOptionEnumeration seJustifications[] = {
277 {"Left", WTJ_LEFT, 0},
278 {"Center", WTJ_CENTER, 0},
279 {"Right", WTJ_RIGHT, 0},
280 {NULL, 0, 0}
283 static WOptionEnumeration seIconPositions[] = {
284 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
285 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
286 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
287 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
288 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
289 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
290 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
291 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
292 {NULL, 0, 0}
295 static WOptionEnumeration seMenuStyles[] = {
296 {"normal", MS_NORMAL, 0},
297 {"singletexture", MS_SINGLE_TEXTURE, 0},
298 {"flat", MS_FLAT, 0},
299 {NULL, 0, 0}
303 static WOptionEnumeration seDisplayPositions[] = {
304 {"none", WD_NONE, 0},
305 {"center", WD_CENTER, 0},
306 {"top", WD_TOP, 0},
307 {"bottom", WD_BOTTOM, 0},
308 {"topleft", WD_TOPLEFT, 0},
309 {"topright", WD_TOPRIGHT, 0},
310 {"bottomleft", WD_BOTTOMLEFT, 0},
311 {"bottomright", WD_BOTTOMRIGHT, 0}
316 * ALL entries in the tables bellow, NEED to have a default value
317 * defined, and this value needs to be correct.
320 /* these options will only affect the window manager on startup
322 * static defaults can't access the screen data, because it is
323 * created after these defaults are read
325 WDefaultEntry staticOptionList[] = {
327 {"DisableDithering", "NO", NULL,
328 &wPreferences.no_dithering, getBool, NULL
330 {"ColormapSize", "4", NULL,
331 &wPreferences.cmap_size, getInt, NULL
333 /* static by laziness */
334 {"IconSize", "64", NULL,
335 &wPreferences.icon_size, getInt, NULL
337 {"ModifierKey", "Mod1", NULL,
338 &wPreferences.modifier_mask, getModMask, NULL
340 {"DisableWSMouseActions", "NO", NULL,
341 &wPreferences.disable_root_mouse, getBool, NULL
343 {"FocusMode", "manual", seFocusModes,
344 &wPreferences.focus_mode, getEnum, NULL
345 }, /* have a problem when switching from manual to sloppy without restart */
346 {"NewStyle", "NO", NULL,
347 &wPreferences.new_style, getBool, NULL
349 {"DisableDock", "NO", (void*) WM_DOCK,
350 NULL, getBool, setIfDockPresent
352 {"DisableClip", "NO", (void*) WM_CLIP,
353 NULL, getBool, setIfDockPresent
355 {"DisableMiniwindows", "NO", NULL,
356 &wPreferences.disable_miniwindows, getBool, NULL
358 {"MultiByteText", "NO", NULL,
359 &wPreferences.multi_byte_text, getBool, setMultiByte
365 WDefaultEntry optionList[] = {
366 /* dynamic options */
367 {"IconPosition", "blh", seIconPositions,
368 &wPreferences.icon_yard, getEnum, setIconPosition
370 {"IconificationStyle", "Zoom", seIconificationStyles,
371 &wPreferences.iconification_style, getEnum, NULL
373 {"SelectWindowsMouseButton", "Left", seMouseButtons,
374 &wPreferences.select_button, getEnum, NULL
376 {"WindowListMouseButton", "Middle", seMouseButtons,
377 &wPreferences.windowl_button, getEnum, NULL
379 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
380 &wPreferences.menu_button, getEnum, NULL
382 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
383 &wPreferences.pixmap_path, getPathList, NULL
385 {"IconPath", DEF_ICON_PATHS, NULL,
386 &wPreferences.icon_path, getPathList, NULL
388 {"ColormapMode", "auto", seColormapModes,
389 &wPreferences.colormap_mode, getEnum, NULL
391 {"AutoFocus", "NO", NULL,
392 &wPreferences.auto_focus, getBool, NULL
394 {"RaiseDelay", "0", NULL,
395 &wPreferences.raise_delay, getInt, NULL
397 {"CirculateRaise", "NO", NULL,
398 &wPreferences.circ_raise, getBool, NULL
400 {"Superfluous", "NO", NULL,
401 &wPreferences.superfluous, getBool, NULL
403 {"AdvanceToNewWorkspace", "NO", NULL,
404 &wPreferences.ws_advance, getBool, NULL
406 {"CycleWorkspaces", "NO", NULL,
407 &wPreferences.ws_cycle, getBool, NULL
409 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
410 &wPreferences.workspace_name_display_position, getEnum, NULL
412 {"StickyIcons", "NO", NULL,
413 &wPreferences.sticky_icons, getBool, setStickyIcons
415 {"SaveSessionOnExit", "NO", NULL,
416 &wPreferences.save_session_on_exit, getBool, NULL
418 {"WrapMenus", "NO", NULL,
419 &wPreferences.wrap_menus, getBool, NULL
421 {"ScrollableMenus", "NO", NULL,
422 &wPreferences.scrollable_menus, getBool, NULL
424 {"MenuScrollSpeed", "medium", seSpeeds,
425 &wPreferences.menu_scroll_speed, getEnum, NULL
427 {"IconSlideSpeed", "medium", seSpeeds,
428 &wPreferences.icon_slide_speed, getEnum, NULL
430 {"ShadeSpeed", "medium", seSpeeds,
431 &wPreferences.shade_speed, getEnum, NULL
433 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
434 &wPreferences.dblclick_time, getInt, setDoubleClick,
436 {"AlignSubmenus", "NO", NULL,
437 &wPreferences.align_menus, getBool, NULL
439 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
440 &wPreferences.open_transients_with_parent, getBool, NULL
442 {"WindowPlacement", "auto", sePlacements,
443 &wPreferences.window_placement, getEnum, NULL
445 {"IgnoreFocusClick","NO", NULL,
446 &wPreferences.ignore_focus_click, getBool, NULL
448 {"UseSaveUnders", "NO", NULL,
449 &wPreferences.use_saveunders, getBool, NULL
451 {"OpaqueMove", "NO", NULL,
452 &wPreferences.opaque_move, getBool, NULL
454 {"DisableSound", "NO", NULL,
455 &wPreferences.no_sound, getBool, NULL
457 {"DisableAnimations", "NO", NULL,
458 &wPreferences.no_animations, getBool, NULL
460 {"DontLinkWorkspaces","NO", NULL,
461 &wPreferences.no_autowrap, getBool, NULL
463 {"AutoArrangeIcons", "NO", NULL,
464 &wPreferences.auto_arrange_icons, getBool, NULL
466 {"NoWindowOverDock", "NO", NULL,
467 &wPreferences.no_window_over_dock, getBool, updateUsableArea
469 {"NoWindowOverIcons", "NO", NULL,
470 &wPreferences.no_window_over_icons, getBool, updateUsableArea
472 {"WindowPlaceOrigin", "(0, 0)", NULL,
473 &wPreferences.window_place_origin, getCoord, NULL
475 {"ResizeDisplay", "corner", seGeomDisplays,
476 &wPreferences.size_display, getEnum, NULL
478 {"MoveDisplay", "corner", seGeomDisplays,
479 &wPreferences.move_display, getEnum, NULL
481 {"DontConfirmKill", "NO", NULL,
482 &wPreferences.dont_confirm_kill, getBool,NULL
484 {"WindowTitleBalloons", "NO", NULL,
485 &wPreferences.window_balloon, getBool, NULL
487 {"MiniwindowTitleBalloons", "NO", NULL,
488 &wPreferences.miniwin_balloon,getBool, NULL
490 {"AppIconBalloons", "NO", NULL,
491 &wPreferences.appicon_balloon,getBool, NULL
493 {"HelpBalloons", "NO", NULL,
494 &wPreferences.help_balloon, getBool, NULL
496 {"EdgeResistance", "30", NULL,
497 &wPreferences.edge_resistance,getInt, NULL
499 {"Attraction", "NO", NULL,
500 &wPreferences.attract, getBool, NULL
502 {"DisableBlinking", "NO", NULL,
503 &wPreferences.dont_blink, getBool, NULL
505 #ifdef WEENDOZE_CYCLE
506 {"WindozeCycling","NO", NULL,
507 &wPreferences.windoze_cycling, getBool, NULL
509 {"PopupSwitchMenu","YES", NULL,
510 &wPreferences.popup_switchmenu, getBool, NULL
512 #endif /* WEENDOZE_CYCLE */
513 /* style options */
514 {"MenuStyle", "normal", seMenuStyles,
515 &wPreferences.menu_style, getEnum, setMenuStyle
517 {"WidgetColor", "(solid, gray)", NULL,
518 NULL, getTexture, setWidgetColor,
520 {"WorkspaceSpecificBack","()", NULL,
521 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
523 /* WorkspaceBack must come after WorkspaceSpecificBack or
524 * WorkspaceBack wont know WorkspaceSpecificBack was also
525 * specified and 2 copies of wmsetbg will be launched */
526 {"WorkspaceBack", "(solid, black)", NULL,
527 NULL, getWSBackground,setWorkspaceBack
529 {"SmoothWorkspaceBack", "NO", NULL,
530 NULL, getBool, NULL
532 {"IconBack", "(solid, gray)", NULL,
533 NULL, getTexture, setIconTile
535 {"TitleJustify", "center", seJustifications,
536 &wPreferences.title_justification, getEnum, setJustify
538 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
539 NULL, getFont, setWinTitleFont,
541 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
542 NULL, getFont, setMenuTitleFont
544 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
545 NULL, getFont, setMenuTextFont
547 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
548 NULL, getFont, setIconTitleFont
550 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
551 NULL, getFont, setClipTitleFont
553 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
554 NULL, getFont, setDisplayFont
556 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
557 NULL, getFont, setLargeDisplayFont
559 {"HighlightColor", "white", NULL,
560 NULL, getColor, setHightlight
562 {"HighlightTextColor", "black", NULL,
563 NULL, getColor, setHightlightText
565 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
566 NULL, getColor, setClipTitleColor
568 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
569 NULL, getColor, setClipTitleColor
571 #ifdef DRAWSTRING_PLUGIN
572 {"FTitleColor", "white", (void*)WS_FOCUSED,
573 NULL, getTextRenderer, setWTitleColor
575 {"PTitleColor", "white", (void*)WS_PFOCUSED,
576 NULL, getTextRenderer, setWTitleColor
578 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
579 NULL, getTextRenderer, setWTitleColor
581 #else
582 {"FTitleColor", "white", (void*)WS_FOCUSED,
583 NULL, getColor, setWTitleColor
585 {"PTitleColor", "white", (void*)WS_PFOCUSED,
586 NULL, getColor, setWTitleColor
588 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
589 NULL, getColor, setWTitleColor
591 #endif
592 {"FTitleBack", "(solid, black)", NULL,
593 NULL, getTexture, setFTitleBack
595 {"PTitleBack", "(solid, \"#616161\")", NULL,
596 NULL, getTexture, setPTitleBack
598 {"UTitleBack", "(solid, gray)", NULL,
599 NULL, getTexture, setUTitleBack
601 {"ResizebarBack", "(solid, gray)", NULL,
602 NULL, getTexture, setResizebarBack
604 #ifdef DRAWSTRING_PLUGIN
605 {"MenuTitleColor", "white", NULL,
606 NULL, getTextRenderer, setMenuTitleColor
608 #else
609 {"MenuTitleColor", "white", NULL,
610 NULL, getColor, setMenuTitleColor
612 #endif
613 {"MenuTextColor", "black", NULL,
614 NULL, getColor, setMenuTextColor
616 {"MenuDisabledColor", "\"#616161\"", NULL,
617 NULL, getColor, setMenuDisabledColor
619 {"MenuTitleBack", "(solid, black)", NULL,
620 NULL, getTexture, setMenuTitleBack
622 {"MenuTextBack", "(solid, gray)", NULL,
623 NULL, getTexture, setMenuTextBack
625 {"IconTitleColor", "white", NULL,
626 NULL, getColor, setIconTitleColor
628 {"IconTitleBack", "black", NULL,
629 NULL, getColor, setIconTitleBack
631 /* keybindings */
632 #ifndef LITE
633 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
634 NULL, getKeybind, setKeyGrab
636 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
637 NULL, getKeybind, setKeyGrab
639 #endif /* LITE */
640 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
641 NULL, getKeybind, setKeyGrab
643 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
644 NULL, getKeybind, setKeyGrab
646 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
647 NULL, getKeybind, setKeyGrab
649 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
650 NULL, getKeybind, setKeyGrab
652 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
653 NULL, getKeybind, setKeyGrab
655 {"HideKey", "None", (void*)WKBD_HIDE,
656 NULL, getKeybind, setKeyGrab
658 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
659 NULL, getKeybind, setKeyGrab
661 {"CloseKey", "None", (void*)WKBD_CLOSE,
662 NULL, getKeybind, setKeyGrab
664 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
665 NULL, getKeybind, setKeyGrab
667 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
668 NULL, getKeybind, setKeyGrab
670 {"RaiseKey", "Meta+Up", (void*)WKBD_RAISE,
671 NULL, getKeybind, setKeyGrab
673 {"LowerKey", "Meta+Down", (void*)WKBD_LOWER,
674 NULL, getKeybind, setKeyGrab
676 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
677 NULL, getKeybind, setKeyGrab
679 {"ShadeKey", "None", (void*)WKBD_SHADE,
680 NULL, getKeybind, setKeyGrab
682 {"SelectKey", "None", (void*)WKBD_SELECT,
683 NULL, getKeybind, setKeyGrab
685 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
686 NULL, getKeybind, setKeyGrab
688 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
689 NULL, getKeybind, setKeyGrab
691 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
692 NULL, getKeybind, setKeyGrab
694 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
695 NULL, getKeybind, setKeyGrab
697 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
698 NULL, getKeybind, setKeyGrab
700 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
701 NULL, getKeybind, setKeyGrab
703 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
704 NULL, getKeybind, setKeyGrab
706 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
707 NULL, getKeybind, setKeyGrab
709 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
710 NULL, getKeybind, setKeyGrab
712 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
713 NULL, getKeybind, setKeyGrab
715 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
716 NULL, getKeybind, setKeyGrab
718 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
719 NULL, getKeybind, setKeyGrab
721 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
722 NULL, getKeybind, setKeyGrab
724 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
725 NULL, getKeybind, setKeyGrab
727 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
728 NULL, getKeybind, setKeyGrab
730 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
731 NULL, getKeybind, setKeyGrab
733 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
734 NULL, getKeybind, setKeyGrab
736 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
737 NULL, getKeybind, setKeyGrab
739 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
740 NULL, getKeybind, setKeyGrab
742 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
743 NULL, getKeybind, setKeyGrab
745 #ifdef EXTEND_WINDOWSHORTCUT
746 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
747 NULL, getKeybind, setKeyGrab
749 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
750 NULL, getKeybind, setKeyGrab
752 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
753 NULL, getKeybind, setKeyGrab
755 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
756 NULL, getKeybind, setKeyGrab
758 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
759 NULL, getKeybind, setKeyGrab
761 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
762 NULL, getKeybind, setKeyGrab
764 #endif /* EXTEND_WINDOWSHORTCUT */
766 #ifdef KEEP_XKB_LOCK_STATUS
767 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
768 NULL, getKeybind, setKeyGrab
770 {"KbdModeLock", "NO", NULL,
771 &wPreferences.modelock, getBool, NULL
773 #endif /* KEEP_XKB_LOCK_STATUS */
777 #if 0
778 static void rereadDefaults(void);
779 #endif
781 #if 0
782 static void
783 rereadDefaults(void)
785 /* must defer the update because accessing X data from a
786 * signal handler can mess up Xlib */
789 #endif
791 static void
792 initDefaults()
794 int i;
795 WDefaultEntry *entry;
797 PLSetStringCmpHook(StringCompareHook);
799 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
800 entry = &optionList[i];
802 entry->plkey = PLMakeString(entry->key);
803 if (entry->default_value)
804 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
805 else
806 entry->plvalue = NULL;
809 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
810 entry = &staticOptionList[i];
812 entry->plkey = PLMakeString(entry->key);
813 if (entry->default_value)
814 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
815 else
816 entry->plvalue = NULL;
820 wDomainName = PLMakeString(WMDOMAIN_NAME);
821 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
823 PLRegister(wDomainName, rereadDefaults);
824 PLRegister(wAttributeDomainName, rereadDefaults);
831 #if 0
832 proplist_t
833 wDefaultsInit(int screen_number)
835 static int defaults_inited = 0;
836 proplist_t dict;
838 if (!defaults_inited) {
839 initDefaults();
842 dict = PLGetDomain(wDomainName);
843 if (!dict) {
844 wwarning(_("could not read domain \"%s\" from defaults database"),
845 PLGetString(wDomainName));
848 return dict;
850 #endif
853 void
854 wDefaultsDestroyDomain(WDDomain *domain)
856 if (domain->dictionary)
857 PLRelease(domain->dictionary);
858 free(domain->path);
859 free(domain);
863 WDDomain*
864 wDefaultsInitDomain(char *domain, Bool requireDictionary)
866 WDDomain *db;
867 struct stat stbuf;
868 static int inited = 0;
869 char path[PATH_MAX];
870 char *the_path;
871 proplist_t shared_dict=NULL;
873 if (!inited) {
874 inited = 1;
875 initDefaults();
878 db = wmalloc(sizeof(WDDomain));
879 memset(db, 0, sizeof(WDDomain));
880 db->domain_name = domain;
881 db->path = wdefaultspathfordomain(domain);
882 the_path = db->path;
884 if (the_path && stat(the_path, &stbuf)>=0) {
885 db->dictionary = ReadProplistFromFile(the_path);
886 if (db->dictionary) {
887 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
888 PLRelease(db->dictionary);
889 db->dictionary = NULL;
890 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
891 domain, the_path);
893 db->timestamp = stbuf.st_mtime;
894 } else {
895 wwarning(_("could not load domain %s from user defaults database"),
896 domain);
900 /* global system dictionary */
901 sprintf(path, "%s/%s", SYSCONFDIR, domain);
902 if (stat(path, &stbuf)>=0) {
903 shared_dict = ReadProplistFromFile(path);
904 if (shared_dict) {
905 if (requireDictionary && !PLIsDictionary(shared_dict)) {
906 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
907 domain, path);
908 PLRelease(shared_dict);
909 shared_dict = NULL;
910 } else {
911 if (db->dictionary && PLIsDictionary(shared_dict) &&
912 PLIsDictionary(db->dictionary)) {
913 PLMergeDictionaries(shared_dict, db->dictionary);
914 PLRelease(db->dictionary);
915 db->dictionary = shared_dict;
916 if (stbuf.st_mtime > db->timestamp)
917 db->timestamp = stbuf.st_mtime;
918 } else if (!db->dictionary) {
919 db->dictionary = shared_dict;
920 if (stbuf.st_mtime > db->timestamp)
921 db->timestamp = stbuf.st_mtime;
924 } else {
925 wwarning(_("could not load domain %s from global defaults database"),
926 domain);
930 /* set to save it in user's directory, no matter from where it was read */
931 if (db->dictionary) {
932 proplist_t tmp = PLMakeString(db->path);
934 PLSetFilename(db->dictionary, tmp);
935 PLRelease(tmp);
938 return db;
942 void
943 wReadStaticDefaults(proplist_t dict)
945 proplist_t plvalue;
946 WDefaultEntry *entry;
947 int i;
948 void *tdata;
951 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
952 entry = &staticOptionList[i];
954 if (dict)
955 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
956 else
957 plvalue = NULL;
959 if (!plvalue) {
960 /* no default in the DB. Use builtin default */
961 plvalue = entry->plvalue;
964 if (plvalue) {
965 /* convert data */
966 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
967 if (entry->update) {
968 (*entry->update)(NULL, entry, tdata, entry->extra_data);
975 void
976 wDefaultsCheckDomains(void *foo)
978 WScreen *scr;
979 struct stat stbuf;
980 proplist_t dict;
981 int i;
982 char path[PATH_MAX];
984 #ifdef HEARTBEAT
985 puts("Checking domains...");
986 #endif
987 if (stat(WDWindowMaker->path, &stbuf)>=0
988 && WDWindowMaker->timestamp < stbuf.st_mtime) {
989 proplist_t shared_dict = NULL;
990 #ifdef HEARTBEAT
991 puts("Checking WindowMaker domain");
992 #endif
993 WDWindowMaker->timestamp = stbuf.st_mtime;
995 /* global dictionary */
996 sprintf(path, "%s/WindowMaker", SYSCONFDIR);
997 if (stat(path, &stbuf)>=0) {
998 shared_dict = ReadProplistFromFile(path);
999 if (shared_dict && !PLIsDictionary(shared_dict)) {
1000 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1001 "WindowMaker", path);
1002 PLRelease(shared_dict);
1003 shared_dict = NULL;
1004 } else if (!shared_dict) {
1005 wwarning(_("could not load domain %s from global defaults database"),
1006 "WindowMaker");
1009 /* user dictionary */
1010 dict = ReadProplistFromFile(WDWindowMaker->path);
1011 if (dict) {
1012 if (!PLIsDictionary(dict)) {
1013 PLRelease(dict);
1014 dict = NULL;
1015 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1016 "WindowMaker", WDWindowMaker->path);
1017 } else {
1018 if (shared_dict) {
1019 PLSetFilename(shared_dict, PLGetFilename(dict));
1020 PLMergeDictionaries(shared_dict, dict);
1021 PLRelease(dict);
1022 dict = shared_dict;
1023 shared_dict = NULL;
1025 for (i=0; i<wScreenCount; i++) {
1026 scr = wScreenWithNumber(i);
1027 if (scr)
1028 wReadDefaults(scr, dict);
1030 if (WDWindowMaker->dictionary) {
1031 PLRelease(WDWindowMaker->dictionary);
1033 WDWindowMaker->dictionary = dict;
1035 } else {
1036 wwarning(_("could not load domain %s from user defaults database"),
1037 "WindowMaker");
1039 if (shared_dict) {
1040 PLRelease(shared_dict);
1044 if (stat(WDWindowAttributes->path, &stbuf)>=0
1045 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1046 #ifdef HEARTBEAT
1047 puts("Checking WMWindowAttributes domain");
1048 #endif
1049 dict = ReadProplistFromFile(WDWindowAttributes->path);
1050 if (dict) {
1051 if (!PLIsDictionary(dict)) {
1052 PLRelease(dict);
1053 dict = NULL;
1054 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1055 "WMWindowAttributes", WDWindowAttributes->path);
1056 } else {
1057 if (WDWindowAttributes->dictionary)
1058 PLRelease(WDWindowAttributes->dictionary);
1059 WDWindowAttributes->dictionary = dict;
1060 for (i=0; i<wScreenCount; i++) {
1061 scr = wScreenWithNumber(i);
1062 if (scr)
1063 wDefaultUpdateIcons(scr);
1066 } else {
1067 wwarning(_("could not load domain %s from user defaults database"),
1068 "WMWindowAttributes");
1070 WDWindowAttributes->timestamp = stbuf.st_mtime;
1073 #ifndef LITE
1074 if (stat(WDRootMenu->path, &stbuf)>=0
1075 && WDRootMenu->timestamp < stbuf.st_mtime) {
1076 dict = ReadProplistFromFile(WDRootMenu->path);
1077 #ifdef HEARTBEAT
1078 puts("Checking WMRootMenu domain");
1079 #endif
1080 if (dict) {
1081 if (!PLIsArray(dict) && !PLIsString(dict)) {
1082 PLRelease(dict);
1083 dict = NULL;
1084 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1085 "WMRootMenu", WDRootMenu->path);
1086 } else {
1087 if (WDRootMenu->dictionary) {
1088 PLRelease(WDRootMenu->dictionary);
1090 WDRootMenu->dictionary = dict;
1092 } else {
1093 wwarning(_("could not load domain %s from user defaults database"),
1094 "WMRootMenu");
1096 WDRootMenu->timestamp = stbuf.st_mtime;
1098 #endif /* !LITE */
1100 if (!foo)
1101 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1105 void
1106 wReadDefaults(WScreen *scr, proplist_t new_dict)
1108 proplist_t plvalue, old_value;
1109 WDefaultEntry *entry;
1110 int i, must_update;
1111 int needs_refresh;
1112 void *tdata;
1113 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1114 ? WDWindowMaker->dictionary : NULL);
1116 must_update = 0;
1118 needs_refresh = 0;
1120 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1121 entry = &optionList[i];
1123 if (new_dict)
1124 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1125 else
1126 plvalue = NULL;
1128 if (!old_dict)
1129 old_value = NULL;
1130 else
1131 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1134 if (!plvalue && !old_value) {
1135 /* no default in the DB. Use builtin default */
1136 plvalue = entry->plvalue;
1137 if (plvalue && new_dict) {
1138 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1139 must_update = 1;
1141 } else if (!plvalue) {
1142 /* value was deleted from DB. Keep current value */
1143 continue;
1144 } else if (!old_value) {
1145 /* set value for the 1st time */
1146 } else if (!PLIsEqual(plvalue, old_value)) {
1147 /* value has changed */
1148 } else {
1149 /* value was not changed since last time */
1150 continue;
1153 if (plvalue) {
1154 #ifdef DEBUG
1155 printf("Updating %s to %s\n", entry->key, PLGetDescription(plvalue));
1156 #endif
1157 /* convert data */
1158 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1159 if (entry->update) {
1160 needs_refresh |=
1161 (*entry->update)(scr, entry, tdata, entry->extra_data);
1167 if (needs_refresh!=0 && !scr->flags.startup) {
1168 int foo;
1170 foo = 0;
1171 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1172 foo |= WTextureSettings;
1173 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1174 foo |= WFontSettings;
1175 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1176 foo |= WColorSettings;
1177 if (foo)
1178 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1179 (void*)foo);
1181 foo = 0;
1182 if (needs_refresh & REFRESH_MENU_TEXTURE)
1183 foo |= WTextureSettings;
1184 if (needs_refresh & REFRESH_MENU_FONT)
1185 foo |= WFontSettings;
1186 if (needs_refresh & REFRESH_MENU_COLOR)
1187 foo |= WColorSettings;
1188 if (foo)
1189 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1190 (void*)foo);
1192 foo = 0;
1193 if (needs_refresh & REFRESH_WINDOW_FONT) {
1194 foo |= WFontSettings;
1196 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1197 foo |= WTextureSettings;
1199 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1200 foo |= WColorSettings;
1202 if (foo)
1203 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1204 (void*)foo);
1206 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1207 foo = 0;
1208 if (needs_refresh & REFRESH_ICON_FONT) {
1209 foo |= WFontSettings;
1211 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1212 foo |= WTextureSettings;
1214 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1215 foo |= WTextureSettings;
1217 if (foo)
1218 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1219 (void*)foo);
1221 if (needs_refresh & REFRESH_ICON_TILE)
1222 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1227 void
1228 wDefaultUpdateIcons(WScreen *scr)
1230 WAppIcon *aicon = scr->app_icon_list;
1231 WWindow *wwin = scr->focused_window;
1232 char *file;
1234 while(aicon) {
1235 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1236 False);
1237 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1238 || (file && !aicon->icon->file)) {
1239 RImage *new_image;
1241 if (aicon->icon->file)
1242 free(aicon->icon->file);
1243 aicon->icon->file = wstrdup(file);
1245 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1246 aicon->wm_class);
1247 if (new_image) {
1248 wIconChangeImage(aicon->icon, new_image);
1249 wAppIconPaint(aicon);
1252 aicon = aicon->next;
1255 if (!wPreferences.flags.noclip)
1256 wClipIconPaint(scr->clip_icon);
1258 while (wwin) {
1259 if (wwin->icon && wwin->flags.miniaturized) {
1260 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1261 False);
1262 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1263 || (file && !wwin->icon->file)) {
1264 RImage *new_image;
1266 if (wwin->icon->file)
1267 free(wwin->icon->file);
1268 wwin->icon->file = wstrdup(file);
1270 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1271 wwin->wm_class);
1272 if (new_image)
1273 wIconChangeImage(wwin->icon, new_image);
1276 wwin = wwin->prev;
1281 /* --------------------------- Local ----------------------- */
1283 #define STRINGP(x) if (!PLIsString(value)) { \
1284 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1285 entry->key, x); \
1286 return False; }
1290 static int
1291 string2index(proplist_t key, proplist_t val, proplist_t def,
1292 WOptionEnumeration *values)
1294 char *str;
1295 WOptionEnumeration *v;
1296 char buffer[TOTAL_VALUES_LENGTH];
1298 if (PLIsString(val) && (str = PLGetString(val))) {
1299 for (v=values; v->string!=NULL; v++) {
1300 if (strcasecmp(v->string, str)==0)
1301 return v->value;
1305 buffer[0] = 0;
1306 for (v=values; v->string!=NULL; v++) {
1307 if (!v->is_alias) {
1308 if (buffer[0]!=0)
1309 strcat(buffer, ", ");
1310 strcat(buffer, v->string);
1313 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1314 PLGetString(key), buffer);
1316 if (def) {
1317 return string2index(key, val, NULL, values);
1320 return -1;
1327 * value - is the value in the defaults DB
1328 * addr - is the address to store the data
1329 * ret - is the address to store a pointer to a temporary buffer. ret
1330 * must not be freed and is used by the set functions
1332 static int
1333 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1334 void **ret)
1336 static char data;
1337 char *val;
1338 int second_pass=0;
1340 STRINGP("Boolean");
1342 val = PLGetString(value);
1344 again:
1345 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1346 || strcasecmp(val, "YES")==0) {
1348 data = 1;
1349 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1350 || strcasecmp(val, "NO")==0) {
1351 data = 0;
1352 } else {
1353 int i;
1354 if (sscanf(val, "%i", &i)==1) {
1355 if (i!=0)
1356 data = 1;
1357 else
1358 data = 0;
1359 } else {
1360 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1361 val, entry->key);
1362 if (second_pass==0) {
1363 val = PLGetString(entry->plvalue);
1364 second_pass = 1;
1365 wwarning(_("using default \"%s\" instead"), val);
1366 goto again;
1368 return False;
1372 if (ret)
1373 *ret = &data;
1375 if (addr) {
1376 *(char*)addr = data;
1379 return True;
1383 static int
1384 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1385 void **ret)
1387 static int data;
1388 char *val;
1391 STRINGP("Integer");
1393 val = PLGetString(value);
1395 if (sscanf(val, "%i", &data)!=1) {
1396 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1397 val, entry->key);
1398 val = PLGetString(entry->plvalue);
1399 wwarning(_("using default \"%s\" instead"), val);
1400 if (sscanf(val, "%i", &data)!=1) {
1401 return False;
1405 if (ret)
1406 *ret = &data;
1408 if (addr) {
1409 *(int*)addr = data;
1411 return True;
1415 static int
1416 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1417 void **ret)
1419 static WCoord data;
1420 char *val_x, *val_y;
1421 int nelem, changed=0;
1422 proplist_t elem_x, elem_y;
1424 again:
1425 if (!PLIsArray(value)) {
1426 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1427 entry->key, "Coordinate");
1428 if (changed==0) {
1429 value = entry->plvalue;
1430 changed = 1;
1431 wwarning(_("using default \"%s\" instead"), entry->default_value);
1432 goto again;
1434 return False;
1437 nelem = PLGetNumberOfElements(value);
1438 if (nelem != 2) {
1439 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1440 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 elem_x = PLGetArrayElement(value, 0);
1451 elem_y = PLGetArrayElement(value, 1);
1453 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1454 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1455 entry->key);
1456 if (changed==0) {
1457 value = entry->plvalue;
1458 changed = 1;
1459 wwarning(_("using default \"%s\" instead"), entry->default_value);
1460 goto again;
1462 return False;
1465 val_x = PLGetString(elem_x);
1466 val_y = PLGetString(elem_y);
1468 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1469 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1470 if (changed==0) {
1471 value = entry->plvalue;
1472 changed = 1;
1473 wwarning(_("using default \"%s\" instead"), entry->default_value);
1474 goto again;
1476 return False;
1479 if (data.x < 0)
1480 data.x = 0;
1481 else if (data.x > scr->scr_width/3)
1482 data.x = scr->scr_width/3;
1483 if (data.y < 0)
1484 data.y = 0;
1485 else if (data.y > scr->scr_height/3)
1486 data.y = scr->scr_height/3;
1488 if (ret)
1489 *ret = &data;
1491 if (addr) {
1492 *(WCoord*)addr = data;
1495 return True;
1499 #if 0
1500 /* This function is not used at the moment. */
1501 static int
1502 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1503 void **ret)
1505 static char *data;
1507 STRINGP("String");
1509 data = PLGetString(value);
1511 if (!data) {
1512 data = PLGetString(entry->plvalue);
1513 if (!data)
1514 return False;
1517 if (ret)
1518 *ret = &data;
1520 if (addr)
1521 *(char**)addr = wstrdup(data);
1523 return True;
1525 #endif
1528 static int
1529 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1530 void **ret)
1532 static char *data;
1533 int i, count, len;
1534 char *ptr;
1535 proplist_t d;
1536 int changed=0;
1538 again:
1539 if (!PLIsArray(value)) {
1540 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1541 entry->key, "an array of paths");
1542 if (changed==0) {
1543 value = entry->plvalue;
1544 changed = 1;
1545 wwarning(_("using default \"%s\" instead"), entry->default_value);
1546 goto again;
1548 return False;
1551 i = 0;
1552 count = PLGetNumberOfElements(value);
1553 if (count < 1) {
1554 if (changed==0) {
1555 value = entry->plvalue;
1556 changed = 1;
1557 wwarning(_("using default \"%s\" instead"), entry->default_value);
1558 goto again;
1560 return False;
1563 len = 0;
1564 for (i=0; i<count; i++) {
1565 d = PLGetArrayElement(value, i);
1566 if (!d || !PLIsString(d)) {
1567 count = i;
1568 break;
1570 len += strlen(PLGetString(d))+1;
1573 ptr = data = wmalloc(len+1);
1575 for (i=0; i<count; i++) {
1576 d = PLGetArrayElement(value, i);
1577 if (!d || !PLIsString(d)) {
1578 break;
1580 strcpy(ptr, PLGetString(d));
1581 ptr += strlen(PLGetString(d));
1582 *ptr = ':';
1583 ptr++;
1585 ptr--; *(ptr--) = 0;
1587 if (*(char**)addr!=NULL) {
1588 free(*(char**)addr);
1590 *(char**)addr = data;
1592 return True;
1596 static int
1597 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1598 void **ret)
1600 static signed char data;
1602 data = string2index(entry->plkey, value, entry->default_value,
1603 (WOptionEnumeration*)entry->extra_data);
1604 if (data < 0)
1605 return False;
1607 if (ret)
1608 *ret = &data;
1610 if (addr)
1611 *(signed char*)addr = data;
1613 return True;
1619 * (solid <color>)
1620 * (hgradient <color> <color>)
1621 * (vgradient <color> <color>)
1622 * (dgradient <color> <color>)
1623 * (mhgradient <color> <color> ...)
1624 * (mvgradient <color> <color> ...)
1625 * (tpixmap <file> <color>)
1626 * (spixmap <file> <color>)
1627 * (cpixmap <file> <color>)
1628 * (thgradient <file> <opaqueness> <color> <color>)
1629 * (tvgradient <file> <opaqueness> <color> <color>)
1630 * (tdgradient <file> <opaqueness> <color> <color>)
1631 * (function <lib> <function> ...)
1634 static WTexture*
1635 parse_texture(WScreen *scr, proplist_t pl)
1637 proplist_t elem;
1638 char *val;
1639 int nelem;
1640 WTexture *texture=NULL;
1642 nelem = PLGetNumberOfElements(pl);
1643 if (nelem < 1)
1644 return NULL;
1647 elem = PLGetArrayElement(pl, 0);
1648 if (!elem || !PLIsString(elem))
1649 return NULL;
1650 val = PLGetString(elem);
1653 if (strcasecmp(val, "solid")==0) {
1654 XColor color;
1656 if (nelem != 2)
1657 return NULL;
1659 /* get color */
1661 elem = PLGetArrayElement(pl, 1);
1662 if (!elem || !PLIsString(elem))
1663 return NULL;
1664 val = PLGetString(elem);
1666 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1667 wwarning(_("\"%s\" is not a valid color name"), val);
1668 return NULL;
1671 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1672 } else if (strcasecmp(val, "dgradient")==0
1673 || strcasecmp(val, "vgradient")==0
1674 || strcasecmp(val, "hgradient")==0) {
1675 RColor color1, color2;
1676 XColor xcolor;
1677 int type;
1679 if (nelem != 3) {
1680 wwarning(_("bad number of arguments in gradient specification"));
1681 return NULL;
1684 if (val[0]=='d' || val[0]=='D')
1685 type = WTEX_DGRADIENT;
1686 else if (val[0]=='h' || val[0]=='H')
1687 type = WTEX_HGRADIENT;
1688 else
1689 type = WTEX_VGRADIENT;
1692 /* get from color */
1693 elem = PLGetArrayElement(pl, 1);
1694 if (!elem || !PLIsString(elem))
1695 return NULL;
1696 val = PLGetString(elem);
1698 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1699 wwarning(_("\"%s\" is not a valid color name"), val);
1700 return NULL;
1702 color1.alpha = 255;
1703 color1.red = xcolor.red >> 8;
1704 color1.green = xcolor.green >> 8;
1705 color1.blue = xcolor.blue >> 8;
1707 /* get to color */
1708 elem = PLGetArrayElement(pl, 2);
1709 if (!elem || !PLIsString(elem)) {
1710 return NULL;
1712 val = PLGetString(elem);
1714 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1715 wwarning(_("\"%s\" is not a valid color name"), val);
1716 return NULL;
1718 color2.alpha = 255;
1719 color2.red = xcolor.red >> 8;
1720 color2.green = xcolor.green >> 8;
1721 color2.blue = xcolor.blue >> 8;
1723 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1725 } else if (strcasecmp(val, "mhgradient")==0
1726 || strcasecmp(val, "mvgradient")==0
1727 || strcasecmp(val, "mdgradient")==0) {
1728 XColor color;
1729 RColor **colors;
1730 int i, count;
1731 int type;
1733 if (nelem < 3) {
1734 wwarning(_("too few arguments in multicolor gradient specification"));
1735 return NULL;
1738 if (val[1]=='h' || val[1]=='H')
1739 type = WTEX_MHGRADIENT;
1740 else if (val[1]=='v' || val[1]=='V')
1741 type = WTEX_MVGRADIENT;
1742 else
1743 type = WTEX_MDGRADIENT;
1745 count = nelem-1;
1747 colors = wmalloc(sizeof(RColor*)*(count+1));
1749 for (i=0; i<count; i++) {
1750 elem = PLGetArrayElement(pl, i+1);
1751 if (!elem || !PLIsString(elem)) {
1752 for (--i; i>=0; --i) {
1753 free(colors[i]);
1755 free(colors);
1756 return NULL;
1758 val = PLGetString(elem);
1760 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1761 wwarning(_("\"%s\" is not a valid color name"), val);
1762 for (--i; i>=0; --i) {
1763 free(colors[i]);
1765 free(colors);
1766 return NULL;
1767 } else {
1768 colors[i] = wmalloc(sizeof(RColor));
1769 colors[i]->red = color.red >> 8;
1770 colors[i]->green = color.green >> 8;
1771 colors[i]->blue = color.blue >> 8;
1774 colors[i] = NULL;
1776 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1777 } else if (strcasecmp(val, "spixmap")==0 ||
1778 strcasecmp(val, "cpixmap")==0 ||
1779 strcasecmp(val, "tpixmap")==0) {
1780 XColor color;
1781 int type;
1783 if (nelem != 3)
1784 return NULL;
1786 if (val[0] == 's' || val[0] == 'S')
1787 type = WTP_SCALE;
1788 else if (val[0] == 'c' || val[0] == 'C')
1789 type = WTP_CENTER;
1790 else
1791 type = WTP_TILE;
1793 /* get color */
1794 elem = PLGetArrayElement(pl, 2);
1795 if (!elem || !PLIsString(elem)) {
1796 return NULL;
1798 val = PLGetString(elem);
1800 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1801 wwarning(_("\"%s\" is not a valid color name"), val);
1802 return NULL;
1805 /* file name */
1806 elem = PLGetArrayElement(pl, 1);
1807 if (!elem || !PLIsString(elem))
1808 return NULL;
1809 val = PLGetString(elem);
1811 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1812 } else if (strcasecmp(val, "thgradient")==0
1813 || strcasecmp(val, "tvgradient")==0
1814 || strcasecmp(val, "tdgradient")==0) {
1815 RColor color1, color2;
1816 XColor xcolor;
1817 int opacity;
1818 int style;
1820 if (val[1]=='h' || val[1]=='H')
1821 style = WTEX_THGRADIENT;
1822 else if (val[1]=='v' || val[1]=='V')
1823 style = WTEX_TVGRADIENT;
1824 else
1825 style = WTEX_TDGRADIENT;
1827 if (nelem != 5) {
1828 wwarning(_("bad number of arguments in textured gradient specification"));
1829 return NULL;
1832 /* get from color */
1833 elem = PLGetArrayElement(pl, 3);
1834 if (!elem || !PLIsString(elem))
1835 return NULL;
1836 val = PLGetString(elem);
1838 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1839 wwarning(_("\"%s\" is not a valid color name"), val);
1840 return NULL;
1842 color1.alpha = 255;
1843 color1.red = xcolor.red >> 8;
1844 color1.green = xcolor.green >> 8;
1845 color1.blue = xcolor.blue >> 8;
1847 /* get to color */
1848 elem = PLGetArrayElement(pl, 4);
1849 if (!elem || !PLIsString(elem)) {
1850 return NULL;
1852 val = PLGetString(elem);
1854 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1855 wwarning(_("\"%s\" is not a valid color name"), val);
1856 return NULL;
1858 color2.alpha = 255;
1859 color2.red = xcolor.red >> 8;
1860 color2.green = xcolor.green >> 8;
1861 color2.blue = xcolor.blue >> 8;
1863 /* get opacity */
1864 elem = PLGetArrayElement(pl, 2);
1865 if (!elem || !PLIsString(elem))
1866 opacity = 128;
1867 else
1868 val = PLGetString(elem);
1870 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1871 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1872 opacity = 128;
1875 /* get file name */
1876 elem = PLGetArrayElement(pl, 1);
1877 if (!elem || !PLIsString(elem))
1878 return NULL;
1879 val = PLGetString(elem);
1881 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1882 val, opacity);
1884 #ifdef TEXTURE_PLUGIN
1885 else if (strcasecmp(val, "function")==0) {
1886 WTexFunction *function;
1887 void (*initFunc) (Display *, Colormap);
1888 char *lib, *func, **argv;
1889 int i, argc;
1891 if (nelem < 3)
1892 return NULL;
1894 /* get the library name */
1895 elem = PLGetArrayElement(pl, 1);
1896 if (!elem || !PLIsString(elem)) {
1897 return NULL;
1899 lib = PLGetString(elem);
1901 /* get the function name */
1902 elem = PLGetArrayElement(pl, 2);
1903 if (!elem || !PLIsString(elem)) {
1904 return NULL;
1906 func = PLGetString(elem);
1908 argc = nelem - 2;
1909 argv = (char **)wmalloc(argc * sizeof(char *));
1911 /* get the parameters */
1912 argv[0] = wstrdup(func);
1913 for (i = 0; i < argc - 1; i++) {
1914 elem = PLGetArrayElement(pl, 3 + i);
1915 if (!elem || !PLIsString(elem)) {
1916 free(argv);
1918 return NULL;
1920 argv[i+1] = wstrdup(PLGetString(elem));
1923 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1925 #ifdef HAVE_DLFCN_H
1926 if (function) {
1927 initFunc = dlsym(function->handle, "initWindowMaker");
1928 if (initFunc) {
1929 initFunc(dpy, scr->w_colormap);
1930 } else {
1931 wwarning(_("could not initialize library %s"), lib);
1933 } else {
1934 wwarning(_("could not find function %s::%s"), lib, func);
1936 #endif /* HAVE_DLFCN_H */
1937 texture = (WTexture*)function;
1939 #endif /* TEXTURE_PLUGIN */
1940 else {
1941 wwarning(_("invalid texture type %s"), val);
1942 return NULL;
1944 return texture;
1949 static int
1950 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1951 void **ret)
1953 static WTexture *texture;
1954 int changed=0;
1956 again:
1957 if (!PLIsArray(value)) {
1958 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1959 entry->key, "Texture");
1960 if (changed==0) {
1961 value = entry->plvalue;
1962 changed = 1;
1963 wwarning(_("using default \"%s\" instead"), entry->default_value);
1964 goto again;
1966 return False;
1969 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1970 proplist_t pl;
1972 pl = PLGetArrayElement(value, 0);
1973 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1974 || strcasecmp(PLGetString(pl), "solid")!=0) {
1975 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1976 entry->key, "Solid Texture");
1978 value = entry->plvalue;
1979 changed = 1;
1980 wwarning(_("using default \"%s\" instead"), entry->default_value);
1981 goto again;
1985 texture = parse_texture(scr, value);
1987 if (!texture) {
1988 wwarning(_("Error in texture specification for key \"%s\""),
1989 entry->key);
1990 if (changed==0) {
1991 value = entry->plvalue;
1992 changed = 1;
1993 wwarning(_("using default \"%s\" instead"), entry->default_value);
1994 goto again;
1996 return False;
1999 if (ret)
2000 *ret = &texture;
2002 if (addr)
2003 *(WTexture**)addr = texture;
2005 return True;
2010 #ifdef DRAWSTRING_PLUGIN
2011 static int
2012 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2013 void *addr, void **ret)
2015 proplist_t elem;
2016 char *val, *lib, *func, **argv;
2017 int argc, i, changed;
2019 if (strcmp(entry->key, "FTitleColor")==0) {
2020 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2021 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2022 } else if (strcmp(entry->key, "UTitleColor")==0) {
2023 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2024 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2025 } else if (strcmp(entry->key, "PTitleColor")==0) {
2026 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2027 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2028 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2029 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2030 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2031 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2032 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2033 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2036 if (PLIsArray(value)) {
2037 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2038 argc -= 2;
2039 argv = (char **)wmalloc(argc * sizeof(char *));
2041 elem = PLGetArrayElement(value,0);
2042 if (!elem || !PLIsString(elem)) return False;
2043 val = PLGetString(elem);
2044 if (strcasecmp(val, "function")==0) {
2045 elem = PLGetArrayElement(value, 1); /* library name */
2046 if (!elem || !PLIsString(elem)) return False;
2047 lib = PLGetString(elem);
2048 elem = PLGetArrayElement(value, 2); /* function name */
2049 if (!elem || !PLIsString(elem)) return False;
2050 func = PLGetString(elem);
2051 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2052 lib, "initDrawString", func, NULL, value,
2053 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2056 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2057 } else if (PLIsString(value)) {
2058 return getColor(scr, entry, value, addr, ret);
2061 #endif /* DRAWSTRING_PLUGIN */
2065 static int
2066 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2067 void *addr, void **ret)
2069 proplist_t elem;
2070 int changed = 0;
2071 char *val;
2072 int nelem;
2074 again:
2075 if (!PLIsArray(value)) {
2076 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2077 "WorkspaceBack", "Texture or None");
2078 if (changed==0) {
2079 value = entry->plvalue;
2080 changed = 1;
2081 wwarning(_("using default \"%s\" instead"), entry->default_value);
2082 goto again;
2084 return False;
2087 /* only do basic error checking and verify for None texture */
2089 nelem = PLGetNumberOfElements(value);
2090 if (nelem > 0) {
2091 elem = PLGetArrayElement(value, 0);
2092 if (!elem || !PLIsString(elem)) {
2093 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2094 if (changed==0) {
2095 value = entry->plvalue;
2096 changed = 1;
2097 wwarning(_("using default \"%s\" instead"), entry->default_value);
2098 goto again;
2100 return False;
2102 val = PLGetString(elem);
2104 if (strcasecmp(val, "None")==0)
2105 return True;
2107 *ret = PLRetain(value);
2109 return True;
2113 static int
2114 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2115 void *addr, void **ret)
2117 proplist_t elem;
2118 int nelem;
2119 int changed = 0;
2121 again:
2122 if (!PLIsArray(value)) {
2123 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2124 "WorkspaceSpecificBack", "an array of textures");
2125 if (changed==0) {
2126 value = entry->plvalue;
2127 changed = 1;
2128 wwarning(_("using default \"%s\" instead"), entry->default_value);
2129 goto again;
2131 return False;
2134 /* only do basic error checking and verify for None texture */
2136 nelem = PLGetNumberOfElements(value);
2137 if (nelem > 0) {
2138 while (nelem--) {
2139 elem = PLGetArrayElement(value, nelem);
2140 if (!elem || !PLIsArray(elem)) {
2141 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2142 nelem);
2147 *ret = PLRetain(value);
2149 #ifdef notworking
2151 * Kluge to force wmsetbg helper to set the default background.
2152 * If the WorkspaceSpecificBack is changed once wmaker has started,
2153 * the WorkspaceBack won't be sent to the helper, unless the user
2154 * changes it's value too. So, we must force this by removing the
2155 * value from the defaults DB.
2157 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2158 proplist_t key = PLMakeString("WorkspaceBack");
2160 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2162 PLRelease(key);
2164 #endif
2165 return True;
2169 static int
2170 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2171 void **ret)
2173 static WMFont *font;
2174 char *val;
2176 STRINGP("Font");
2178 val = PLGetString(value);
2180 font = WMCreateFont(scr->wmscreen, val);
2181 if (!font)
2182 font = WMCreateFont(scr->wmscreen, "fixed");
2184 if (!font) {
2185 wfatal(_("could not load any usable font!!!"));
2186 exit(1);
2189 if (ret)
2190 *ret = font;
2192 /* can't assign font value outside update function */
2193 wassertrv(addr == NULL, True);
2195 return True;
2199 static int
2200 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2201 void **ret)
2203 static XColor color;
2204 char *val;
2205 int second_pass=0;
2207 STRINGP("Color");
2209 val = PLGetString(value);
2211 again:
2212 if (!wGetColor(scr, val, &color)) {
2213 wwarning(_("could not get color for key \"%s\""),
2214 entry->key);
2215 if (second_pass==0) {
2216 val = PLGetString(entry->plvalue);
2217 second_pass = 1;
2218 wwarning(_("using default \"%s\" instead"), val);
2219 goto again;
2221 return False;
2224 if (ret)
2225 *ret = &color;
2227 assert(addr==NULL);
2229 if (addr)
2230 *(unsigned long*)addr = pixel;
2233 return True;
2238 static int
2239 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2240 void **ret)
2242 static WShortKey shortcut;
2243 KeySym ksym;
2244 char *val;
2245 char *k;
2246 char buf[128], *b;
2249 STRINGP("Key spec");
2251 val = PLGetString(value);
2253 if (!val || strcasecmp(val, "NONE")==0) {
2254 shortcut.keycode = 0;
2255 shortcut.modifier = 0;
2256 if (ret)
2257 *ret = &shortcut;
2258 return True;
2261 strcpy(buf, val);
2263 b = (char*)buf;
2265 /* get modifiers */
2266 shortcut.modifier = 0;
2267 while ((k = strchr(b, '+'))!=NULL) {
2268 int mod;
2270 *k = 0;
2271 mod = wXModifierFromKey(b);
2272 if (mod<0) {
2273 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2274 return False;
2276 shortcut.modifier |= mod;
2278 b = k+1;
2281 /* get key */
2282 ksym = XStringToKeysym(b);
2284 if (ksym==NoSymbol) {
2285 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2286 val);
2287 return False;
2290 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2291 if (shortcut.keycode==0) {
2292 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2293 return False;
2296 if (ret)
2297 *ret = &shortcut;
2299 return True;
2303 static int
2304 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2305 void **ret)
2307 static unsigned int mask;
2308 char *str;
2310 STRINGP("Modifier Key");
2312 str = PLGetString(value);
2313 if (!str)
2314 return False;
2316 mask = wXModifierFromKey(str);
2317 if (mask < 0) {
2318 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2319 mask = 0;
2320 return False;
2323 if (addr)
2324 *(unsigned int*)addr = mask;
2326 if (ret)
2327 *ret = &mask;
2329 return True;
2333 #ifdef NEWSTUFF
2334 static int
2335 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2336 void *addr, void **ret)
2338 unsigned int mask;
2339 char *str;
2340 RImage *image;
2341 int i, n;
2342 int w, h;
2344 STRINGP("Image File Path");
2346 str = PLGetString(value);
2347 if (!str)
2348 return False;
2350 image = RLoadImage(scr->rcontext, str, 0);
2351 if (!image) {
2352 wwarning(_("could not load image in option %s: %s"), entry->key,
2353 RMessageForError(RErrorCode));
2354 return False;
2357 if (*(RImage**)addr) {
2358 RDestroyImage(*(RImage**)addr);
2360 if (addr)
2361 *(RImage**)addr = image;
2363 assert(ret == NULL);
2365 if (ret)
2366 *(RImage**)ret = image;
2369 return True;
2371 #endif
2374 /* ---------------- value setting functions --------------- */
2375 static int
2376 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2378 return REFRESH_WINDOW_TITLE_COLOR;
2382 static int
2383 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2385 switch (which) {
2386 case WM_DOCK:
2387 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2388 break;
2389 case WM_CLIP:
2390 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2391 break;
2392 default:
2393 break;
2395 return 0;
2399 static int
2400 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2402 if (scr->workspaces) {
2403 wWorkspaceForceChange(scr, scr->current_workspace);
2404 wArrangeIcons(scr, False);
2406 return 0;
2409 #if not_used
2410 static int
2411 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2413 if (*value <= 0)
2414 *(int*)foo = 1;
2416 return 0;
2418 #endif
2422 static int
2423 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2425 Pixmap pixmap;
2426 RImage *img;
2427 int reset = 0;
2429 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2430 wPreferences.icon_size,
2431 ((*texture)->any.type & WREL_BORDER_MASK)
2432 ? WREL_ICON : WREL_FLAT);
2433 if (!img) {
2434 wwarning(_("could not render texture for icon background"));
2435 if (!entry->addr)
2436 wTextureDestroy(scr, *texture);
2437 return 0;
2439 RConvertImage(scr->rcontext, img, &pixmap);
2441 if (scr->icon_tile) {
2442 reset = 1;
2443 RDestroyImage(scr->icon_tile);
2444 XFreePixmap(dpy, scr->icon_tile_pixmap);
2447 scr->icon_tile = img;
2449 if (!wPreferences.flags.noclip) {
2450 if (scr->clip_tile) {
2451 RDestroyImage(scr->clip_tile);
2453 scr->clip_tile = wClipMakeTile(scr, img);
2456 scr->icon_tile_pixmap = pixmap;
2458 if (scr->def_icon_pixmap) {
2459 XFreePixmap(dpy, scr->def_icon_pixmap);
2460 scr->def_icon_pixmap = None;
2462 if (scr->def_ticon_pixmap) {
2463 XFreePixmap(dpy, scr->def_ticon_pixmap);
2464 scr->def_ticon_pixmap = None;
2467 if (scr->icon_back_texture) {
2468 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2470 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2472 if (scr->clip_balloon)
2473 XSetWindowBackground(dpy, scr->clip_balloon,
2474 (*texture)->any.color.pixel);
2477 * Free the texture as nobody else will use it, nor refer to it.
2479 if (!entry->addr)
2480 wTextureDestroy(scr, *texture);
2482 return (reset ? REFRESH_ICON_TILE : 0);
2487 static int
2488 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2490 if (scr->title_font) {
2491 WMReleaseFont(scr->title_font);
2493 scr->title_font = font;
2495 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2499 static int
2500 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2502 if (scr->menu_title_font) {
2503 WMReleaseFont(scr->menu_title_font);
2506 scr->menu_title_font = font;
2508 return REFRESH_MENU_TITLE_FONT;
2512 static int
2513 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2515 if (scr->menu_entry_font) {
2516 WMReleaseFont(scr->menu_entry_font);
2518 scr->menu_entry_font = font;
2520 return REFRESH_MENU_FONT;
2525 static int
2526 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2528 if (scr->icon_title_font) {
2529 WMReleaseFont(scr->icon_title_font);
2532 scr->icon_title_font = font;
2534 return REFRESH_ICON_FONT;
2538 static int
2539 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2541 if (scr->clip_title_font) {
2542 WMReleaseFont(scr->clip_title_font);
2545 scr->clip_title_font = font;
2547 return REFRESH_ICON_FONT;
2551 static int
2552 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2554 if (scr->info_text_font) {
2555 WMReleaseFont(scr->info_text_font);
2558 scr->info_text_font = font;
2560 /* This test works because the scr structure is initially zeroed out
2561 and None = 0. Any other time, the window should be valid. */
2562 if (scr->geometry_display != None) {
2563 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2564 &scr->geometry_display_height);
2565 XResizeWindow(dpy, scr->geometry_display,
2566 scr->geometry_display_width, scr->geometry_display_height);
2569 return 0;
2573 static int
2574 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2576 if (scr->workspace_name_font) {
2577 WMReleaseFont(scr->workspace_name_font);
2580 scr->workspace_name_font = font;
2582 return 0;
2586 static int
2587 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2589 if (scr->select_pixel!=scr->white_pixel &&
2590 scr->select_pixel!=scr->black_pixel) {
2591 wFreeColor(scr, scr->select_pixel);
2594 scr->select_pixel = color->pixel;
2596 return REFRESH_MENU_COLOR;
2600 static int
2601 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2603 if (scr->select_text_pixel!=scr->white_pixel &&
2604 scr->select_text_pixel!=scr->black_pixel) {
2605 wFreeColor(scr, scr->select_text_pixel);
2608 scr->select_text_pixel = color->pixel;
2610 return REFRESH_MENU_COLOR;
2614 static int
2615 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2617 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2618 scr->clip_title_pixel[index]!=scr->black_pixel) {
2619 wFreeColor(scr, scr->clip_title_pixel[index]);
2621 scr->clip_title_pixel[index] = color->pixel;
2623 #ifdef GRADIENT_CLIP_ARROW
2624 if (index == CLIP_NORMAL) {
2625 RImage *image;
2626 RColor color1, color2;
2627 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2628 int as = pt - 15; /* 15 = 5+5+5 */
2630 FREE_PIXMAP(scr->clip_arrow_gradient);
2632 color1.red = (color->red >> 8)*6/10;
2633 color1.green = (color->green >> 8)*6/10;
2634 color1.blue = (color->blue >> 8)*6/10;
2636 color2.red = WMIN((color->red >> 8)*20/10, 255);
2637 color2.green = WMIN((color->green >> 8)*20/10, 255);
2638 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2640 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2641 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2642 RDestroyImage(image);
2644 #endif /* GRADIENT_CLIP_ARROW */
2646 return REFRESH_ICON_TITLE_COLOR;
2650 static int
2651 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2653 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2654 scr->window_title_pixel[index]!=scr->black_pixel) {
2655 wFreeColor(scr, scr->window_title_pixel[index]);
2658 scr->window_title_pixel[index] = color->pixel;
2660 if (index == WS_UNFOCUSED)
2661 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2663 return REFRESH_WINDOW_TITLE_COLOR;
2667 static int
2668 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2670 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2671 scr->menu_title_pixel[0]!=scr->black_pixel) {
2672 #ifdef DRAWSTRING_PLUGIN
2673 if(!scr->drawstring_func[W_STRING_MTITLE])
2674 #endif
2675 wFreeColor(scr, scr->menu_title_pixel[0]);
2678 scr->menu_title_pixel[0] = color->pixel;
2679 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2681 return REFRESH_MENU_TITLE_COLOR;
2685 static int
2686 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2688 XGCValues gcv;
2689 #define gcm (GCForeground|GCBackground|GCFillStyle)
2691 if (scr->mtext_pixel!=scr->white_pixel &&
2692 scr->mtext_pixel!=scr->black_pixel) {
2693 wFreeColor(scr, scr->mtext_pixel);
2696 scr->mtext_pixel = color->pixel;
2698 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2701 if (scr->dtext_pixel == scr->mtext_pixel) {
2702 gcv.foreground = scr->white_pixel;
2703 gcv.background = scr->black_pixel;
2704 gcv.fill_style = FillStippled;
2705 } else {
2706 gcv.foreground = scr->dtext_pixel;
2707 gcv.fill_style = FillSolid;
2709 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2711 return REFRESH_MENU_COLOR;
2712 #undef gcm
2716 static int
2717 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2719 XGCValues gcv;
2720 #define gcm (GCForeground|GCBackground|GCFillStyle)
2722 if (scr->dtext_pixel!=scr->white_pixel &&
2723 scr->dtext_pixel!=scr->black_pixel) {
2724 wFreeColor(scr, scr->dtext_pixel);
2727 scr->dtext_pixel = color->pixel;
2729 if (scr->dtext_pixel == scr->mtext_pixel) {
2730 gcv.foreground = scr->white_pixel;
2731 gcv.background = scr->black_pixel;
2732 gcv.fill_style = FillStippled;
2733 } else {
2734 gcv.foreground = scr->dtext_pixel;
2735 gcv.fill_style = FillSolid;
2737 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2739 return REFRESH_MENU_COLOR;
2740 #undef gcm
2743 static int
2744 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2746 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2748 return REFRESH_ICON_TITLE_COLOR;
2752 static int
2753 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2755 if (scr->icon_title_texture) {
2756 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2758 XQueryColor (dpy, scr->w_colormap, color);
2759 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2761 return REFRESH_ICON_TITLE_BACK;
2765 static void
2766 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2768 close(scr->helper_fd);
2769 scr->helper_fd = 0;
2770 scr->helper_pid = 0;
2771 scr->flags.backimage_helper_launched = 0;
2775 static int
2776 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2777 void *bar)
2779 int i;
2780 proplist_t val;
2781 char *str;
2783 if (scr->flags.backimage_helper_launched) {
2784 if (PLGetNumberOfElements(value)==0) {
2785 SendHelperMessage(scr, 'C', 0, NULL);
2786 SendHelperMessage(scr, 'K', 0, NULL);
2788 PLRelease(value);
2789 return 0;
2791 } else {
2792 pid_t pid;
2793 int filedes[2];
2795 if (PLGetNumberOfElements(value) == 0)
2796 return 0;
2798 if (pipe(filedes) < 0) {
2799 wsyserror("pipe() failed:can't set workspace specific background image");
2801 PLRelease(value);
2802 return 0;
2805 pid = fork();
2806 if (pid < 0) {
2807 wsyserror("fork() failed:can't set workspace specific background image");
2808 if (close(filedes[0]) < 0)
2809 wsyserror("could not close pipe");
2810 if (close(filedes[1]) < 0)
2811 wsyserror("could not close pipe");
2813 } else if (pid == 0) {
2814 SetupEnvironment(scr);
2816 if (close(0) < 0)
2817 wsyserror("could not close pipe");
2818 if (dup(filedes[0]) < 0) {
2819 wsyserror("dup() failed:can't set workspace specific background image");
2821 if (wPreferences.smooth_workspace_back)
2822 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2823 else
2824 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2825 wsyserror("could not execute wmsetbg");
2826 exit(1);
2827 } else {
2829 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2830 wsyserror("error setting close-on-exec flag");
2832 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2833 wsyserror("error setting close-on-exec flag");
2836 scr->helper_fd = filedes[1];
2837 scr->helper_pid = pid;
2838 scr->flags.backimage_helper_launched = 1;
2840 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2842 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2846 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2847 val = PLGetArrayElement(value, i);
2848 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2849 str = PLGetDescription(val);
2851 SendHelperMessage(scr, 'S', i+1, str);
2853 free(str);
2854 } else {
2855 SendHelperMessage(scr, 'U', i+1, NULL);
2858 sleep(1);
2860 PLRelease(value);
2861 return 0;
2865 static int
2866 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2867 void *bar)
2869 if (scr->flags.backimage_helper_launched) {
2870 char *str;
2872 if (PLGetNumberOfElements(value)==0) {
2873 SendHelperMessage(scr, 'U', 0, NULL);
2874 } else {
2875 /* set the default workspace background to this one */
2876 str = PLGetDescription(value);
2877 if (str) {
2878 SendHelperMessage(scr, 'S', 0, str);
2879 free(str);
2880 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2881 } else {
2882 SendHelperMessage(scr, 'U', 0, NULL);
2885 } else {
2886 char *command;
2887 char *text;
2889 SetupEnvironment(scr);
2890 text = PLGetDescription(value);
2891 command = wmalloc(strlen(text)+40);
2892 if (wPreferences.smooth_workspace_back)
2893 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2894 else
2895 sprintf(command, "wmsetbg -d -p '%s' &", text);
2896 free(text);
2897 system(command);
2898 free(command);
2900 PLRelease(value);
2902 return 0;
2906 static int
2907 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2909 if (scr->widget_texture) {
2910 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2912 scr->widget_texture = *(WTexSolid**)texture;
2914 if (scr->geometry_display != None)
2915 XSetWindowBackground(dpy, scr->geometry_display,
2916 scr->widget_texture->normal.pixel);
2918 return 0;
2922 static int
2923 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2925 if (scr->window_title_texture[WS_FOCUSED]) {
2926 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2928 scr->window_title_texture[WS_FOCUSED] = *texture;
2930 return REFRESH_WINDOW_TEXTURES;
2934 static int
2935 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2937 if (scr->window_title_texture[WS_PFOCUSED]) {
2938 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2940 scr->window_title_texture[WS_PFOCUSED] = *texture;
2942 return REFRESH_WINDOW_TEXTURES;
2946 static int
2947 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2949 if (scr->window_title_texture[WS_UNFOCUSED]) {
2950 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2952 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2954 return REFRESH_WINDOW_TEXTURES;
2958 static int
2959 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2961 if (scr->resizebar_texture[0]) {
2962 wTextureDestroy(scr, scr->resizebar_texture[0]);
2964 scr->resizebar_texture[0] = *texture;
2966 return REFRESH_WINDOW_TEXTURES;
2970 static int
2971 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2973 if (scr->menu_title_texture[0]) {
2974 wTextureDestroy(scr, scr->menu_title_texture[0]);
2976 scr->menu_title_texture[0] = *texture;
2978 return REFRESH_MENU_TITLE_TEXTURE;
2982 static int
2983 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2985 if (scr->menu_item_texture) {
2986 wTextureDestroy(scr, scr->menu_item_texture);
2987 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
2989 scr->menu_item_texture = *texture;
2991 scr->menu_item_auxtexture
2992 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2994 return REFRESH_MENU_TEXTURE;
2998 static int
2999 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3001 WWindow *wwin;
3002 wKeyBindings[index] = *shortcut;
3004 wwin = scr->focused_window;
3006 while (wwin!=NULL) {
3007 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3009 if (!WFLAGP(wwin, no_bind_keys)) {
3010 wWindowSetKeyGrabs(wwin);
3012 wwin = wwin->prev;
3015 return 0;
3019 static int
3020 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3022 wArrangeIcons(scr, True);
3024 return 0;
3028 static int
3029 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3031 wScreenUpdateUsableArea(scr);
3033 return 0;
3037 static int
3038 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3040 return REFRESH_MENU_TEXTURE;
3045 static int
3046 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3048 return REFRESH_BUTTON_IMAGES;
3053 * Very ugly kluge.
3054 * Need access to the double click variables, so that all widgets in
3055 * wmaker panels will have the same dbl-click values.
3056 * TODO: figure a better way of dealing with it.
3058 #include "WINGsP.h"
3060 static int
3061 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3063 extern _WINGsConfiguration WINGsConfiguration;
3065 if (*value <= 0)
3066 *(int*)foo = 1;
3068 WINGsConfiguration.doubleClickDelay = *value;
3070 return 0;
3075 static int
3076 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3078 extern _WINGsConfiguration WINGsConfiguration;
3080 WINGsConfiguration.useMultiByte = *value;
3082 return 0;