Updated korean po files
[wmaker-crm.git] / src / defaults.c
blob4d0051c17694b2758e93beca2dc8e5d07d89b5f4
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_AUTO, 0}, {"Smart", WPM_SMART, 0},
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 {"None", -1, 0},
260 {"Left", Button1, 0}, {"Button1", Button1, 1},
261 {"Middle", Button2, 0}, {"Button2", Button2, 1},
262 {"Right", Button3, 0}, {"Button3", Button3, 1},
263 {"Button4", Button4, 0},
264 {"Button5", Button5, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seIconificationStyles[] = {
269 {"Zoom", WIS_ZOOM, 0},
270 {"Twist", WIS_TWIST, 0},
271 {"Flip", WIS_FLIP, 0},
272 {"None", WIS_NONE, 0},
273 {"random", WIS_RANDOM, 0},
274 {NULL, 0, 0}
277 static WOptionEnumeration seJustifications[] = {
278 {"Left", WTJ_LEFT, 0},
279 {"Center", WTJ_CENTER, 0},
280 {"Right", WTJ_RIGHT, 0},
281 {NULL, 0, 0}
284 static WOptionEnumeration seIconPositions[] = {
285 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
286 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
287 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
288 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
289 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
290 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
291 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
292 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
293 {NULL, 0, 0}
296 static WOptionEnumeration seMenuStyles[] = {
297 {"normal", MS_NORMAL, 0},
298 {"singletexture", MS_SINGLE_TEXTURE, 0},
299 {"flat", MS_FLAT, 0},
300 {NULL, 0, 0}
304 static WOptionEnumeration seDisplayPositions[] = {
305 {"none", WD_NONE, 0},
306 {"center", WD_CENTER, 0},
307 {"top", WD_TOP, 0},
308 {"bottom", WD_BOTTOM, 0},
309 {"topleft", WD_TOPLEFT, 0},
310 {"topright", WD_TOPRIGHT, 0},
311 {"bottomleft", WD_BOTTOMLEFT, 0},
312 {"bottomright", WD_BOTTOMRIGHT, 0}
317 * ALL entries in the tables bellow, NEED to have a default value
318 * defined, and this value needs to be correct.
321 /* these options will only affect the window manager on startup
323 * static defaults can't access the screen data, because it is
324 * created after these defaults are read
326 WDefaultEntry staticOptionList[] = {
328 {"DisableDithering", "NO", NULL,
329 &wPreferences.no_dithering, getBool, NULL
331 {"ColormapSize", "4", NULL,
332 &wPreferences.cmap_size, getInt, NULL
334 /* static by laziness */
335 {"IconSize", "64", NULL,
336 &wPreferences.icon_size, getInt, NULL
338 {"ModifierKey", "Mod1", NULL,
339 &wPreferences.modifier_mask, getModMask, NULL
341 {"DisableWSMouseActions", "NO", NULL,
342 &wPreferences.disable_root_mouse, getBool, NULL
344 {"FocusMode", "manual", seFocusModes,
345 &wPreferences.focus_mode, getEnum, NULL
346 }, /* have a problem when switching from manual to sloppy without restart */
347 {"NewStyle", "NO", NULL,
348 &wPreferences.new_style, getBool, NULL
350 {"DisableDock", "NO", (void*) WM_DOCK,
351 NULL, getBool, setIfDockPresent
353 {"DisableClip", "NO", (void*) WM_CLIP,
354 NULL, getBool, setIfDockPresent
356 {"DisableMiniwindows", "NO", NULL,
357 &wPreferences.disable_miniwindows, getBool, NULL
359 {"MultiByteText", "NO", NULL,
360 &wPreferences.multi_byte_text, getBool, setMultiByte
366 WDefaultEntry optionList[] = {
367 /* dynamic options */
368 {"IconPosition", "blh", seIconPositions,
369 &wPreferences.icon_yard, getEnum, setIconPosition
371 {"IconificationStyle", "Zoom", seIconificationStyles,
372 &wPreferences.iconification_style, getEnum, NULL
374 {"SelectWindowsMouseButton", "Left", seMouseButtons,
375 &wPreferences.select_button, getEnum, NULL
377 {"WindowListMouseButton", "Middle", seMouseButtons,
378 &wPreferences.windowl_button, getEnum, NULL
380 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
381 &wPreferences.menu_button, getEnum, NULL
383 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
384 &wPreferences.pixmap_path, getPathList, NULL
386 {"IconPath", DEF_ICON_PATHS, NULL,
387 &wPreferences.icon_path, getPathList, NULL
389 {"ColormapMode", "auto", seColormapModes,
390 &wPreferences.colormap_mode, getEnum, NULL
392 {"AutoFocus", "NO", NULL,
393 &wPreferences.auto_focus, getBool, NULL
395 {"RaiseDelay", "0", NULL,
396 &wPreferences.raise_delay, getInt, NULL
398 {"CirculateRaise", "NO", NULL,
399 &wPreferences.circ_raise, getBool, NULL
401 {"Superfluous", "NO", NULL,
402 &wPreferences.superfluous, getBool, NULL
404 {"AdvanceToNewWorkspace", "NO", NULL,
405 &wPreferences.ws_advance, getBool, NULL
407 {"CycleWorkspaces", "NO", NULL,
408 &wPreferences.ws_cycle, getBool, NULL
410 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
411 &wPreferences.workspace_name_display_position, getEnum, NULL
413 {"StickyIcons", "NO", NULL,
414 &wPreferences.sticky_icons, getBool, setStickyIcons
416 {"SaveSessionOnExit", "NO", NULL,
417 &wPreferences.save_session_on_exit, getBool, NULL
419 {"WrapMenus", "NO", NULL,
420 &wPreferences.wrap_menus, getBool, NULL
422 {"ScrollableMenus", "NO", NULL,
423 &wPreferences.scrollable_menus, getBool, NULL
425 {"MenuScrollSpeed", "medium", seSpeeds,
426 &wPreferences.menu_scroll_speed, getEnum, NULL
428 {"IconSlideSpeed", "medium", seSpeeds,
429 &wPreferences.icon_slide_speed, getEnum, NULL
431 {"ShadeSpeed", "medium", seSpeeds,
432 &wPreferences.shade_speed, getEnum, NULL
434 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
435 &wPreferences.dblclick_time, getInt, setDoubleClick,
437 {"AlignSubmenus", "NO", NULL,
438 &wPreferences.align_menus, getBool, NULL
440 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
441 &wPreferences.open_transients_with_parent, getBool, NULL
443 {"WindowPlacement", "auto", sePlacements,
444 &wPreferences.window_placement, getEnum, NULL
446 {"IgnoreFocusClick","NO", NULL,
447 &wPreferences.ignore_focus_click, getBool, NULL
449 {"UseSaveUnders", "NO", NULL,
450 &wPreferences.use_saveunders, getBool, NULL
452 {"OpaqueMove", "NO", NULL,
453 &wPreferences.opaque_move, getBool, NULL
455 {"DisableSound", "NO", NULL,
456 &wPreferences.no_sound, getBool, NULL
458 {"DisableAnimations", "NO", NULL,
459 &wPreferences.no_animations, getBool, NULL
461 {"DontLinkWorkspaces","NO", NULL,
462 &wPreferences.no_autowrap, getBool, NULL
464 {"AutoArrangeIcons", "NO", NULL,
465 &wPreferences.auto_arrange_icons, getBool, NULL
467 {"NoWindowOverDock", "NO", NULL,
468 &wPreferences.no_window_over_dock, getBool, updateUsableArea
470 {"NoWindowOverIcons", "NO", NULL,
471 &wPreferences.no_window_over_icons, getBool, updateUsableArea
473 {"WindowPlaceOrigin", "(0, 0)", NULL,
474 &wPreferences.window_place_origin, getCoord, NULL
476 {"ResizeDisplay", "corner", seGeomDisplays,
477 &wPreferences.size_display, getEnum, NULL
479 {"MoveDisplay", "corner", seGeomDisplays,
480 &wPreferences.move_display, getEnum, NULL
482 {"DontConfirmKill", "NO", NULL,
483 &wPreferences.dont_confirm_kill, getBool,NULL
485 {"WindowTitleBalloons", "NO", NULL,
486 &wPreferences.window_balloon, getBool, NULL
488 {"MiniwindowTitleBalloons", "NO", NULL,
489 &wPreferences.miniwin_balloon,getBool, NULL
491 {"AppIconBalloons", "NO", NULL,
492 &wPreferences.appicon_balloon,getBool, NULL
494 {"HelpBalloons", "NO", NULL,
495 &wPreferences.help_balloon, getBool, NULL
497 {"EdgeResistance", "30", NULL,
498 &wPreferences.edge_resistance,getInt, NULL
500 {"Attraction", "NO", NULL,
501 &wPreferences.attract, getBool, NULL
503 {"DisableBlinking", "NO", NULL,
504 &wPreferences.dont_blink, getBool, NULL
506 #ifdef WEENDOZE_CYCLE
507 {"WindozeCycling","NO", NULL,
508 &wPreferences.windoze_cycling, getBool, NULL
510 {"PopupSwitchMenu","YES", NULL,
511 &wPreferences.popup_switchmenu, getBool, NULL
513 #endif /* WEENDOZE_CYCLE */
514 /* style options */
515 {"MenuStyle", "normal", seMenuStyles,
516 &wPreferences.menu_style, getEnum, setMenuStyle
518 {"WidgetColor", "(solid, gray)", NULL,
519 NULL, getTexture, setWidgetColor,
521 {"WorkspaceSpecificBack","()", NULL,
522 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
524 /* WorkspaceBack must come after WorkspaceSpecificBack or
525 * WorkspaceBack wont know WorkspaceSpecificBack was also
526 * specified and 2 copies of wmsetbg will be launched */
527 {"WorkspaceBack", "(solid, black)", NULL,
528 NULL, getWSBackground,setWorkspaceBack
530 {"SmoothWorkspaceBack", "NO", NULL,
531 NULL, getBool, NULL
533 {"IconBack", "(solid, gray)", NULL,
534 NULL, getTexture, setIconTile
536 {"TitleJustify", "center", seJustifications,
537 &wPreferences.title_justification, getEnum, setJustify
539 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
540 NULL, getFont, setWinTitleFont,
542 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
543 NULL, getFont, setMenuTitleFont
545 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
546 NULL, getFont, setMenuTextFont
548 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
549 NULL, getFont, setIconTitleFont
551 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
552 NULL, getFont, setClipTitleFont
554 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
555 NULL, getFont, setDisplayFont
557 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
558 NULL, getFont, setLargeDisplayFont
560 {"HighlightColor", "white", NULL,
561 NULL, getColor, setHightlight
563 {"HighlightTextColor", "black", NULL,
564 NULL, getColor, setHightlightText
566 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
567 NULL, getColor, setClipTitleColor
569 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
570 NULL, getColor, setClipTitleColor
572 #ifdef DRAWSTRING_PLUGIN
573 {"FTitleColor", "white", (void*)WS_FOCUSED,
574 NULL, getTextRenderer, setWTitleColor
576 {"PTitleColor", "white", (void*)WS_PFOCUSED,
577 NULL, getTextRenderer, setWTitleColor
579 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
580 NULL, getTextRenderer, setWTitleColor
582 #else
583 {"FTitleColor", "white", (void*)WS_FOCUSED,
584 NULL, getColor, setWTitleColor
586 {"PTitleColor", "white", (void*)WS_PFOCUSED,
587 NULL, getColor, setWTitleColor
589 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
590 NULL, getColor, setWTitleColor
592 #endif
593 {"FTitleBack", "(solid, black)", NULL,
594 NULL, getTexture, setFTitleBack
596 {"PTitleBack", "(solid, \"#616161\")", NULL,
597 NULL, getTexture, setPTitleBack
599 {"UTitleBack", "(solid, gray)", NULL,
600 NULL, getTexture, setUTitleBack
602 {"ResizebarBack", "(solid, gray)", NULL,
603 NULL, getTexture, setResizebarBack
605 #ifdef DRAWSTRING_PLUGIN
606 {"MenuTitleColor", "white", NULL,
607 NULL, getTextRenderer, setMenuTitleColor
609 #else
610 {"MenuTitleColor", "white", NULL,
611 NULL, getColor, setMenuTitleColor
613 #endif
614 {"MenuTextColor", "black", NULL,
615 NULL, getColor, setMenuTextColor
617 {"MenuDisabledColor", "\"#616161\"", NULL,
618 NULL, getColor, setMenuDisabledColor
620 {"MenuTitleBack", "(solid, black)", NULL,
621 NULL, getTexture, setMenuTitleBack
623 {"MenuTextBack", "(solid, gray)", NULL,
624 NULL, getTexture, setMenuTextBack
626 {"IconTitleColor", "white", NULL,
627 NULL, getColor, setIconTitleColor
629 {"IconTitleBack", "black", NULL,
630 NULL, getColor, setIconTitleBack
632 /* keybindings */
633 #ifndef LITE
634 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
635 NULL, getKeybind, setKeyGrab
637 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
638 NULL, getKeybind, setKeyGrab
640 #endif /* LITE */
641 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
642 NULL, getKeybind, setKeyGrab
644 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
645 NULL, getKeybind, setKeyGrab
647 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
648 NULL, getKeybind, setKeyGrab
650 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
651 NULL, getKeybind, setKeyGrab
653 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
654 NULL, getKeybind, setKeyGrab
656 {"HideKey", "None", (void*)WKBD_HIDE,
657 NULL, getKeybind, setKeyGrab
659 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
660 NULL, getKeybind, setKeyGrab
662 {"CloseKey", "None", (void*)WKBD_CLOSE,
663 NULL, getKeybind, setKeyGrab
665 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
666 NULL, getKeybind, setKeyGrab
668 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
669 NULL, getKeybind, setKeyGrab
671 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
672 NULL, getKeybind, setKeyGrab
674 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
675 NULL, getKeybind, setKeyGrab
677 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
678 NULL, getKeybind, setKeyGrab
680 {"ShadeKey", "None", (void*)WKBD_SHADE,
681 NULL, getKeybind, setKeyGrab
683 {"SelectKey", "None", (void*)WKBD_SELECT,
684 NULL, getKeybind, setKeyGrab
686 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
687 NULL, getKeybind, setKeyGrab
689 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
690 NULL, getKeybind, setKeyGrab
692 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
693 NULL, getKeybind, setKeyGrab
695 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
696 NULL, getKeybind, setKeyGrab
698 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
699 NULL, getKeybind, setKeyGrab
701 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
702 NULL, getKeybind, setKeyGrab
704 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
705 NULL, getKeybind, setKeyGrab
707 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
708 NULL, getKeybind, setKeyGrab
710 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
711 NULL, getKeybind, setKeyGrab
713 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
714 NULL, getKeybind, setKeyGrab
716 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
717 NULL, getKeybind, setKeyGrab
719 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
720 NULL, getKeybind, setKeyGrab
722 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
723 NULL, getKeybind, setKeyGrab
725 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
726 NULL, getKeybind, setKeyGrab
728 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
729 NULL, getKeybind, setKeyGrab
731 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
732 NULL, getKeybind, setKeyGrab
734 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
735 NULL, getKeybind, setKeyGrab
737 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
738 NULL, getKeybind, setKeyGrab
740 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
741 NULL, getKeybind, setKeyGrab
743 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
744 NULL, getKeybind, setKeyGrab
746 #ifdef EXTEND_WINDOWSHORTCUT
747 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
748 NULL, getKeybind, setKeyGrab
750 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
751 NULL, getKeybind, setKeyGrab
753 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
754 NULL, getKeybind, setKeyGrab
756 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
757 NULL, getKeybind, setKeyGrab
759 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
760 NULL, getKeybind, setKeyGrab
762 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
763 NULL, getKeybind, setKeyGrab
765 #endif /* EXTEND_WINDOWSHORTCUT */
767 #ifdef KEEP_XKB_LOCK_STATUS
768 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
769 NULL, getKeybind, setKeyGrab
771 {"KbdModeLock", "NO", NULL,
772 &wPreferences.modelock, getBool, NULL
774 #endif /* KEEP_XKB_LOCK_STATUS */
778 #if 0
779 static void rereadDefaults(void);
780 #endif
782 #if 0
783 static void
784 rereadDefaults(void)
786 /* must defer the update because accessing X data from a
787 * signal handler can mess up Xlib */
790 #endif
792 static void
793 initDefaults()
795 int i;
796 WDefaultEntry *entry;
798 PLSetStringCmpHook(StringCompareHook);
800 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
801 entry = &optionList[i];
803 entry->plkey = PLMakeString(entry->key);
804 if (entry->default_value)
805 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
806 else
807 entry->plvalue = NULL;
810 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
811 entry = &staticOptionList[i];
813 entry->plkey = PLMakeString(entry->key);
814 if (entry->default_value)
815 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
816 else
817 entry->plvalue = NULL;
821 wDomainName = PLMakeString(WMDOMAIN_NAME);
822 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
824 PLRegister(wDomainName, rereadDefaults);
825 PLRegister(wAttributeDomainName, rereadDefaults);
832 #if 0
833 proplist_t
834 wDefaultsInit(int screen_number)
836 static int defaults_inited = 0;
837 proplist_t dict;
839 if (!defaults_inited) {
840 initDefaults();
843 dict = PLGetDomain(wDomainName);
844 if (!dict) {
845 wwarning(_("could not read domain \"%s\" from defaults database"),
846 PLGetString(wDomainName));
849 return dict;
851 #endif
854 void
855 wDefaultsDestroyDomain(WDDomain *domain)
857 if (domain->dictionary)
858 PLRelease(domain->dictionary);
859 free(domain->path);
860 free(domain);
864 WDDomain*
865 wDefaultsInitDomain(char *domain, Bool requireDictionary)
867 WDDomain *db;
868 struct stat stbuf;
869 static int inited = 0;
870 char path[PATH_MAX];
871 char *the_path;
872 proplist_t shared_dict=NULL;
874 if (!inited) {
875 inited = 1;
876 initDefaults();
879 db = wmalloc(sizeof(WDDomain));
880 memset(db, 0, sizeof(WDDomain));
881 db->domain_name = domain;
882 db->path = wdefaultspathfordomain(domain);
883 the_path = db->path;
885 if (the_path && stat(the_path, &stbuf)>=0) {
886 db->dictionary = ReadProplistFromFile(the_path);
887 if (db->dictionary) {
888 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
889 PLRelease(db->dictionary);
890 db->dictionary = NULL;
891 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
892 domain, the_path);
894 db->timestamp = stbuf.st_mtime;
895 } else {
896 wwarning(_("could not load domain %s from user defaults database"),
897 domain);
901 /* global system dictionary */
902 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
903 if (stat(path, &stbuf)>=0) {
904 shared_dict = ReadProplistFromFile(path);
905 if (shared_dict) {
906 if (requireDictionary && !PLIsDictionary(shared_dict)) {
907 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
908 domain, path);
909 PLRelease(shared_dict);
910 shared_dict = NULL;
911 } else {
912 if (db->dictionary && PLIsDictionary(shared_dict) &&
913 PLIsDictionary(db->dictionary)) {
914 PLMergeDictionaries(shared_dict, db->dictionary);
915 PLRelease(db->dictionary);
916 db->dictionary = shared_dict;
917 if (stbuf.st_mtime > db->timestamp)
918 db->timestamp = stbuf.st_mtime;
919 } else if (!db->dictionary) {
920 db->dictionary = shared_dict;
921 if (stbuf.st_mtime > db->timestamp)
922 db->timestamp = stbuf.st_mtime;
925 } else {
926 wwarning(_("could not load domain %s from global defaults database (%s)"),
927 domain, path);
931 /* set to save it in user's directory, no matter from where it was read */
932 if (db->dictionary) {
933 proplist_t tmp = PLMakeString(db->path);
935 PLSetFilename(db->dictionary, tmp);
936 PLRelease(tmp);
939 return db;
943 void
944 wReadStaticDefaults(proplist_t dict)
946 proplist_t plvalue;
947 WDefaultEntry *entry;
948 int i;
949 void *tdata;
952 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
953 entry = &staticOptionList[i];
955 if (dict)
956 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
957 else
958 plvalue = NULL;
960 if (!plvalue) {
961 /* no default in the DB. Use builtin default */
962 plvalue = entry->plvalue;
965 if (plvalue) {
966 /* convert data */
967 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
968 if (entry->update) {
969 (*entry->update)(NULL, entry, tdata, entry->extra_data);
976 void
977 wDefaultsCheckDomains(void *foo)
979 WScreen *scr;
980 struct stat stbuf;
981 proplist_t dict;
982 int i;
983 char path[PATH_MAX];
985 #ifdef HEARTBEAT
986 puts("Checking domains...");
987 #endif
988 if (stat(WDWindowMaker->path, &stbuf)>=0
989 && WDWindowMaker->timestamp < stbuf.st_mtime) {
990 proplist_t shared_dict = NULL;
991 #ifdef HEARTBEAT
992 puts("Checking WindowMaker domain");
993 #endif
994 WDWindowMaker->timestamp = stbuf.st_mtime;
996 /* global dictionary */
997 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
998 if (stat(path, &stbuf)>=0) {
999 shared_dict = ReadProplistFromFile(path);
1000 if (shared_dict && !PLIsDictionary(shared_dict)) {
1001 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1002 "WindowMaker", path);
1003 PLRelease(shared_dict);
1004 shared_dict = NULL;
1005 } else if (!shared_dict) {
1006 wwarning(_("could not load domain %s from global defaults database"),
1007 "WindowMaker");
1010 /* user dictionary */
1011 dict = ReadProplistFromFile(WDWindowMaker->path);
1012 if (dict) {
1013 if (!PLIsDictionary(dict)) {
1014 PLRelease(dict);
1015 dict = NULL;
1016 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1017 "WindowMaker", WDWindowMaker->path);
1018 } else {
1019 if (shared_dict) {
1020 PLSetFilename(shared_dict, PLGetFilename(dict));
1021 PLMergeDictionaries(shared_dict, dict);
1022 PLRelease(dict);
1023 dict = shared_dict;
1024 shared_dict = NULL;
1026 for (i=0; i<wScreenCount; i++) {
1027 scr = wScreenWithNumber(i);
1028 if (scr)
1029 wReadDefaults(scr, dict);
1031 if (WDWindowMaker->dictionary) {
1032 PLRelease(WDWindowMaker->dictionary);
1034 WDWindowMaker->dictionary = dict;
1036 } else {
1037 wwarning(_("could not load domain %s from user defaults database"),
1038 "WindowMaker");
1040 if (shared_dict) {
1041 PLRelease(shared_dict);
1045 if (stat(WDWindowAttributes->path, &stbuf)>=0
1046 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1047 #ifdef HEARTBEAT
1048 puts("Checking WMWindowAttributes domain");
1049 #endif
1050 dict = ReadProplistFromFile(WDWindowAttributes->path);
1051 if (dict) {
1052 if (!PLIsDictionary(dict)) {
1053 PLRelease(dict);
1054 dict = NULL;
1055 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1056 "WMWindowAttributes", WDWindowAttributes->path);
1057 } else {
1058 if (WDWindowAttributes->dictionary)
1059 PLRelease(WDWindowAttributes->dictionary);
1060 WDWindowAttributes->dictionary = dict;
1061 for (i=0; i<wScreenCount; i++) {
1062 scr = wScreenWithNumber(i);
1063 if (scr)
1064 wDefaultUpdateIcons(scr);
1067 } else {
1068 wwarning(_("could not load domain %s from user defaults database"),
1069 "WMWindowAttributes");
1071 WDWindowAttributes->timestamp = stbuf.st_mtime;
1074 #ifndef LITE
1075 if (stat(WDRootMenu->path, &stbuf)>=0
1076 && WDRootMenu->timestamp < stbuf.st_mtime) {
1077 dict = ReadProplistFromFile(WDRootMenu->path);
1078 #ifdef HEARTBEAT
1079 puts("Checking WMRootMenu domain");
1080 #endif
1081 if (dict) {
1082 if (!PLIsArray(dict) && !PLIsString(dict)) {
1083 PLRelease(dict);
1084 dict = NULL;
1085 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1086 "WMRootMenu", WDRootMenu->path);
1087 } else {
1088 if (WDRootMenu->dictionary) {
1089 PLRelease(WDRootMenu->dictionary);
1091 WDRootMenu->dictionary = dict;
1093 } else {
1094 wwarning(_("could not load domain %s from user defaults database"),
1095 "WMRootMenu");
1097 WDRootMenu->timestamp = stbuf.st_mtime;
1099 #endif /* !LITE */
1101 if (!foo)
1102 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1106 void
1107 wReadDefaults(WScreen *scr, proplist_t new_dict)
1109 proplist_t plvalue, old_value;
1110 WDefaultEntry *entry;
1111 int i, must_update;
1112 int update_workspace_back = 0; /* kluge :/ */
1113 int needs_refresh;
1114 void *tdata;
1115 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1116 ? WDWindowMaker->dictionary : NULL);
1118 must_update = 0;
1120 needs_refresh = 0;
1122 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1123 entry = &optionList[i];
1125 if (new_dict)
1126 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1127 else
1128 plvalue = NULL;
1130 if (!old_dict)
1131 old_value = NULL;
1132 else
1133 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1136 if (!plvalue && !old_value) {
1137 /* no default in the DB. Use builtin default */
1138 plvalue = entry->plvalue;
1139 if (plvalue && new_dict) {
1140 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1141 must_update = 1;
1143 } else if (!plvalue) {
1144 /* value was deleted from DB. Keep current value */
1145 continue;
1146 } else if (!old_value) {
1147 /* set value for the 1st time */
1148 } else if (!PLIsEqual(plvalue, old_value)) {
1149 /* value has changed */
1150 } else {
1152 if (strcmp(entry->key, "WorkspaceBack") == 0
1153 && update_workspace_back
1154 && scr->flags.backimage_helper_launched) {
1155 } else {
1156 /* value was not changed since last time */
1157 continue;
1161 if (plvalue) {
1162 #ifdef DEBUG
1163 printf("Updating %s to %s\n", entry->key,
1164 PLGetDescription(plvalue));
1165 #endif
1166 /* convert data */
1167 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1169 * If the WorkspaceSpecificBack data has been changed
1170 * so that the helper will be launched now, we must be
1171 * sure to send the default background texture config
1172 * to the helper.
1174 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1175 && !scr->flags.backimage_helper_launched) {
1176 update_workspace_back = 1;
1178 if (entry->update) {
1179 needs_refresh |=
1180 (*entry->update)(scr, entry, tdata, entry->extra_data);
1186 if (needs_refresh!=0 && !scr->flags.startup) {
1187 int foo;
1189 foo = 0;
1190 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1191 foo |= WTextureSettings;
1192 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1193 foo |= WFontSettings;
1194 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1195 foo |= WColorSettings;
1196 if (foo)
1197 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1198 (void*)foo);
1200 foo = 0;
1201 if (needs_refresh & REFRESH_MENU_TEXTURE)
1202 foo |= WTextureSettings;
1203 if (needs_refresh & REFRESH_MENU_FONT)
1204 foo |= WFontSettings;
1205 if (needs_refresh & REFRESH_MENU_COLOR)
1206 foo |= WColorSettings;
1207 if (foo)
1208 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1209 (void*)foo);
1211 foo = 0;
1212 if (needs_refresh & REFRESH_WINDOW_FONT) {
1213 foo |= WFontSettings;
1215 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1216 foo |= WTextureSettings;
1218 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1219 foo |= WColorSettings;
1221 if (foo)
1222 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1223 (void*)foo);
1225 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1226 foo = 0;
1227 if (needs_refresh & REFRESH_ICON_FONT) {
1228 foo |= WFontSettings;
1230 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1231 foo |= WTextureSettings;
1233 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1234 foo |= WTextureSettings;
1236 if (foo)
1237 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1238 (void*)foo);
1240 if (needs_refresh & REFRESH_ICON_TILE)
1241 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1246 void
1247 wDefaultUpdateIcons(WScreen *scr)
1249 WAppIcon *aicon = scr->app_icon_list;
1250 WWindow *wwin = scr->focused_window;
1251 char *file;
1253 while(aicon) {
1254 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1255 False);
1256 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1257 || (file && !aicon->icon->file)) {
1258 RImage *new_image;
1260 if (aicon->icon->file)
1261 free(aicon->icon->file);
1262 aicon->icon->file = wstrdup(file);
1264 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1265 aicon->wm_class);
1266 if (new_image) {
1267 wIconChangeImage(aicon->icon, new_image);
1268 wAppIconPaint(aicon);
1271 aicon = aicon->next;
1274 if (!wPreferences.flags.noclip)
1275 wClipIconPaint(scr->clip_icon);
1277 while (wwin) {
1278 if (wwin->icon && wwin->flags.miniaturized) {
1279 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1280 False);
1281 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1282 || (file && !wwin->icon->file)) {
1283 RImage *new_image;
1285 if (wwin->icon->file)
1286 free(wwin->icon->file);
1287 wwin->icon->file = wstrdup(file);
1289 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1290 wwin->wm_class);
1291 if (new_image)
1292 wIconChangeImage(wwin->icon, new_image);
1295 wwin = wwin->prev;
1300 /* --------------------------- Local ----------------------- */
1302 #define STRINGP(x) if (!PLIsString(value)) { \
1303 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1304 entry->key, x); \
1305 return False; }
1309 static int
1310 string2index(proplist_t key, proplist_t val, proplist_t def,
1311 WOptionEnumeration *values)
1313 char *str;
1314 WOptionEnumeration *v;
1315 char buffer[TOTAL_VALUES_LENGTH];
1317 if (PLIsString(val) && (str = PLGetString(val))) {
1318 for (v=values; v->string!=NULL; v++) {
1319 if (strcasecmp(v->string, str)==0)
1320 return v->value;
1324 buffer[0] = 0;
1325 for (v=values; v->string!=NULL; v++) {
1326 if (!v->is_alias) {
1327 if (buffer[0]!=0)
1328 strcat(buffer, ", ");
1329 strcat(buffer, v->string);
1332 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1333 PLGetString(key), buffer);
1335 if (def) {
1336 return string2index(key, val, NULL, values);
1339 return -1;
1346 * value - is the value in the defaults DB
1347 * addr - is the address to store the data
1348 * ret - is the address to store a pointer to a temporary buffer. ret
1349 * must not be freed and is used by the set functions
1351 static int
1352 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1353 void **ret)
1355 static char data;
1356 char *val;
1357 int second_pass=0;
1359 STRINGP("Boolean");
1361 val = PLGetString(value);
1363 again:
1364 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1365 || strcasecmp(val, "YES")==0) {
1367 data = 1;
1368 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1369 || strcasecmp(val, "NO")==0) {
1370 data = 0;
1371 } else {
1372 int i;
1373 if (sscanf(val, "%i", &i)==1) {
1374 if (i!=0)
1375 data = 1;
1376 else
1377 data = 0;
1378 } else {
1379 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1380 val, entry->key);
1381 if (second_pass==0) {
1382 val = PLGetString(entry->plvalue);
1383 second_pass = 1;
1384 wwarning(_("using default \"%s\" instead"), val);
1385 goto again;
1387 return False;
1391 if (ret)
1392 *ret = &data;
1394 if (addr) {
1395 *(char*)addr = data;
1398 return True;
1402 static int
1403 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1404 void **ret)
1406 static int data;
1407 char *val;
1410 STRINGP("Integer");
1412 val = PLGetString(value);
1414 if (sscanf(val, "%i", &data)!=1) {
1415 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1416 val, entry->key);
1417 val = PLGetString(entry->plvalue);
1418 wwarning(_("using default \"%s\" instead"), val);
1419 if (sscanf(val, "%i", &data)!=1) {
1420 return False;
1424 if (ret)
1425 *ret = &data;
1427 if (addr) {
1428 *(int*)addr = data;
1430 return True;
1434 static int
1435 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1436 void **ret)
1438 static WCoord data;
1439 char *val_x, *val_y;
1440 int nelem, changed=0;
1441 proplist_t elem_x, elem_y;
1443 again:
1444 if (!PLIsArray(value)) {
1445 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1446 entry->key, "Coordinate");
1447 if (changed==0) {
1448 value = entry->plvalue;
1449 changed = 1;
1450 wwarning(_("using default \"%s\" instead"), entry->default_value);
1451 goto again;
1453 return False;
1456 nelem = PLGetNumberOfElements(value);
1457 if (nelem != 2) {
1458 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1459 entry->key);
1460 if (changed==0) {
1461 value = entry->plvalue;
1462 changed = 1;
1463 wwarning(_("using default \"%s\" instead"), entry->default_value);
1464 goto again;
1466 return False;
1469 elem_x = PLGetArrayElement(value, 0);
1470 elem_y = PLGetArrayElement(value, 1);
1472 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1473 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1474 entry->key);
1475 if (changed==0) {
1476 value = entry->plvalue;
1477 changed = 1;
1478 wwarning(_("using default \"%s\" instead"), entry->default_value);
1479 goto again;
1481 return False;
1484 val_x = PLGetString(elem_x);
1485 val_y = PLGetString(elem_y);
1487 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1488 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1489 if (changed==0) {
1490 value = entry->plvalue;
1491 changed = 1;
1492 wwarning(_("using default \"%s\" instead"), entry->default_value);
1493 goto again;
1495 return False;
1498 if (data.x < 0)
1499 data.x = 0;
1500 else if (data.x > scr->scr_width/3)
1501 data.x = scr->scr_width/3;
1502 if (data.y < 0)
1503 data.y = 0;
1504 else if (data.y > scr->scr_height/3)
1505 data.y = scr->scr_height/3;
1507 if (ret)
1508 *ret = &data;
1510 if (addr) {
1511 *(WCoord*)addr = data;
1514 return True;
1518 #if 0
1519 /* This function is not used at the moment. */
1520 static int
1521 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1522 void **ret)
1524 static char *data;
1526 STRINGP("String");
1528 data = PLGetString(value);
1530 if (!data) {
1531 data = PLGetString(entry->plvalue);
1532 if (!data)
1533 return False;
1536 if (ret)
1537 *ret = &data;
1539 if (addr)
1540 *(char**)addr = wstrdup(data);
1542 return True;
1544 #endif
1547 static int
1548 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1549 void **ret)
1551 static char *data;
1552 int i, count, len;
1553 char *ptr;
1554 proplist_t d;
1555 int changed=0;
1557 again:
1558 if (!PLIsArray(value)) {
1559 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1560 entry->key, "an array of paths");
1561 if (changed==0) {
1562 value = entry->plvalue;
1563 changed = 1;
1564 wwarning(_("using default \"%s\" instead"), entry->default_value);
1565 goto again;
1567 return False;
1570 i = 0;
1571 count = PLGetNumberOfElements(value);
1572 if (count < 1) {
1573 if (changed==0) {
1574 value = entry->plvalue;
1575 changed = 1;
1576 wwarning(_("using default \"%s\" instead"), entry->default_value);
1577 goto again;
1579 return False;
1582 len = 0;
1583 for (i=0; i<count; i++) {
1584 d = PLGetArrayElement(value, i);
1585 if (!d || !PLIsString(d)) {
1586 count = i;
1587 break;
1589 len += strlen(PLGetString(d))+1;
1592 ptr = data = wmalloc(len+1);
1594 for (i=0; i<count; i++) {
1595 d = PLGetArrayElement(value, i);
1596 if (!d || !PLIsString(d)) {
1597 break;
1599 strcpy(ptr, PLGetString(d));
1600 ptr += strlen(PLGetString(d));
1601 *ptr = ':';
1602 ptr++;
1604 ptr--; *(ptr--) = 0;
1606 if (*(char**)addr!=NULL) {
1607 free(*(char**)addr);
1609 *(char**)addr = data;
1611 return True;
1615 static int
1616 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1617 void **ret)
1619 static signed char data;
1621 data = string2index(entry->plkey, value, entry->default_value,
1622 (WOptionEnumeration*)entry->extra_data);
1623 if (data < 0)
1624 return False;
1626 if (ret)
1627 *ret = &data;
1629 if (addr)
1630 *(signed char*)addr = data;
1632 return True;
1638 * (solid <color>)
1639 * (hgradient <color> <color>)
1640 * (vgradient <color> <color>)
1641 * (dgradient <color> <color>)
1642 * (mhgradient <color> <color> ...)
1643 * (mvgradient <color> <color> ...)
1644 * (tpixmap <file> <color>)
1645 * (spixmap <file> <color>)
1646 * (cpixmap <file> <color>)
1647 * (thgradient <file> <opaqueness> <color> <color>)
1648 * (tvgradient <file> <opaqueness> <color> <color>)
1649 * (tdgradient <file> <opaqueness> <color> <color>)
1650 * (function <lib> <function> ...)
1653 static WTexture*
1654 parse_texture(WScreen *scr, proplist_t pl)
1656 proplist_t elem;
1657 char *val;
1658 int nelem;
1659 WTexture *texture=NULL;
1661 nelem = PLGetNumberOfElements(pl);
1662 if (nelem < 1)
1663 return NULL;
1666 elem = PLGetArrayElement(pl, 0);
1667 if (!elem || !PLIsString(elem))
1668 return NULL;
1669 val = PLGetString(elem);
1672 if (strcasecmp(val, "solid")==0) {
1673 XColor color;
1675 if (nelem != 2)
1676 return NULL;
1678 /* get color */
1680 elem = PLGetArrayElement(pl, 1);
1681 if (!elem || !PLIsString(elem))
1682 return NULL;
1683 val = PLGetString(elem);
1685 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1686 wwarning(_("\"%s\" is not a valid color name"), val);
1687 return NULL;
1690 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1691 } else if (strcasecmp(val, "dgradient")==0
1692 || strcasecmp(val, "vgradient")==0
1693 || strcasecmp(val, "hgradient")==0) {
1694 RColor color1, color2;
1695 XColor xcolor;
1696 int type;
1698 if (nelem != 3) {
1699 wwarning(_("bad number of arguments in gradient specification"));
1700 return NULL;
1703 if (val[0]=='d' || val[0]=='D')
1704 type = WTEX_DGRADIENT;
1705 else if (val[0]=='h' || val[0]=='H')
1706 type = WTEX_HGRADIENT;
1707 else
1708 type = WTEX_VGRADIENT;
1711 /* get from color */
1712 elem = PLGetArrayElement(pl, 1);
1713 if (!elem || !PLIsString(elem))
1714 return NULL;
1715 val = PLGetString(elem);
1717 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1718 wwarning(_("\"%s\" is not a valid color name"), val);
1719 return NULL;
1721 color1.alpha = 255;
1722 color1.red = xcolor.red >> 8;
1723 color1.green = xcolor.green >> 8;
1724 color1.blue = xcolor.blue >> 8;
1726 /* get to color */
1727 elem = PLGetArrayElement(pl, 2);
1728 if (!elem || !PLIsString(elem)) {
1729 return NULL;
1731 val = PLGetString(elem);
1733 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1734 wwarning(_("\"%s\" is not a valid color name"), val);
1735 return NULL;
1737 color2.alpha = 255;
1738 color2.red = xcolor.red >> 8;
1739 color2.green = xcolor.green >> 8;
1740 color2.blue = xcolor.blue >> 8;
1742 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1744 } else if (strcasecmp(val, "mhgradient")==0
1745 || strcasecmp(val, "mvgradient")==0
1746 || strcasecmp(val, "mdgradient")==0) {
1747 XColor color;
1748 RColor **colors;
1749 int i, count;
1750 int type;
1752 if (nelem < 3) {
1753 wwarning(_("too few arguments in multicolor gradient specification"));
1754 return NULL;
1757 if (val[1]=='h' || val[1]=='H')
1758 type = WTEX_MHGRADIENT;
1759 else if (val[1]=='v' || val[1]=='V')
1760 type = WTEX_MVGRADIENT;
1761 else
1762 type = WTEX_MDGRADIENT;
1764 count = nelem-1;
1766 colors = wmalloc(sizeof(RColor*)*(count+1));
1768 for (i=0; i<count; i++) {
1769 elem = PLGetArrayElement(pl, i+1);
1770 if (!elem || !PLIsString(elem)) {
1771 for (--i; i>=0; --i) {
1772 free(colors[i]);
1774 free(colors);
1775 return NULL;
1777 val = PLGetString(elem);
1779 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1780 wwarning(_("\"%s\" is not a valid color name"), val);
1781 for (--i; i>=0; --i) {
1782 free(colors[i]);
1784 free(colors);
1785 return NULL;
1786 } else {
1787 colors[i] = wmalloc(sizeof(RColor));
1788 colors[i]->red = color.red >> 8;
1789 colors[i]->green = color.green >> 8;
1790 colors[i]->blue = color.blue >> 8;
1793 colors[i] = NULL;
1795 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1796 } else if (strcasecmp(val, "spixmap")==0 ||
1797 strcasecmp(val, "cpixmap")==0 ||
1798 strcasecmp(val, "tpixmap")==0) {
1799 XColor color;
1800 int type;
1802 if (nelem != 3)
1803 return NULL;
1805 if (val[0] == 's' || val[0] == 'S')
1806 type = WTP_SCALE;
1807 else if (val[0] == 'c' || val[0] == 'C')
1808 type = WTP_CENTER;
1809 else
1810 type = WTP_TILE;
1812 /* get color */
1813 elem = PLGetArrayElement(pl, 2);
1814 if (!elem || !PLIsString(elem)) {
1815 return NULL;
1817 val = PLGetString(elem);
1819 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1820 wwarning(_("\"%s\" is not a valid color name"), val);
1821 return NULL;
1824 /* file name */
1825 elem = PLGetArrayElement(pl, 1);
1826 if (!elem || !PLIsString(elem))
1827 return NULL;
1828 val = PLGetString(elem);
1830 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1831 } else if (strcasecmp(val, "thgradient")==0
1832 || strcasecmp(val, "tvgradient")==0
1833 || strcasecmp(val, "tdgradient")==0) {
1834 RColor color1, color2;
1835 XColor xcolor;
1836 int opacity;
1837 int style;
1839 if (val[1]=='h' || val[1]=='H')
1840 style = WTEX_THGRADIENT;
1841 else if (val[1]=='v' || val[1]=='V')
1842 style = WTEX_TVGRADIENT;
1843 else
1844 style = WTEX_TDGRADIENT;
1846 if (nelem != 5) {
1847 wwarning(_("bad number of arguments in textured gradient specification"));
1848 return NULL;
1851 /* get from color */
1852 elem = PLGetArrayElement(pl, 3);
1853 if (!elem || !PLIsString(elem))
1854 return NULL;
1855 val = PLGetString(elem);
1857 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1858 wwarning(_("\"%s\" is not a valid color name"), val);
1859 return NULL;
1861 color1.alpha = 255;
1862 color1.red = xcolor.red >> 8;
1863 color1.green = xcolor.green >> 8;
1864 color1.blue = xcolor.blue >> 8;
1866 /* get to color */
1867 elem = PLGetArrayElement(pl, 4);
1868 if (!elem || !PLIsString(elem)) {
1869 return NULL;
1871 val = PLGetString(elem);
1873 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1874 wwarning(_("\"%s\" is not a valid color name"), val);
1875 return NULL;
1877 color2.alpha = 255;
1878 color2.red = xcolor.red >> 8;
1879 color2.green = xcolor.green >> 8;
1880 color2.blue = xcolor.blue >> 8;
1882 /* get opacity */
1883 elem = PLGetArrayElement(pl, 2);
1884 if (!elem || !PLIsString(elem))
1885 opacity = 128;
1886 else
1887 val = PLGetString(elem);
1889 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1890 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1891 opacity = 128;
1894 /* get file name */
1895 elem = PLGetArrayElement(pl, 1);
1896 if (!elem || !PLIsString(elem))
1897 return NULL;
1898 val = PLGetString(elem);
1900 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1901 val, opacity);
1903 #ifdef TEXTURE_PLUGIN
1904 else if (strcasecmp(val, "function")==0) {
1905 WTexFunction *function;
1906 void (*initFunc) (Display *, Colormap);
1907 char *lib, *func, **argv;
1908 int i, argc;
1910 if (nelem < 3)
1911 return NULL;
1913 /* get the library name */
1914 elem = PLGetArrayElement(pl, 1);
1915 if (!elem || !PLIsString(elem)) {
1916 return NULL;
1918 lib = PLGetString(elem);
1920 /* get the function name */
1921 elem = PLGetArrayElement(pl, 2);
1922 if (!elem || !PLIsString(elem)) {
1923 return NULL;
1925 func = PLGetString(elem);
1927 argc = nelem - 2;
1928 argv = (char **)wmalloc(argc * sizeof(char *));
1930 /* get the parameters */
1931 argv[0] = wstrdup(func);
1932 for (i = 0; i < argc - 1; i++) {
1933 elem = PLGetArrayElement(pl, 3 + i);
1934 if (!elem || !PLIsString(elem)) {
1935 free(argv);
1937 return NULL;
1939 argv[i+1] = wstrdup(PLGetString(elem));
1942 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1944 #ifdef HAVE_DLFCN_H
1945 if (function) {
1946 initFunc = dlsym(function->handle, "initWindowMaker");
1947 if (initFunc) {
1948 initFunc(dpy, scr->w_colormap);
1949 } else {
1950 wwarning(_("could not initialize library %s"), lib);
1952 } else {
1953 wwarning(_("could not find function %s::%s"), lib, func);
1955 #endif /* HAVE_DLFCN_H */
1956 texture = (WTexture*)function;
1958 #endif /* TEXTURE_PLUGIN */
1959 else {
1960 wwarning(_("invalid texture type %s"), val);
1961 return NULL;
1963 return texture;
1968 static int
1969 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1970 void **ret)
1972 static WTexture *texture;
1973 int changed=0;
1975 again:
1976 if (!PLIsArray(value)) {
1977 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1978 entry->key, "Texture");
1979 if (changed==0) {
1980 value = entry->plvalue;
1981 changed = 1;
1982 wwarning(_("using default \"%s\" instead"), entry->default_value);
1983 goto again;
1985 return False;
1988 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
1989 proplist_t pl;
1991 pl = PLGetArrayElement(value, 0);
1992 if (!pl || !PLIsString(pl) || !PLGetString(pl)
1993 || strcasecmp(PLGetString(pl), "solid")!=0) {
1994 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1995 entry->key, "Solid Texture");
1997 value = entry->plvalue;
1998 changed = 1;
1999 wwarning(_("using default \"%s\" instead"), entry->default_value);
2000 goto again;
2004 texture = parse_texture(scr, value);
2006 if (!texture) {
2007 wwarning(_("Error in texture specification for key \"%s\""),
2008 entry->key);
2009 if (changed==0) {
2010 value = entry->plvalue;
2011 changed = 1;
2012 wwarning(_("using default \"%s\" instead"), entry->default_value);
2013 goto again;
2015 return False;
2018 if (ret)
2019 *ret = &texture;
2021 if (addr)
2022 *(WTexture**)addr = texture;
2024 return True;
2029 #ifdef DRAWSTRING_PLUGIN
2030 static int
2031 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2032 void *addr, void **ret)
2034 proplist_t elem;
2035 char *val, *lib, *func, **argv;
2036 int argc, changed;
2038 if (strcmp(entry->key, "FTitleColor")==0) {
2039 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2040 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2041 } else if (strcmp(entry->key, "UTitleColor")==0) {
2042 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2043 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2044 } else if (strcmp(entry->key, "PTitleColor")==0) {
2045 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2046 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2047 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2048 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2049 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2050 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2051 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2052 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2055 if (PLIsArray(value)) {
2056 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2057 argc -= 2;
2058 argv = (char **)wmalloc(argc * sizeof(char *));
2060 elem = PLGetArrayElement(value,0);
2061 if (!elem || !PLIsString(elem)) return False;
2062 val = PLGetString(elem);
2063 if (strcasecmp(val, "function")==0) {
2064 elem = PLGetArrayElement(value, 1); /* library name */
2065 if (!elem || !PLIsString(elem)) return False;
2066 lib = PLGetString(elem);
2067 elem = PLGetArrayElement(value, 2); /* function name */
2068 if (!elem || !PLIsString(elem)) return False;
2069 func = PLGetString(elem);
2070 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2071 lib, "initDrawString", func, NULL, value,
2072 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2075 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2076 } else if (PLIsString(value)) {
2077 return getColor(scr, entry, value, addr, ret);
2080 return False;
2082 #endif /* DRAWSTRING_PLUGIN */
2086 static int
2087 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2088 void *addr, void **ret)
2090 proplist_t elem;
2091 int changed = 0;
2092 char *val;
2093 int nelem;
2095 again:
2096 if (!PLIsArray(value)) {
2097 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2098 "WorkspaceBack", "Texture or None");
2099 if (changed==0) {
2100 value = entry->plvalue;
2101 changed = 1;
2102 wwarning(_("using default \"%s\" instead"), entry->default_value);
2103 goto again;
2105 return False;
2108 /* only do basic error checking and verify for None texture */
2110 nelem = PLGetNumberOfElements(value);
2111 if (nelem > 0) {
2112 elem = PLGetArrayElement(value, 0);
2113 if (!elem || !PLIsString(elem)) {
2114 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2115 if (changed==0) {
2116 value = entry->plvalue;
2117 changed = 1;
2118 wwarning(_("using default \"%s\" instead"), entry->default_value);
2119 goto again;
2121 return False;
2123 val = PLGetString(elem);
2125 if (strcasecmp(val, "None")==0)
2126 return True;
2128 *ret = PLRetain(value);
2130 return True;
2134 static int
2135 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2136 void *addr, void **ret)
2138 proplist_t elem;
2139 int nelem;
2140 int changed = 0;
2142 again:
2143 if (!PLIsArray(value)) {
2144 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2145 "WorkspaceSpecificBack", "an array of textures");
2146 if (changed==0) {
2147 value = entry->plvalue;
2148 changed = 1;
2149 wwarning(_("using default \"%s\" instead"), entry->default_value);
2150 goto again;
2152 return False;
2155 /* only do basic error checking and verify for None texture */
2157 nelem = PLGetNumberOfElements(value);
2158 if (nelem > 0) {
2159 while (nelem--) {
2160 elem = PLGetArrayElement(value, nelem);
2161 if (!elem || !PLIsArray(elem)) {
2162 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2163 nelem);
2168 *ret = PLRetain(value);
2170 #ifdef notworking
2172 * Kluge to force wmsetbg helper to set the default background.
2173 * If the WorkspaceSpecificBack is changed once wmaker has started,
2174 * the WorkspaceBack won't be sent to the helper, unless the user
2175 * changes it's value too. So, we must force this by removing the
2176 * value from the defaults DB.
2178 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2179 proplist_t key = PLMakeString("WorkspaceBack");
2181 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2183 PLRelease(key);
2185 #endif
2186 return True;
2190 static int
2191 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2192 void **ret)
2194 static WMFont *font;
2195 char *val;
2197 STRINGP("Font");
2199 val = PLGetString(value);
2201 font = WMCreateFont(scr->wmscreen, val);
2202 if (!font)
2203 font = WMCreateFont(scr->wmscreen, "fixed");
2205 if (!font) {
2206 wfatal(_("could not load any usable font!!!"));
2207 exit(1);
2210 if (ret)
2211 *ret = font;
2213 /* can't assign font value outside update function */
2214 wassertrv(addr == NULL, True);
2216 return True;
2220 static int
2221 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2222 void **ret)
2224 static XColor color;
2225 char *val;
2226 int second_pass=0;
2228 STRINGP("Color");
2230 val = PLGetString(value);
2232 again:
2233 if (!wGetColor(scr, val, &color)) {
2234 wwarning(_("could not get color for key \"%s\""),
2235 entry->key);
2236 if (second_pass==0) {
2237 val = PLGetString(entry->plvalue);
2238 second_pass = 1;
2239 wwarning(_("using default \"%s\" instead"), val);
2240 goto again;
2242 return False;
2245 if (ret)
2246 *ret = &color;
2248 assert(addr==NULL);
2250 if (addr)
2251 *(unsigned long*)addr = pixel;
2254 return True;
2259 static int
2260 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2261 void **ret)
2263 static WShortKey shortcut;
2264 KeySym ksym;
2265 char *val;
2266 char *k;
2267 char buf[128], *b;
2270 STRINGP("Key spec");
2272 val = PLGetString(value);
2274 if (!val || strcasecmp(val, "NONE")==0) {
2275 shortcut.keycode = 0;
2276 shortcut.modifier = 0;
2277 if (ret)
2278 *ret = &shortcut;
2279 return True;
2282 strcpy(buf, val);
2284 b = (char*)buf;
2286 /* get modifiers */
2287 shortcut.modifier = 0;
2288 while ((k = strchr(b, '+'))!=NULL) {
2289 int mod;
2291 *k = 0;
2292 mod = wXModifierFromKey(b);
2293 if (mod<0) {
2294 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2295 return False;
2297 shortcut.modifier |= mod;
2299 b = k+1;
2302 /* get key */
2303 ksym = XStringToKeysym(b);
2305 if (ksym==NoSymbol) {
2306 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2307 val);
2308 return False;
2311 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2312 if (shortcut.keycode==0) {
2313 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2314 return False;
2317 if (ret)
2318 *ret = &shortcut;
2320 return True;
2324 static int
2325 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2326 void **ret)
2328 static unsigned int mask;
2329 char *str;
2331 STRINGP("Modifier Key");
2333 str = PLGetString(value);
2334 if (!str)
2335 return False;
2337 mask = wXModifierFromKey(str);
2338 if (mask < 0) {
2339 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2340 mask = 0;
2341 return False;
2344 if (addr)
2345 *(unsigned int*)addr = mask;
2347 if (ret)
2348 *ret = &mask;
2350 return True;
2354 #ifdef NEWSTUFF
2355 static int
2356 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2357 void *addr, void **ret)
2359 unsigned int mask;
2360 char *str;
2361 RImage *image;
2362 int i, n;
2363 int w, h;
2365 STRINGP("Image File Path");
2367 str = PLGetString(value);
2368 if (!str)
2369 return False;
2371 image = RLoadImage(scr->rcontext, str, 0);
2372 if (!image) {
2373 wwarning(_("could not load image in option %s: %s"), entry->key,
2374 RMessageForError(RErrorCode));
2375 return False;
2378 if (*(RImage**)addr) {
2379 RDestroyImage(*(RImage**)addr);
2381 if (addr)
2382 *(RImage**)addr = image;
2384 assert(ret == NULL);
2386 if (ret)
2387 *(RImage**)ret = image;
2390 return True;
2392 #endif
2395 /* ---------------- value setting functions --------------- */
2396 static int
2397 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2399 return REFRESH_WINDOW_TITLE_COLOR;
2403 static int
2404 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2406 switch (which) {
2407 case WM_DOCK:
2408 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2409 break;
2410 case WM_CLIP:
2411 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2412 break;
2413 default:
2414 break;
2416 return 0;
2420 static int
2421 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2423 if (scr->workspaces) {
2424 wWorkspaceForceChange(scr, scr->current_workspace);
2425 wArrangeIcons(scr, False);
2427 return 0;
2430 #if not_used
2431 static int
2432 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2434 if (*value <= 0)
2435 *(int*)foo = 1;
2437 return 0;
2439 #endif
2443 static int
2444 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2446 Pixmap pixmap;
2447 RImage *img;
2448 int reset = 0;
2450 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2451 wPreferences.icon_size,
2452 ((*texture)->any.type & WREL_BORDER_MASK)
2453 ? WREL_ICON : WREL_FLAT);
2454 if (!img) {
2455 wwarning(_("could not render texture for icon background"));
2456 if (!entry->addr)
2457 wTextureDestroy(scr, *texture);
2458 return 0;
2460 RConvertImage(scr->rcontext, img, &pixmap);
2462 if (scr->icon_tile) {
2463 reset = 1;
2464 RDestroyImage(scr->icon_tile);
2465 XFreePixmap(dpy, scr->icon_tile_pixmap);
2468 scr->icon_tile = img;
2470 if (!wPreferences.flags.noclip) {
2471 if (scr->clip_tile) {
2472 RDestroyImage(scr->clip_tile);
2474 scr->clip_tile = wClipMakeTile(scr, img);
2477 scr->icon_tile_pixmap = pixmap;
2479 if (scr->def_icon_pixmap) {
2480 XFreePixmap(dpy, scr->def_icon_pixmap);
2481 scr->def_icon_pixmap = None;
2483 if (scr->def_ticon_pixmap) {
2484 XFreePixmap(dpy, scr->def_ticon_pixmap);
2485 scr->def_ticon_pixmap = None;
2488 if (scr->icon_back_texture) {
2489 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2491 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2493 if (scr->clip_balloon)
2494 XSetWindowBackground(dpy, scr->clip_balloon,
2495 (*texture)->any.color.pixel);
2498 * Free the texture as nobody else will use it, nor refer to it.
2500 if (!entry->addr)
2501 wTextureDestroy(scr, *texture);
2503 return (reset ? REFRESH_ICON_TILE : 0);
2508 static int
2509 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2511 if (scr->title_font) {
2512 WMReleaseFont(scr->title_font);
2514 scr->title_font = font;
2516 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2520 static int
2521 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2523 if (scr->menu_title_font) {
2524 WMReleaseFont(scr->menu_title_font);
2527 scr->menu_title_font = font;
2529 return REFRESH_MENU_TITLE_FONT;
2533 static int
2534 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2536 if (scr->menu_entry_font) {
2537 WMReleaseFont(scr->menu_entry_font);
2539 scr->menu_entry_font = font;
2541 return REFRESH_MENU_FONT;
2546 static int
2547 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2549 if (scr->icon_title_font) {
2550 WMReleaseFont(scr->icon_title_font);
2553 scr->icon_title_font = font;
2555 return REFRESH_ICON_FONT;
2559 static int
2560 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2562 if (scr->clip_title_font) {
2563 WMReleaseFont(scr->clip_title_font);
2566 scr->clip_title_font = font;
2568 return REFRESH_ICON_FONT;
2572 static int
2573 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2575 if (scr->info_text_font) {
2576 WMReleaseFont(scr->info_text_font);
2579 scr->info_text_font = font;
2581 /* This test works because the scr structure is initially zeroed out
2582 and None = 0. Any other time, the window should be valid. */
2583 if (scr->geometry_display != None) {
2584 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2585 &scr->geometry_display_height);
2586 XResizeWindow(dpy, scr->geometry_display,
2587 scr->geometry_display_width, scr->geometry_display_height);
2590 return 0;
2594 static int
2595 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2597 if (scr->workspace_name_font) {
2598 WMReleaseFont(scr->workspace_name_font);
2601 scr->workspace_name_font = font;
2603 return 0;
2607 static int
2608 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2610 if (scr->select_pixel!=scr->white_pixel &&
2611 scr->select_pixel!=scr->black_pixel) {
2612 wFreeColor(scr, scr->select_pixel);
2615 scr->select_pixel = color->pixel;
2617 return REFRESH_MENU_COLOR;
2621 static int
2622 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2624 if (scr->select_text_pixel!=scr->white_pixel &&
2625 scr->select_text_pixel!=scr->black_pixel) {
2626 wFreeColor(scr, scr->select_text_pixel);
2629 scr->select_text_pixel = color->pixel;
2631 return REFRESH_MENU_COLOR;
2635 static int
2636 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2638 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2639 scr->clip_title_pixel[index]!=scr->black_pixel) {
2640 wFreeColor(scr, scr->clip_title_pixel[index]);
2642 scr->clip_title_pixel[index] = color->pixel;
2644 #ifdef GRADIENT_CLIP_ARROW
2645 if (index == CLIP_NORMAL) {
2646 RImage *image;
2647 RColor color1, color2;
2648 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2649 int as = pt - 15; /* 15 = 5+5+5 */
2651 FREE_PIXMAP(scr->clip_arrow_gradient);
2653 color1.red = (color->red >> 8)*6/10;
2654 color1.green = (color->green >> 8)*6/10;
2655 color1.blue = (color->blue >> 8)*6/10;
2657 color2.red = WMIN((color->red >> 8)*20/10, 255);
2658 color2.green = WMIN((color->green >> 8)*20/10, 255);
2659 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2661 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2662 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2663 RDestroyImage(image);
2665 #endif /* GRADIENT_CLIP_ARROW */
2667 return REFRESH_ICON_TITLE_COLOR;
2671 static int
2672 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2674 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2675 scr->window_title_pixel[index]!=scr->black_pixel) {
2676 wFreeColor(scr, scr->window_title_pixel[index]);
2679 scr->window_title_pixel[index] = color->pixel;
2681 if (index == WS_UNFOCUSED)
2682 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2684 return REFRESH_WINDOW_TITLE_COLOR;
2688 static int
2689 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2691 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2692 scr->menu_title_pixel[0]!=scr->black_pixel) {
2693 #ifdef DRAWSTRING_PLUGIN
2694 if(!scr->drawstring_func[W_STRING_MTITLE])
2695 #endif
2696 wFreeColor(scr, scr->menu_title_pixel[0]);
2699 scr->menu_title_pixel[0] = color->pixel;
2700 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2702 return REFRESH_MENU_TITLE_COLOR;
2706 static int
2707 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2709 XGCValues gcv;
2710 #define gcm (GCForeground|GCBackground|GCFillStyle)
2712 if (scr->mtext_pixel!=scr->white_pixel &&
2713 scr->mtext_pixel!=scr->black_pixel) {
2714 wFreeColor(scr, scr->mtext_pixel);
2717 scr->mtext_pixel = color->pixel;
2719 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2722 if (scr->dtext_pixel == scr->mtext_pixel) {
2723 gcv.foreground = scr->white_pixel;
2724 gcv.background = scr->black_pixel;
2725 gcv.fill_style = FillStippled;
2726 } else {
2727 gcv.foreground = scr->dtext_pixel;
2728 gcv.fill_style = FillSolid;
2730 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2732 return REFRESH_MENU_COLOR;
2733 #undef gcm
2737 static int
2738 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2740 XGCValues gcv;
2741 #define gcm (GCForeground|GCBackground|GCFillStyle)
2743 if (scr->dtext_pixel!=scr->white_pixel &&
2744 scr->dtext_pixel!=scr->black_pixel) {
2745 wFreeColor(scr, scr->dtext_pixel);
2748 scr->dtext_pixel = color->pixel;
2750 if (scr->dtext_pixel == scr->mtext_pixel) {
2751 gcv.foreground = scr->white_pixel;
2752 gcv.background = scr->black_pixel;
2753 gcv.fill_style = FillStippled;
2754 } else {
2755 gcv.foreground = scr->dtext_pixel;
2756 gcv.fill_style = FillSolid;
2758 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2760 return REFRESH_MENU_COLOR;
2761 #undef gcm
2764 static int
2765 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2767 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2769 return REFRESH_ICON_TITLE_COLOR;
2773 static int
2774 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2776 if (scr->icon_title_texture) {
2777 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2779 XQueryColor (dpy, scr->w_colormap, color);
2780 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2782 return REFRESH_ICON_TITLE_BACK;
2786 static void
2787 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2789 close(scr->helper_fd);
2790 scr->helper_fd = 0;
2791 scr->helper_pid = 0;
2792 scr->flags.backimage_helper_launched = 0;
2796 static int
2797 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2798 void *bar)
2800 int i;
2801 proplist_t val;
2802 char *str;
2804 if (scr->flags.backimage_helper_launched) {
2805 if (PLGetNumberOfElements(value)==0) {
2806 SendHelperMessage(scr, 'C', 0, NULL);
2807 SendHelperMessage(scr, 'K', 0, NULL);
2809 PLRelease(value);
2810 return 0;
2812 } else {
2813 pid_t pid;
2814 int filedes[2];
2816 if (PLGetNumberOfElements(value) == 0)
2817 return 0;
2819 if (pipe(filedes) < 0) {
2820 wsyserror("pipe() failed:can't set workspace specific background image");
2822 PLRelease(value);
2823 return 0;
2826 pid = fork();
2827 if (pid < 0) {
2828 wsyserror("fork() failed:can't set workspace specific background image");
2829 if (close(filedes[0]) < 0)
2830 wsyserror("could not close pipe");
2831 if (close(filedes[1]) < 0)
2832 wsyserror("could not close pipe");
2834 } else if (pid == 0) {
2835 SetupEnvironment(scr);
2837 if (close(0) < 0)
2838 wsyserror("could not close pipe");
2839 if (dup(filedes[0]) < 0) {
2840 wsyserror("dup() failed:can't set workspace specific background image");
2842 if (wPreferences.smooth_workspace_back)
2843 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2844 else
2845 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2846 wsyserror("could not execute wmsetbg");
2847 exit(1);
2848 } else {
2850 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2851 wsyserror("error setting close-on-exec flag");
2853 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2854 wsyserror("error setting close-on-exec flag");
2857 scr->helper_fd = filedes[1];
2858 scr->helper_pid = pid;
2859 scr->flags.backimage_helper_launched = 1;
2861 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2863 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2868 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2869 val = PLGetArrayElement(value, i);
2870 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2871 str = PLGetDescription(val);
2873 SendHelperMessage(scr, 'S', i+1, str);
2875 free(str);
2876 } else {
2877 SendHelperMessage(scr, 'U', i+1, NULL);
2880 sleep(1);
2882 PLRelease(value);
2883 return 0;
2887 static int
2888 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2889 void *bar)
2891 if (scr->flags.backimage_helper_launched) {
2892 char *str;
2894 if (PLGetNumberOfElements(value)==0) {
2895 SendHelperMessage(scr, 'U', 0, NULL);
2896 } else {
2897 /* set the default workspace background to this one */
2898 str = PLGetDescription(value);
2899 if (str) {
2900 SendHelperMessage(scr, 'S', 0, str);
2901 free(str);
2902 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2903 } else {
2904 SendHelperMessage(scr, 'U', 0, NULL);
2907 } else {
2908 char *command;
2909 char *text;
2911 SetupEnvironment(scr);
2912 text = PLGetDescription(value);
2913 command = wmalloc(strlen(text)+40);
2914 if (wPreferences.smooth_workspace_back)
2915 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2916 else
2917 sprintf(command, "wmsetbg -d -p '%s' &", text);
2918 free(text);
2919 system(command);
2920 free(command);
2922 PLRelease(value);
2924 return 0;
2928 static int
2929 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2931 if (scr->widget_texture) {
2932 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2934 scr->widget_texture = *(WTexSolid**)texture;
2936 if (scr->geometry_display != None)
2937 XSetWindowBackground(dpy, scr->geometry_display,
2938 scr->widget_texture->normal.pixel);
2940 return 0;
2944 static int
2945 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2947 if (scr->window_title_texture[WS_FOCUSED]) {
2948 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2950 scr->window_title_texture[WS_FOCUSED] = *texture;
2952 return REFRESH_WINDOW_TEXTURES;
2956 static int
2957 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2959 if (scr->window_title_texture[WS_PFOCUSED]) {
2960 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2962 scr->window_title_texture[WS_PFOCUSED] = *texture;
2964 return REFRESH_WINDOW_TEXTURES;
2968 static int
2969 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2971 if (scr->window_title_texture[WS_UNFOCUSED]) {
2972 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2974 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2976 return REFRESH_WINDOW_TEXTURES;
2980 static int
2981 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2983 if (scr->resizebar_texture[0]) {
2984 wTextureDestroy(scr, scr->resizebar_texture[0]);
2986 scr->resizebar_texture[0] = *texture;
2988 return REFRESH_WINDOW_TEXTURES;
2992 static int
2993 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2995 if (scr->menu_title_texture[0]) {
2996 wTextureDestroy(scr, scr->menu_title_texture[0]);
2998 scr->menu_title_texture[0] = *texture;
3000 return REFRESH_MENU_TITLE_TEXTURE;
3004 static int
3005 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3007 if (scr->menu_item_texture) {
3008 wTextureDestroy(scr, scr->menu_item_texture);
3009 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3011 scr->menu_item_texture = *texture;
3013 scr->menu_item_auxtexture
3014 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3016 return REFRESH_MENU_TEXTURE;
3020 static int
3021 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3023 WWindow *wwin;
3024 wKeyBindings[index] = *shortcut;
3026 wwin = scr->focused_window;
3028 while (wwin!=NULL) {
3029 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3031 if (!WFLAGP(wwin, no_bind_keys)) {
3032 wWindowSetKeyGrabs(wwin);
3034 wwin = wwin->prev;
3037 return 0;
3041 static int
3042 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3044 wArrangeIcons(scr, True);
3046 return 0;
3050 static int
3051 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3053 wScreenUpdateUsableArea(scr);
3055 return 0;
3059 static int
3060 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3062 return REFRESH_MENU_TEXTURE;
3067 static int
3068 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3070 return REFRESH_BUTTON_IMAGES;
3075 * Very ugly kluge.
3076 * Need access to the double click variables, so that all widgets in
3077 * wmaker panels will have the same dbl-click values.
3078 * TODO: figure a better way of dealing with it.
3080 #include "WINGsP.h"
3082 static int
3083 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3085 extern _WINGsConfiguration WINGsConfiguration;
3087 if (*value <= 0)
3088 *(int*)foo = 1;
3090 WINGsConfiguration.doubleClickDelay = *value;
3092 return 0;
3097 static int
3098 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3100 extern _WINGsConfiguration WINGsConfiguration;
3102 WINGsConfiguration.useMultiByte = *value;
3104 return 0;