clearance for text on titlebar.
[wmaker-crm.git] / src / defaults.c
blobf985422a6bbe9e5351b1678614773ed5f1ba358d
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 setClearance();
145 static int setIfDockPresent();
146 static int setStickyIcons();
148 static int setPositive();
150 static int setWidgetColor();
151 static int setIconTile();
152 static int setWinTitleFont();
153 static int setMenuTitleFont();
154 static int setMenuTextFont();
155 static int setIconTitleFont();
156 static int setIconTitleColor();
157 static int setIconTitleBack();
158 static int setDisplayFont();
159 static int setLargeDisplayFont();
160 static int setWTitleColor();
161 static int setFTitleBack();
162 static int setPTitleBack();
163 static int setUTitleBack();
164 static int setResizebarBack();
165 static int setWorkspaceBack();
166 static int setWorkspaceSpecificBack();
167 static int setMenuTitleColor();
168 static int setMenuTextColor();
169 static int setMenuDisabledColor();
170 static int setMenuTitleBack();
171 static int setMenuTextBack();
172 static int setHightlight();
173 static int setHightlightText();
174 static int setKeyGrab();
175 static int setDoubleClick();
176 static int setIconPosition();
178 static int setClipTitleFont();
179 static int setClipTitleColor();
181 static int setMenuStyle();
182 static int setMultiByte();
184 static int updateUsableArea();
189 * Tables to convert strings to enumeration values.
190 * Values stored are char
194 /* WARNING: sum of length of all value strings must not exceed
195 * this value */
196 #define TOTAL_VALUES_LENGTH 80
201 #define REFRESH_WINDOW_TEXTURES (1<<0)
202 #define REFRESH_MENU_TEXTURE (1<<1)
203 #define REFRESH_MENU_FONT (1<<2)
204 #define REFRESH_MENU_COLOR (1<<3)
205 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
206 #define REFRESH_MENU_TITLE_FONT (1<<5)
207 #define REFRESH_MENU_TITLE_COLOR (1<<6)
208 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
209 #define REFRESH_WINDOW_FONT (1<<8)
210 #define REFRESH_ICON_TILE (1<<9)
211 #define REFRESH_ICON_FONT (1<<10)
212 #define REFRESH_WORKSPACE_BACK (1<<11)
214 #define REFRESH_BUTTON_IMAGES (1<<12)
216 #define REFRESH_ICON_TITLE_COLOR (1<<13)
217 #define REFRESH_ICON_TITLE_BACK (1<<14)
221 static WOptionEnumeration seFocusModes[] = {
222 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
223 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
224 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
225 {NULL, 0, 0}
228 static WOptionEnumeration seColormapModes[] = {
229 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
230 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
231 {NULL, 0, 0}
234 static WOptionEnumeration sePlacements[] = {
235 {"Auto", WPM_AUTO, 0},
236 {"Smart", WPM_SMART, 0},
237 {"Cascade", WPM_CASCADE, 0},
238 {"Random", WPM_RANDOM, 0},
239 {"Manual", WPM_MANUAL, 0},
240 {NULL, 0, 0}
243 static WOptionEnumeration seGeomDisplays[] = {
244 {"Center", WDIS_CENTER, 0},
245 {"Corner", WDIS_TOPLEFT, 0},
246 {"Floating", WDIS_FRAME_CENTER, 0},
247 {"Line", WDIS_NEW, 0},
248 {NULL, 0, 0}
251 static WOptionEnumeration seSpeeds[] = {
252 {"UltraFast", SPEED_ULTRAFAST, 0},
253 {"Fast", SPEED_FAST, 0},
254 {"Medium", SPEED_MEDIUM, 0},
255 {"Slow", SPEED_SLOW, 0},
256 {"UltraSlow", SPEED_ULTRASLOW, 0},
257 {NULL, 0, 0}
260 static WOptionEnumeration seMouseButtons[] = {
261 {"None", -1, 0},
262 {"Left", Button1, 0}, {"Button1", Button1, 1},
263 {"Middle", Button2, 0}, {"Button2", Button2, 1},
264 {"Right", Button3, 0}, {"Button3", Button3, 1},
265 {"Button4", Button4, 0},
266 {"Button5", Button5, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seIconificationStyles[] = {
271 {"Zoom", WIS_ZOOM, 0},
272 {"Twist", WIS_TWIST, 0},
273 {"Flip", WIS_FLIP, 0},
274 {"None", WIS_NONE, 0},
275 {"random", WIS_RANDOM, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seJustifications[] = {
280 {"Left", WTJ_LEFT, 0},
281 {"Center", WTJ_CENTER, 0},
282 {"Right", WTJ_RIGHT, 0},
283 {NULL, 0, 0}
286 static WOptionEnumeration seIconPositions[] = {
287 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
288 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
289 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
290 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
291 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
292 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
293 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
294 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
295 {NULL, 0, 0}
298 static WOptionEnumeration seMenuStyles[] = {
299 {"normal", MS_NORMAL, 0},
300 {"singletexture", MS_SINGLE_TEXTURE, 0},
301 {"flat", MS_FLAT, 0},
302 {NULL, 0, 0}
306 static WOptionEnumeration seDisplayPositions[] = {
307 {"none", WD_NONE, 0},
308 {"center", WD_CENTER, 0},
309 {"top", WD_TOP, 0},
310 {"bottom", WD_BOTTOM, 0},
311 {"topleft", WD_TOPLEFT, 0},
312 {"topright", WD_TOPRIGHT, 0},
313 {"bottomleft", WD_BOTTOMLEFT, 0},
314 {"bottomright", WD_BOTTOMRIGHT, 0}
319 * ALL entries in the tables bellow, NEED to have a default value
320 * defined, and this value needs to be correct.
323 /* these options will only affect the window manager on startup
325 * static defaults can't access the screen data, because it is
326 * created after these defaults are read
328 WDefaultEntry staticOptionList[] = {
330 {"DisableDithering", "NO", NULL,
331 &wPreferences.no_dithering, getBool, NULL
333 {"ColormapSize", "4", NULL,
334 &wPreferences.cmap_size, getInt, NULL
336 /* static by laziness */
337 {"IconSize", "64", NULL,
338 &wPreferences.icon_size, getInt, NULL
340 {"ModifierKey", "Mod1", NULL,
341 &wPreferences.modifier_mask, getModMask, NULL
343 {"DisableWSMouseActions", "NO", NULL,
344 &wPreferences.disable_root_mouse, getBool, NULL
346 {"FocusMode", "manual", seFocusModes,
347 &wPreferences.focus_mode, getEnum, NULL
348 }, /* have a problem when switching from manual to sloppy without restart */
349 {"NewStyle", "NO", NULL,
350 &wPreferences.new_style, getBool, NULL
352 {"DisableDock", "NO", (void*) WM_DOCK,
353 NULL, getBool, setIfDockPresent
355 {"DisableClip", "NO", (void*) WM_CLIP,
356 NULL, getBool, setIfDockPresent
358 {"DisableMiniwindows", "NO", NULL,
359 &wPreferences.disable_miniwindows, getBool, NULL
361 {"MultiByteText", "NO", NULL,
362 &wPreferences.multi_byte_text, getBool, setMultiByte
368 WDefaultEntry optionList[] = {
369 /* dynamic options */
370 {"IconPosition", "blh", seIconPositions,
371 &wPreferences.icon_yard, getEnum, setIconPosition
373 {"IconificationStyle", "Zoom", seIconificationStyles,
374 &wPreferences.iconification_style, getEnum, NULL
376 {"SelectWindowsMouseButton", "Left", seMouseButtons,
377 &wPreferences.select_button, getEnum, NULL
379 {"WindowListMouseButton", "Middle", seMouseButtons,
380 &wPreferences.windowl_button, getEnum, NULL
382 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
383 &wPreferences.menu_button, getEnum, NULL
385 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
386 &wPreferences.pixmap_path, getPathList, NULL
388 {"IconPath", DEF_ICON_PATHS, NULL,
389 &wPreferences.icon_path, getPathList, NULL
391 {"ColormapMode", "auto", seColormapModes,
392 &wPreferences.colormap_mode, getEnum, NULL
394 {"AutoFocus", "NO", NULL,
395 &wPreferences.auto_focus, getBool, NULL
397 {"RaiseDelay", "0", NULL,
398 &wPreferences.raise_delay, getInt, NULL
400 {"CirculateRaise", "NO", NULL,
401 &wPreferences.circ_raise, getBool, NULL
403 {"Superfluous", "NO", NULL,
404 &wPreferences.superfluous, getBool, NULL
406 {"AdvanceToNewWorkspace", "NO", NULL,
407 &wPreferences.ws_advance, getBool, NULL
409 {"CycleWorkspaces", "NO", NULL,
410 &wPreferences.ws_cycle, getBool, NULL
412 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
413 &wPreferences.workspace_name_display_position, getEnum, NULL
415 #ifdef VIRTUAL_DESKTOP
416 {"VirtualEdgeThickness", "1", NULL,
417 &wPreferences.vedge_thickness, getInt, NULL
419 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
420 &wPreferences.vedge_hscrollspeed, getInt, NULL
422 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
423 &wPreferences.vedge_vscrollspeed, getInt, NULL
425 {"VirtualEdgeWidth", "2000", NULL,
426 &wPreferences.vedge_width, getInt, NULL
428 {"VirtualEdgeHeight", "2000", NULL,
429 &wPreferences.vedge_height, getInt, NULL
431 #endif
432 {"StickyIcons", "NO", NULL,
433 &wPreferences.sticky_icons, getBool, setStickyIcons
435 {"SaveSessionOnExit", "NO", NULL,
436 &wPreferences.save_session_on_exit, getBool, NULL
438 {"WrapMenus", "NO", NULL,
439 &wPreferences.wrap_menus, getBool, NULL
441 {"ScrollableMenus", "NO", NULL,
442 &wPreferences.scrollable_menus, getBool, NULL
444 {"MenuScrollSpeed", "medium", seSpeeds,
445 &wPreferences.menu_scroll_speed, getEnum, NULL
447 {"IconSlideSpeed", "medium", seSpeeds,
448 &wPreferences.icon_slide_speed, getEnum, NULL
450 {"ShadeSpeed", "medium", seSpeeds,
451 &wPreferences.shade_speed, getEnum, NULL
453 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
454 &wPreferences.dblclick_time, getInt, setDoubleClick,
456 {"AlignSubmenus", "NO", NULL,
457 &wPreferences.align_menus, getBool, NULL
459 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
460 &wPreferences.open_transients_with_parent, getBool, NULL
462 {"WindowPlacement", "auto", sePlacements,
463 &wPreferences.window_placement, getEnum, NULL
465 {"IgnoreFocusClick","NO", NULL,
466 &wPreferences.ignore_focus_click, getBool, NULL
468 {"UseSaveUnders", "NO", NULL,
469 &wPreferences.use_saveunders, getBool, NULL
471 {"OpaqueMove", "NO", NULL,
472 &wPreferences.opaque_move, getBool, NULL
474 {"DisableSound", "NO", NULL,
475 &wPreferences.no_sound, getBool, NULL
477 {"DisableAnimations", "NO", NULL,
478 &wPreferences.no_animations, getBool, NULL
480 {"DontLinkWorkspaces","NO", NULL,
481 &wPreferences.no_autowrap, getBool, NULL
483 {"AutoArrangeIcons", "NO", NULL,
484 &wPreferences.auto_arrange_icons, getBool, NULL
486 {"NoWindowOverDock", "NO", NULL,
487 &wPreferences.no_window_over_dock, getBool, updateUsableArea
489 {"NoWindowOverIcons", "NO", NULL,
490 &wPreferences.no_window_over_icons, getBool, updateUsableArea
492 {"WindowPlaceOrigin", "(0, 0)", NULL,
493 &wPreferences.window_place_origin, getCoord, NULL
495 {"ResizeDisplay", "corner", seGeomDisplays,
496 &wPreferences.size_display, getEnum, NULL
498 {"MoveDisplay", "corner", seGeomDisplays,
499 &wPreferences.move_display, getEnum, NULL
501 {"DontConfirmKill", "NO", NULL,
502 &wPreferences.dont_confirm_kill, getBool,NULL
504 {"WindowTitleBalloons", "NO", NULL,
505 &wPreferences.window_balloon, getBool, NULL
507 {"MiniwindowTitleBalloons", "NO", NULL,
508 &wPreferences.miniwin_balloon,getBool, NULL
510 {"AppIconBalloons", "NO", NULL,
511 &wPreferences.appicon_balloon,getBool, NULL
513 {"HelpBalloons", "NO", NULL,
514 &wPreferences.help_balloon, getBool, NULL
516 {"EdgeResistance", "30", NULL,
517 &wPreferences.edge_resistance,getInt, NULL
519 {"Attraction", "NO", NULL,
520 &wPreferences.attract, getBool, NULL
522 {"DisableBlinking", "NO", NULL,
523 &wPreferences.dont_blink, getBool, NULL
525 #ifdef WEENDOZE_CYCLE
526 {"WindozeCycling","NO", NULL,
527 &wPreferences.windoze_cycling, getBool, NULL
529 {"PopupSwitchMenu","YES", NULL,
530 &wPreferences.popup_switchmenu, getBool, NULL
532 #endif /* WEENDOZE_CYCLE */
533 /* style options */
534 {"MenuStyle", "normal", seMenuStyles,
535 &wPreferences.menu_style, getEnum, setMenuStyle
537 {"WidgetColor", "(solid, gray)", NULL,
538 NULL, getTexture, setWidgetColor,
540 {"WorkspaceSpecificBack","()", NULL,
541 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
543 /* WorkspaceBack must come after WorkspaceSpecificBack or
544 * WorkspaceBack wont know WorkspaceSpecificBack was also
545 * specified and 2 copies of wmsetbg will be launched */
546 {"WorkspaceBack", "(solid, black)", NULL,
547 NULL, getWSBackground,setWorkspaceBack
549 {"SmoothWorkspaceBack", "NO", NULL,
550 NULL, getBool, NULL
552 {"IconBack", "(solid, gray)", NULL,
553 NULL, getTexture, setIconTile
555 {"TitleJustify", "center", seJustifications,
556 &wPreferences.title_justification, getEnum, setJustify
558 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
559 NULL, getFont, setWinTitleFont,
561 {"WindowTitleClearance", DEF_TITLE_CLEARANCE, NULL,
562 &wPreferences.title_clearance, getInt, setClearance
564 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
565 NULL, getFont, setMenuTitleFont
567 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
568 NULL, getFont, setMenuTextFont
570 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
571 NULL, getFont, setIconTitleFont
573 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
574 NULL, getFont, setClipTitleFont
576 {"DisplayFont", DEF_INFO_TEXT_FONT, NULL,
577 NULL, getFont, setDisplayFont
579 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
580 NULL, getFont, setLargeDisplayFont
582 {"HighlightColor", "white", NULL,
583 NULL, getColor, setHightlight
585 {"HighlightTextColor", "black", NULL,
586 NULL, getColor, setHightlightText
588 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
589 NULL, getColor, setClipTitleColor
591 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
592 NULL, getColor, setClipTitleColor
594 #ifdef DRAWSTRING_PLUGIN
595 {"FTitleColor", "white", (void*)WS_FOCUSED,
596 NULL, getTextRenderer, setWTitleColor
598 {"PTitleColor", "white", (void*)WS_PFOCUSED,
599 NULL, getTextRenderer, setWTitleColor
601 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
602 NULL, getTextRenderer, setWTitleColor
604 #else
605 {"FTitleColor", "white", (void*)WS_FOCUSED,
606 NULL, getColor, setWTitleColor
608 {"PTitleColor", "white", (void*)WS_PFOCUSED,
609 NULL, getColor, setWTitleColor
611 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
612 NULL, getColor, setWTitleColor
614 #endif
615 {"FTitleBack", "(solid, black)", NULL,
616 NULL, getTexture, setFTitleBack
618 {"PTitleBack", "(solid, \"#616161\")", NULL,
619 NULL, getTexture, setPTitleBack
621 {"UTitleBack", "(solid, gray)", NULL,
622 NULL, getTexture, setUTitleBack
624 {"ResizebarBack", "(solid, gray)", NULL,
625 NULL, getTexture, setResizebarBack
627 #ifdef DRAWSTRING_PLUGIN
628 {"MenuTitleColor", "white", NULL,
629 NULL, getTextRenderer, setMenuTitleColor
631 #else
632 {"MenuTitleColor", "white", NULL,
633 NULL, getColor, setMenuTitleColor
635 #endif
636 {"MenuTextColor", "black", NULL,
637 NULL, getColor, setMenuTextColor
639 {"MenuDisabledColor", "\"#616161\"", NULL,
640 NULL, getColor, setMenuDisabledColor
642 {"MenuTitleBack", "(solid, black)", NULL,
643 NULL, getTexture, setMenuTitleBack
645 {"MenuTextBack", "(solid, gray)", NULL,
646 NULL, getTexture, setMenuTextBack
648 {"IconTitleColor", "white", NULL,
649 NULL, getColor, setIconTitleColor
651 {"IconTitleBack", "black", NULL,
652 NULL, getColor, setIconTitleBack
654 /* keybindings */
655 #ifndef LITE
656 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
657 NULL, getKeybind, setKeyGrab
659 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
660 NULL, getKeybind, setKeyGrab
662 #endif /* LITE */
663 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
664 NULL, getKeybind, setKeyGrab
666 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
667 NULL, getKeybind, setKeyGrab
669 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
670 NULL, getKeybind, setKeyGrab
672 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
673 NULL, getKeybind, setKeyGrab
675 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
676 NULL, getKeybind, setKeyGrab
678 {"HideKey", "None", (void*)WKBD_HIDE,
679 NULL, getKeybind, setKeyGrab
681 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
682 NULL, getKeybind, setKeyGrab
684 {"CloseKey", "None", (void*)WKBD_CLOSE,
685 NULL, getKeybind, setKeyGrab
687 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
688 NULL, getKeybind, setKeyGrab
690 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
691 NULL, getKeybind, setKeyGrab
693 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
694 NULL, getKeybind, setKeyGrab
696 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
697 NULL, getKeybind, setKeyGrab
699 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
700 NULL, getKeybind, setKeyGrab
702 {"ShadeKey", "None", (void*)WKBD_SHADE,
703 NULL, getKeybind, setKeyGrab
705 {"SelectKey", "None", (void*)WKBD_SELECT,
706 NULL, getKeybind, setKeyGrab
708 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
709 NULL, getKeybind, setKeyGrab
711 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
712 NULL, getKeybind, setKeyGrab
714 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
715 NULL, getKeybind, setKeyGrab
717 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
718 NULL, getKeybind, setKeyGrab
720 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
721 NULL, getKeybind, setKeyGrab
723 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
724 NULL, getKeybind, setKeyGrab
726 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
727 NULL, getKeybind, setKeyGrab
729 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
730 NULL, getKeybind, setKeyGrab
732 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
733 NULL, getKeybind, setKeyGrab
735 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
754 NULL, getKeybind, setKeyGrab
756 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
757 NULL, getKeybind, setKeyGrab
759 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
760 NULL, getKeybind, setKeyGrab
762 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
763 NULL, getKeybind, setKeyGrab
765 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
766 NULL, getKeybind, setKeyGrab
768 #ifdef EXTEND_WINDOWSHORTCUT
769 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
770 NULL, getKeybind, setKeyGrab
772 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
773 NULL, getKeybind, setKeyGrab
775 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
776 NULL, getKeybind, setKeyGrab
778 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
779 NULL, getKeybind, setKeyGrab
781 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
782 NULL, getKeybind, setKeyGrab
784 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
785 NULL, getKeybind, setKeyGrab
787 #endif /* EXTEND_WINDOWSHORTCUT */
789 #ifdef KEEP_XKB_LOCK_STATUS
790 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
791 NULL, getKeybind, setKeyGrab
793 {"KbdModeLock", "NO", NULL,
794 &wPreferences.modelock, getBool, NULL
796 #endif /* KEEP_XKB_LOCK_STATUS */
800 #if 0
801 static void rereadDefaults(void);
802 #endif
804 #if 0
805 static void
806 rereadDefaults(void)
808 /* must defer the update because accessing X data from a
809 * signal handler can mess up Xlib */
812 #endif
814 static void
815 initDefaults()
817 int i;
818 WDefaultEntry *entry;
820 PLSetStringCmpHook(StringCompareHook);
822 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
823 entry = &optionList[i];
825 entry->plkey = PLMakeString(entry->key);
826 if (entry->default_value)
827 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
828 else
829 entry->plvalue = NULL;
832 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
833 entry = &staticOptionList[i];
835 entry->plkey = PLMakeString(entry->key);
836 if (entry->default_value)
837 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
838 else
839 entry->plvalue = NULL;
843 wDomainName = PLMakeString(WMDOMAIN_NAME);
844 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
846 PLRegister(wDomainName, rereadDefaults);
847 PLRegister(wAttributeDomainName, rereadDefaults);
854 #if 0
855 proplist_t
856 wDefaultsInit(int screen_number)
858 static int defaults_inited = 0;
859 proplist_t dict;
861 if (!defaults_inited) {
862 initDefaults();
865 dict = PLGetDomain(wDomainName);
866 if (!dict) {
867 wwarning(_("could not read domain \"%s\" from defaults database"),
868 PLGetString(wDomainName));
871 return dict;
873 #endif
876 void
877 wDefaultsDestroyDomain(WDDomain *domain)
879 if (domain->dictionary)
880 PLRelease(domain->dictionary);
881 free(domain->path);
882 free(domain);
886 WDDomain*
887 wDefaultsInitDomain(char *domain, Bool requireDictionary)
889 WDDomain *db;
890 struct stat stbuf;
891 static int inited = 0;
892 char path[PATH_MAX];
893 char *the_path;
894 proplist_t shared_dict=NULL;
896 if (!inited) {
897 inited = 1;
898 initDefaults();
901 db = wmalloc(sizeof(WDDomain));
902 memset(db, 0, sizeof(WDDomain));
903 db->domain_name = domain;
904 db->path = wdefaultspathfordomain(domain);
905 the_path = db->path;
907 if (the_path && stat(the_path, &stbuf)>=0) {
908 db->dictionary = ReadProplistFromFile(the_path);
909 if (db->dictionary) {
910 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
911 PLRelease(db->dictionary);
912 db->dictionary = NULL;
913 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
914 domain, the_path);
916 db->timestamp = stbuf.st_mtime;
917 } else {
918 wwarning(_("could not load domain %s from user defaults database"),
919 domain);
923 /* global system dictionary */
924 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
925 if (stat(path, &stbuf)>=0) {
926 shared_dict = ReadProplistFromFile(path);
927 if (shared_dict) {
928 if (requireDictionary && !PLIsDictionary(shared_dict)) {
929 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
930 domain, path);
931 PLRelease(shared_dict);
932 shared_dict = NULL;
933 } else {
934 if (db->dictionary && PLIsDictionary(shared_dict) &&
935 PLIsDictionary(db->dictionary)) {
936 PLMergeDictionaries(shared_dict, db->dictionary);
937 PLRelease(db->dictionary);
938 db->dictionary = shared_dict;
939 if (stbuf.st_mtime > db->timestamp)
940 db->timestamp = stbuf.st_mtime;
941 } else if (!db->dictionary) {
942 db->dictionary = shared_dict;
943 if (stbuf.st_mtime > db->timestamp)
944 db->timestamp = stbuf.st_mtime;
947 } else {
948 wwarning(_("could not load domain %s from global defaults database (%s)"),
949 domain, path);
953 /* set to save it in user's directory, no matter from where it was read */
954 if (db->dictionary) {
955 proplist_t tmp = PLMakeString(db->path);
957 PLSetFilename(db->dictionary, tmp);
958 PLRelease(tmp);
961 return db;
965 void
966 wReadStaticDefaults(proplist_t dict)
968 proplist_t plvalue;
969 WDefaultEntry *entry;
970 int i;
971 void *tdata;
974 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
975 entry = &staticOptionList[i];
977 if (dict)
978 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
979 else
980 plvalue = NULL;
982 if (!plvalue) {
983 /* no default in the DB. Use builtin default */
984 plvalue = entry->plvalue;
987 if (plvalue) {
988 /* convert data */
989 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
990 if (entry->update) {
991 (*entry->update)(NULL, entry, tdata, entry->extra_data);
998 void
999 wDefaultsCheckDomains(void *foo)
1001 WScreen *scr;
1002 struct stat stbuf;
1003 proplist_t dict;
1004 int i;
1005 char path[PATH_MAX];
1007 #ifdef HEARTBEAT
1008 puts("Checking domains...");
1009 #endif
1010 if (stat(WDWindowMaker->path, &stbuf)>=0
1011 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1012 proplist_t shared_dict = NULL;
1013 #ifdef HEARTBEAT
1014 puts("Checking WindowMaker domain");
1015 #endif
1016 WDWindowMaker->timestamp = stbuf.st_mtime;
1018 /* global dictionary */
1019 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1020 if (stat(path, &stbuf)>=0) {
1021 shared_dict = ReadProplistFromFile(path);
1022 if (shared_dict && !PLIsDictionary(shared_dict)) {
1023 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1024 "WindowMaker", path);
1025 PLRelease(shared_dict);
1026 shared_dict = NULL;
1027 } else if (!shared_dict) {
1028 wwarning(_("could not load domain %s from global defaults database"),
1029 "WindowMaker");
1032 /* user dictionary */
1033 dict = ReadProplistFromFile(WDWindowMaker->path);
1034 if (dict) {
1035 if (!PLIsDictionary(dict)) {
1036 PLRelease(dict);
1037 dict = NULL;
1038 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1039 "WindowMaker", WDWindowMaker->path);
1040 } else {
1041 if (shared_dict) {
1042 PLSetFilename(shared_dict, PLGetFilename(dict));
1043 PLMergeDictionaries(shared_dict, dict);
1044 PLRelease(dict);
1045 dict = shared_dict;
1046 shared_dict = NULL;
1048 for (i=0; i<wScreenCount; i++) {
1049 scr = wScreenWithNumber(i);
1050 if (scr)
1051 wReadDefaults(scr, dict);
1053 if (WDWindowMaker->dictionary) {
1054 PLRelease(WDWindowMaker->dictionary);
1056 WDWindowMaker->dictionary = dict;
1058 } else {
1059 wwarning(_("could not load domain %s from user defaults database"),
1060 "WindowMaker");
1062 if (shared_dict) {
1063 PLRelease(shared_dict);
1067 if (stat(WDWindowAttributes->path, &stbuf)>=0
1068 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1069 #ifdef HEARTBEAT
1070 puts("Checking WMWindowAttributes domain");
1071 #endif
1072 dict = ReadProplistFromFile(WDWindowAttributes->path);
1073 if (dict) {
1074 if (!PLIsDictionary(dict)) {
1075 PLRelease(dict);
1076 dict = NULL;
1077 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1078 "WMWindowAttributes", WDWindowAttributes->path);
1079 } else {
1080 if (WDWindowAttributes->dictionary)
1081 PLRelease(WDWindowAttributes->dictionary);
1082 WDWindowAttributes->dictionary = dict;
1083 for (i=0; i<wScreenCount; i++) {
1084 scr = wScreenWithNumber(i);
1085 if (scr)
1086 wDefaultUpdateIcons(scr);
1089 } else {
1090 wwarning(_("could not load domain %s from user defaults database"),
1091 "WMWindowAttributes");
1093 WDWindowAttributes->timestamp = stbuf.st_mtime;
1096 #ifndef LITE
1097 if (stat(WDRootMenu->path, &stbuf)>=0
1098 && WDRootMenu->timestamp < stbuf.st_mtime) {
1099 dict = ReadProplistFromFile(WDRootMenu->path);
1100 #ifdef HEARTBEAT
1101 puts("Checking WMRootMenu domain");
1102 #endif
1103 if (dict) {
1104 if (!PLIsArray(dict) && !PLIsString(dict)) {
1105 PLRelease(dict);
1106 dict = NULL;
1107 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1108 "WMRootMenu", WDRootMenu->path);
1109 } else {
1110 if (WDRootMenu->dictionary) {
1111 PLRelease(WDRootMenu->dictionary);
1113 WDRootMenu->dictionary = dict;
1115 } else {
1116 wwarning(_("could not load domain %s from user defaults database"),
1117 "WMRootMenu");
1119 WDRootMenu->timestamp = stbuf.st_mtime;
1121 #endif /* !LITE */
1123 if (!foo)
1124 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1128 void
1129 wReadDefaults(WScreen *scr, proplist_t new_dict)
1131 proplist_t plvalue, old_value;
1132 WDefaultEntry *entry;
1133 int i, must_update;
1134 int update_workspace_back = 0; /* kluge :/ */
1135 int needs_refresh;
1136 void *tdata;
1137 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1138 ? WDWindowMaker->dictionary : NULL);
1140 must_update = 0;
1142 needs_refresh = 0;
1144 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1145 entry = &optionList[i];
1147 if (new_dict)
1148 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1149 else
1150 plvalue = NULL;
1152 if (!old_dict)
1153 old_value = NULL;
1154 else
1155 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1158 if (!plvalue && !old_value) {
1159 /* no default in the DB. Use builtin default */
1160 plvalue = entry->plvalue;
1161 if (plvalue && new_dict) {
1162 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1163 must_update = 1;
1165 } else if (!plvalue) {
1166 /* value was deleted from DB. Keep current value */
1167 continue;
1168 } else if (!old_value) {
1169 /* set value for the 1st time */
1170 } else if (!PLIsEqual(plvalue, old_value)) {
1171 /* value has changed */
1172 } else {
1174 if (strcmp(entry->key, "WorkspaceBack") == 0
1175 && update_workspace_back
1176 && scr->flags.backimage_helper_launched) {
1177 } else {
1178 /* value was not changed since last time */
1179 continue;
1183 if (plvalue) {
1184 #ifdef DEBUG
1185 printf("Updating %s to %s\n", entry->key,
1186 PLGetDescription(plvalue));
1187 #endif
1188 /* convert data */
1189 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1191 * If the WorkspaceSpecificBack data has been changed
1192 * so that the helper will be launched now, we must be
1193 * sure to send the default background texture config
1194 * to the helper.
1196 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1197 && !scr->flags.backimage_helper_launched) {
1198 update_workspace_back = 1;
1200 if (entry->update) {
1201 needs_refresh |=
1202 (*entry->update)(scr, entry, tdata, entry->extra_data);
1208 if (needs_refresh!=0 && !scr->flags.startup) {
1209 int foo;
1211 foo = 0;
1212 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1213 foo |= WTextureSettings;
1214 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1215 foo |= WFontSettings;
1216 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1217 foo |= WColorSettings;
1218 if (foo)
1219 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1220 (void*)foo);
1222 foo = 0;
1223 if (needs_refresh & REFRESH_MENU_TEXTURE)
1224 foo |= WTextureSettings;
1225 if (needs_refresh & REFRESH_MENU_FONT)
1226 foo |= WFontSettings;
1227 if (needs_refresh & REFRESH_MENU_COLOR)
1228 foo |= WColorSettings;
1229 if (foo)
1230 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1231 (void*)foo);
1233 foo = 0;
1234 if (needs_refresh & REFRESH_WINDOW_FONT) {
1235 foo |= WFontSettings;
1237 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1238 foo |= WTextureSettings;
1240 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1241 foo |= WColorSettings;
1243 if (foo)
1244 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1245 (void*)foo);
1247 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1248 foo = 0;
1249 if (needs_refresh & REFRESH_ICON_FONT) {
1250 foo |= WFontSettings;
1252 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1253 foo |= WTextureSettings;
1255 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1256 foo |= WTextureSettings;
1258 if (foo)
1259 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1260 (void*)foo);
1262 if (needs_refresh & REFRESH_ICON_TILE)
1263 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1268 void
1269 wDefaultUpdateIcons(WScreen *scr)
1271 WAppIcon *aicon = scr->app_icon_list;
1272 WWindow *wwin = scr->focused_window;
1273 char *file;
1275 while(aicon) {
1276 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1277 False);
1278 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1279 || (file && !aicon->icon->file)) {
1280 RImage *new_image;
1282 if (aicon->icon->file)
1283 free(aicon->icon->file);
1284 aicon->icon->file = wstrdup(file);
1286 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1287 aicon->wm_class);
1288 if (new_image) {
1289 wIconChangeImage(aicon->icon, new_image);
1290 wAppIconPaint(aicon);
1293 aicon = aicon->next;
1296 if (!wPreferences.flags.noclip)
1297 wClipIconPaint(scr->clip_icon);
1299 while (wwin) {
1300 if (wwin->icon && wwin->flags.miniaturized) {
1301 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1302 False);
1303 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1304 || (file && !wwin->icon->file)) {
1305 RImage *new_image;
1307 if (wwin->icon->file)
1308 free(wwin->icon->file);
1309 wwin->icon->file = wstrdup(file);
1311 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1312 wwin->wm_class);
1313 if (new_image)
1314 wIconChangeImage(wwin->icon, new_image);
1317 wwin = wwin->prev;
1322 /* --------------------------- Local ----------------------- */
1324 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1325 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1326 entry->key, x); \
1327 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1328 var = entry->default_value;\
1329 } else var = PLGetString(value)\
1335 static int
1336 string2index(proplist_t key, proplist_t val, proplist_t def,
1337 WOptionEnumeration *values)
1339 char *str;
1340 WOptionEnumeration *v;
1341 char buffer[TOTAL_VALUES_LENGTH];
1343 if (PLIsString(val) && (str = PLGetString(val))) {
1344 for (v=values; v->string!=NULL; v++) {
1345 if (strcasecmp(v->string, str)==0)
1346 return v->value;
1350 buffer[0] = 0;
1351 for (v=values; v->string!=NULL; v++) {
1352 if (!v->is_alias) {
1353 if (buffer[0]!=0)
1354 strcat(buffer, ", ");
1355 strcat(buffer, v->string);
1358 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1359 PLGetString(key), buffer);
1361 if (def) {
1362 return string2index(key, val, NULL, values);
1365 return -1;
1372 * value - is the value in the defaults DB
1373 * addr - is the address to store the data
1374 * ret - is the address to store a pointer to a temporary buffer. ret
1375 * must not be freed and is used by the set functions
1377 static int
1378 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1379 void **ret)
1381 static char data;
1382 char *val;
1383 int second_pass=0;
1385 GET_STRING_OR_DEFAULT("Boolean", val);
1387 again:
1388 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1389 || strcasecmp(val, "YES")==0) {
1391 data = 1;
1392 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1393 || strcasecmp(val, "NO")==0) {
1394 data = 0;
1395 } else {
1396 int i;
1397 if (sscanf(val, "%i", &i)==1) {
1398 if (i!=0)
1399 data = 1;
1400 else
1401 data = 0;
1402 } else {
1403 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1404 val, entry->key);
1405 if (second_pass==0) {
1406 val = PLGetString(entry->plvalue);
1407 second_pass = 1;
1408 wwarning(_("using default \"%s\" instead"), val);
1409 goto again;
1411 return False;
1415 if (ret)
1416 *ret = &data;
1418 if (addr) {
1419 *(char*)addr = data;
1422 return True;
1426 static int
1427 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1428 void **ret)
1430 static int data;
1431 char *val;
1434 GET_STRING_OR_DEFAULT("Integer", val);
1436 if (sscanf(val, "%i", &data)!=1) {
1437 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1438 val, entry->key);
1439 val = PLGetString(entry->plvalue);
1440 wwarning(_("using default \"%s\" instead"), val);
1441 if (sscanf(val, "%i", &data)!=1) {
1442 return False;
1446 if (ret)
1447 *ret = &data;
1449 if (addr) {
1450 *(int*)addr = data;
1452 return True;
1456 static int
1457 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1458 void **ret)
1460 static WCoord data;
1461 char *val_x, *val_y;
1462 int nelem, changed=0;
1463 proplist_t elem_x, elem_y;
1465 again:
1466 if (!PLIsArray(value)) {
1467 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1468 entry->key, "Coordinate");
1469 if (changed==0) {
1470 value = entry->plvalue;
1471 changed = 1;
1472 wwarning(_("using default \"%s\" instead"), entry->default_value);
1473 goto again;
1475 return False;
1478 nelem = PLGetNumberOfElements(value);
1479 if (nelem != 2) {
1480 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1481 entry->key);
1482 if (changed==0) {
1483 value = entry->plvalue;
1484 changed = 1;
1485 wwarning(_("using default \"%s\" instead"), entry->default_value);
1486 goto again;
1488 return False;
1491 elem_x = PLGetArrayElement(value, 0);
1492 elem_y = PLGetArrayElement(value, 1);
1494 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1495 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1496 entry->key);
1497 if (changed==0) {
1498 value = entry->plvalue;
1499 changed = 1;
1500 wwarning(_("using default \"%s\" instead"), entry->default_value);
1501 goto again;
1503 return False;
1506 val_x = PLGetString(elem_x);
1507 val_y = PLGetString(elem_y);
1509 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1510 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1511 if (changed==0) {
1512 value = entry->plvalue;
1513 changed = 1;
1514 wwarning(_("using default \"%s\" instead"), entry->default_value);
1515 goto again;
1517 return False;
1520 if (data.x < 0)
1521 data.x = 0;
1522 else if (data.x > scr->scr_width/3)
1523 data.x = scr->scr_width/3;
1524 if (data.y < 0)
1525 data.y = 0;
1526 else if (data.y > scr->scr_height/3)
1527 data.y = scr->scr_height/3;
1529 if (ret)
1530 *ret = &data;
1532 if (addr) {
1533 *(WCoord*)addr = data;
1536 return True;
1540 #if 0
1541 /* This function is not used at the moment. */
1542 static int
1543 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1544 void **ret)
1546 static char *data;
1548 GET_STRING_OR_DEFAULT("String", data);
1550 if (!data) {
1551 data = PLGetString(entry->plvalue);
1552 if (!data)
1553 return False;
1556 if (ret)
1557 *ret = &data;
1559 if (addr)
1560 *(char**)addr = wstrdup(data);
1562 return True;
1564 #endif
1567 static int
1568 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1569 void **ret)
1571 static char *data;
1572 int i, count, len;
1573 char *ptr;
1574 proplist_t d;
1575 int changed=0;
1577 again:
1578 if (!PLIsArray(value)) {
1579 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1580 entry->key, "an array of paths");
1581 if (changed==0) {
1582 value = entry->plvalue;
1583 changed = 1;
1584 wwarning(_("using default \"%s\" instead"), entry->default_value);
1585 goto again;
1587 return False;
1590 i = 0;
1591 count = PLGetNumberOfElements(value);
1592 if (count < 1) {
1593 if (changed==0) {
1594 value = entry->plvalue;
1595 changed = 1;
1596 wwarning(_("using default \"%s\" instead"), entry->default_value);
1597 goto again;
1599 return False;
1602 len = 0;
1603 for (i=0; i<count; i++) {
1604 d = PLGetArrayElement(value, i);
1605 if (!d || !PLIsString(d)) {
1606 count = i;
1607 break;
1609 len += strlen(PLGetString(d))+1;
1612 ptr = data = wmalloc(len+1);
1614 for (i=0; i<count; i++) {
1615 d = PLGetArrayElement(value, i);
1616 if (!d || !PLIsString(d)) {
1617 break;
1619 strcpy(ptr, PLGetString(d));
1620 ptr += strlen(PLGetString(d));
1621 *ptr = ':';
1622 ptr++;
1624 ptr--; *(ptr--) = 0;
1626 if (*(char**)addr!=NULL) {
1627 free(*(char**)addr);
1629 *(char**)addr = data;
1631 return True;
1635 static int
1636 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1637 void **ret)
1639 static signed char data;
1641 data = string2index(entry->plkey, value, entry->default_value,
1642 (WOptionEnumeration*)entry->extra_data);
1643 if (data < 0)
1644 return False;
1646 if (ret)
1647 *ret = &data;
1649 if (addr)
1650 *(signed char*)addr = data;
1652 return True;
1658 * (solid <color>)
1659 * (hgradient <color> <color>)
1660 * (vgradient <color> <color>)
1661 * (dgradient <color> <color>)
1662 * (mhgradient <color> <color> ...)
1663 * (mvgradient <color> <color> ...)
1664 * (tpixmap <file> <color>)
1665 * (spixmap <file> <color>)
1666 * (cpixmap <file> <color>)
1667 * (thgradient <file> <opaqueness> <color> <color>)
1668 * (tvgradient <file> <opaqueness> <color> <color>)
1669 * (tdgradient <file> <opaqueness> <color> <color>)
1670 * (function <lib> <function> ...)
1673 static WTexture*
1674 parse_texture(WScreen *scr, proplist_t pl)
1676 proplist_t elem;
1677 char *val;
1678 int nelem;
1679 WTexture *texture=NULL;
1681 nelem = PLGetNumberOfElements(pl);
1682 if (nelem < 1)
1683 return NULL;
1686 elem = PLGetArrayElement(pl, 0);
1687 if (!elem || !PLIsString(elem))
1688 return NULL;
1689 val = PLGetString(elem);
1692 if (strcasecmp(val, "solid")==0) {
1693 XColor color;
1695 if (nelem != 2)
1696 return NULL;
1698 /* get color */
1700 elem = PLGetArrayElement(pl, 1);
1701 if (!elem || !PLIsString(elem))
1702 return NULL;
1703 val = PLGetString(elem);
1705 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1706 wwarning(_("\"%s\" is not a valid color name"), val);
1707 return NULL;
1710 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1711 } else if (strcasecmp(val, "dgradient")==0
1712 || strcasecmp(val, "vgradient")==0
1713 || strcasecmp(val, "hgradient")==0) {
1714 RColor color1, color2;
1715 XColor xcolor;
1716 int type;
1718 if (nelem != 3) {
1719 wwarning(_("bad number of arguments in gradient specification"));
1720 return NULL;
1723 if (val[0]=='d' || val[0]=='D')
1724 type = WTEX_DGRADIENT;
1725 else if (val[0]=='h' || val[0]=='H')
1726 type = WTEX_HGRADIENT;
1727 else
1728 type = WTEX_VGRADIENT;
1731 /* get from color */
1732 elem = PLGetArrayElement(pl, 1);
1733 if (!elem || !PLIsString(elem))
1734 return NULL;
1735 val = PLGetString(elem);
1737 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1738 wwarning(_("\"%s\" is not a valid color name"), val);
1739 return NULL;
1741 color1.alpha = 255;
1742 color1.red = xcolor.red >> 8;
1743 color1.green = xcolor.green >> 8;
1744 color1.blue = xcolor.blue >> 8;
1746 /* get to color */
1747 elem = PLGetArrayElement(pl, 2);
1748 if (!elem || !PLIsString(elem)) {
1749 return NULL;
1751 val = PLGetString(elem);
1753 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1754 wwarning(_("\"%s\" is not a valid color name"), val);
1755 return NULL;
1757 color2.alpha = 255;
1758 color2.red = xcolor.red >> 8;
1759 color2.green = xcolor.green >> 8;
1760 color2.blue = xcolor.blue >> 8;
1762 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1764 } else if (strcasecmp(val, "mhgradient")==0
1765 || strcasecmp(val, "mvgradient")==0
1766 || strcasecmp(val, "mdgradient")==0) {
1767 XColor color;
1768 RColor **colors;
1769 int i, count;
1770 int type;
1772 if (nelem < 3) {
1773 wwarning(_("too few arguments in multicolor gradient specification"));
1774 return NULL;
1777 if (val[1]=='h' || val[1]=='H')
1778 type = WTEX_MHGRADIENT;
1779 else if (val[1]=='v' || val[1]=='V')
1780 type = WTEX_MVGRADIENT;
1781 else
1782 type = WTEX_MDGRADIENT;
1784 count = nelem-1;
1786 colors = wmalloc(sizeof(RColor*)*(count+1));
1788 for (i=0; i<count; i++) {
1789 elem = PLGetArrayElement(pl, i+1);
1790 if (!elem || !PLIsString(elem)) {
1791 for (--i; i>=0; --i) {
1792 free(colors[i]);
1794 free(colors);
1795 return NULL;
1797 val = PLGetString(elem);
1799 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1800 wwarning(_("\"%s\" is not a valid color name"), val);
1801 for (--i; i>=0; --i) {
1802 free(colors[i]);
1804 free(colors);
1805 return NULL;
1806 } else {
1807 colors[i] = wmalloc(sizeof(RColor));
1808 colors[i]->red = color.red >> 8;
1809 colors[i]->green = color.green >> 8;
1810 colors[i]->blue = color.blue >> 8;
1813 colors[i] = NULL;
1815 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1816 } else if (strcasecmp(val, "spixmap")==0 ||
1817 strcasecmp(val, "cpixmap")==0 ||
1818 strcasecmp(val, "tpixmap")==0) {
1819 XColor color;
1820 int type;
1822 if (nelem != 3)
1823 return NULL;
1825 if (val[0] == 's' || val[0] == 'S')
1826 type = WTP_SCALE;
1827 else if (val[0] == 'c' || val[0] == 'C')
1828 type = WTP_CENTER;
1829 else
1830 type = WTP_TILE;
1832 /* get color */
1833 elem = PLGetArrayElement(pl, 2);
1834 if (!elem || !PLIsString(elem)) {
1835 return NULL;
1837 val = PLGetString(elem);
1839 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1840 wwarning(_("\"%s\" is not a valid color name"), val);
1841 return NULL;
1844 /* file name */
1845 elem = PLGetArrayElement(pl, 1);
1846 if (!elem || !PLIsString(elem))
1847 return NULL;
1848 val = PLGetString(elem);
1850 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1851 } else if (strcasecmp(val, "thgradient")==0
1852 || strcasecmp(val, "tvgradient")==0
1853 || strcasecmp(val, "tdgradient")==0) {
1854 RColor color1, color2;
1855 XColor xcolor;
1856 int opacity;
1857 int style;
1859 if (val[1]=='h' || val[1]=='H')
1860 style = WTEX_THGRADIENT;
1861 else if (val[1]=='v' || val[1]=='V')
1862 style = WTEX_TVGRADIENT;
1863 else
1864 style = WTEX_TDGRADIENT;
1866 if (nelem != 5) {
1867 wwarning(_("bad number of arguments in textured gradient specification"));
1868 return NULL;
1871 /* get from color */
1872 elem = PLGetArrayElement(pl, 3);
1873 if (!elem || !PLIsString(elem))
1874 return NULL;
1875 val = PLGetString(elem);
1877 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1878 wwarning(_("\"%s\" is not a valid color name"), val);
1879 return NULL;
1881 color1.alpha = 255;
1882 color1.red = xcolor.red >> 8;
1883 color1.green = xcolor.green >> 8;
1884 color1.blue = xcolor.blue >> 8;
1886 /* get to color */
1887 elem = PLGetArrayElement(pl, 4);
1888 if (!elem || !PLIsString(elem)) {
1889 return NULL;
1891 val = PLGetString(elem);
1893 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1894 wwarning(_("\"%s\" is not a valid color name"), val);
1895 return NULL;
1897 color2.alpha = 255;
1898 color2.red = xcolor.red >> 8;
1899 color2.green = xcolor.green >> 8;
1900 color2.blue = xcolor.blue >> 8;
1902 /* get opacity */
1903 elem = PLGetArrayElement(pl, 2);
1904 if (!elem || !PLIsString(elem))
1905 opacity = 128;
1906 else
1907 val = PLGetString(elem);
1909 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1910 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1911 opacity = 128;
1914 /* get file name */
1915 elem = PLGetArrayElement(pl, 1);
1916 if (!elem || !PLIsString(elem))
1917 return NULL;
1918 val = PLGetString(elem);
1920 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1921 val, opacity);
1923 #ifdef TEXTURE_PLUGIN
1924 else if (strcasecmp(val, "function")==0) {
1925 WTexFunction *function;
1926 void (*initFunc) (Display *, Colormap);
1927 char *lib, *func, **argv;
1928 int i, argc;
1930 if (nelem < 3)
1931 return NULL;
1933 /* get the library name */
1934 elem = PLGetArrayElement(pl, 1);
1935 if (!elem || !PLIsString(elem)) {
1936 return NULL;
1938 lib = PLGetString(elem);
1940 /* get the function name */
1941 elem = PLGetArrayElement(pl, 2);
1942 if (!elem || !PLIsString(elem)) {
1943 return NULL;
1945 func = PLGetString(elem);
1947 argc = nelem - 2;
1948 argv = (char **)wmalloc(argc * sizeof(char *));
1950 /* get the parameters */
1951 argv[0] = wstrdup(func);
1952 for (i = 0; i < argc - 1; i++) {
1953 elem = PLGetArrayElement(pl, 3 + i);
1954 if (!elem || !PLIsString(elem)) {
1955 free(argv);
1957 return NULL;
1959 argv[i+1] = wstrdup(PLGetString(elem));
1962 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1964 #ifdef HAVE_DLFCN_H
1965 if (function) {
1966 initFunc = dlsym(function->handle, "initWindowMaker");
1967 if (initFunc) {
1968 initFunc(dpy, scr->w_colormap);
1969 } else {
1970 wwarning(_("could not initialize library %s"), lib);
1972 } else {
1973 wwarning(_("could not find function %s::%s"), lib, func);
1975 #endif /* HAVE_DLFCN_H */
1976 texture = (WTexture*)function;
1978 #endif /* TEXTURE_PLUGIN */
1979 else {
1980 wwarning(_("invalid texture type %s"), val);
1981 return NULL;
1983 return texture;
1988 static int
1989 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1990 void **ret)
1992 static WTexture *texture;
1993 int changed=0;
1995 again:
1996 if (!PLIsArray(value)) {
1997 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1998 entry->key, "Texture");
1999 if (changed==0) {
2000 value = entry->plvalue;
2001 changed = 1;
2002 wwarning(_("using default \"%s\" instead"), entry->default_value);
2003 goto again;
2005 return False;
2008 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2009 proplist_t pl;
2011 pl = PLGetArrayElement(value, 0);
2012 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2013 || strcasecmp(PLGetString(pl), "solid")!=0) {
2014 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2015 entry->key, "Solid Texture");
2017 value = entry->plvalue;
2018 changed = 1;
2019 wwarning(_("using default \"%s\" instead"), entry->default_value);
2020 goto again;
2024 texture = parse_texture(scr, value);
2026 if (!texture) {
2027 wwarning(_("Error in texture specification for key \"%s\""),
2028 entry->key);
2029 if (changed==0) {
2030 value = entry->plvalue;
2031 changed = 1;
2032 wwarning(_("using default \"%s\" instead"), entry->default_value);
2033 goto again;
2035 return False;
2038 if (ret)
2039 *ret = &texture;
2041 if (addr)
2042 *(WTexture**)addr = texture;
2044 return True;
2049 #ifdef DRAWSTRING_PLUGIN
2050 static int
2051 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2052 void *addr, void **ret)
2054 proplist_t elem;
2055 char *val, *lib, *func, **argv;
2056 int argc, changed;
2058 if (strcmp(entry->key, "FTitleColor")==0) {
2059 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2060 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2061 } else if (strcmp(entry->key, "UTitleColor")==0) {
2062 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2063 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2064 } else if (strcmp(entry->key, "PTitleColor")==0) {
2065 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2066 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2067 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2068 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2069 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2070 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2071 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2072 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2075 if (PLIsArray(value)) {
2076 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2077 argc -= 2;
2078 argv = (char **)wmalloc(argc * sizeof(char *));
2080 elem = PLGetArrayElement(value,0);
2081 if (!elem || !PLIsString(elem)) return False;
2082 val = PLGetString(elem);
2083 if (strcasecmp(val, "function")==0) {
2084 elem = PLGetArrayElement(value, 1); /* library name */
2085 if (!elem || !PLIsString(elem)) return False;
2086 lib = PLGetString(elem);
2087 elem = PLGetArrayElement(value, 2); /* function name */
2088 if (!elem || !PLIsString(elem)) return False;
2089 func = PLGetString(elem);
2090 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2091 lib, "initDrawString", func, NULL, value,
2092 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2095 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2096 } else if (PLIsString(value)) {
2097 return getColor(scr, entry, value, addr, ret);
2100 return False;
2102 #endif /* DRAWSTRING_PLUGIN */
2106 static int
2107 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2108 void *addr, void **ret)
2110 proplist_t elem;
2111 int changed = 0;
2112 char *val;
2113 int nelem;
2115 again:
2116 if (!PLIsArray(value)) {
2117 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2118 "WorkspaceBack", "Texture or None");
2119 if (changed==0) {
2120 value = entry->plvalue;
2121 changed = 1;
2122 wwarning(_("using default \"%s\" instead"), entry->default_value);
2123 goto again;
2125 return False;
2128 /* only do basic error checking and verify for None texture */
2130 nelem = PLGetNumberOfElements(value);
2131 if (nelem > 0) {
2132 elem = PLGetArrayElement(value, 0);
2133 if (!elem || !PLIsString(elem)) {
2134 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2135 if (changed==0) {
2136 value = entry->plvalue;
2137 changed = 1;
2138 wwarning(_("using default \"%s\" instead"), entry->default_value);
2139 goto again;
2141 return False;
2143 val = PLGetString(elem);
2145 if (strcasecmp(val, "None")==0)
2146 return True;
2148 *ret = PLRetain(value);
2150 return True;
2154 static int
2155 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2156 void *addr, void **ret)
2158 proplist_t elem;
2159 int nelem;
2160 int changed = 0;
2162 again:
2163 if (!PLIsArray(value)) {
2164 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2165 "WorkspaceSpecificBack", "an array of textures");
2166 if (changed==0) {
2167 value = entry->plvalue;
2168 changed = 1;
2169 wwarning(_("using default \"%s\" instead"), entry->default_value);
2170 goto again;
2172 return False;
2175 /* only do basic error checking and verify for None texture */
2177 nelem = PLGetNumberOfElements(value);
2178 if (nelem > 0) {
2179 while (nelem--) {
2180 elem = PLGetArrayElement(value, nelem);
2181 if (!elem || !PLIsArray(elem)) {
2182 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2183 nelem);
2188 *ret = PLRetain(value);
2190 #ifdef notworking
2192 * Kluge to force wmsetbg helper to set the default background.
2193 * If the WorkspaceSpecificBack is changed once wmaker has started,
2194 * the WorkspaceBack won't be sent to the helper, unless the user
2195 * changes it's value too. So, we must force this by removing the
2196 * value from the defaults DB.
2198 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2199 proplist_t key = PLMakeString("WorkspaceBack");
2201 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2203 PLRelease(key);
2205 #endif
2206 return True;
2210 static int
2211 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2212 void **ret)
2214 static WMFont *font;
2215 char *val;
2217 GET_STRING_OR_DEFAULT("Font", val);
2219 font = WMCreateFont(scr->wmscreen, val);
2220 if (!font)
2221 font = WMCreateFont(scr->wmscreen, "fixed");
2223 if (!font) {
2224 wfatal(_("could not load any usable font!!!"));
2225 exit(1);
2228 if (ret)
2229 *ret = font;
2231 /* can't assign font value outside update function */
2232 wassertrv(addr == NULL, True);
2234 return True;
2238 static int
2239 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2240 void **ret)
2242 static XColor color;
2243 char *val;
2244 int second_pass=0;
2246 GET_STRING_OR_DEFAULT("Color", val);
2249 again:
2250 if (!wGetColor(scr, val, &color)) {
2251 wwarning(_("could not get color for key \"%s\""),
2252 entry->key);
2253 if (second_pass==0) {
2254 val = PLGetString(entry->plvalue);
2255 second_pass = 1;
2256 wwarning(_("using default \"%s\" instead"), val);
2257 goto again;
2259 return False;
2262 if (ret)
2263 *ret = &color;
2265 assert(addr==NULL);
2267 if (addr)
2268 *(unsigned long*)addr = pixel;
2271 return True;
2276 static int
2277 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2278 void **ret)
2280 static WShortKey shortcut;
2281 KeySym ksym;
2282 char *val;
2283 char *k;
2284 char buf[128], *b;
2287 GET_STRING_OR_DEFAULT("Key spec", val);
2289 if (!val || strcasecmp(val, "NONE")==0) {
2290 shortcut.keycode = 0;
2291 shortcut.modifier = 0;
2292 if (ret)
2293 *ret = &shortcut;
2294 return True;
2297 strcpy(buf, val);
2299 b = (char*)buf;
2301 /* get modifiers */
2302 shortcut.modifier = 0;
2303 while ((k = strchr(b, '+'))!=NULL) {
2304 int mod;
2306 *k = 0;
2307 mod = wXModifierFromKey(b);
2308 if (mod<0) {
2309 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2310 return False;
2312 shortcut.modifier |= mod;
2314 b = k+1;
2317 /* get key */
2318 ksym = XStringToKeysym(b);
2320 if (ksym==NoSymbol) {
2321 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2322 val);
2323 return False;
2326 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2327 if (shortcut.keycode==0) {
2328 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2329 return False;
2332 if (ret)
2333 *ret = &shortcut;
2335 return True;
2339 static int
2340 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2341 void **ret)
2343 static unsigned int mask;
2344 char *str;
2346 GET_STRING_OR_DEFAULT("Modifier Key", str);
2348 if (!str)
2349 return False;
2351 mask = wXModifierFromKey(str);
2352 if (mask < 0) {
2353 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2354 mask = 0;
2355 return False;
2358 if (addr)
2359 *(unsigned int*)addr = mask;
2361 if (ret)
2362 *ret = &mask;
2364 return True;
2368 #ifdef NEWSTUFF
2369 static int
2370 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2371 void *addr, void **ret)
2373 unsigned int mask;
2374 char *str;
2375 RImage *image;
2376 int i, n;
2377 int w, h;
2379 GET_STRING_OR_DEFAULT("Image File Path", str);
2380 if (!str)
2381 return False;
2383 image = RLoadImage(scr->rcontext, str, 0);
2384 if (!image) {
2385 wwarning(_("could not load image in option %s: %s"), entry->key,
2386 RMessageForError(RErrorCode));
2387 return False;
2390 if (*(RImage**)addr) {
2391 RDestroyImage(*(RImage**)addr);
2393 if (addr)
2394 *(RImage**)addr = image;
2396 assert(ret == NULL);
2398 if (ret)
2399 *(RImage**)ret = image;
2402 return True;
2404 #endif
2407 /* ---------------- value setting functions --------------- */
2408 static int
2409 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2411 return REFRESH_WINDOW_TITLE_COLOR;
2414 static int
2415 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2417 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT;
2420 static int
2421 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which)
2423 switch (which) {
2424 case WM_DOCK:
2425 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2426 break;
2427 case WM_CLIP:
2428 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2429 break;
2430 default:
2431 break;
2433 return 0;
2437 static int
2438 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2440 if (scr->workspaces) {
2441 wWorkspaceForceChange(scr, scr->current_workspace);
2442 wArrangeIcons(scr, False);
2444 return 0;
2447 #if not_used
2448 static int
2449 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2451 if (*value <= 0)
2452 *(int*)foo = 1;
2454 return 0;
2456 #endif
2460 static int
2461 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2463 Pixmap pixmap;
2464 RImage *img;
2465 int reset = 0;
2467 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2468 wPreferences.icon_size,
2469 ((*texture)->any.type & WREL_BORDER_MASK)
2470 ? WREL_ICON : WREL_FLAT);
2471 if (!img) {
2472 wwarning(_("could not render texture for icon background"));
2473 if (!entry->addr)
2474 wTextureDestroy(scr, *texture);
2475 return 0;
2477 RConvertImage(scr->rcontext, img, &pixmap);
2479 if (scr->icon_tile) {
2480 reset = 1;
2481 RDestroyImage(scr->icon_tile);
2482 XFreePixmap(dpy, scr->icon_tile_pixmap);
2485 scr->icon_tile = img;
2487 if (!wPreferences.flags.noclip) {
2488 if (scr->clip_tile) {
2489 RDestroyImage(scr->clip_tile);
2491 scr->clip_tile = wClipMakeTile(scr, img);
2494 scr->icon_tile_pixmap = pixmap;
2496 if (scr->def_icon_pixmap) {
2497 XFreePixmap(dpy, scr->def_icon_pixmap);
2498 scr->def_icon_pixmap = None;
2500 if (scr->def_ticon_pixmap) {
2501 XFreePixmap(dpy, scr->def_ticon_pixmap);
2502 scr->def_ticon_pixmap = None;
2505 if (scr->icon_back_texture) {
2506 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2508 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2510 if (scr->clip_balloon)
2511 XSetWindowBackground(dpy, scr->clip_balloon,
2512 (*texture)->any.color.pixel);
2515 * Free the texture as nobody else will use it, nor refer to it.
2517 if (!entry->addr)
2518 wTextureDestroy(scr, *texture);
2520 return (reset ? REFRESH_ICON_TILE : 0);
2525 static int
2526 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2528 if (scr->title_font) {
2529 WMReleaseFont(scr->title_font);
2531 scr->title_font = font;
2533 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2537 static int
2538 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2540 if (scr->menu_title_font) {
2541 WMReleaseFont(scr->menu_title_font);
2544 scr->menu_title_font = font;
2546 return REFRESH_MENU_TITLE_FONT;
2550 static int
2551 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2553 if (scr->menu_entry_font) {
2554 WMReleaseFont(scr->menu_entry_font);
2556 scr->menu_entry_font = font;
2558 return REFRESH_MENU_FONT;
2563 static int
2564 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2566 if (scr->icon_title_font) {
2567 WMReleaseFont(scr->icon_title_font);
2570 scr->icon_title_font = font;
2572 return REFRESH_ICON_FONT;
2576 static int
2577 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2579 if (scr->clip_title_font) {
2580 WMReleaseFont(scr->clip_title_font);
2583 scr->clip_title_font = font;
2585 return REFRESH_ICON_FONT;
2589 static int
2590 setDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2592 if (scr->info_text_font) {
2593 WMReleaseFont(scr->info_text_font);
2596 scr->info_text_font = font;
2598 /* This test works because the scr structure is initially zeroed out
2599 and None = 0. Any other time, the window should be valid. */
2600 if (scr->geometry_display != None) {
2601 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
2602 &scr->geometry_display_height);
2603 XResizeWindow(dpy, scr->geometry_display,
2604 scr->geometry_display_width, scr->geometry_display_height);
2607 return 0;
2611 static int
2612 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2614 if (scr->workspace_name_font) {
2615 WMReleaseFont(scr->workspace_name_font);
2618 scr->workspace_name_font = font;
2620 return 0;
2624 static int
2625 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2627 if (scr->select_pixel!=scr->white_pixel &&
2628 scr->select_pixel!=scr->black_pixel) {
2629 wFreeColor(scr, scr->select_pixel);
2632 scr->select_pixel = color->pixel;
2634 return REFRESH_MENU_COLOR;
2638 static int
2639 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2641 if (scr->select_text_pixel!=scr->white_pixel &&
2642 scr->select_text_pixel!=scr->black_pixel) {
2643 wFreeColor(scr, scr->select_text_pixel);
2646 scr->select_text_pixel = color->pixel;
2648 return REFRESH_MENU_COLOR;
2652 static int
2653 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2655 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2656 scr->clip_title_pixel[index]!=scr->black_pixel) {
2657 wFreeColor(scr, scr->clip_title_pixel[index]);
2659 scr->clip_title_pixel[index] = color->pixel;
2661 #ifdef GRADIENT_CLIP_ARROW
2662 if (index == CLIP_NORMAL) {
2663 RImage *image;
2664 RColor color1, color2;
2665 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2666 int as = pt - 15; /* 15 = 5+5+5 */
2668 FREE_PIXMAP(scr->clip_arrow_gradient);
2670 color1.red = (color->red >> 8)*6/10;
2671 color1.green = (color->green >> 8)*6/10;
2672 color1.blue = (color->blue >> 8)*6/10;
2674 color2.red = WMIN((color->red >> 8)*20/10, 255);
2675 color2.green = WMIN((color->green >> 8)*20/10, 255);
2676 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2678 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2679 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2680 RDestroyImage(image);
2682 #endif /* GRADIENT_CLIP_ARROW */
2684 return REFRESH_ICON_TITLE_COLOR;
2688 static int
2689 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2691 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2692 scr->window_title_pixel[index]!=scr->black_pixel) {
2693 wFreeColor(scr, scr->window_title_pixel[index]);
2696 scr->window_title_pixel[index] = color->pixel;
2698 if (index == WS_UNFOCUSED)
2699 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2701 return REFRESH_WINDOW_TITLE_COLOR;
2705 static int
2706 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2708 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2709 scr->menu_title_pixel[0]!=scr->black_pixel) {
2710 #ifdef DRAWSTRING_PLUGIN
2711 if(!scr->drawstring_func[W_STRING_MTITLE])
2712 #endif
2713 wFreeColor(scr, scr->menu_title_pixel[0]);
2716 scr->menu_title_pixel[0] = color->pixel;
2717 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
2719 return REFRESH_MENU_TITLE_COLOR;
2723 static int
2724 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2726 XGCValues gcv;
2727 #define gcm (GCForeground|GCBackground|GCFillStyle)
2729 if (scr->mtext_pixel!=scr->white_pixel &&
2730 scr->mtext_pixel!=scr->black_pixel) {
2731 wFreeColor(scr, scr->mtext_pixel);
2734 scr->mtext_pixel = color->pixel;
2736 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
2739 if (scr->dtext_pixel == scr->mtext_pixel) {
2740 gcv.foreground = scr->white_pixel;
2741 gcv.background = scr->black_pixel;
2742 gcv.fill_style = FillStippled;
2743 } else {
2744 gcv.foreground = scr->dtext_pixel;
2745 gcv.fill_style = FillSolid;
2747 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2749 return REFRESH_MENU_COLOR;
2750 #undef gcm
2754 static int
2755 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2757 XGCValues gcv;
2758 #define gcm (GCForeground|GCBackground|GCFillStyle)
2760 if (scr->dtext_pixel!=scr->white_pixel &&
2761 scr->dtext_pixel!=scr->black_pixel) {
2762 wFreeColor(scr, scr->dtext_pixel);
2765 scr->dtext_pixel = color->pixel;
2767 if (scr->dtext_pixel == scr->mtext_pixel) {
2768 gcv.foreground = scr->white_pixel;
2769 gcv.background = scr->black_pixel;
2770 gcv.fill_style = FillStippled;
2771 } else {
2772 gcv.foreground = scr->dtext_pixel;
2773 gcv.fill_style = FillSolid;
2775 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
2777 return REFRESH_MENU_COLOR;
2778 #undef gcm
2781 static int
2782 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2784 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
2786 return REFRESH_ICON_TITLE_COLOR;
2790 static int
2791 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2793 if (scr->icon_title_texture) {
2794 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
2796 XQueryColor (dpy, scr->w_colormap, color);
2797 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2799 return REFRESH_ICON_TITLE_BACK;
2803 static void
2804 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
2806 close(scr->helper_fd);
2807 scr->helper_fd = 0;
2808 scr->helper_pid = 0;
2809 scr->flags.backimage_helper_launched = 0;
2813 static int
2814 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2815 void *bar)
2817 int i;
2818 proplist_t val;
2819 char *str;
2821 if (scr->flags.backimage_helper_launched) {
2822 if (PLGetNumberOfElements(value)==0) {
2823 SendHelperMessage(scr, 'C', 0, NULL);
2824 SendHelperMessage(scr, 'K', 0, NULL);
2826 PLRelease(value);
2827 return 0;
2829 } else {
2830 pid_t pid;
2831 int filedes[2];
2833 if (PLGetNumberOfElements(value) == 0)
2834 return 0;
2836 if (pipe(filedes) < 0) {
2837 wsyserror("pipe() failed:can't set workspace specific background image");
2839 PLRelease(value);
2840 return 0;
2843 pid = fork();
2844 if (pid < 0) {
2845 wsyserror("fork() failed:can't set workspace specific background image");
2846 if (close(filedes[0]) < 0)
2847 wsyserror("could not close pipe");
2848 if (close(filedes[1]) < 0)
2849 wsyserror("could not close pipe");
2851 } else if (pid == 0) {
2852 SetupEnvironment(scr);
2854 if (close(0) < 0)
2855 wsyserror("could not close pipe");
2856 if (dup(filedes[0]) < 0) {
2857 wsyserror("dup() failed:can't set workspace specific background image");
2859 if (wPreferences.smooth_workspace_back)
2860 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
2861 else
2862 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
2863 wsyserror("could not execute wmsetbg");
2864 exit(1);
2865 } else {
2867 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2868 wsyserror("error setting close-on-exec flag");
2870 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2871 wsyserror("error setting close-on-exec flag");
2874 scr->helper_fd = filedes[1];
2875 scr->helper_pid = pid;
2876 scr->flags.backimage_helper_launched = 1;
2878 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
2880 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2885 for (i = 0; i < PLGetNumberOfElements(value); i++) {
2886 val = PLGetArrayElement(value, i);
2887 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
2888 str = PLGetDescription(val);
2890 SendHelperMessage(scr, 'S', i+1, str);
2892 free(str);
2893 } else {
2894 SendHelperMessage(scr, 'U', i+1, NULL);
2897 sleep(1);
2899 PLRelease(value);
2900 return 0;
2904 static int
2905 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2906 void *bar)
2908 if (scr->flags.backimage_helper_launched) {
2909 char *str;
2911 if (PLGetNumberOfElements(value)==0) {
2912 SendHelperMessage(scr, 'U', 0, NULL);
2913 } else {
2914 /* set the default workspace background to this one */
2915 str = PLGetDescription(value);
2916 if (str) {
2917 SendHelperMessage(scr, 'S', 0, str);
2918 free(str);
2919 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
2920 } else {
2921 SendHelperMessage(scr, 'U', 0, NULL);
2924 } else {
2925 char *command;
2926 char *text;
2928 SetupEnvironment(scr);
2929 text = PLGetDescription(value);
2930 command = wmalloc(strlen(text)+40);
2931 if (wPreferences.smooth_workspace_back)
2932 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
2933 else
2934 sprintf(command, "wmsetbg -d -p '%s' &", text);
2935 free(text);
2936 system(command);
2937 free(command);
2939 PLRelease(value);
2941 return 0;
2945 static int
2946 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2948 if (scr->widget_texture) {
2949 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
2951 scr->widget_texture = *(WTexSolid**)texture;
2953 if (scr->geometry_display != None)
2954 XSetWindowBackground(dpy, scr->geometry_display,
2955 scr->widget_texture->normal.pixel);
2957 return 0;
2961 static int
2962 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2964 if (scr->window_title_texture[WS_FOCUSED]) {
2965 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2967 scr->window_title_texture[WS_FOCUSED] = *texture;
2969 return REFRESH_WINDOW_TEXTURES;
2973 static int
2974 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2976 if (scr->window_title_texture[WS_PFOCUSED]) {
2977 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2979 scr->window_title_texture[WS_PFOCUSED] = *texture;
2981 return REFRESH_WINDOW_TEXTURES;
2985 static int
2986 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2988 if (scr->window_title_texture[WS_UNFOCUSED]) {
2989 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2991 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2993 return REFRESH_WINDOW_TEXTURES;
2997 static int
2998 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3000 if (scr->resizebar_texture[0]) {
3001 wTextureDestroy(scr, scr->resizebar_texture[0]);
3003 scr->resizebar_texture[0] = *texture;
3005 return REFRESH_WINDOW_TEXTURES;
3009 static int
3010 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3012 if (scr->menu_title_texture[0]) {
3013 wTextureDestroy(scr, scr->menu_title_texture[0]);
3015 scr->menu_title_texture[0] = *texture;
3017 return REFRESH_MENU_TITLE_TEXTURE;
3021 static int
3022 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3024 if (scr->menu_item_texture) {
3025 wTextureDestroy(scr, scr->menu_item_texture);
3026 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3028 scr->menu_item_texture = *texture;
3030 scr->menu_item_auxtexture
3031 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3033 return REFRESH_MENU_TEXTURE;
3037 static int
3038 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3040 WWindow *wwin;
3041 wKeyBindings[index] = *shortcut;
3043 wwin = scr->focused_window;
3045 while (wwin!=NULL) {
3046 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3048 if (!WFLAGP(wwin, no_bind_keys)) {
3049 wWindowSetKeyGrabs(wwin);
3051 wwin = wwin->prev;
3054 return 0;
3058 static int
3059 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3061 wArrangeIcons(scr, True);
3063 return 0;
3067 static int
3068 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3070 wScreenUpdateUsableArea(scr);
3072 return 0;
3076 static int
3077 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3079 return REFRESH_MENU_TEXTURE;
3084 static int
3085 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3087 return REFRESH_BUTTON_IMAGES;
3092 * Very ugly kluge.
3093 * Need access to the double click variables, so that all widgets in
3094 * wmaker panels will have the same dbl-click values.
3095 * TODO: figure a better way of dealing with it.
3097 #include "WINGsP.h"
3099 static int
3100 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3102 extern _WINGsConfiguration WINGsConfiguration;
3104 if (*value <= 0)
3105 *(int*)foo = 1;
3107 WINGsConfiguration.doubleClickDelay = *value;
3109 return 0;
3114 static int
3115 setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3117 extern _WINGsConfiguration WINGsConfiguration;
3119 WINGsConfiguration.useMultiByte = *value;
3121 return 0;