- Made all changes for moving WINGs headers in the WINGs subdirectory.
[wmaker-crm.git] / src / defaults.c
blob3d74b0e5e70351547915cc41f53b9114c874725c
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
55 #include "WindowMaker.h"
56 #include "wcore.h"
57 #include "framewin.h"
58 #include "window.h"
59 #include "texture.h"
60 #include "screen.h"
61 #include "resources.h"
62 #include "defaults.h"
63 #include "keybind.h"
64 #include "xmodifier.h"
65 #include "icon.h"
66 #include "funcs.h"
67 #include "actions.h"
68 #include "dock.h"
69 #include "workspace.h"
70 #include "properties.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;
89 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
90 extern Atom _XA_WINDOWMAKER_ICON_TILE;
93 extern proplist_t wDomainName;
94 extern proplist_t wAttributeDomainName;
96 extern WPreferences wPreferences;
98 extern WShortKey wKeyBindings[WKBD_LAST];
100 typedef struct {
101 char *key;
102 char *default_value;
103 void *extra_data;
104 void *addr;
105 int (*convert)();
106 int (*update)();
107 proplist_t plkey;
108 proplist_t plvalue; /* default value */
109 } WDefaultEntry;
112 /* used to map strings to integers */
113 typedef struct {
114 char *string;
115 short value;
116 char is_alias;
117 } WOptionEnumeration;
120 /* type converters */
121 static int getBool();
122 static int getInt();
123 static int getCoord();
124 #if 0
125 /* this is not used yet */
126 static int getString();
127 #endif
128 static int getPathList();
129 static int getEnum();
130 static int getTexture();
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 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 #if 0
182 static int setMultiByte();
183 #endif
184 static int updateUsableArea();
186 #ifdef DEFINABLE_CURSOR
187 extern Cursor wCursor[WCUR_LAST];
188 static int getCursor();
189 static int setCursor();
190 #endif
194 * Tables to convert strings to enumeration values.
195 * Values stored are char
199 /* WARNING: sum of length of all value strings must not exceed
200 * this value */
201 #define TOTAL_VALUES_LENGTH 80
206 #define REFRESH_WINDOW_TEXTURES (1<<0)
207 #define REFRESH_MENU_TEXTURE (1<<1)
208 #define REFRESH_MENU_FONT (1<<2)
209 #define REFRESH_MENU_COLOR (1<<3)
210 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
211 #define REFRESH_MENU_TITLE_FONT (1<<5)
212 #define REFRESH_MENU_TITLE_COLOR (1<<6)
213 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
214 #define REFRESH_WINDOW_FONT (1<<8)
215 #define REFRESH_ICON_TILE (1<<9)
216 #define REFRESH_ICON_FONT (1<<10)
217 #define REFRESH_WORKSPACE_BACK (1<<11)
219 #define REFRESH_BUTTON_IMAGES (1<<12)
221 #define REFRESH_ICON_TITLE_COLOR (1<<13)
222 #define REFRESH_ICON_TITLE_BACK (1<<14)
226 static WOptionEnumeration seFocusModes[] = {
227 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
228 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
229 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
230 {NULL, 0, 0}
233 static WOptionEnumeration seColormapModes[] = {
234 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
235 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
236 {NULL, 0, 0}
239 static WOptionEnumeration sePlacements[] = {
240 {"Auto", WPM_AUTO, 0},
241 {"Smart", WPM_SMART, 0},
242 {"Cascade", WPM_CASCADE, 0},
243 {"Random", WPM_RANDOM, 0},
244 {"Manual", WPM_MANUAL, 0},
245 {NULL, 0, 0}
248 static WOptionEnumeration seGeomDisplays[] = {
249 {"Center", WDIS_CENTER, 0},
250 {"Corner", WDIS_TOPLEFT, 0},
251 {"Floating", WDIS_FRAME_CENTER, 0},
252 {"Line", WDIS_NEW, 0},
253 {NULL, 0, 0}
256 static WOptionEnumeration seSpeeds[] = {
257 {"UltraFast", SPEED_ULTRAFAST, 0},
258 {"Fast", SPEED_FAST, 0},
259 {"Medium", SPEED_MEDIUM, 0},
260 {"Slow", SPEED_SLOW, 0},
261 {"UltraSlow", SPEED_ULTRASLOW, 0},
262 {NULL, 0, 0}
265 static WOptionEnumeration seMouseButtons[] = {
266 {"None", -1, 0},
267 {"Left", Button1, 0}, {"Button1", Button1, 1},
268 {"Middle", Button2, 0}, {"Button2", Button2, 1},
269 {"Right", Button3, 0}, {"Button3", Button3, 1},
270 {"Button4", Button4, 0},
271 {"Button5", Button5, 0},
272 {NULL, 0, 0}
275 static WOptionEnumeration seIconificationStyles[] = {
276 {"Zoom", WIS_ZOOM, 0},
277 {"Twist", WIS_TWIST, 0},
278 {"Flip", WIS_FLIP, 0},
279 {"None", WIS_NONE, 0},
280 {"random", WIS_RANDOM, 0},
281 {NULL, 0, 0}
284 static WOptionEnumeration seJustifications[] = {
285 {"Left", WTJ_LEFT, 0},
286 {"Center", WTJ_CENTER, 0},
287 {"Right", WTJ_RIGHT, 0},
288 {NULL, 0, 0}
291 static WOptionEnumeration seIconPositions[] = {
292 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
293 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
294 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
295 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
296 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
297 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
298 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
299 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
300 {NULL, 0, 0}
303 static WOptionEnumeration seMenuStyles[] = {
304 {"normal", MS_NORMAL, 0},
305 {"singletexture", MS_SINGLE_TEXTURE, 0},
306 {"flat", MS_FLAT, 0},
307 {NULL, 0, 0}
311 static WOptionEnumeration seDisplayPositions[] = {
312 {"none", WD_NONE, 0},
313 {"center", WD_CENTER, 0},
314 {"top", WD_TOP, 0},
315 {"bottom", WD_BOTTOM, 0},
316 {"topleft", WD_TOPLEFT, 0},
317 {"topright", WD_TOPRIGHT, 0},
318 {"bottomleft", WD_BOTTOMLEFT, 0},
319 {"bottomright", WD_BOTTOMRIGHT, 0},
320 {NULL, 0, 0}
323 static WOptionEnumeration seWorkspaceBorder[] = {
324 {"None", WB_NONE, 0},
325 {"LeftRight", WB_LEFTRIGHT, 0},
326 {"TopBottom", WB_TOPBOTTOM, 0},
327 {"AllDirections", WB_ALLDIRS, 0},
328 {NULL, 0, 0}
333 * ALL entries in the tables bellow, NEED to have a default value
334 * defined, and this value needs to be correct.
337 /* these options will only affect the window manager on startup
339 * static defaults can't access the screen data, because it is
340 * created after these defaults are read
342 WDefaultEntry staticOptionList[] = {
344 {"ColormapSize", "4", NULL,
345 &wPreferences.cmap_size, getInt, NULL
347 {"DisableDithering", "NO", NULL,
348 &wPreferences.no_dithering, getBool, NULL
350 /* static by laziness */
351 {"IconSize", "64", NULL,
352 &wPreferences.icon_size, getInt, NULL
354 {"ModifierKey", "Mod1", NULL,
355 &wPreferences.modifier_mask, getModMask, NULL
357 {"DisableWSMouseActions", "NO", NULL,
358 &wPreferences.disable_root_mouse, getBool, NULL
360 {"FocusMode", "manual", seFocusModes,
361 &wPreferences.focus_mode, getEnum, NULL
362 }, /* have a problem when switching from manual to sloppy without restart */
363 {"NewStyle", "NO", NULL,
364 &wPreferences.new_style, getBool, NULL
366 {"DisableDock", "NO", (void*) WM_DOCK,
367 NULL, getBool, setIfDockPresent
369 {"DisableClip", "NO", (void*) WM_CLIP,
370 NULL, getBool, setIfDockPresent
372 {"DisableMiniwindows", "NO", NULL,
373 &wPreferences.disable_miniwindows, getBool, NULL
375 #if 0
376 ,{"MultiByteText", "NO", NULL,
377 &wPreferences.multi_byte_text, getBool, setMultiByte
379 #endif
384 WDefaultEntry optionList[] = {
385 /* dynamic options */
386 {"IconPosition", "blh", seIconPositions,
387 &wPreferences.icon_yard, getEnum, setIconPosition
389 {"IconificationStyle", "Zoom", seIconificationStyles,
390 &wPreferences.iconification_style, getEnum, NULL
392 {"SelectWindowsMouseButton", "Left", seMouseButtons,
393 &wPreferences.select_button, getEnum, NULL
395 {"WindowListMouseButton", "Middle", seMouseButtons,
396 &wPreferences.windowl_button, getEnum, NULL
398 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
399 &wPreferences.menu_button, getEnum, NULL
401 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
402 &wPreferences.pixmap_path, getPathList, NULL
404 {"IconPath", DEF_ICON_PATHS, NULL,
405 &wPreferences.icon_path, getPathList, NULL
407 {"ColormapMode", "auto", seColormapModes,
408 &wPreferences.colormap_mode, getEnum, NULL
410 {"AutoFocus", "NO", NULL,
411 &wPreferences.auto_focus, getBool, NULL
413 {"RaiseDelay", "0", NULL,
414 &wPreferences.raise_delay, getInt, NULL
416 {"WindozeCycling", "YES", NULL,
417 &wPreferences.windows_cycling,getBool, NULL
419 {"CirculateRaise", "NO", NULL,
420 &wPreferences.circ_raise, getBool, NULL
422 {"Superfluous", "NO", NULL,
423 &wPreferences.superfluous, getBool, NULL
425 {"AdvanceToNewWorkspace", "NO", NULL,
426 &wPreferences.ws_advance, getBool, NULL
428 {"CycleWorkspaces", "NO", NULL,
429 &wPreferences.ws_cycle, getBool, NULL
431 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
432 &wPreferences.workspace_name_display_position, getEnum, NULL
434 {"WorkspaceBorder", "None", seWorkspaceBorder,
435 &wPreferences.workspace_border_position, getEnum, updateUsableArea
437 {"WorkspaceBorderSize", "0", NULL,
438 &wPreferences.workspace_border_size, getInt, updateUsableArea
440 #ifdef VIRTUAL_DESKTOP
441 {"VirtualEdgeThickness", "1", NULL,
442 &wPreferences.vedge_thickness, getInt, NULL
444 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
445 &wPreferences.vedge_hscrollspeed, getInt, NULL
447 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
448 &wPreferences.vedge_vscrollspeed, getInt, NULL
450 {"VirtualEdgeMaximumWidth", "3000", NULL,
451 &wPreferences.vedge_maxwidth, getInt, NULL
453 {"VirtualEdgeMaximumHeight", "3000", NULL,
454 &wPreferences.vedge_maxheight, getInt, NULL
456 #endif
457 {"StickyIcons", "NO", NULL,
458 &wPreferences.sticky_icons, getBool, setStickyIcons
460 {"SaveSessionOnExit", "NO", NULL,
461 &wPreferences.save_session_on_exit, getBool, NULL
463 {"WrapMenus", "NO", NULL,
464 &wPreferences.wrap_menus, getBool, NULL
466 {"ScrollableMenus", "NO", NULL,
467 &wPreferences.scrollable_menus, getBool, NULL
469 {"MenuScrollSpeed", "medium", seSpeeds,
470 &wPreferences.menu_scroll_speed, getEnum, NULL
472 {"IconSlideSpeed", "medium", seSpeeds,
473 &wPreferences.icon_slide_speed, getEnum, NULL
475 {"ShadeSpeed", "medium", seSpeeds,
476 &wPreferences.shade_speed, getEnum, NULL
478 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
479 &wPreferences.dblclick_time, getInt, setDoubleClick,
481 {"AlignSubmenus", "NO", NULL,
482 &wPreferences.align_menus, getBool, NULL
484 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
485 &wPreferences.open_transients_with_parent, getBool, NULL
487 {"WindowPlacement", "auto", sePlacements,
488 &wPreferences.window_placement, getEnum, NULL
490 {"IgnoreFocusClick","NO", NULL,
491 &wPreferences.ignore_focus_click, getBool, NULL
493 {"UseSaveUnders", "NO", NULL,
494 &wPreferences.use_saveunders, getBool, NULL
496 {"OpaqueMove", "NO", NULL,
497 &wPreferences.opaque_move, getBool, NULL
499 {"DisableSound", "NO", NULL,
500 &wPreferences.no_sound, getBool, NULL
502 {"DisableAnimations", "NO", NULL,
503 &wPreferences.no_animations, getBool, NULL
505 {"DontLinkWorkspaces","NO", NULL,
506 &wPreferences.no_autowrap, getBool, NULL
508 {"AutoArrangeIcons", "NO", NULL,
509 &wPreferences.auto_arrange_icons, getBool, NULL
511 {"NoWindowOverDock", "NO", NULL,
512 &wPreferences.no_window_over_dock, getBool, updateUsableArea
514 {"NoWindowOverIcons", "NO", NULL,
515 &wPreferences.no_window_over_icons, getBool, updateUsableArea
517 {"WindowPlaceOrigin", "(0, 0)", NULL,
518 &wPreferences.window_place_origin, getCoord, NULL
520 {"ResizeDisplay", "corner", seGeomDisplays,
521 &wPreferences.size_display, getEnum, NULL
523 {"MoveDisplay", "corner", seGeomDisplays,
524 &wPreferences.move_display, getEnum, NULL
526 {"DontConfirmKill", "NO", NULL,
527 &wPreferences.dont_confirm_kill, getBool,NULL
529 {"WindowTitleBalloons", "NO", NULL,
530 &wPreferences.window_balloon, getBool, NULL
532 {"MiniwindowTitleBalloons", "NO", NULL,
533 &wPreferences.miniwin_balloon,getBool, NULL
535 {"AppIconBalloons", "NO", NULL,
536 &wPreferences.appicon_balloon,getBool, NULL
538 {"HelpBalloons", "NO", NULL,
539 &wPreferences.help_balloon, getBool, NULL
541 {"EdgeResistance", "30", NULL,
542 &wPreferences.edge_resistance,getInt, NULL
544 {"Attraction", "NO", NULL,
545 &wPreferences.attract, getBool, NULL
547 {"DisableBlinking", "NO", NULL,
548 &wPreferences.dont_blink, getBool, NULL
550 /* style options */
551 {"MenuStyle", "normal", seMenuStyles,
552 &wPreferences.menu_style, getEnum, setMenuStyle
554 {"WidgetColor", "(solid, gray)", NULL,
555 NULL, getTexture, setWidgetColor,
557 {"WorkspaceSpecificBack","()", NULL,
558 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
560 /* WorkspaceBack must come after WorkspaceSpecificBack or
561 * WorkspaceBack wont know WorkspaceSpecificBack was also
562 * specified and 2 copies of wmsetbg will be launched */
563 {"WorkspaceBack", "(solid, black)", NULL,
564 NULL, getWSBackground,setWorkspaceBack
566 {"SmoothWorkspaceBack", "NO", NULL,
567 NULL, getBool, NULL
569 {"IconBack", "(solid, gray)", NULL,
570 NULL, getTexture, setIconTile
572 {"TitleJustify", "center", seJustifications,
573 &wPreferences.title_justification, getEnum, setJustify
575 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
576 NULL, getFont, setWinTitleFont,
578 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
579 &wPreferences.window_title_clearance, getInt, setClearance
581 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
582 &wPreferences.menu_title_clearance, getInt, setClearance
584 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
585 &wPreferences.menu_text_clearance, getInt, setClearance
587 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
588 NULL, getFont, setMenuTitleFont
590 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
591 NULL, getFont, setMenuTextFont
593 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
594 NULL, getFont, setIconTitleFont
596 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
597 NULL, getFont, setClipTitleFont
599 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
600 NULL, getFont, setLargeDisplayFont
602 {"HighlightColor", "white", NULL,
603 NULL, getColor, setHightlight
605 {"HighlightTextColor", "black", NULL,
606 NULL, getColor, setHightlightText
608 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
609 NULL, getColor, setClipTitleColor
611 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
612 NULL, getColor, setClipTitleColor
614 {"FTitleColor", "white", (void*)WS_FOCUSED,
615 NULL, getColor, setWTitleColor
617 {"PTitleColor", "white", (void*)WS_PFOCUSED,
618 NULL, getColor, setWTitleColor
620 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
621 NULL, getColor, setWTitleColor
623 {"FTitleBack", "(solid, black)", NULL,
624 NULL, getTexture, setFTitleBack
626 {"PTitleBack", "(solid, \"#616161\")", NULL,
627 NULL, getTexture, setPTitleBack
629 {"UTitleBack", "(solid, gray)", NULL,
630 NULL, getTexture, setUTitleBack
632 {"ResizebarBack", "(solid, gray)", NULL,
633 NULL, getTexture, setResizebarBack
635 {"MenuTitleColor", "white", NULL,
636 NULL, getColor, setMenuTitleColor
638 {"MenuTextColor", "black", NULL,
639 NULL, getColor, setMenuTextColor
641 {"MenuDisabledColor", "\"#616161\"", NULL,
642 NULL, getColor, setMenuDisabledColor
644 {"MenuTitleBack", "(solid, black)", NULL,
645 NULL, getTexture, setMenuTitleBack
647 {"MenuTextBack", "(solid, gray)", NULL,
648 NULL, getTexture, setMenuTextBack
650 {"IconTitleColor", "white", NULL,
651 NULL, getColor, setIconTitleColor
653 {"IconTitleBack", "black", NULL,
654 NULL, getColor, setIconTitleBack
656 /* keybindings */
657 #ifndef LITE
658 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
659 NULL, getKeybind, setKeyGrab
661 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
662 NULL, getKeybind, setKeyGrab
664 #endif /* LITE */
665 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
666 NULL, getKeybind, setKeyGrab
668 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
669 NULL, getKeybind, setKeyGrab
671 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
672 NULL, getKeybind, setKeyGrab
674 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
675 NULL, getKeybind, setKeyGrab
677 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
678 NULL, getKeybind, setKeyGrab
680 {"HideKey", "None", (void*)WKBD_HIDE,
681 NULL, getKeybind, setKeyGrab
683 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
684 NULL, getKeybind, setKeyGrab
686 {"CloseKey", "None", (void*)WKBD_CLOSE,
687 NULL, getKeybind, setKeyGrab
689 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
690 NULL, getKeybind, setKeyGrab
692 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
693 NULL, getKeybind, setKeyGrab
695 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
696 NULL, getKeybind, setKeyGrab
698 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
699 NULL, getKeybind, setKeyGrab
701 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
702 NULL, getKeybind, setKeyGrab
704 {"ShadeKey", "None", (void*)WKBD_SHADE,
705 NULL, getKeybind, setKeyGrab
707 {"SelectKey", "None", (void*)WKBD_SELECT,
708 NULL, getKeybind, setKeyGrab
710 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
711 NULL, getKeybind, setKeyGrab
713 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
714 NULL, getKeybind, setKeyGrab
716 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
717 NULL, getKeybind, setKeyGrab
719 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
720 NULL, getKeybind, setKeyGrab
722 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
723 NULL, getKeybind, setKeyGrab
725 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
726 NULL, getKeybind, setKeyGrab
728 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
729 NULL, getKeybind, setKeyGrab
731 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
732 NULL, getKeybind, setKeyGrab
734 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
735 NULL, getKeybind, setKeyGrab
737 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
738 NULL, getKeybind, setKeyGrab
740 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
741 NULL, getKeybind, setKeyGrab
743 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
744 NULL, getKeybind, setKeyGrab
746 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
756 NULL, getKeybind, setKeyGrab
758 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
759 NULL, getKeybind, setKeyGrab
761 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
762 NULL, getKeybind, setKeyGrab
764 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
765 NULL, getKeybind, setKeyGrab
767 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
768 NULL, getKeybind, setKeyGrab
770 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
771 NULL, getKeybind, setKeyGrab
773 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
774 NULL, getKeybind, setKeyGrab
776 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
783 NULL, getKeybind, setKeyGrab
785 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
786 NULL, getKeybind, setKeyGrab
788 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
789 NULL, getKeybind, setKeyGrab
792 #ifdef KEEP_XKB_LOCK_STATUS
793 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
794 NULL, getKeybind, setKeyGrab
796 {"KbdModeLock", "NO", NULL,
797 &wPreferences.modelock, getBool, NULL
799 #endif /* KEEP_XKB_LOCK_STATUS */
800 #ifdef DEFINABLE_CURSOR
801 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
802 NULL, getCursor, setCursor
804 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
805 NULL, getCursor, setCursor
807 #if 0
808 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
809 NULL, getCursor, setCursor
811 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
812 NULL, getCursor, setCursor
814 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
815 NULL, getCursor, setCursor
817 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
818 NULL, getCursor, setCursor
820 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
821 NULL, getCursor, setCursor
823 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
824 NULL, getCursor, setCursor
826 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
827 NULL, getCursor, setCursor
829 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
830 NULL, getCursor, setCursor
832 #endif
833 #endif /* DEFINABLE_CURSOR */
837 #if 0
838 static void rereadDefaults(void);
839 #endif
841 #if 0
842 static void
843 rereadDefaults(void)
845 /* must defer the update because accessing X data from a
846 * signal handler can mess up Xlib */
849 #endif
851 static void
852 initDefaults()
854 int i;
855 WDefaultEntry *entry;
857 PLSetStringCmpHook(StringCompareHook);
859 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
860 entry = &optionList[i];
862 entry->plkey = PLMakeString(entry->key);
863 if (entry->default_value)
864 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
865 else
866 entry->plvalue = NULL;
869 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
870 entry = &staticOptionList[i];
872 entry->plkey = PLMakeString(entry->key);
873 if (entry->default_value)
874 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
875 else
876 entry->plvalue = NULL;
880 wDomainName = PLMakeString(WMDOMAIN_NAME);
881 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
883 PLRegister(wDomainName, rereadDefaults);
884 PLRegister(wAttributeDomainName, rereadDefaults);
891 #if 0
892 proplist_t
893 wDefaultsInit(int screen_number)
895 static int defaults_inited = 0;
896 proplist_t dict;
898 if (!defaults_inited) {
899 initDefaults();
902 dict = PLGetDomain(wDomainName);
903 if (!dict) {
904 wwarning(_("could not read domain \"%s\" from defaults database"),
905 PLGetString(wDomainName));
908 return dict;
910 #endif
913 void
914 wDefaultsDestroyDomain(WDDomain *domain)
916 if (domain->dictionary)
917 PLRelease(domain->dictionary);
918 wfree(domain->path);
919 wfree(domain);
923 WDDomain*
924 wDefaultsInitDomain(char *domain, Bool requireDictionary)
926 WDDomain *db;
927 struct stat stbuf;
928 static int inited = 0;
929 char path[PATH_MAX];
930 char *the_path;
931 proplist_t shared_dict=NULL;
933 if (!inited) {
934 inited = 1;
935 initDefaults();
938 db = wmalloc(sizeof(WDDomain));
939 memset(db, 0, sizeof(WDDomain));
940 db->domain_name = domain;
941 db->path = wdefaultspathfordomain(domain);
942 the_path = db->path;
944 if (the_path && stat(the_path, &stbuf)>=0) {
945 db->dictionary = ReadProplistFromFile(the_path);
946 if (db->dictionary) {
947 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
948 PLRelease(db->dictionary);
949 db->dictionary = NULL;
950 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
951 domain, the_path);
953 db->timestamp = stbuf.st_mtime;
954 } else {
955 wwarning(_("could not load domain %s from user defaults database"),
956 domain);
960 /* global system dictionary */
961 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
962 if (stat(path, &stbuf)>=0) {
963 shared_dict = ReadProplistFromFile(path);
964 if (shared_dict) {
965 if (requireDictionary && !PLIsDictionary(shared_dict)) {
966 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
967 domain, path);
968 PLRelease(shared_dict);
969 shared_dict = NULL;
970 } else {
971 if (db->dictionary && PLIsDictionary(shared_dict) &&
972 PLIsDictionary(db->dictionary)) {
973 PLMergeDictionaries(shared_dict, db->dictionary);
974 PLRelease(db->dictionary);
975 db->dictionary = shared_dict;
976 if (stbuf.st_mtime > db->timestamp)
977 db->timestamp = stbuf.st_mtime;
978 } else if (!db->dictionary) {
979 db->dictionary = shared_dict;
980 if (stbuf.st_mtime > db->timestamp)
981 db->timestamp = stbuf.st_mtime;
984 } else {
985 wwarning(_("could not load domain %s from global defaults database (%s)"),
986 domain, path);
990 /* set to save it in user's directory, no matter from where it was read */
991 if (db->dictionary) {
992 proplist_t tmp = PLMakeString(db->path);
994 PLSetFilename(db->dictionary, tmp);
995 PLRelease(tmp);
998 return db;
1002 void
1003 wReadStaticDefaults(proplist_t dict)
1005 proplist_t plvalue;
1006 WDefaultEntry *entry;
1007 int i;
1008 void *tdata;
1011 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1012 entry = &staticOptionList[i];
1014 if (dict)
1015 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1016 else
1017 plvalue = NULL;
1019 if (!plvalue) {
1020 /* no default in the DB. Use builtin default */
1021 plvalue = entry->plvalue;
1024 if (plvalue) {
1025 /* convert data */
1026 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1027 if (entry->update) {
1028 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1035 void
1036 wDefaultsCheckDomains(void *foo)
1038 WScreen *scr;
1039 struct stat stbuf;
1040 proplist_t dict;
1041 int i;
1042 char path[PATH_MAX];
1044 #ifdef HEARTBEAT
1045 puts("Checking domains...");
1046 #endif
1047 if (stat(WDWindowMaker->path, &stbuf)>=0
1048 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1049 proplist_t shared_dict = NULL;
1050 #ifdef HEARTBEAT
1051 puts("Checking WindowMaker domain");
1052 #endif
1053 WDWindowMaker->timestamp = stbuf.st_mtime;
1055 /* global dictionary */
1056 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1057 if (stat(path, &stbuf)>=0) {
1058 shared_dict = ReadProplistFromFile(path);
1059 if (shared_dict && !PLIsDictionary(shared_dict)) {
1060 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1061 "WindowMaker", path);
1062 PLRelease(shared_dict);
1063 shared_dict = NULL;
1064 } else if (!shared_dict) {
1065 wwarning(_("could not load domain %s from global defaults database"),
1066 "WindowMaker");
1069 /* user dictionary */
1070 dict = ReadProplistFromFile(WDWindowMaker->path);
1071 if (dict) {
1072 if (!PLIsDictionary(dict)) {
1073 PLRelease(dict);
1074 dict = NULL;
1075 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1076 "WindowMaker", WDWindowMaker->path);
1077 } else {
1078 if (shared_dict) {
1079 PLSetFilename(shared_dict, PLGetFilename(dict));
1080 PLMergeDictionaries(shared_dict, dict);
1081 PLRelease(dict);
1082 dict = shared_dict;
1083 shared_dict = NULL;
1085 for (i=0; i<wScreenCount; i++) {
1086 scr = wScreenWithNumber(i);
1087 if (scr)
1088 wReadDefaults(scr, dict);
1090 if (WDWindowMaker->dictionary) {
1091 PLRelease(WDWindowMaker->dictionary);
1093 WDWindowMaker->dictionary = dict;
1095 } else {
1096 wwarning(_("could not load domain %s from user defaults database"),
1097 "WindowMaker");
1099 if (shared_dict) {
1100 PLRelease(shared_dict);
1104 if (stat(WDWindowAttributes->path, &stbuf)>=0
1105 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1106 #ifdef HEARTBEAT
1107 puts("Checking WMWindowAttributes domain");
1108 #endif
1109 dict = ReadProplistFromFile(WDWindowAttributes->path);
1110 if (dict) {
1111 if (!PLIsDictionary(dict)) {
1112 PLRelease(dict);
1113 dict = NULL;
1114 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1115 "WMWindowAttributes", WDWindowAttributes->path);
1116 } else {
1117 if (WDWindowAttributes->dictionary)
1118 PLRelease(WDWindowAttributes->dictionary);
1119 WDWindowAttributes->dictionary = dict;
1120 for (i=0; i<wScreenCount; i++) {
1121 scr = wScreenWithNumber(i);
1122 if (scr)
1123 wDefaultUpdateIcons(scr);
1126 } else {
1127 wwarning(_("could not load domain %s from user defaults database"),
1128 "WMWindowAttributes");
1130 WDWindowAttributes->timestamp = stbuf.st_mtime;
1133 #ifndef LITE
1134 if (stat(WDRootMenu->path, &stbuf)>=0
1135 && WDRootMenu->timestamp < stbuf.st_mtime) {
1136 dict = ReadProplistFromFile(WDRootMenu->path);
1137 #ifdef HEARTBEAT
1138 puts("Checking WMRootMenu domain");
1139 #endif
1140 if (dict) {
1141 if (!PLIsArray(dict) && !PLIsString(dict)) {
1142 PLRelease(dict);
1143 dict = NULL;
1144 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1145 "WMRootMenu", WDRootMenu->path);
1146 } else {
1147 if (WDRootMenu->dictionary) {
1148 PLRelease(WDRootMenu->dictionary);
1150 WDRootMenu->dictionary = dict;
1152 } else {
1153 wwarning(_("could not load domain %s from user defaults database"),
1154 "WMRootMenu");
1156 WDRootMenu->timestamp = stbuf.st_mtime;
1158 #endif /* !LITE */
1160 if (!foo)
1161 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1165 void
1166 wReadDefaults(WScreen *scr, proplist_t new_dict)
1168 proplist_t plvalue, old_value;
1169 WDefaultEntry *entry;
1170 int i, must_update;
1171 int update_workspace_back = 0; /* kluge :/ */
1172 int needs_refresh;
1173 void *tdata;
1174 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1175 ? WDWindowMaker->dictionary : NULL);
1177 must_update = 0;
1179 needs_refresh = 0;
1181 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1182 entry = &optionList[i];
1184 if (new_dict)
1185 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1186 else
1187 plvalue = NULL;
1189 if (!old_dict)
1190 old_value = NULL;
1191 else
1192 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1195 if (!plvalue && !old_value) {
1196 /* no default in the DB. Use builtin default */
1197 plvalue = entry->plvalue;
1198 if (plvalue && new_dict) {
1199 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1200 must_update = 1;
1202 } else if (!plvalue) {
1203 /* value was deleted from DB. Keep current value */
1204 continue;
1205 } else if (!old_value) {
1206 /* set value for the 1st time */
1207 } else if (!PLIsEqual(plvalue, old_value)) {
1208 /* value has changed */
1209 } else {
1211 if (strcmp(entry->key, "WorkspaceBack") == 0
1212 && update_workspace_back
1213 && scr->flags.backimage_helper_launched) {
1214 } else {
1215 /* value was not changed since last time */
1216 continue;
1220 if (plvalue) {
1221 #ifdef DEBUG
1222 printf("Updating %s to %s\n", entry->key,
1223 PLGetDescription(plvalue));
1224 #endif
1225 /* convert data */
1226 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1228 * If the WorkspaceSpecificBack data has been changed
1229 * so that the helper will be launched now, we must be
1230 * sure to send the default background texture config
1231 * to the helper.
1233 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1234 && !scr->flags.backimage_helper_launched) {
1235 update_workspace_back = 1;
1237 if (entry->update) {
1238 needs_refresh |=
1239 (*entry->update)(scr, entry, tdata, entry->extra_data);
1245 if (needs_refresh!=0 && !scr->flags.startup) {
1246 int foo;
1248 foo = 0;
1249 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1250 foo |= WTextureSettings;
1251 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1252 foo |= WFontSettings;
1253 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1254 foo |= WColorSettings;
1255 if (foo)
1256 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1257 (void*)foo);
1259 foo = 0;
1260 if (needs_refresh & REFRESH_MENU_TEXTURE)
1261 foo |= WTextureSettings;
1262 if (needs_refresh & REFRESH_MENU_FONT)
1263 foo |= WFontSettings;
1264 if (needs_refresh & REFRESH_MENU_COLOR)
1265 foo |= WColorSettings;
1266 if (foo)
1267 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1268 (void*)foo);
1270 foo = 0;
1271 if (needs_refresh & REFRESH_WINDOW_FONT) {
1272 foo |= WFontSettings;
1274 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1275 foo |= WTextureSettings;
1277 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1278 foo |= WColorSettings;
1280 if (foo)
1281 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1282 (void*)foo);
1284 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1285 foo = 0;
1286 if (needs_refresh & REFRESH_ICON_FONT) {
1287 foo |= WFontSettings;
1289 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1290 foo |= WTextureSettings;
1292 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1293 foo |= WTextureSettings;
1295 if (foo)
1296 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1297 (void*)foo);
1299 if (needs_refresh & REFRESH_ICON_TILE)
1300 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1305 void
1306 wDefaultUpdateIcons(WScreen *scr)
1308 WAppIcon *aicon = scr->app_icon_list;
1309 WWindow *wwin = scr->focused_window;
1310 char *file;
1312 while(aicon) {
1313 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1314 False);
1315 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1316 || (file && !aicon->icon->file)) {
1317 RImage *new_image;
1319 if (aicon->icon->file)
1320 wfree(aicon->icon->file);
1321 aicon->icon->file = wstrdup(file);
1323 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1324 aicon->wm_class);
1325 if (new_image) {
1326 wIconChangeImage(aicon->icon, new_image);
1327 wAppIconPaint(aicon);
1330 aicon = aicon->next;
1333 if (!wPreferences.flags.noclip)
1334 wClipIconPaint(scr->clip_icon);
1336 while (wwin) {
1337 if (wwin->icon && wwin->flags.miniaturized) {
1338 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1339 False);
1340 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1341 || (file && !wwin->icon->file)) {
1342 RImage *new_image;
1344 if (wwin->icon->file)
1345 wfree(wwin->icon->file);
1346 wwin->icon->file = wstrdup(file);
1348 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1349 wwin->wm_class);
1350 if (new_image)
1351 wIconChangeImage(wwin->icon, new_image);
1354 wwin = wwin->prev;
1359 /* --------------------------- Local ----------------------- */
1361 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1362 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1363 entry->key, x); \
1364 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1365 var = entry->default_value;\
1366 } else var = PLGetString(value)\
1372 static int
1373 string2index(proplist_t key, proplist_t val, proplist_t def,
1374 WOptionEnumeration *values)
1376 char *str;
1377 WOptionEnumeration *v;
1378 char buffer[TOTAL_VALUES_LENGTH];
1380 if (PLIsString(val) && (str = PLGetString(val))) {
1381 for (v=values; v->string!=NULL; v++) {
1382 if (strcasecmp(v->string, str)==0)
1383 return v->value;
1387 buffer[0] = 0;
1388 for (v=values; v->string!=NULL; v++) {
1389 if (!v->is_alias) {
1390 if (buffer[0]!=0)
1391 strcat(buffer, ", ");
1392 strcat(buffer, v->string);
1395 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1396 PLGetString(key), buffer);
1398 if (def) {
1399 return string2index(key, val, NULL, values);
1402 return -1;
1409 * value - is the value in the defaults DB
1410 * addr - is the address to store the data
1411 * ret - is the address to store a pointer to a temporary buffer. ret
1412 * must not be freed and is used by the set functions
1414 static int
1415 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1416 void **ret)
1418 static char data;
1419 char *val;
1420 int second_pass=0;
1422 GET_STRING_OR_DEFAULT("Boolean", val);
1424 again:
1425 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1426 || strcasecmp(val, "YES")==0) {
1428 data = 1;
1429 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1430 || strcasecmp(val, "NO")==0) {
1431 data = 0;
1432 } else {
1433 int i;
1434 if (sscanf(val, "%i", &i)==1) {
1435 if (i!=0)
1436 data = 1;
1437 else
1438 data = 0;
1439 } else {
1440 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1441 val, entry->key);
1442 if (second_pass==0) {
1443 val = PLGetString(entry->plvalue);
1444 second_pass = 1;
1445 wwarning(_("using default \"%s\" instead"), val);
1446 goto again;
1448 return False;
1452 if (ret)
1453 *ret = &data;
1455 if (addr) {
1456 *(char*)addr = data;
1459 return True;
1463 static int
1464 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1465 void **ret)
1467 static int data;
1468 char *val;
1471 GET_STRING_OR_DEFAULT("Integer", val);
1473 if (sscanf(val, "%i", &data)!=1) {
1474 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1475 val, entry->key);
1476 val = PLGetString(entry->plvalue);
1477 wwarning(_("using default \"%s\" instead"), val);
1478 if (sscanf(val, "%i", &data)!=1) {
1479 return False;
1483 if (ret)
1484 *ret = &data;
1486 if (addr) {
1487 *(int*)addr = data;
1489 return True;
1493 static int
1494 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1495 void **ret)
1497 static WCoord data;
1498 char *val_x, *val_y;
1499 int nelem, changed=0;
1500 proplist_t elem_x, elem_y;
1502 again:
1503 if (!PLIsArray(value)) {
1504 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1505 entry->key, "Coordinate");
1506 if (changed==0) {
1507 value = entry->plvalue;
1508 changed = 1;
1509 wwarning(_("using default \"%s\" instead"), entry->default_value);
1510 goto again;
1512 return False;
1515 nelem = PLGetNumberOfElements(value);
1516 if (nelem != 2) {
1517 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1518 entry->key);
1519 if (changed==0) {
1520 value = entry->plvalue;
1521 changed = 1;
1522 wwarning(_("using default \"%s\" instead"), entry->default_value);
1523 goto again;
1525 return False;
1528 elem_x = PLGetArrayElement(value, 0);
1529 elem_y = PLGetArrayElement(value, 1);
1531 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1532 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1533 entry->key);
1534 if (changed==0) {
1535 value = entry->plvalue;
1536 changed = 1;
1537 wwarning(_("using default \"%s\" instead"), entry->default_value);
1538 goto again;
1540 return False;
1543 val_x = PLGetString(elem_x);
1544 val_y = PLGetString(elem_y);
1546 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1547 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1548 if (changed==0) {
1549 value = entry->plvalue;
1550 changed = 1;
1551 wwarning(_("using default \"%s\" instead"), entry->default_value);
1552 goto again;
1554 return False;
1557 if (data.x < 0)
1558 data.x = 0;
1559 else if (data.x > scr->scr_width/3)
1560 data.x = scr->scr_width/3;
1561 if (data.y < 0)
1562 data.y = 0;
1563 else if (data.y > scr->scr_height/3)
1564 data.y = scr->scr_height/3;
1566 if (ret)
1567 *ret = &data;
1569 if (addr) {
1570 *(WCoord*)addr = data;
1573 return True;
1577 #if 0
1578 /* This function is not used at the moment. */
1579 static int
1580 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1581 void **ret)
1583 static char *data;
1585 GET_STRING_OR_DEFAULT("String", data);
1587 if (!data) {
1588 data = PLGetString(entry->plvalue);
1589 if (!data)
1590 return False;
1593 if (ret)
1594 *ret = &data;
1596 if (addr)
1597 *(char**)addr = wstrdup(data);
1599 return True;
1601 #endif
1604 static int
1605 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1606 void **ret)
1608 static char *data;
1609 int i, count, len;
1610 char *ptr;
1611 proplist_t d;
1612 int changed=0;
1614 again:
1615 if (!PLIsArray(value)) {
1616 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1617 entry->key, "an array of paths");
1618 if (changed==0) {
1619 value = entry->plvalue;
1620 changed = 1;
1621 wwarning(_("using default \"%s\" instead"), entry->default_value);
1622 goto again;
1624 return False;
1627 i = 0;
1628 count = PLGetNumberOfElements(value);
1629 if (count < 1) {
1630 if (changed==0) {
1631 value = entry->plvalue;
1632 changed = 1;
1633 wwarning(_("using default \"%s\" instead"), entry->default_value);
1634 goto again;
1636 return False;
1639 len = 0;
1640 for (i=0; i<count; i++) {
1641 d = PLGetArrayElement(value, i);
1642 if (!d || !PLIsString(d)) {
1643 count = i;
1644 break;
1646 len += strlen(PLGetString(d))+1;
1649 ptr = data = wmalloc(len+1);
1651 for (i=0; i<count; i++) {
1652 d = PLGetArrayElement(value, i);
1653 if (!d || !PLIsString(d)) {
1654 break;
1656 strcpy(ptr, PLGetString(d));
1657 ptr += strlen(PLGetString(d));
1658 *ptr = ':';
1659 ptr++;
1661 ptr--; *(ptr--) = 0;
1663 if (*(char**)addr!=NULL) {
1664 wfree(*(char**)addr);
1666 *(char**)addr = data;
1668 return True;
1672 static int
1673 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1674 void **ret)
1676 static signed char data;
1678 data = string2index(entry->plkey, value, entry->default_value,
1679 (WOptionEnumeration*)entry->extra_data);
1680 if (data < 0)
1681 return False;
1683 if (ret)
1684 *ret = &data;
1686 if (addr)
1687 *(signed char*)addr = data;
1689 return True;
1695 * (solid <color>)
1696 * (hgradient <color> <color>)
1697 * (vgradient <color> <color>)
1698 * (dgradient <color> <color>)
1699 * (mhgradient <color> <color> ...)
1700 * (mvgradient <color> <color> ...)
1701 * (mdgradient <color> <color> ...)
1702 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1703 * (tpixmap <file> <color>)
1704 * (spixmap <file> <color>)
1705 * (cpixmap <file> <color>)
1706 * (thgradient <file> <opaqueness> <color> <color>)
1707 * (tvgradient <file> <opaqueness> <color> <color>)
1708 * (tdgradient <file> <opaqueness> <color> <color>)
1709 * (function <lib> <function> ...)
1712 static WTexture*
1713 parse_texture(WScreen *scr, proplist_t pl)
1715 proplist_t elem;
1716 char *val;
1717 int nelem;
1718 WTexture *texture=NULL;
1720 nelem = PLGetNumberOfElements(pl);
1721 if (nelem < 1)
1722 return NULL;
1725 elem = PLGetArrayElement(pl, 0);
1726 if (!elem || !PLIsString(elem))
1727 return NULL;
1728 val = PLGetString(elem);
1731 if (strcasecmp(val, "solid")==0) {
1732 XColor color;
1734 if (nelem != 2)
1735 return NULL;
1737 /* get color */
1739 elem = PLGetArrayElement(pl, 1);
1740 if (!elem || !PLIsString(elem))
1741 return NULL;
1742 val = PLGetString(elem);
1744 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1745 wwarning(_("\"%s\" is not a valid color name"), val);
1746 return NULL;
1749 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1750 } else if (strcasecmp(val, "dgradient")==0
1751 || strcasecmp(val, "vgradient")==0
1752 || strcasecmp(val, "hgradient")==0) {
1753 RColor color1, color2;
1754 XColor xcolor;
1755 int type;
1757 if (nelem != 3) {
1758 wwarning(_("bad number of arguments in gradient specification"));
1759 return NULL;
1762 if (val[0]=='d' || val[0]=='D')
1763 type = WTEX_DGRADIENT;
1764 else if (val[0]=='h' || val[0]=='H')
1765 type = WTEX_HGRADIENT;
1766 else
1767 type = WTEX_VGRADIENT;
1770 /* get from color */
1771 elem = PLGetArrayElement(pl, 1);
1772 if (!elem || !PLIsString(elem))
1773 return NULL;
1774 val = PLGetString(elem);
1776 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1777 wwarning(_("\"%s\" is not a valid color name"), val);
1778 return NULL;
1780 color1.alpha = 255;
1781 color1.red = xcolor.red >> 8;
1782 color1.green = xcolor.green >> 8;
1783 color1.blue = xcolor.blue >> 8;
1785 /* get to color */
1786 elem = PLGetArrayElement(pl, 2);
1787 if (!elem || !PLIsString(elem)) {
1788 return NULL;
1790 val = PLGetString(elem);
1792 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1793 wwarning(_("\"%s\" is not a valid color name"), val);
1794 return NULL;
1796 color2.alpha = 255;
1797 color2.red = xcolor.red >> 8;
1798 color2.green = xcolor.green >> 8;
1799 color2.blue = xcolor.blue >> 8;
1801 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1803 } else if (strcasecmp(val, "igradient")==0) {
1804 RColor colors1[2], colors2[2];
1805 int th1, th2;
1806 XColor xcolor;
1807 int i;
1809 if (nelem != 7) {
1810 wwarning(_("bad number of arguments in gradient specification"));
1811 return NULL;
1814 /* get from color */
1815 for (i = 0; i < 2; i++) {
1816 elem = PLGetArrayElement(pl, 1+i);
1817 if (!elem || !PLIsString(elem))
1818 return NULL;
1819 val = PLGetString(elem);
1821 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1822 wwarning(_("\"%s\" is not a valid color name"), val);
1823 return NULL;
1825 colors1[i].alpha = 255;
1826 colors1[i].red = xcolor.red >> 8;
1827 colors1[i].green = xcolor.green >> 8;
1828 colors1[i].blue = xcolor.blue >> 8;
1830 elem = PLGetArrayElement(pl, 3);
1831 if (!elem || !PLIsString(elem))
1832 return NULL;
1833 val = PLGetString(elem);
1834 th1 = atoi(val);
1837 /* get from color */
1838 for (i = 0; i < 2; i++) {
1839 elem = PLGetArrayElement(pl, 4+i);
1840 if (!elem || !PLIsString(elem))
1841 return NULL;
1842 val = PLGetString(elem);
1844 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1845 wwarning(_("\"%s\" is not a valid color name"), val);
1846 return NULL;
1848 colors2[i].alpha = 255;
1849 colors2[i].red = xcolor.red >> 8;
1850 colors2[i].green = xcolor.green >> 8;
1851 colors2[i].blue = xcolor.blue >> 8;
1853 elem = PLGetArrayElement(pl, 6);
1854 if (!elem || !PLIsString(elem))
1855 return NULL;
1856 val = PLGetString(elem);
1857 th2 = atoi(val);
1859 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1860 th2, colors2);
1862 } else if (strcasecmp(val, "mhgradient")==0
1863 || strcasecmp(val, "mvgradient")==0
1864 || strcasecmp(val, "mdgradient")==0) {
1865 XColor color;
1866 RColor **colors;
1867 int i, count;
1868 int type;
1870 if (nelem < 3) {
1871 wwarning(_("too few arguments in multicolor gradient specification"));
1872 return NULL;
1875 if (val[1]=='h' || val[1]=='H')
1876 type = WTEX_MHGRADIENT;
1877 else if (val[1]=='v' || val[1]=='V')
1878 type = WTEX_MVGRADIENT;
1879 else
1880 type = WTEX_MDGRADIENT;
1882 count = nelem-1;
1884 colors = wmalloc(sizeof(RColor*)*(count+1));
1886 for (i=0; i<count; i++) {
1887 elem = PLGetArrayElement(pl, i+1);
1888 if (!elem || !PLIsString(elem)) {
1889 for (--i; i>=0; --i) {
1890 wfree(colors[i]);
1892 wfree(colors);
1893 return NULL;
1895 val = PLGetString(elem);
1897 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1898 wwarning(_("\"%s\" is not a valid color name"), val);
1899 for (--i; i>=0; --i) {
1900 wfree(colors[i]);
1902 wfree(colors);
1903 return NULL;
1904 } else {
1905 colors[i] = wmalloc(sizeof(RColor));
1906 colors[i]->red = color.red >> 8;
1907 colors[i]->green = color.green >> 8;
1908 colors[i]->blue = color.blue >> 8;
1911 colors[i] = NULL;
1913 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1914 } else if (strcasecmp(val, "spixmap")==0 ||
1915 strcasecmp(val, "cpixmap")==0 ||
1916 strcasecmp(val, "tpixmap")==0) {
1917 XColor color;
1918 int type;
1920 if (nelem != 3)
1921 return NULL;
1923 if (val[0] == 's' || val[0] == 'S')
1924 type = WTP_SCALE;
1925 else if (val[0] == 'c' || val[0] == 'C')
1926 type = WTP_CENTER;
1927 else
1928 type = WTP_TILE;
1930 /* get color */
1931 elem = PLGetArrayElement(pl, 2);
1932 if (!elem || !PLIsString(elem)) {
1933 return NULL;
1935 val = PLGetString(elem);
1937 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1938 wwarning(_("\"%s\" is not a valid color name"), val);
1939 return NULL;
1942 /* file name */
1943 elem = PLGetArrayElement(pl, 1);
1944 if (!elem || !PLIsString(elem))
1945 return NULL;
1946 val = PLGetString(elem);
1948 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1949 } else if (strcasecmp(val, "thgradient")==0
1950 || strcasecmp(val, "tvgradient")==0
1951 || strcasecmp(val, "tdgradient")==0) {
1952 RColor color1, color2;
1953 XColor xcolor;
1954 int opacity;
1955 int style;
1957 if (val[1]=='h' || val[1]=='H')
1958 style = WTEX_THGRADIENT;
1959 else if (val[1]=='v' || val[1]=='V')
1960 style = WTEX_TVGRADIENT;
1961 else
1962 style = WTEX_TDGRADIENT;
1964 if (nelem != 5) {
1965 wwarning(_("bad number of arguments in textured gradient specification"));
1966 return NULL;
1969 /* get from color */
1970 elem = PLGetArrayElement(pl, 3);
1971 if (!elem || !PLIsString(elem))
1972 return NULL;
1973 val = PLGetString(elem);
1975 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1976 wwarning(_("\"%s\" is not a valid color name"), val);
1977 return NULL;
1979 color1.alpha = 255;
1980 color1.red = xcolor.red >> 8;
1981 color1.green = xcolor.green >> 8;
1982 color1.blue = xcolor.blue >> 8;
1984 /* get to color */
1985 elem = PLGetArrayElement(pl, 4);
1986 if (!elem || !PLIsString(elem)) {
1987 return NULL;
1989 val = PLGetString(elem);
1991 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1992 wwarning(_("\"%s\" is not a valid color name"), val);
1993 return NULL;
1995 color2.alpha = 255;
1996 color2.red = xcolor.red >> 8;
1997 color2.green = xcolor.green >> 8;
1998 color2.blue = xcolor.blue >> 8;
2000 /* get opacity */
2001 elem = PLGetArrayElement(pl, 2);
2002 if (!elem || !PLIsString(elem))
2003 opacity = 128;
2004 else
2005 val = PLGetString(elem);
2007 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2008 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2009 opacity = 128;
2012 /* get file name */
2013 elem = PLGetArrayElement(pl, 1);
2014 if (!elem || !PLIsString(elem))
2015 return NULL;
2016 val = PLGetString(elem);
2018 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2019 val, opacity);
2021 #ifdef TEXTURE_PLUGIN
2022 else if (strcasecmp(val, "function")==0) {
2023 WTexFunction *function;
2024 void (*initFunc) (Display *, Colormap);
2025 char *lib, *func, **argv;
2026 int i, argc;
2028 if (nelem < 3)
2029 return NULL;
2031 /* get the library name */
2032 elem = PLGetArrayElement(pl, 1);
2033 if (!elem || !PLIsString(elem)) {
2034 return NULL;
2036 lib = PLGetString(elem);
2038 /* get the function name */
2039 elem = PLGetArrayElement(pl, 2);
2040 if (!elem || !PLIsString(elem)) {
2041 return NULL;
2043 func = PLGetString(elem);
2045 argc = nelem - 2;
2046 argv = (char **)wmalloc(argc * sizeof(char *));
2048 /* get the parameters */
2049 argv[0] = wstrdup(func);
2050 for (i = 0; i < argc - 1; i++) {
2051 elem = PLGetArrayElement(pl, 3 + i);
2052 if (!elem || !PLIsString(elem)) {
2053 wfree(argv);
2055 return NULL;
2057 argv[i+1] = wstrdup(PLGetString(elem));
2060 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2062 #ifdef HAVE_DLFCN_H
2063 if (function) {
2064 initFunc = dlsym(function->handle, "initWindowMaker");
2065 if (initFunc) {
2066 initFunc(dpy, scr->w_colormap);
2067 } else {
2068 wwarning(_("could not initialize library %s"), lib);
2070 } else {
2071 wwarning(_("could not find function %s::%s"), lib, func);
2073 #endif /* HAVE_DLFCN_H */
2074 texture = (WTexture*)function;
2076 #endif /* TEXTURE_PLUGIN */
2077 else {
2078 wwarning(_("invalid texture type %s"), val);
2079 return NULL;
2081 return texture;
2086 static int
2087 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2088 void **ret)
2090 static WTexture *texture;
2091 int changed=0;
2093 again:
2094 if (!PLIsArray(value)) {
2095 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2096 entry->key, "Texture");
2097 if (changed==0) {
2098 value = entry->plvalue;
2099 changed = 1;
2100 wwarning(_("using default \"%s\" instead"), entry->default_value);
2101 goto again;
2103 return False;
2106 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2107 proplist_t pl;
2109 pl = PLGetArrayElement(value, 0);
2110 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2111 || strcasecmp(PLGetString(pl), "solid")!=0) {
2112 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2113 entry->key, "Solid Texture");
2115 value = entry->plvalue;
2116 changed = 1;
2117 wwarning(_("using default \"%s\" instead"), entry->default_value);
2118 goto again;
2122 texture = parse_texture(scr, value);
2124 if (!texture) {
2125 wwarning(_("Error in texture specification for key \"%s\""),
2126 entry->key);
2127 if (changed==0) {
2128 value = entry->plvalue;
2129 changed = 1;
2130 wwarning(_("using default \"%s\" instead"), entry->default_value);
2131 goto again;
2133 return False;
2136 if (ret)
2137 *ret = &texture;
2139 if (addr)
2140 *(WTexture**)addr = texture;
2142 return True;
2146 static int
2147 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2148 void *addr, void **ret)
2150 proplist_t elem;
2151 int changed = 0;
2152 char *val;
2153 int nelem;
2155 again:
2156 if (!PLIsArray(value)) {
2157 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2158 "WorkspaceBack", "Texture or None");
2159 if (changed==0) {
2160 value = entry->plvalue;
2161 changed = 1;
2162 wwarning(_("using default \"%s\" instead"), entry->default_value);
2163 goto again;
2165 return False;
2168 /* only do basic error checking and verify for None texture */
2170 nelem = PLGetNumberOfElements(value);
2171 if (nelem > 0) {
2172 elem = PLGetArrayElement(value, 0);
2173 if (!elem || !PLIsString(elem)) {
2174 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2175 if (changed==0) {
2176 value = entry->plvalue;
2177 changed = 1;
2178 wwarning(_("using default \"%s\" instead"), entry->default_value);
2179 goto again;
2181 return False;
2183 val = PLGetString(elem);
2185 if (strcasecmp(val, "None")==0)
2186 return True;
2188 *ret = PLRetain(value);
2190 return True;
2194 static int
2195 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2196 void *addr, void **ret)
2198 proplist_t elem;
2199 int nelem;
2200 int changed = 0;
2202 again:
2203 if (!PLIsArray(value)) {
2204 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2205 "WorkspaceSpecificBack", "an array of textures");
2206 if (changed==0) {
2207 value = entry->plvalue;
2208 changed = 1;
2209 wwarning(_("using default \"%s\" instead"), entry->default_value);
2210 goto again;
2212 return False;
2215 /* only do basic error checking and verify for None texture */
2217 nelem = PLGetNumberOfElements(value);
2218 if (nelem > 0) {
2219 while (nelem--) {
2220 elem = PLGetArrayElement(value, nelem);
2221 if (!elem || !PLIsArray(elem)) {
2222 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2223 nelem);
2228 *ret = PLRetain(value);
2230 #ifdef notworking
2232 * Kluge to force wmsetbg helper to set the default background.
2233 * If the WorkspaceSpecificBack is changed once wmaker has started,
2234 * the WorkspaceBack won't be sent to the helper, unless the user
2235 * changes it's value too. So, we must force this by removing the
2236 * value from the defaults DB.
2238 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2239 proplist_t key = PLMakeString("WorkspaceBack");
2241 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2243 PLRelease(key);
2245 #endif
2246 return True;
2250 static int
2251 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2252 void **ret)
2254 static WMFont *font;
2255 char *val;
2257 GET_STRING_OR_DEFAULT("Font", val);
2259 font = WMCreateFont(scr->wmscreen, val);
2260 if (!font)
2261 font = WMCreateFont(scr->wmscreen, "fixed");
2263 if (!font) {
2264 wfatal(_("could not load any usable font!!!"));
2265 exit(1);
2268 if (ret)
2269 *ret = font;
2271 /* can't assign font value outside update function */
2272 wassertrv(addr == NULL, True);
2274 return True;
2278 static int
2279 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2280 void **ret)
2282 static XColor color;
2283 char *val;
2284 int second_pass=0;
2286 GET_STRING_OR_DEFAULT("Color", val);
2289 again:
2290 if (!wGetColor(scr, val, &color)) {
2291 wwarning(_("could not get color for key \"%s\""),
2292 entry->key);
2293 if (second_pass==0) {
2294 val = PLGetString(entry->plvalue);
2295 second_pass = 1;
2296 wwarning(_("using default \"%s\" instead"), val);
2297 goto again;
2299 return False;
2302 if (ret)
2303 *ret = &color;
2305 assert(addr==NULL);
2307 if (addr)
2308 *(unsigned long*)addr = pixel;
2311 return True;
2316 static int
2317 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2318 void **ret)
2320 static WShortKey shortcut;
2321 KeySym ksym;
2322 char *val;
2323 char *k;
2324 char buf[128], *b;
2327 GET_STRING_OR_DEFAULT("Key spec", val);
2329 if (!val || strcasecmp(val, "NONE")==0) {
2330 shortcut.keycode = 0;
2331 shortcut.modifier = 0;
2332 if (ret)
2333 *ret = &shortcut;
2334 return True;
2337 strcpy(buf, val);
2339 b = (char*)buf;
2341 /* get modifiers */
2342 shortcut.modifier = 0;
2343 while ((k = strchr(b, '+'))!=NULL) {
2344 int mod;
2346 *k = 0;
2347 mod = wXModifierFromKey(b);
2348 if (mod<0) {
2349 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2350 return False;
2352 shortcut.modifier |= mod;
2354 b = k+1;
2357 /* get key */
2358 ksym = XStringToKeysym(b);
2360 if (ksym==NoSymbol) {
2361 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2362 val);
2363 return False;
2366 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2367 if (shortcut.keycode==0) {
2368 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2369 return False;
2372 if (ret)
2373 *ret = &shortcut;
2375 return True;
2379 static int
2380 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2381 void **ret)
2383 static unsigned int mask;
2384 char *str;
2386 GET_STRING_OR_DEFAULT("Modifier Key", str);
2388 if (!str)
2389 return False;
2391 mask = wXModifierFromKey(str);
2392 if (mask < 0) {
2393 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2394 mask = 0;
2395 return False;
2398 if (addr)
2399 *(unsigned int*)addr = mask;
2401 if (ret)
2402 *ret = &mask;
2404 return True;
2408 #ifdef NEWSTUFF
2409 static int
2410 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2411 void *addr, void **ret)
2413 unsigned int mask;
2414 char *str;
2415 RImage *image;
2416 int i, n;
2417 int w, h;
2419 GET_STRING_OR_DEFAULT("Image File Path", str);
2420 if (!str)
2421 return False;
2423 image = RLoadImage(scr->rcontext, str, 0);
2424 if (!image) {
2425 wwarning(_("could not load image in option %s: %s"), entry->key,
2426 RMessageForError(RErrorCode));
2427 return False;
2430 if (*(RImage**)addr) {
2431 RDestroyImage(*(RImage**)addr);
2433 if (addr)
2434 *(RImage**)addr = image;
2436 assert(ret == NULL);
2438 if (ret)
2439 *(RImage**)ret = image;
2442 return True;
2444 #endif
2446 #ifdef DEFINABLE_CURSOR
2448 # include <X11/cursorfont.h>
2449 typedef struct
2451 char *name;
2452 int id;
2453 } WCursorLookup;
2455 #define CURSOR_ID_NONE (XC_num_glyphs)
2457 static WCursorLookup cursor_table[] =
2459 { "X_cursor", XC_X_cursor },
2460 { "arrow", XC_arrow },
2461 { "based_arrow_down", XC_based_arrow_down },
2462 { "based_arrow_up", XC_based_arrow_up },
2463 { "boat", XC_boat },
2464 { "bogosity", XC_bogosity },
2465 { "bottom_left_corner", XC_bottom_left_corner },
2466 { "bottom_right_corner", XC_bottom_right_corner },
2467 { "bottom_side", XC_bottom_side },
2468 { "bottom_tee", XC_bottom_tee },
2469 { "box_spiral", XC_box_spiral },
2470 { "center_ptr", XC_center_ptr },
2471 { "circle", XC_circle },
2472 { "clock", XC_clock },
2473 { "coffee_mug", XC_coffee_mug },
2474 { "cross", XC_cross },
2475 { "cross_reverse", XC_cross_reverse },
2476 { "crosshair", XC_crosshair },
2477 { "diamond_cross", XC_diamond_cross },
2478 { "dot", XC_dot },
2479 { "dotbox", XC_dotbox },
2480 { "double_arrow", XC_double_arrow },
2481 { "draft_large", XC_draft_large },
2482 { "draft_small", XC_draft_small },
2483 { "draped_box", XC_draped_box },
2484 { "exchange", XC_exchange },
2485 { "fleur", XC_fleur },
2486 { "gobbler", XC_gobbler },
2487 { "gumby", XC_gumby },
2488 { "hand1", XC_hand1 },
2489 { "hand2", XC_hand2 },
2490 { "heart", XC_heart },
2491 { "icon", XC_icon },
2492 { "iron_cross", XC_iron_cross },
2493 { "left_ptr", XC_left_ptr },
2494 { "left_side", XC_left_side },
2495 { "left_tee", XC_left_tee },
2496 { "leftbutton", XC_leftbutton },
2497 { "ll_angle", XC_ll_angle },
2498 { "lr_angle", XC_lr_angle },
2499 { "man", XC_man },
2500 { "middlebutton", XC_middlebutton },
2501 { "mouse", XC_mouse },
2502 { "pencil", XC_pencil },
2503 { "pirate", XC_pirate },
2504 { "plus", XC_plus },
2505 { "question_arrow", XC_question_arrow },
2506 { "right_ptr", XC_right_ptr },
2507 { "right_side", XC_right_side },
2508 { "right_tee", XC_right_tee },
2509 { "rightbutton", XC_rightbutton },
2510 { "rtl_logo", XC_rtl_logo },
2511 { "sailboat", XC_sailboat },
2512 { "sb_down_arrow", XC_sb_down_arrow },
2513 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2514 { "sb_left_arrow", XC_sb_left_arrow },
2515 { "sb_right_arrow", XC_sb_right_arrow },
2516 { "sb_up_arrow", XC_sb_up_arrow },
2517 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2518 { "shuttle", XC_shuttle },
2519 { "sizing", XC_sizing },
2520 { "spider", XC_spider },
2521 { "spraycan", XC_spraycan },
2522 { "star", XC_star },
2523 { "target", XC_target },
2524 { "tcross", XC_tcross },
2525 { "top_left_arrow", XC_top_left_arrow },
2526 { "top_left_corner", XC_top_left_corner },
2527 { "top_right_corner", XC_top_right_corner },
2528 { "top_side", XC_top_side },
2529 { "top_tee", XC_top_tee },
2530 { "trek", XC_trek },
2531 { "ul_angle", XC_ul_angle },
2532 { "umbrella", XC_umbrella },
2533 { "ur_angle", XC_ur_angle },
2534 { "watch", XC_watch },
2535 { "xterm", XC_xterm },
2536 { NULL, CURSOR_ID_NONE }
2539 static void
2540 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2542 switch(status) {
2543 case BitmapOpenFailed:
2544 wwarning(_("failed to open bitmap file \"%s\""), filename);
2545 break;
2546 case BitmapFileInvalid:
2547 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2548 break;
2549 case BitmapNoMemory:
2550 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2551 break;
2552 case BitmapSuccess:
2553 XFreePixmap(dpy, bitmap);
2554 break;
2559 * (none)
2560 * (builtin, <cursor_name>)
2561 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2563 static int
2564 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2566 proplist_t elem;
2567 char *val;
2568 int nelem;
2569 int status = 0;
2571 nelem = PLGetNumberOfElements(pl);
2572 if (nelem < 1) {
2573 return(status);
2575 elem = PLGetArrayElement(pl, 0);
2576 if (!elem || !PLIsString(elem)) {
2577 return(status);
2579 val = PLGetString(elem);
2581 if (0 == strcasecmp(val, "none")) {
2582 status = 1;
2583 *cursor = None;
2584 } else if (0 == strcasecmp(val, "builtin")) {
2585 int i;
2586 int cursor_id = CURSOR_ID_NONE;
2588 if (2 != nelem) {
2589 wwarning(_("bad number of arguments in cursor specification"));
2590 return(status);
2592 elem = PLGetArrayElement(pl, 1);
2593 if (!elem || !PLIsString(elem)) {
2594 return(status);
2596 val = PLGetString(elem);
2598 for (i = 0; NULL != cursor_table[i].name; i++) {
2599 if (0 == strcasecmp(val, cursor_table[i].name)) {
2600 cursor_id = cursor_table[i].id;
2601 break;
2604 if (CURSOR_ID_NONE == cursor_id) {
2605 wwarning(_("unknown builtin cursor name \"%s\""), val);
2606 } else {
2607 *cursor = XCreateFontCursor(dpy, cursor_id);
2608 status = 1;
2610 } else if (0 == strcasecmp(val, "bitmap")) {
2611 char *bitmap_name;
2612 char *mask_name;
2613 int bitmap_status;
2614 int mask_status;
2615 Pixmap bitmap;
2616 Pixmap mask;
2617 unsigned int w, h;
2618 int x, y;
2619 XColor fg, bg;
2621 if (3 != nelem) {
2622 wwarning(_("bad number of arguments in cursor specification"));
2623 return(status);
2625 elem = PLGetArrayElement(pl, 1);
2626 if (!elem || !PLIsString(elem)) {
2627 return(status);
2629 val = PLGetString(elem);
2630 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2631 if (!bitmap_name) {
2632 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2633 return(status);
2635 elem = PLGetArrayElement(pl, 2);
2636 if (!elem || !PLIsString(elem)) {
2637 wfree(bitmap_name);
2638 return(status);
2640 val = PLGetString(elem);
2641 mask_name = FindImage(wPreferences.pixmap_path, val);
2642 if (!mask_name) {
2643 wfree(bitmap_name);
2644 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2645 return(status);
2647 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2648 &mask, &x, &y);
2649 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2650 &bitmap, &x, &y);
2651 if ((BitmapSuccess == bitmap_status) &&
2652 (BitmapSuccess == mask_status)) {
2653 fg.pixel = scr->black_pixel;
2654 bg.pixel = scr->white_pixel;
2655 XQueryColor(dpy, scr->w_colormap, &fg);
2656 XQueryColor(dpy, scr->w_colormap, &bg);
2657 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2658 status = 1;
2660 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2661 check_bitmap_status(mask_status, mask_name, mask);
2662 wfree(bitmap_name);
2663 wfree(mask_name);
2665 return(status);
2669 static int
2670 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2671 void **ret)
2673 static Cursor cursor;
2674 int status;
2675 int changed = 0;
2677 again:
2678 if (!PLIsArray(value)) {
2679 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2680 entry->key, "cursor specification");
2681 if (!changed) {
2682 value = entry->plvalue;
2683 changed = 1;
2684 wwarning(_("using default \"%s\" instead"), entry->default_value);
2685 goto again;
2687 return(False);
2689 status = parse_cursor(scr, value, &cursor);
2690 if (!status) {
2691 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2692 if (!changed) {
2693 value = entry->plvalue;
2694 changed = 1;
2695 wwarning(_("using default \"%s\" instead"), entry->default_value);
2696 goto again;
2698 return(False);
2700 if (ret) {
2701 *ret = &cursor;
2703 if (addr) {
2704 *(Cursor *)addr = cursor;
2706 return(True);
2708 #undef CURSOR_ID_NONE
2710 #endif /* DEFINABLE_CURSOR */
2713 /* ---------------- value setting functions --------------- */
2714 static int
2715 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2717 return REFRESH_WINDOW_TITLE_COLOR;
2720 static int
2721 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2723 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2726 static int
2727 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2729 switch (which) {
2730 case WM_DOCK:
2731 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2732 break;
2733 case WM_CLIP:
2734 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2735 break;
2736 default:
2737 break;
2739 return 0;
2743 static int
2744 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2746 if (scr->workspaces) {
2747 wWorkspaceForceChange(scr, scr->current_workspace);
2748 wArrangeIcons(scr, False);
2750 return 0;
2753 #if not_used
2754 static int
2755 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2757 if (*value <= 0)
2758 *(int*)foo = 1;
2760 return 0;
2762 #endif
2766 static int
2767 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2769 Pixmap pixmap;
2770 RImage *img;
2771 int reset = 0;
2773 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2774 wPreferences.icon_size,
2775 ((*texture)->any.type & WREL_BORDER_MASK)
2776 ? WREL_ICON : WREL_FLAT);
2777 if (!img) {
2778 wwarning(_("could not render texture for icon background"));
2779 if (!entry->addr)
2780 wTextureDestroy(scr, *texture);
2781 return 0;
2783 RConvertImage(scr->rcontext, img, &pixmap);
2785 if (scr->icon_tile) {
2786 reset = 1;
2787 RDestroyImage(scr->icon_tile);
2788 XFreePixmap(dpy, scr->icon_tile_pixmap);
2791 scr->icon_tile = img;
2794 /* put the icon in the noticeboard hint */
2795 PropSetIconTileHint(scr, img);
2798 if (!wPreferences.flags.noclip) {
2799 if (scr->clip_tile) {
2800 RDestroyImage(scr->clip_tile);
2802 scr->clip_tile = wClipMakeTile(scr, img);
2805 scr->icon_tile_pixmap = pixmap;
2807 if (scr->def_icon_pixmap) {
2808 XFreePixmap(dpy, scr->def_icon_pixmap);
2809 scr->def_icon_pixmap = None;
2811 if (scr->def_ticon_pixmap) {
2812 XFreePixmap(dpy, scr->def_ticon_pixmap);
2813 scr->def_ticon_pixmap = None;
2816 if (scr->icon_back_texture) {
2817 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2819 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2821 if (scr->clip_balloon)
2822 XSetWindowBackground(dpy, scr->clip_balloon,
2823 (*texture)->any.color.pixel);
2826 * Free the texture as nobody else will use it, nor refer to it.
2828 if (!entry->addr)
2829 wTextureDestroy(scr, *texture);
2831 return (reset ? REFRESH_ICON_TILE : 0);
2836 static int
2837 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2839 if (scr->title_font) {
2840 WMReleaseFont(scr->title_font);
2842 scr->title_font = font;
2844 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2848 static int
2849 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2851 if (scr->menu_title_font) {
2852 WMReleaseFont(scr->menu_title_font);
2855 scr->menu_title_font = font;
2857 return REFRESH_MENU_TITLE_FONT;
2861 static int
2862 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2864 if (scr->menu_entry_font) {
2865 WMReleaseFont(scr->menu_entry_font);
2867 scr->menu_entry_font = font;
2869 return REFRESH_MENU_FONT;
2874 static int
2875 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2877 if (scr->icon_title_font) {
2878 WMReleaseFont(scr->icon_title_font);
2881 scr->icon_title_font = font;
2883 return REFRESH_ICON_FONT;
2887 static int
2888 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2890 if (scr->clip_title_font) {
2891 WMReleaseFont(scr->clip_title_font);
2894 scr->clip_title_font = font;
2896 return REFRESH_ICON_FONT;
2900 static int
2901 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2903 if (scr->workspace_name_font) {
2904 WMReleaseFont(scr->workspace_name_font);
2907 scr->workspace_name_font = font;
2909 return 0;
2913 static int
2914 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2916 if (scr->select_pixel!=scr->white_pixel &&
2917 scr->select_pixel!=scr->black_pixel) {
2918 wFreeColor(scr, scr->select_pixel);
2921 scr->select_pixel = color->pixel;
2923 return REFRESH_MENU_COLOR;
2927 static int
2928 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2930 if (scr->select_text_pixel!=scr->white_pixel &&
2931 scr->select_text_pixel!=scr->black_pixel) {
2932 wFreeColor(scr, scr->select_text_pixel);
2935 scr->select_text_pixel = color->pixel;
2937 return REFRESH_MENU_COLOR;
2941 static int
2942 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2944 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2945 scr->clip_title_pixel[index]!=scr->black_pixel) {
2946 wFreeColor(scr, scr->clip_title_pixel[index]);
2948 scr->clip_title_pixel[index] = color->pixel;
2950 #ifdef GRADIENT_CLIP_ARROW
2951 if (index == CLIP_NORMAL) {
2952 RImage *image;
2953 RColor color1, color2;
2954 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2955 int as = pt - 15; /* 15 = 5+5+5 */
2957 FREE_PIXMAP(scr->clip_arrow_gradient);
2959 color1.red = (color->red >> 8)*6/10;
2960 color1.green = (color->green >> 8)*6/10;
2961 color1.blue = (color->blue >> 8)*6/10;
2963 color2.red = WMIN((color->red >> 8)*20/10, 255);
2964 color2.green = WMIN((color->green >> 8)*20/10, 255);
2965 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2967 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2968 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2969 RDestroyImage(image);
2971 #endif /* GRADIENT_CLIP_ARROW */
2973 return REFRESH_ICON_TITLE_COLOR;
2977 static int
2978 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2980 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2981 scr->window_title_pixel[index]!=scr->black_pixel) {
2982 wFreeColor(scr, scr->window_title_pixel[index]);
2985 scr->window_title_pixel[index] = color->pixel;
2987 if (index == WS_UNFOCUSED)
2988 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2990 return REFRESH_WINDOW_TITLE_COLOR;
2994 static int
2995 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2997 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2998 scr->menu_title_pixel[0]!=scr->black_pixel) {
2999 wFreeColor(scr, scr->menu_title_pixel[0]);
3002 scr->menu_title_pixel[0] = color->pixel;
3003 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3005 return REFRESH_MENU_TITLE_COLOR;
3009 static int
3010 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3012 XGCValues gcv;
3013 #define gcm (GCForeground|GCBackground|GCFillStyle)
3015 if (scr->mtext_pixel!=scr->white_pixel &&
3016 scr->mtext_pixel!=scr->black_pixel) {
3017 wFreeColor(scr, scr->mtext_pixel);
3020 scr->mtext_pixel = color->pixel;
3022 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3025 if (scr->dtext_pixel == scr->mtext_pixel) {
3026 gcv.foreground = scr->white_pixel;
3027 gcv.background = scr->black_pixel;
3028 gcv.fill_style = FillStippled;
3029 } else {
3030 gcv.foreground = scr->dtext_pixel;
3031 gcv.fill_style = FillSolid;
3033 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3035 return REFRESH_MENU_COLOR;
3036 #undef gcm
3040 static int
3041 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3043 XGCValues gcv;
3044 #define gcm (GCForeground|GCBackground|GCFillStyle)
3046 if (scr->dtext_pixel!=scr->white_pixel &&
3047 scr->dtext_pixel!=scr->black_pixel) {
3048 wFreeColor(scr, scr->dtext_pixel);
3051 scr->dtext_pixel = color->pixel;
3053 if (scr->dtext_pixel == scr->mtext_pixel) {
3054 gcv.foreground = scr->white_pixel;
3055 gcv.background = scr->black_pixel;
3056 gcv.fill_style = FillStippled;
3057 } else {
3058 gcv.foreground = scr->dtext_pixel;
3059 gcv.fill_style = FillSolid;
3061 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3063 return REFRESH_MENU_COLOR;
3064 #undef gcm
3067 static int
3068 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3070 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3072 return REFRESH_ICON_TITLE_COLOR;
3076 static int
3077 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3079 if (scr->icon_title_texture) {
3080 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3082 XQueryColor (dpy, scr->w_colormap, color);
3083 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3085 return REFRESH_ICON_TITLE_BACK;
3089 static void
3090 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3092 close(scr->helper_fd);
3093 scr->helper_fd = 0;
3094 scr->helper_pid = 0;
3095 scr->flags.backimage_helper_launched = 0;
3099 static int
3100 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3101 void *bar)
3103 int i;
3104 proplist_t val;
3105 char *str;
3107 if (scr->flags.backimage_helper_launched) {
3108 if (PLGetNumberOfElements(value)==0) {
3109 SendHelperMessage(scr, 'C', 0, NULL);
3110 SendHelperMessage(scr, 'K', 0, NULL);
3112 PLRelease(value);
3113 return 0;
3115 } else {
3116 pid_t pid;
3117 int filedes[2];
3119 if (PLGetNumberOfElements(value) == 0)
3120 return 0;
3122 if (pipe(filedes) < 0) {
3123 wsyserror("pipe() failed:can't set workspace specific background image");
3125 PLRelease(value);
3126 return 0;
3129 pid = fork();
3130 if (pid < 0) {
3131 wsyserror("fork() failed:can't set workspace specific background image");
3132 if (close(filedes[0]) < 0)
3133 wsyserror("could not close pipe");
3134 if (close(filedes[1]) < 0)
3135 wsyserror("could not close pipe");
3137 } else if (pid == 0) {
3138 SetupEnvironment(scr);
3140 if (close(0) < 0)
3141 wsyserror("could not close pipe");
3142 if (dup(filedes[0]) < 0) {
3143 wsyserror("dup() failed:can't set workspace specific background image");
3145 if (wPreferences.smooth_workspace_back)
3146 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3147 else
3148 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3149 wsyserror("could not execute wmsetbg");
3150 exit(1);
3151 } else {
3153 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3154 wsyserror("error setting close-on-exec flag");
3156 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3157 wsyserror("error setting close-on-exec flag");
3160 scr->helper_fd = filedes[1];
3161 scr->helper_pid = pid;
3162 scr->flags.backimage_helper_launched = 1;
3164 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3166 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3171 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3172 val = PLGetArrayElement(value, i);
3173 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3174 str = PLGetDescription(val);
3176 SendHelperMessage(scr, 'S', i+1, str);
3178 wfree(str);
3179 } else {
3180 SendHelperMessage(scr, 'U', i+1, NULL);
3183 sleep(1);
3185 PLRelease(value);
3186 return 0;
3190 static int
3191 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3192 void *bar)
3194 if (scr->flags.backimage_helper_launched) {
3195 char *str;
3197 if (PLGetNumberOfElements(value)==0) {
3198 SendHelperMessage(scr, 'U', 0, NULL);
3199 } else {
3200 /* set the default workspace background to this one */
3201 str = PLGetDescription(value);
3202 if (str) {
3203 SendHelperMessage(scr, 'S', 0, str);
3204 wfree(str);
3205 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3206 } else {
3207 SendHelperMessage(scr, 'U', 0, NULL);
3210 } else if (PLGetNumberOfElements(value) > 0) {
3211 char *command;
3212 char *text;
3214 SetupEnvironment(scr);
3215 text = PLGetDescription(value);
3216 command = wmalloc(strlen(text)+40);
3217 if (wPreferences.smooth_workspace_back)
3218 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3219 else
3220 sprintf(command, "wmsetbg -d -p '%s' &", text);
3221 wfree(text);
3222 system(command);
3223 wfree(command);
3225 PLRelease(value);
3227 return 0;
3231 static int
3232 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3234 if (scr->widget_texture) {
3235 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3237 scr->widget_texture = *(WTexSolid**)texture;
3239 return 0;
3243 static int
3244 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3246 if (scr->window_title_texture[WS_FOCUSED]) {
3247 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3249 scr->window_title_texture[WS_FOCUSED] = *texture;
3251 return REFRESH_WINDOW_TEXTURES;
3255 static int
3256 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3258 if (scr->window_title_texture[WS_PFOCUSED]) {
3259 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3261 scr->window_title_texture[WS_PFOCUSED] = *texture;
3263 return REFRESH_WINDOW_TEXTURES;
3267 static int
3268 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3270 if (scr->window_title_texture[WS_UNFOCUSED]) {
3271 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3273 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3275 return REFRESH_WINDOW_TEXTURES;
3279 static int
3280 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3282 if (scr->resizebar_texture[0]) {
3283 wTextureDestroy(scr, scr->resizebar_texture[0]);
3285 scr->resizebar_texture[0] = *texture;
3287 return REFRESH_WINDOW_TEXTURES;
3291 static int
3292 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3294 if (scr->menu_title_texture[0]) {
3295 wTextureDestroy(scr, scr->menu_title_texture[0]);
3297 scr->menu_title_texture[0] = *texture;
3299 return REFRESH_MENU_TITLE_TEXTURE;
3303 static int
3304 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3306 if (scr->menu_item_texture) {
3307 wTextureDestroy(scr, scr->menu_item_texture);
3308 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3310 scr->menu_item_texture = *texture;
3312 scr->menu_item_auxtexture
3313 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3315 return REFRESH_MENU_TEXTURE;
3319 static int
3320 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3322 WWindow *wwin;
3323 wKeyBindings[index] = *shortcut;
3325 wwin = scr->focused_window;
3327 while (wwin!=NULL) {
3328 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3330 if (!WFLAGP(wwin, no_bind_keys)) {
3331 wWindowSetKeyGrabs(wwin);
3333 wwin = wwin->prev;
3336 return 0;
3340 static int
3341 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3343 wArrangeIcons(scr, True);
3345 return 0;
3349 static int
3350 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3352 wScreenUpdateUsableArea(scr);
3354 return 0;
3358 static int
3359 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3361 return REFRESH_MENU_TEXTURE;
3366 static int
3367 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3369 return REFRESH_BUTTON_IMAGES;
3374 * Very ugly kluge.
3375 * Need access to the double click variables, so that all widgets in
3376 * wmaker panels will have the same dbl-click values.
3377 * TODO: figure a better way of dealing with it.
3379 #include <WINGs/WINGsP.h>
3381 static int
3382 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3384 extern _WINGsConfiguration WINGsConfiguration;
3386 if (*value <= 0)
3387 *(int*)foo = 1;
3389 WINGsConfiguration.doubleClickDelay = *value;
3391 return 0;
3395 #if 0
3396 static int
3397 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3399 extern _WINGsConfiguration WINGsConfiguration;
3401 WINGsConfiguration.useMultiByte = *value;
3403 return 0;
3405 #endif
3407 #ifdef DEFINABLE_CURSOR
3408 static int
3409 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3411 if (None != wCursor[index])
3413 XFreeCursor(dpy, wCursor[index]);
3416 wCursor[index] = *cursor;
3418 if ((WCUR_ROOT == index) && (None != *cursor))
3420 XDefineCursor(dpy, scr->root_win, *cursor);
3423 return 0;
3425 #endif /* DEFINABLE_CURSOR*/