allow to scroll the virtual desktop further than the desktop geometry.
[wmaker-crm.git] / src / defaults.c
blobbdfec8584af3dc9d7042befae296c8702dcdc329
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 {"VirtualEdgeExtendSpace", "0", NULL,
445 &wPreferences.vedge_bordersize, getInt, NULL
447 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
448 &wPreferences.vedge_hscrollspeed, getInt, NULL
450 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
451 &wPreferences.vedge_vscrollspeed, getInt, NULL
453 {"VirtualEdgeMaximumWidth", "3000", NULL,
454 &wPreferences.vedge_maxwidth, getInt, NULL
456 {"VirtualEdgeMaximumHeight", "3000", NULL,
457 &wPreferences.vedge_maxheight, getInt, NULL
459 #endif
460 {"StickyIcons", "NO", NULL,
461 &wPreferences.sticky_icons, getBool, setStickyIcons
463 {"SaveSessionOnExit", "NO", NULL,
464 &wPreferences.save_session_on_exit, getBool, NULL
466 {"WrapMenus", "NO", NULL,
467 &wPreferences.wrap_menus, getBool, NULL
469 {"ScrollableMenus", "NO", NULL,
470 &wPreferences.scrollable_menus, getBool, NULL
472 {"MenuScrollSpeed", "medium", seSpeeds,
473 &wPreferences.menu_scroll_speed, getEnum, NULL
475 {"IconSlideSpeed", "medium", seSpeeds,
476 &wPreferences.icon_slide_speed, getEnum, NULL
478 {"ShadeSpeed", "medium", seSpeeds,
479 &wPreferences.shade_speed, getEnum, NULL
481 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
482 &wPreferences.dblclick_time, getInt, setDoubleClick,
484 {"AlignSubmenus", "NO", NULL,
485 &wPreferences.align_menus, getBool, NULL
487 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
488 &wPreferences.open_transients_with_parent, getBool, NULL
490 {"WindowPlacement", "auto", sePlacements,
491 &wPreferences.window_placement, getEnum, NULL
493 {"IgnoreFocusClick","NO", NULL,
494 &wPreferences.ignore_focus_click, getBool, NULL
496 {"UseSaveUnders", "NO", NULL,
497 &wPreferences.use_saveunders, getBool, NULL
499 {"OpaqueMove", "NO", NULL,
500 &wPreferences.opaque_move, getBool, NULL
502 {"DisableSound", "NO", NULL,
503 &wPreferences.no_sound, getBool, NULL
505 {"DisableAnimations", "NO", NULL,
506 &wPreferences.no_animations, getBool, NULL
508 {"DontLinkWorkspaces","NO", NULL,
509 &wPreferences.no_autowrap, getBool, NULL
511 {"AutoArrangeIcons", "NO", NULL,
512 &wPreferences.auto_arrange_icons, getBool, NULL
514 {"NoWindowOverDock", "NO", NULL,
515 &wPreferences.no_window_over_dock, getBool, updateUsableArea
517 {"NoWindowOverIcons", "NO", NULL,
518 &wPreferences.no_window_over_icons, getBool, updateUsableArea
520 {"WindowPlaceOrigin", "(0, 0)", NULL,
521 &wPreferences.window_place_origin, getCoord, NULL
523 {"ResizeDisplay", "corner", seGeomDisplays,
524 &wPreferences.size_display, getEnum, NULL
526 {"MoveDisplay", "corner", seGeomDisplays,
527 &wPreferences.move_display, getEnum, NULL
529 {"DontConfirmKill", "NO", NULL,
530 &wPreferences.dont_confirm_kill, getBool,NULL
532 {"WindowTitleBalloons", "NO", NULL,
533 &wPreferences.window_balloon, getBool, NULL
535 {"MiniwindowTitleBalloons", "NO", NULL,
536 &wPreferences.miniwin_balloon,getBool, NULL
538 {"AppIconBalloons", "NO", NULL,
539 &wPreferences.appicon_balloon,getBool, NULL
541 {"HelpBalloons", "NO", NULL,
542 &wPreferences.help_balloon, getBool, NULL
544 {"EdgeResistance", "30", NULL,
545 &wPreferences.edge_resistance,getInt, NULL
547 {"Attraction", "NO", NULL,
548 &wPreferences.attract, getBool, NULL
550 {"DisableBlinking", "NO", NULL,
551 &wPreferences.dont_blink, getBool, NULL
553 /* style options */
554 {"MenuStyle", "normal", seMenuStyles,
555 &wPreferences.menu_style, getEnum, setMenuStyle
557 {"WidgetColor", "(solid, gray)", NULL,
558 NULL, getTexture, setWidgetColor,
560 {"WorkspaceSpecificBack","()", NULL,
561 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
563 /* WorkspaceBack must come after WorkspaceSpecificBack or
564 * WorkspaceBack wont know WorkspaceSpecificBack was also
565 * specified and 2 copies of wmsetbg will be launched */
566 {"WorkspaceBack", "(solid, black)", NULL,
567 NULL, getWSBackground,setWorkspaceBack
569 {"SmoothWorkspaceBack", "NO", NULL,
570 NULL, getBool, NULL
572 {"IconBack", "(solid, gray)", NULL,
573 NULL, getTexture, setIconTile
575 {"TitleJustify", "center", seJustifications,
576 &wPreferences.title_justification, getEnum, setJustify
578 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
579 NULL, getFont, setWinTitleFont,
581 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
582 &wPreferences.window_title_clearance, getInt, setClearance
584 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
585 &wPreferences.menu_title_clearance, getInt, setClearance
587 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
588 &wPreferences.menu_text_clearance, getInt, setClearance
590 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
591 NULL, getFont, setMenuTitleFont
593 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
594 NULL, getFont, setMenuTextFont
596 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
597 NULL, getFont, setIconTitleFont
599 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
600 NULL, getFont, setClipTitleFont
602 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
603 NULL, getFont, setLargeDisplayFont
605 {"HighlightColor", "white", NULL,
606 NULL, getColor, setHightlight
608 {"HighlightTextColor", "black", NULL,
609 NULL, getColor, setHightlightText
611 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
612 NULL, getColor, setClipTitleColor
614 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
615 NULL, getColor, setClipTitleColor
617 {"FTitleColor", "white", (void*)WS_FOCUSED,
618 NULL, getColor, setWTitleColor
620 {"PTitleColor", "white", (void*)WS_PFOCUSED,
621 NULL, getColor, setWTitleColor
623 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
624 NULL, getColor, setWTitleColor
626 {"FTitleBack", "(solid, black)", NULL,
627 NULL, getTexture, setFTitleBack
629 {"PTitleBack", "(solid, \"#616161\")", NULL,
630 NULL, getTexture, setPTitleBack
632 {"UTitleBack", "(solid, gray)", NULL,
633 NULL, getTexture, setUTitleBack
635 {"ResizebarBack", "(solid, gray)", NULL,
636 NULL, getTexture, setResizebarBack
638 {"MenuTitleColor", "white", NULL,
639 NULL, getColor, setMenuTitleColor
641 {"MenuTextColor", "black", NULL,
642 NULL, getColor, setMenuTextColor
644 {"MenuDisabledColor", "\"#616161\"", NULL,
645 NULL, getColor, setMenuDisabledColor
647 {"MenuTitleBack", "(solid, black)", NULL,
648 NULL, getTexture, setMenuTitleBack
650 {"MenuTextBack", "(solid, gray)", NULL,
651 NULL, getTexture, setMenuTextBack
653 {"IconTitleColor", "white", NULL,
654 NULL, getColor, setIconTitleColor
656 {"IconTitleBack", "black", NULL,
657 NULL, getColor, setIconTitleBack
659 /* keybindings */
660 #ifndef LITE
661 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
662 NULL, getKeybind, setKeyGrab
664 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
665 NULL, getKeybind, setKeyGrab
667 #endif /* LITE */
668 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
669 NULL, getKeybind, setKeyGrab
671 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
672 NULL, getKeybind, setKeyGrab
674 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
675 NULL, getKeybind, setKeyGrab
677 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
678 NULL, getKeybind, setKeyGrab
680 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
681 NULL, getKeybind, setKeyGrab
683 {"HideKey", "None", (void*)WKBD_HIDE,
684 NULL, getKeybind, setKeyGrab
686 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
687 NULL, getKeybind, setKeyGrab
689 {"CloseKey", "None", (void*)WKBD_CLOSE,
690 NULL, getKeybind, setKeyGrab
692 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
693 NULL, getKeybind, setKeyGrab
695 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
696 NULL, getKeybind, setKeyGrab
698 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
699 NULL, getKeybind, setKeyGrab
701 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
702 NULL, getKeybind, setKeyGrab
704 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
705 NULL, getKeybind, setKeyGrab
707 {"ShadeKey", "None", (void*)WKBD_SHADE,
708 NULL, getKeybind, setKeyGrab
710 {"SelectKey", "None", (void*)WKBD_SELECT,
711 NULL, getKeybind, setKeyGrab
713 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
714 NULL, getKeybind, setKeyGrab
716 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
717 NULL, getKeybind, setKeyGrab
719 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
720 NULL, getKeybind, setKeyGrab
722 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
723 NULL, getKeybind, setKeyGrab
725 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
726 NULL, getKeybind, setKeyGrab
728 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
729 NULL, getKeybind, setKeyGrab
731 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
732 NULL, getKeybind, setKeyGrab
734 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
735 NULL, getKeybind, setKeyGrab
737 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
738 NULL, getKeybind, setKeyGrab
740 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
741 NULL, getKeybind, setKeyGrab
743 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
744 NULL, getKeybind, setKeyGrab
746 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
756 NULL, getKeybind, setKeyGrab
758 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
759 NULL, getKeybind, setKeyGrab
761 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
762 NULL, getKeybind, setKeyGrab
764 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
765 NULL, getKeybind, setKeyGrab
767 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
768 NULL, getKeybind, setKeyGrab
770 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
771 NULL, getKeybind, setKeyGrab
773 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
774 NULL, getKeybind, setKeyGrab
776 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
783 NULL, getKeybind, setKeyGrab
785 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
786 NULL, getKeybind, setKeyGrab
788 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
789 NULL, getKeybind, setKeyGrab
791 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
792 NULL, getKeybind, setKeyGrab
795 #ifdef KEEP_XKB_LOCK_STATUS
796 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
797 NULL, getKeybind, setKeyGrab
799 {"KbdModeLock", "NO", NULL,
800 &wPreferences.modelock, getBool, NULL
802 #endif /* KEEP_XKB_LOCK_STATUS */
803 #ifdef DEFINABLE_CURSOR
804 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
805 NULL, getCursor, setCursor
807 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
808 NULL, getCursor, setCursor
810 #if 0
811 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
812 NULL, getCursor, setCursor
814 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
815 NULL, getCursor, setCursor
817 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
818 NULL, getCursor, setCursor
820 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
821 NULL, getCursor, setCursor
823 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
824 NULL, getCursor, setCursor
826 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
827 NULL, getCursor, setCursor
829 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
830 NULL, getCursor, setCursor
832 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
833 NULL, getCursor, setCursor
835 #endif
836 #endif /* DEFINABLE_CURSOR */
840 #if 0
841 static void rereadDefaults(void);
842 #endif
844 #if 0
845 static void
846 rereadDefaults(void)
848 /* must defer the update because accessing X data from a
849 * signal handler can mess up Xlib */
852 #endif
854 static void
855 initDefaults()
857 int i;
858 WDefaultEntry *entry;
860 PLSetStringCmpHook(StringCompareHook);
862 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
863 entry = &optionList[i];
865 entry->plkey = PLMakeString(entry->key);
866 if (entry->default_value)
867 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
868 else
869 entry->plvalue = NULL;
872 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
873 entry = &staticOptionList[i];
875 entry->plkey = PLMakeString(entry->key);
876 if (entry->default_value)
877 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
878 else
879 entry->plvalue = NULL;
883 wDomainName = PLMakeString(WMDOMAIN_NAME);
884 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
886 PLRegister(wDomainName, rereadDefaults);
887 PLRegister(wAttributeDomainName, rereadDefaults);
894 #if 0
895 proplist_t
896 wDefaultsInit(int screen_number)
898 static int defaults_inited = 0;
899 proplist_t dict;
901 if (!defaults_inited) {
902 initDefaults();
905 dict = PLGetDomain(wDomainName);
906 if (!dict) {
907 wwarning(_("could not read domain \"%s\" from defaults database"),
908 PLGetString(wDomainName));
911 return dict;
913 #endif
916 void
917 wDefaultsDestroyDomain(WDDomain *domain)
919 if (domain->dictionary)
920 PLRelease(domain->dictionary);
921 wfree(domain->path);
922 wfree(domain);
926 WDDomain*
927 wDefaultsInitDomain(char *domain, Bool requireDictionary)
929 WDDomain *db;
930 struct stat stbuf;
931 static int inited = 0;
932 char path[PATH_MAX];
933 char *the_path;
934 proplist_t shared_dict=NULL;
936 if (!inited) {
937 inited = 1;
938 initDefaults();
941 db = wmalloc(sizeof(WDDomain));
942 memset(db, 0, sizeof(WDDomain));
943 db->domain_name = domain;
944 db->path = wdefaultspathfordomain(domain);
945 the_path = db->path;
947 if (the_path && stat(the_path, &stbuf)>=0) {
948 db->dictionary = ReadProplistFromFile(the_path);
949 if (db->dictionary) {
950 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
951 PLRelease(db->dictionary);
952 db->dictionary = NULL;
953 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
954 domain, the_path);
956 db->timestamp = stbuf.st_mtime;
957 } else {
958 wwarning(_("could not load domain %s from user defaults database"),
959 domain);
963 /* global system dictionary */
964 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
965 if (stat(path, &stbuf)>=0) {
966 shared_dict = ReadProplistFromFile(path);
967 if (shared_dict) {
968 if (requireDictionary && !PLIsDictionary(shared_dict)) {
969 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
970 domain, path);
971 PLRelease(shared_dict);
972 shared_dict = NULL;
973 } else {
974 if (db->dictionary && PLIsDictionary(shared_dict) &&
975 PLIsDictionary(db->dictionary)) {
976 PLMergeDictionaries(shared_dict, db->dictionary);
977 PLRelease(db->dictionary);
978 db->dictionary = shared_dict;
979 if (stbuf.st_mtime > db->timestamp)
980 db->timestamp = stbuf.st_mtime;
981 } else if (!db->dictionary) {
982 db->dictionary = shared_dict;
983 if (stbuf.st_mtime > db->timestamp)
984 db->timestamp = stbuf.st_mtime;
987 } else {
988 wwarning(_("could not load domain %s from global defaults database (%s)"),
989 domain, path);
993 /* set to save it in user's directory, no matter from where it was read */
994 if (db->dictionary) {
995 proplist_t tmp = PLMakeString(db->path);
997 PLSetFilename(db->dictionary, tmp);
998 PLRelease(tmp);
1001 return db;
1005 void
1006 wReadStaticDefaults(proplist_t dict)
1008 proplist_t plvalue;
1009 WDefaultEntry *entry;
1010 int i;
1011 void *tdata;
1014 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1015 entry = &staticOptionList[i];
1017 if (dict)
1018 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1019 else
1020 plvalue = NULL;
1022 if (!plvalue) {
1023 /* no default in the DB. Use builtin default */
1024 plvalue = entry->plvalue;
1027 if (plvalue) {
1028 /* convert data */
1029 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1030 if (entry->update) {
1031 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1038 void
1039 wDefaultsCheckDomains(void *foo)
1041 WScreen *scr;
1042 struct stat stbuf;
1043 proplist_t dict;
1044 int i;
1045 char path[PATH_MAX];
1047 #ifdef HEARTBEAT
1048 puts("Checking domains...");
1049 #endif
1050 if (stat(WDWindowMaker->path, &stbuf)>=0
1051 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1052 proplist_t shared_dict = NULL;
1053 #ifdef HEARTBEAT
1054 puts("Checking WindowMaker domain");
1055 #endif
1056 WDWindowMaker->timestamp = stbuf.st_mtime;
1058 /* global dictionary */
1059 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1060 if (stat(path, &stbuf)>=0) {
1061 shared_dict = ReadProplistFromFile(path);
1062 if (shared_dict && !PLIsDictionary(shared_dict)) {
1063 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1064 "WindowMaker", path);
1065 PLRelease(shared_dict);
1066 shared_dict = NULL;
1067 } else if (!shared_dict) {
1068 wwarning(_("could not load domain %s from global defaults database"),
1069 "WindowMaker");
1072 /* user dictionary */
1073 dict = ReadProplistFromFile(WDWindowMaker->path);
1074 if (dict) {
1075 if (!PLIsDictionary(dict)) {
1076 PLRelease(dict);
1077 dict = NULL;
1078 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1079 "WindowMaker", WDWindowMaker->path);
1080 } else {
1081 if (shared_dict) {
1082 PLSetFilename(shared_dict, PLGetFilename(dict));
1083 PLMergeDictionaries(shared_dict, dict);
1084 PLRelease(dict);
1085 dict = shared_dict;
1086 shared_dict = NULL;
1088 for (i=0; i<wScreenCount; i++) {
1089 scr = wScreenWithNumber(i);
1090 if (scr)
1091 wReadDefaults(scr, dict);
1093 if (WDWindowMaker->dictionary) {
1094 PLRelease(WDWindowMaker->dictionary);
1096 WDWindowMaker->dictionary = dict;
1098 } else {
1099 wwarning(_("could not load domain %s from user defaults database"),
1100 "WindowMaker");
1102 if (shared_dict) {
1103 PLRelease(shared_dict);
1107 if (stat(WDWindowAttributes->path, &stbuf)>=0
1108 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1109 #ifdef HEARTBEAT
1110 puts("Checking WMWindowAttributes domain");
1111 #endif
1112 dict = ReadProplistFromFile(WDWindowAttributes->path);
1113 if (dict) {
1114 if (!PLIsDictionary(dict)) {
1115 PLRelease(dict);
1116 dict = NULL;
1117 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1118 "WMWindowAttributes", WDWindowAttributes->path);
1119 } else {
1120 if (WDWindowAttributes->dictionary)
1121 PLRelease(WDWindowAttributes->dictionary);
1122 WDWindowAttributes->dictionary = dict;
1123 for (i=0; i<wScreenCount; i++) {
1124 scr = wScreenWithNumber(i);
1125 if (scr)
1126 wDefaultUpdateIcons(scr);
1129 } else {
1130 wwarning(_("could not load domain %s from user defaults database"),
1131 "WMWindowAttributes");
1133 WDWindowAttributes->timestamp = stbuf.st_mtime;
1136 #ifndef LITE
1137 if (stat(WDRootMenu->path, &stbuf)>=0
1138 && WDRootMenu->timestamp < stbuf.st_mtime) {
1139 dict = ReadProplistFromFile(WDRootMenu->path);
1140 #ifdef HEARTBEAT
1141 puts("Checking WMRootMenu domain");
1142 #endif
1143 if (dict) {
1144 if (!PLIsArray(dict) && !PLIsString(dict)) {
1145 PLRelease(dict);
1146 dict = NULL;
1147 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1148 "WMRootMenu", WDRootMenu->path);
1149 } else {
1150 if (WDRootMenu->dictionary) {
1151 PLRelease(WDRootMenu->dictionary);
1153 WDRootMenu->dictionary = dict;
1155 } else {
1156 wwarning(_("could not load domain %s from user defaults database"),
1157 "WMRootMenu");
1159 WDRootMenu->timestamp = stbuf.st_mtime;
1161 #endif /* !LITE */
1163 if (!foo)
1164 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1168 void
1169 wReadDefaults(WScreen *scr, proplist_t new_dict)
1171 proplist_t plvalue, old_value;
1172 WDefaultEntry *entry;
1173 int i, must_update;
1174 int update_workspace_back = 0; /* kluge :/ */
1175 int needs_refresh;
1176 void *tdata;
1177 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1178 ? WDWindowMaker->dictionary : NULL);
1180 must_update = 0;
1182 needs_refresh = 0;
1184 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1185 entry = &optionList[i];
1187 if (new_dict)
1188 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1189 else
1190 plvalue = NULL;
1192 if (!old_dict)
1193 old_value = NULL;
1194 else
1195 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1198 if (!plvalue && !old_value) {
1199 /* no default in the DB. Use builtin default */
1200 plvalue = entry->plvalue;
1201 if (plvalue && new_dict) {
1202 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1203 must_update = 1;
1205 } else if (!plvalue) {
1206 /* value was deleted from DB. Keep current value */
1207 continue;
1208 } else if (!old_value) {
1209 /* set value for the 1st time */
1210 } else if (!PLIsEqual(plvalue, old_value)) {
1211 /* value has changed */
1212 } else {
1214 if (strcmp(entry->key, "WorkspaceBack") == 0
1215 && update_workspace_back
1216 && scr->flags.backimage_helper_launched) {
1217 } else {
1218 /* value was not changed since last time */
1219 continue;
1223 if (plvalue) {
1224 #ifdef DEBUG
1225 printf("Updating %s to %s\n", entry->key,
1226 PLGetDescription(plvalue));
1227 #endif
1228 /* convert data */
1229 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1231 * If the WorkspaceSpecificBack data has been changed
1232 * so that the helper will be launched now, we must be
1233 * sure to send the default background texture config
1234 * to the helper.
1236 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1237 && !scr->flags.backimage_helper_launched) {
1238 update_workspace_back = 1;
1240 if (entry->update) {
1241 needs_refresh |=
1242 (*entry->update)(scr, entry, tdata, entry->extra_data);
1248 if (needs_refresh!=0 && !scr->flags.startup) {
1249 int foo;
1251 foo = 0;
1252 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1253 foo |= WTextureSettings;
1254 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1255 foo |= WFontSettings;
1256 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1257 foo |= WColorSettings;
1258 if (foo)
1259 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1260 (void*)foo);
1262 foo = 0;
1263 if (needs_refresh & REFRESH_MENU_TEXTURE)
1264 foo |= WTextureSettings;
1265 if (needs_refresh & REFRESH_MENU_FONT)
1266 foo |= WFontSettings;
1267 if (needs_refresh & REFRESH_MENU_COLOR)
1268 foo |= WColorSettings;
1269 if (foo)
1270 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1271 (void*)foo);
1273 foo = 0;
1274 if (needs_refresh & REFRESH_WINDOW_FONT) {
1275 foo |= WFontSettings;
1277 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1278 foo |= WTextureSettings;
1280 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1281 foo |= WColorSettings;
1283 if (foo)
1284 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1285 (void*)foo);
1287 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1288 foo = 0;
1289 if (needs_refresh & REFRESH_ICON_FONT) {
1290 foo |= WFontSettings;
1292 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1293 foo |= WTextureSettings;
1295 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1296 foo |= WTextureSettings;
1298 if (foo)
1299 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1300 (void*)foo);
1302 if (needs_refresh & REFRESH_ICON_TILE)
1303 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1308 void
1309 wDefaultUpdateIcons(WScreen *scr)
1311 WAppIcon *aicon = scr->app_icon_list;
1312 WWindow *wwin = scr->focused_window;
1313 char *file;
1315 while(aicon) {
1316 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1317 False);
1318 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1319 || (file && !aicon->icon->file)) {
1320 RImage *new_image;
1322 if (aicon->icon->file)
1323 wfree(aicon->icon->file);
1324 aicon->icon->file = wstrdup(file);
1326 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1327 aicon->wm_class);
1328 if (new_image) {
1329 wIconChangeImage(aicon->icon, new_image);
1330 wAppIconPaint(aicon);
1333 aicon = aicon->next;
1336 if (!wPreferences.flags.noclip)
1337 wClipIconPaint(scr->clip_icon);
1339 while (wwin) {
1340 if (wwin->icon && wwin->flags.miniaturized) {
1341 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1342 False);
1343 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1344 || (file && !wwin->icon->file)) {
1345 RImage *new_image;
1347 if (wwin->icon->file)
1348 wfree(wwin->icon->file);
1349 wwin->icon->file = wstrdup(file);
1351 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1352 wwin->wm_class);
1353 if (new_image)
1354 wIconChangeImage(wwin->icon, new_image);
1357 wwin = wwin->prev;
1362 /* --------------------------- Local ----------------------- */
1364 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1365 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1366 entry->key, x); \
1367 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1368 var = entry->default_value;\
1369 } else var = PLGetString(value)\
1375 static int
1376 string2index(proplist_t key, proplist_t val, proplist_t def,
1377 WOptionEnumeration *values)
1379 char *str;
1380 WOptionEnumeration *v;
1381 char buffer[TOTAL_VALUES_LENGTH];
1383 if (PLIsString(val) && (str = PLGetString(val))) {
1384 for (v=values; v->string!=NULL; v++) {
1385 if (strcasecmp(v->string, str)==0)
1386 return v->value;
1390 buffer[0] = 0;
1391 for (v=values; v->string!=NULL; v++) {
1392 if (!v->is_alias) {
1393 if (buffer[0]!=0)
1394 strcat(buffer, ", ");
1395 strcat(buffer, v->string);
1398 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1399 PLGetString(key), buffer);
1401 if (def) {
1402 return string2index(key, val, NULL, values);
1405 return -1;
1412 * value - is the value in the defaults DB
1413 * addr - is the address to store the data
1414 * ret - is the address to store a pointer to a temporary buffer. ret
1415 * must not be freed and is used by the set functions
1417 static int
1418 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1419 void **ret)
1421 static char data;
1422 char *val;
1423 int second_pass=0;
1425 GET_STRING_OR_DEFAULT("Boolean", val);
1427 again:
1428 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1429 || strcasecmp(val, "YES")==0) {
1431 data = 1;
1432 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1433 || strcasecmp(val, "NO")==0) {
1434 data = 0;
1435 } else {
1436 int i;
1437 if (sscanf(val, "%i", &i)==1) {
1438 if (i!=0)
1439 data = 1;
1440 else
1441 data = 0;
1442 } else {
1443 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1444 val, entry->key);
1445 if (second_pass==0) {
1446 val = PLGetString(entry->plvalue);
1447 second_pass = 1;
1448 wwarning(_("using default \"%s\" instead"), val);
1449 goto again;
1451 return False;
1455 if (ret)
1456 *ret = &data;
1458 if (addr) {
1459 *(char*)addr = data;
1462 return True;
1466 static int
1467 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1468 void **ret)
1470 static int data;
1471 char *val;
1474 GET_STRING_OR_DEFAULT("Integer", val);
1476 if (sscanf(val, "%i", &data)!=1) {
1477 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1478 val, entry->key);
1479 val = PLGetString(entry->plvalue);
1480 wwarning(_("using default \"%s\" instead"), val);
1481 if (sscanf(val, "%i", &data)!=1) {
1482 return False;
1486 if (ret)
1487 *ret = &data;
1489 if (addr) {
1490 *(int*)addr = data;
1492 return True;
1496 static int
1497 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1498 void **ret)
1500 static WCoord data;
1501 char *val_x, *val_y;
1502 int nelem, changed=0;
1503 proplist_t elem_x, elem_y;
1505 again:
1506 if (!PLIsArray(value)) {
1507 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1508 entry->key, "Coordinate");
1509 if (changed==0) {
1510 value = entry->plvalue;
1511 changed = 1;
1512 wwarning(_("using default \"%s\" instead"), entry->default_value);
1513 goto again;
1515 return False;
1518 nelem = PLGetNumberOfElements(value);
1519 if (nelem != 2) {
1520 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1521 entry->key);
1522 if (changed==0) {
1523 value = entry->plvalue;
1524 changed = 1;
1525 wwarning(_("using default \"%s\" instead"), entry->default_value);
1526 goto again;
1528 return False;
1531 elem_x = PLGetArrayElement(value, 0);
1532 elem_y = PLGetArrayElement(value, 1);
1534 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1535 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1536 entry->key);
1537 if (changed==0) {
1538 value = entry->plvalue;
1539 changed = 1;
1540 wwarning(_("using default \"%s\" instead"), entry->default_value);
1541 goto again;
1543 return False;
1546 val_x = PLGetString(elem_x);
1547 val_y = PLGetString(elem_y);
1549 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1550 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1551 if (changed==0) {
1552 value = entry->plvalue;
1553 changed = 1;
1554 wwarning(_("using default \"%s\" instead"), entry->default_value);
1555 goto again;
1557 return False;
1560 if (data.x < 0)
1561 data.x = 0;
1562 else if (data.x > scr->scr_width/3)
1563 data.x = scr->scr_width/3;
1564 if (data.y < 0)
1565 data.y = 0;
1566 else if (data.y > scr->scr_height/3)
1567 data.y = scr->scr_height/3;
1569 if (ret)
1570 *ret = &data;
1572 if (addr) {
1573 *(WCoord*)addr = data;
1576 return True;
1580 #if 0
1581 /* This function is not used at the moment. */
1582 static int
1583 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1584 void **ret)
1586 static char *data;
1588 GET_STRING_OR_DEFAULT("String", data);
1590 if (!data) {
1591 data = PLGetString(entry->plvalue);
1592 if (!data)
1593 return False;
1596 if (ret)
1597 *ret = &data;
1599 if (addr)
1600 *(char**)addr = wstrdup(data);
1602 return True;
1604 #endif
1607 static int
1608 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1609 void **ret)
1611 static char *data;
1612 int i, count, len;
1613 char *ptr;
1614 proplist_t d;
1615 int changed=0;
1617 again:
1618 if (!PLIsArray(value)) {
1619 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1620 entry->key, "an array of paths");
1621 if (changed==0) {
1622 value = entry->plvalue;
1623 changed = 1;
1624 wwarning(_("using default \"%s\" instead"), entry->default_value);
1625 goto again;
1627 return False;
1630 i = 0;
1631 count = PLGetNumberOfElements(value);
1632 if (count < 1) {
1633 if (changed==0) {
1634 value = entry->plvalue;
1635 changed = 1;
1636 wwarning(_("using default \"%s\" instead"), entry->default_value);
1637 goto again;
1639 return False;
1642 len = 0;
1643 for (i=0; i<count; i++) {
1644 d = PLGetArrayElement(value, i);
1645 if (!d || !PLIsString(d)) {
1646 count = i;
1647 break;
1649 len += strlen(PLGetString(d))+1;
1652 ptr = data = wmalloc(len+1);
1654 for (i=0; i<count; i++) {
1655 d = PLGetArrayElement(value, i);
1656 if (!d || !PLIsString(d)) {
1657 break;
1659 strcpy(ptr, PLGetString(d));
1660 ptr += strlen(PLGetString(d));
1661 *ptr = ':';
1662 ptr++;
1664 ptr--; *(ptr--) = 0;
1666 if (*(char**)addr!=NULL) {
1667 wfree(*(char**)addr);
1669 *(char**)addr = data;
1671 return True;
1675 static int
1676 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1677 void **ret)
1679 static signed char data;
1681 data = string2index(entry->plkey, value, entry->default_value,
1682 (WOptionEnumeration*)entry->extra_data);
1683 if (data < 0)
1684 return False;
1686 if (ret)
1687 *ret = &data;
1689 if (addr)
1690 *(signed char*)addr = data;
1692 return True;
1698 * (solid <color>)
1699 * (hgradient <color> <color>)
1700 * (vgradient <color> <color>)
1701 * (dgradient <color> <color>)
1702 * (mhgradient <color> <color> ...)
1703 * (mvgradient <color> <color> ...)
1704 * (mdgradient <color> <color> ...)
1705 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1706 * (tpixmap <file> <color>)
1707 * (spixmap <file> <color>)
1708 * (cpixmap <file> <color>)
1709 * (thgradient <file> <opaqueness> <color> <color>)
1710 * (tvgradient <file> <opaqueness> <color> <color>)
1711 * (tdgradient <file> <opaqueness> <color> <color>)
1712 * (function <lib> <function> ...)
1715 static WTexture*
1716 parse_texture(WScreen *scr, proplist_t pl)
1718 proplist_t elem;
1719 char *val;
1720 int nelem;
1721 WTexture *texture=NULL;
1723 nelem = PLGetNumberOfElements(pl);
1724 if (nelem < 1)
1725 return NULL;
1728 elem = PLGetArrayElement(pl, 0);
1729 if (!elem || !PLIsString(elem))
1730 return NULL;
1731 val = PLGetString(elem);
1734 if (strcasecmp(val, "solid")==0) {
1735 XColor color;
1737 if (nelem != 2)
1738 return NULL;
1740 /* get color */
1742 elem = PLGetArrayElement(pl, 1);
1743 if (!elem || !PLIsString(elem))
1744 return NULL;
1745 val = PLGetString(elem);
1747 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1748 wwarning(_("\"%s\" is not a valid color name"), val);
1749 return NULL;
1752 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1753 } else if (strcasecmp(val, "dgradient")==0
1754 || strcasecmp(val, "vgradient")==0
1755 || strcasecmp(val, "hgradient")==0) {
1756 RColor color1, color2;
1757 XColor xcolor;
1758 int type;
1760 if (nelem != 3) {
1761 wwarning(_("bad number of arguments in gradient specification"));
1762 return NULL;
1765 if (val[0]=='d' || val[0]=='D')
1766 type = WTEX_DGRADIENT;
1767 else if (val[0]=='h' || val[0]=='H')
1768 type = WTEX_HGRADIENT;
1769 else
1770 type = WTEX_VGRADIENT;
1773 /* get from color */
1774 elem = PLGetArrayElement(pl, 1);
1775 if (!elem || !PLIsString(elem))
1776 return NULL;
1777 val = PLGetString(elem);
1779 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1780 wwarning(_("\"%s\" is not a valid color name"), val);
1781 return NULL;
1783 color1.alpha = 255;
1784 color1.red = xcolor.red >> 8;
1785 color1.green = xcolor.green >> 8;
1786 color1.blue = xcolor.blue >> 8;
1788 /* get to color */
1789 elem = PLGetArrayElement(pl, 2);
1790 if (!elem || !PLIsString(elem)) {
1791 return NULL;
1793 val = PLGetString(elem);
1795 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1796 wwarning(_("\"%s\" is not a valid color name"), val);
1797 return NULL;
1799 color2.alpha = 255;
1800 color2.red = xcolor.red >> 8;
1801 color2.green = xcolor.green >> 8;
1802 color2.blue = xcolor.blue >> 8;
1804 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1806 } else if (strcasecmp(val, "igradient")==0) {
1807 RColor colors1[2], colors2[2];
1808 int th1, th2;
1809 XColor xcolor;
1810 int i;
1812 if (nelem != 7) {
1813 wwarning(_("bad number of arguments in gradient specification"));
1814 return NULL;
1817 /* get from color */
1818 for (i = 0; i < 2; i++) {
1819 elem = PLGetArrayElement(pl, 1+i);
1820 if (!elem || !PLIsString(elem))
1821 return NULL;
1822 val = PLGetString(elem);
1824 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1825 wwarning(_("\"%s\" is not a valid color name"), val);
1826 return NULL;
1828 colors1[i].alpha = 255;
1829 colors1[i].red = xcolor.red >> 8;
1830 colors1[i].green = xcolor.green >> 8;
1831 colors1[i].blue = xcolor.blue >> 8;
1833 elem = PLGetArrayElement(pl, 3);
1834 if (!elem || !PLIsString(elem))
1835 return NULL;
1836 val = PLGetString(elem);
1837 th1 = atoi(val);
1840 /* get from color */
1841 for (i = 0; i < 2; i++) {
1842 elem = PLGetArrayElement(pl, 4+i);
1843 if (!elem || !PLIsString(elem))
1844 return NULL;
1845 val = PLGetString(elem);
1847 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1848 wwarning(_("\"%s\" is not a valid color name"), val);
1849 return NULL;
1851 colors2[i].alpha = 255;
1852 colors2[i].red = xcolor.red >> 8;
1853 colors2[i].green = xcolor.green >> 8;
1854 colors2[i].blue = xcolor.blue >> 8;
1856 elem = PLGetArrayElement(pl, 6);
1857 if (!elem || !PLIsString(elem))
1858 return NULL;
1859 val = PLGetString(elem);
1860 th2 = atoi(val);
1862 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1863 th2, colors2);
1865 } else if (strcasecmp(val, "mhgradient")==0
1866 || strcasecmp(val, "mvgradient")==0
1867 || strcasecmp(val, "mdgradient")==0) {
1868 XColor color;
1869 RColor **colors;
1870 int i, count;
1871 int type;
1873 if (nelem < 3) {
1874 wwarning(_("too few arguments in multicolor gradient specification"));
1875 return NULL;
1878 if (val[1]=='h' || val[1]=='H')
1879 type = WTEX_MHGRADIENT;
1880 else if (val[1]=='v' || val[1]=='V')
1881 type = WTEX_MVGRADIENT;
1882 else
1883 type = WTEX_MDGRADIENT;
1885 count = nelem-1;
1887 colors = wmalloc(sizeof(RColor*)*(count+1));
1889 for (i=0; i<count; i++) {
1890 elem = PLGetArrayElement(pl, i+1);
1891 if (!elem || !PLIsString(elem)) {
1892 for (--i; i>=0; --i) {
1893 wfree(colors[i]);
1895 wfree(colors);
1896 return NULL;
1898 val = PLGetString(elem);
1900 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1901 wwarning(_("\"%s\" is not a valid color name"), val);
1902 for (--i; i>=0; --i) {
1903 wfree(colors[i]);
1905 wfree(colors);
1906 return NULL;
1907 } else {
1908 colors[i] = wmalloc(sizeof(RColor));
1909 colors[i]->red = color.red >> 8;
1910 colors[i]->green = color.green >> 8;
1911 colors[i]->blue = color.blue >> 8;
1914 colors[i] = NULL;
1916 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1917 } else if (strcasecmp(val, "spixmap")==0 ||
1918 strcasecmp(val, "cpixmap")==0 ||
1919 strcasecmp(val, "tpixmap")==0) {
1920 XColor color;
1921 int type;
1923 if (nelem != 3)
1924 return NULL;
1926 if (val[0] == 's' || val[0] == 'S')
1927 type = WTP_SCALE;
1928 else if (val[0] == 'c' || val[0] == 'C')
1929 type = WTP_CENTER;
1930 else
1931 type = WTP_TILE;
1933 /* get color */
1934 elem = PLGetArrayElement(pl, 2);
1935 if (!elem || !PLIsString(elem)) {
1936 return NULL;
1938 val = PLGetString(elem);
1940 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1941 wwarning(_("\"%s\" is not a valid color name"), val);
1942 return NULL;
1945 /* file name */
1946 elem = PLGetArrayElement(pl, 1);
1947 if (!elem || !PLIsString(elem))
1948 return NULL;
1949 val = PLGetString(elem);
1951 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1952 } else if (strcasecmp(val, "thgradient")==0
1953 || strcasecmp(val, "tvgradient")==0
1954 || strcasecmp(val, "tdgradient")==0) {
1955 RColor color1, color2;
1956 XColor xcolor;
1957 int opacity;
1958 int style;
1960 if (val[1]=='h' || val[1]=='H')
1961 style = WTEX_THGRADIENT;
1962 else if (val[1]=='v' || val[1]=='V')
1963 style = WTEX_TVGRADIENT;
1964 else
1965 style = WTEX_TDGRADIENT;
1967 if (nelem != 5) {
1968 wwarning(_("bad number of arguments in textured gradient specification"));
1969 return NULL;
1972 /* get from color */
1973 elem = PLGetArrayElement(pl, 3);
1974 if (!elem || !PLIsString(elem))
1975 return NULL;
1976 val = PLGetString(elem);
1978 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1979 wwarning(_("\"%s\" is not a valid color name"), val);
1980 return NULL;
1982 color1.alpha = 255;
1983 color1.red = xcolor.red >> 8;
1984 color1.green = xcolor.green >> 8;
1985 color1.blue = xcolor.blue >> 8;
1987 /* get to color */
1988 elem = PLGetArrayElement(pl, 4);
1989 if (!elem || !PLIsString(elem)) {
1990 return NULL;
1992 val = PLGetString(elem);
1994 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1995 wwarning(_("\"%s\" is not a valid color name"), val);
1996 return NULL;
1998 color2.alpha = 255;
1999 color2.red = xcolor.red >> 8;
2000 color2.green = xcolor.green >> 8;
2001 color2.blue = xcolor.blue >> 8;
2003 /* get opacity */
2004 elem = PLGetArrayElement(pl, 2);
2005 if (!elem || !PLIsString(elem))
2006 opacity = 128;
2007 else
2008 val = PLGetString(elem);
2010 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2011 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2012 opacity = 128;
2015 /* get file name */
2016 elem = PLGetArrayElement(pl, 1);
2017 if (!elem || !PLIsString(elem))
2018 return NULL;
2019 val = PLGetString(elem);
2021 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2022 val, opacity);
2024 #ifdef TEXTURE_PLUGIN
2025 else if (strcasecmp(val, "function")==0) {
2026 WTexFunction *function;
2027 void (*initFunc) (Display *, Colormap);
2028 char *lib, *func, **argv;
2029 int i, argc;
2031 if (nelem < 3)
2032 return NULL;
2034 /* get the library name */
2035 elem = PLGetArrayElement(pl, 1);
2036 if (!elem || !PLIsString(elem)) {
2037 return NULL;
2039 lib = PLGetString(elem);
2041 /* get the function name */
2042 elem = PLGetArrayElement(pl, 2);
2043 if (!elem || !PLIsString(elem)) {
2044 return NULL;
2046 func = PLGetString(elem);
2048 argc = nelem - 2;
2049 argv = (char **)wmalloc(argc * sizeof(char *));
2051 /* get the parameters */
2052 argv[0] = wstrdup(func);
2053 for (i = 0; i < argc - 1; i++) {
2054 elem = PLGetArrayElement(pl, 3 + i);
2055 if (!elem || !PLIsString(elem)) {
2056 wfree(argv);
2058 return NULL;
2060 argv[i+1] = wstrdup(PLGetString(elem));
2063 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2065 #ifdef HAVE_DLFCN_H
2066 if (function) {
2067 initFunc = dlsym(function->handle, "initWindowMaker");
2068 if (initFunc) {
2069 initFunc(dpy, scr->w_colormap);
2070 } else {
2071 wwarning(_("could not initialize library %s"), lib);
2073 } else {
2074 wwarning(_("could not find function %s::%s"), lib, func);
2076 #endif /* HAVE_DLFCN_H */
2077 texture = (WTexture*)function;
2079 #endif /* TEXTURE_PLUGIN */
2080 else {
2081 wwarning(_("invalid texture type %s"), val);
2082 return NULL;
2084 return texture;
2089 static int
2090 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2091 void **ret)
2093 static WTexture *texture;
2094 int changed=0;
2096 again:
2097 if (!PLIsArray(value)) {
2098 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2099 entry->key, "Texture");
2100 if (changed==0) {
2101 value = entry->plvalue;
2102 changed = 1;
2103 wwarning(_("using default \"%s\" instead"), entry->default_value);
2104 goto again;
2106 return False;
2109 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2110 proplist_t pl;
2112 pl = PLGetArrayElement(value, 0);
2113 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2114 || strcasecmp(PLGetString(pl), "solid")!=0) {
2115 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2116 entry->key, "Solid Texture");
2118 value = entry->plvalue;
2119 changed = 1;
2120 wwarning(_("using default \"%s\" instead"), entry->default_value);
2121 goto again;
2125 texture = parse_texture(scr, value);
2127 if (!texture) {
2128 wwarning(_("Error in texture specification for key \"%s\""),
2129 entry->key);
2130 if (changed==0) {
2131 value = entry->plvalue;
2132 changed = 1;
2133 wwarning(_("using default \"%s\" instead"), entry->default_value);
2134 goto again;
2136 return False;
2139 if (ret)
2140 *ret = &texture;
2142 if (addr)
2143 *(WTexture**)addr = texture;
2145 return True;
2149 static int
2150 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2151 void *addr, void **ret)
2153 proplist_t elem;
2154 int changed = 0;
2155 char *val;
2156 int nelem;
2158 again:
2159 if (!PLIsArray(value)) {
2160 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2161 "WorkspaceBack", "Texture or None");
2162 if (changed==0) {
2163 value = entry->plvalue;
2164 changed = 1;
2165 wwarning(_("using default \"%s\" instead"), entry->default_value);
2166 goto again;
2168 return False;
2171 /* only do basic error checking and verify for None texture */
2173 nelem = PLGetNumberOfElements(value);
2174 if (nelem > 0) {
2175 elem = PLGetArrayElement(value, 0);
2176 if (!elem || !PLIsString(elem)) {
2177 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2178 if (changed==0) {
2179 value = entry->plvalue;
2180 changed = 1;
2181 wwarning(_("using default \"%s\" instead"), entry->default_value);
2182 goto again;
2184 return False;
2186 val = PLGetString(elem);
2188 if (strcasecmp(val, "None")==0)
2189 return True;
2191 *ret = PLRetain(value);
2193 return True;
2197 static int
2198 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2199 void *addr, void **ret)
2201 proplist_t elem;
2202 int nelem;
2203 int changed = 0;
2205 again:
2206 if (!PLIsArray(value)) {
2207 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2208 "WorkspaceSpecificBack", "an array of textures");
2209 if (changed==0) {
2210 value = entry->plvalue;
2211 changed = 1;
2212 wwarning(_("using default \"%s\" instead"), entry->default_value);
2213 goto again;
2215 return False;
2218 /* only do basic error checking and verify for None texture */
2220 nelem = PLGetNumberOfElements(value);
2221 if (nelem > 0) {
2222 while (nelem--) {
2223 elem = PLGetArrayElement(value, nelem);
2224 if (!elem || !PLIsArray(elem)) {
2225 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2226 nelem);
2231 *ret = PLRetain(value);
2233 #ifdef notworking
2235 * Kluge to force wmsetbg helper to set the default background.
2236 * If the WorkspaceSpecificBack is changed once wmaker has started,
2237 * the WorkspaceBack won't be sent to the helper, unless the user
2238 * changes it's value too. So, we must force this by removing the
2239 * value from the defaults DB.
2241 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2242 proplist_t key = PLMakeString("WorkspaceBack");
2244 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2246 PLRelease(key);
2248 #endif
2249 return True;
2253 static int
2254 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2255 void **ret)
2257 static WMFont *font;
2258 char *val;
2260 GET_STRING_OR_DEFAULT("Font", val);
2262 font = WMCreateFont(scr->wmscreen, val);
2263 if (!font)
2264 font = WMCreateFont(scr->wmscreen, "fixed");
2266 if (!font) {
2267 wfatal(_("could not load any usable font!!!"));
2268 exit(1);
2271 if (ret)
2272 *ret = font;
2274 /* can't assign font value outside update function */
2275 wassertrv(addr == NULL, True);
2277 return True;
2281 static int
2282 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2283 void **ret)
2285 static XColor color;
2286 char *val;
2287 int second_pass=0;
2289 GET_STRING_OR_DEFAULT("Color", val);
2292 again:
2293 if (!wGetColor(scr, val, &color)) {
2294 wwarning(_("could not get color for key \"%s\""),
2295 entry->key);
2296 if (second_pass==0) {
2297 val = PLGetString(entry->plvalue);
2298 second_pass = 1;
2299 wwarning(_("using default \"%s\" instead"), val);
2300 goto again;
2302 return False;
2305 if (ret)
2306 *ret = &color;
2308 assert(addr==NULL);
2310 if (addr)
2311 *(unsigned long*)addr = pixel;
2314 return True;
2319 static int
2320 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2321 void **ret)
2323 static WShortKey shortcut;
2324 KeySym ksym;
2325 char *val;
2326 char *k;
2327 char buf[128], *b;
2330 GET_STRING_OR_DEFAULT("Key spec", val);
2332 if (!val || strcasecmp(val, "NONE")==0) {
2333 shortcut.keycode = 0;
2334 shortcut.modifier = 0;
2335 if (ret)
2336 *ret = &shortcut;
2337 return True;
2340 strcpy(buf, val);
2342 b = (char*)buf;
2344 /* get modifiers */
2345 shortcut.modifier = 0;
2346 while ((k = strchr(b, '+'))!=NULL) {
2347 int mod;
2349 *k = 0;
2350 mod = wXModifierFromKey(b);
2351 if (mod<0) {
2352 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2353 return False;
2355 shortcut.modifier |= mod;
2357 b = k+1;
2360 /* get key */
2361 ksym = XStringToKeysym(b);
2363 if (ksym==NoSymbol) {
2364 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2365 val);
2366 return False;
2369 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2370 if (shortcut.keycode==0) {
2371 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2372 return False;
2375 if (ret)
2376 *ret = &shortcut;
2378 return True;
2382 static int
2383 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2384 void **ret)
2386 static unsigned int mask;
2387 char *str;
2389 GET_STRING_OR_DEFAULT("Modifier Key", str);
2391 if (!str)
2392 return False;
2394 mask = wXModifierFromKey(str);
2395 if (mask < 0) {
2396 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2397 mask = 0;
2398 return False;
2401 if (addr)
2402 *(unsigned int*)addr = mask;
2404 if (ret)
2405 *ret = &mask;
2407 return True;
2411 #ifdef NEWSTUFF
2412 static int
2413 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2414 void *addr, void **ret)
2416 unsigned int mask;
2417 char *str;
2418 RImage *image;
2419 int i, n;
2420 int w, h;
2422 GET_STRING_OR_DEFAULT("Image File Path", str);
2423 if (!str)
2424 return False;
2426 image = RLoadImage(scr->rcontext, str, 0);
2427 if (!image) {
2428 wwarning(_("could not load image in option %s: %s"), entry->key,
2429 RMessageForError(RErrorCode));
2430 return False;
2433 if (*(RImage**)addr) {
2434 RDestroyImage(*(RImage**)addr);
2436 if (addr)
2437 *(RImage**)addr = image;
2439 assert(ret == NULL);
2441 if (ret)
2442 *(RImage**)ret = image;
2445 return True;
2447 #endif
2449 #ifdef DEFINABLE_CURSOR
2451 # include <X11/cursorfont.h>
2452 typedef struct
2454 char *name;
2455 int id;
2456 } WCursorLookup;
2458 #define CURSOR_ID_NONE (XC_num_glyphs)
2460 static WCursorLookup cursor_table[] =
2462 { "X_cursor", XC_X_cursor },
2463 { "arrow", XC_arrow },
2464 { "based_arrow_down", XC_based_arrow_down },
2465 { "based_arrow_up", XC_based_arrow_up },
2466 { "boat", XC_boat },
2467 { "bogosity", XC_bogosity },
2468 { "bottom_left_corner", XC_bottom_left_corner },
2469 { "bottom_right_corner", XC_bottom_right_corner },
2470 { "bottom_side", XC_bottom_side },
2471 { "bottom_tee", XC_bottom_tee },
2472 { "box_spiral", XC_box_spiral },
2473 { "center_ptr", XC_center_ptr },
2474 { "circle", XC_circle },
2475 { "clock", XC_clock },
2476 { "coffee_mug", XC_coffee_mug },
2477 { "cross", XC_cross },
2478 { "cross_reverse", XC_cross_reverse },
2479 { "crosshair", XC_crosshair },
2480 { "diamond_cross", XC_diamond_cross },
2481 { "dot", XC_dot },
2482 { "dotbox", XC_dotbox },
2483 { "double_arrow", XC_double_arrow },
2484 { "draft_large", XC_draft_large },
2485 { "draft_small", XC_draft_small },
2486 { "draped_box", XC_draped_box },
2487 { "exchange", XC_exchange },
2488 { "fleur", XC_fleur },
2489 { "gobbler", XC_gobbler },
2490 { "gumby", XC_gumby },
2491 { "hand1", XC_hand1 },
2492 { "hand2", XC_hand2 },
2493 { "heart", XC_heart },
2494 { "icon", XC_icon },
2495 { "iron_cross", XC_iron_cross },
2496 { "left_ptr", XC_left_ptr },
2497 { "left_side", XC_left_side },
2498 { "left_tee", XC_left_tee },
2499 { "leftbutton", XC_leftbutton },
2500 { "ll_angle", XC_ll_angle },
2501 { "lr_angle", XC_lr_angle },
2502 { "man", XC_man },
2503 { "middlebutton", XC_middlebutton },
2504 { "mouse", XC_mouse },
2505 { "pencil", XC_pencil },
2506 { "pirate", XC_pirate },
2507 { "plus", XC_plus },
2508 { "question_arrow", XC_question_arrow },
2509 { "right_ptr", XC_right_ptr },
2510 { "right_side", XC_right_side },
2511 { "right_tee", XC_right_tee },
2512 { "rightbutton", XC_rightbutton },
2513 { "rtl_logo", XC_rtl_logo },
2514 { "sailboat", XC_sailboat },
2515 { "sb_down_arrow", XC_sb_down_arrow },
2516 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2517 { "sb_left_arrow", XC_sb_left_arrow },
2518 { "sb_right_arrow", XC_sb_right_arrow },
2519 { "sb_up_arrow", XC_sb_up_arrow },
2520 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2521 { "shuttle", XC_shuttle },
2522 { "sizing", XC_sizing },
2523 { "spider", XC_spider },
2524 { "spraycan", XC_spraycan },
2525 { "star", XC_star },
2526 { "target", XC_target },
2527 { "tcross", XC_tcross },
2528 { "top_left_arrow", XC_top_left_arrow },
2529 { "top_left_corner", XC_top_left_corner },
2530 { "top_right_corner", XC_top_right_corner },
2531 { "top_side", XC_top_side },
2532 { "top_tee", XC_top_tee },
2533 { "trek", XC_trek },
2534 { "ul_angle", XC_ul_angle },
2535 { "umbrella", XC_umbrella },
2536 { "ur_angle", XC_ur_angle },
2537 { "watch", XC_watch },
2538 { "xterm", XC_xterm },
2539 { NULL, CURSOR_ID_NONE }
2542 static void
2543 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2545 switch(status) {
2546 case BitmapOpenFailed:
2547 wwarning(_("failed to open bitmap file \"%s\""), filename);
2548 break;
2549 case BitmapFileInvalid:
2550 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2551 break;
2552 case BitmapNoMemory:
2553 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2554 break;
2555 case BitmapSuccess:
2556 XFreePixmap(dpy, bitmap);
2557 break;
2562 * (none)
2563 * (builtin, <cursor_name>)
2564 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2566 static int
2567 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2569 proplist_t elem;
2570 char *val;
2571 int nelem;
2572 int status = 0;
2574 nelem = PLGetNumberOfElements(pl);
2575 if (nelem < 1) {
2576 return(status);
2578 elem = PLGetArrayElement(pl, 0);
2579 if (!elem || !PLIsString(elem)) {
2580 return(status);
2582 val = PLGetString(elem);
2584 if (0 == strcasecmp(val, "none")) {
2585 status = 1;
2586 *cursor = None;
2587 } else if (0 == strcasecmp(val, "builtin")) {
2588 int i;
2589 int cursor_id = CURSOR_ID_NONE;
2591 if (2 != nelem) {
2592 wwarning(_("bad number of arguments in cursor specification"));
2593 return(status);
2595 elem = PLGetArrayElement(pl, 1);
2596 if (!elem || !PLIsString(elem)) {
2597 return(status);
2599 val = PLGetString(elem);
2601 for (i = 0; NULL != cursor_table[i].name; i++) {
2602 if (0 == strcasecmp(val, cursor_table[i].name)) {
2603 cursor_id = cursor_table[i].id;
2604 break;
2607 if (CURSOR_ID_NONE == cursor_id) {
2608 wwarning(_("unknown builtin cursor name \"%s\""), val);
2609 } else {
2610 *cursor = XCreateFontCursor(dpy, cursor_id);
2611 status = 1;
2613 } else if (0 == strcasecmp(val, "bitmap")) {
2614 char *bitmap_name;
2615 char *mask_name;
2616 int bitmap_status;
2617 int mask_status;
2618 Pixmap bitmap;
2619 Pixmap mask;
2620 unsigned int w, h;
2621 int x, y;
2622 XColor fg, bg;
2624 if (3 != nelem) {
2625 wwarning(_("bad number of arguments in cursor specification"));
2626 return(status);
2628 elem = PLGetArrayElement(pl, 1);
2629 if (!elem || !PLIsString(elem)) {
2630 return(status);
2632 val = PLGetString(elem);
2633 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2634 if (!bitmap_name) {
2635 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2636 return(status);
2638 elem = PLGetArrayElement(pl, 2);
2639 if (!elem || !PLIsString(elem)) {
2640 wfree(bitmap_name);
2641 return(status);
2643 val = PLGetString(elem);
2644 mask_name = FindImage(wPreferences.pixmap_path, val);
2645 if (!mask_name) {
2646 wfree(bitmap_name);
2647 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2648 return(status);
2650 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2651 &mask, &x, &y);
2652 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2653 &bitmap, &x, &y);
2654 if ((BitmapSuccess == bitmap_status) &&
2655 (BitmapSuccess == mask_status)) {
2656 fg.pixel = scr->black_pixel;
2657 bg.pixel = scr->white_pixel;
2658 XQueryColor(dpy, scr->w_colormap, &fg);
2659 XQueryColor(dpy, scr->w_colormap, &bg);
2660 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2661 status = 1;
2663 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2664 check_bitmap_status(mask_status, mask_name, mask);
2665 wfree(bitmap_name);
2666 wfree(mask_name);
2668 return(status);
2672 static int
2673 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2674 void **ret)
2676 static Cursor cursor;
2677 int status;
2678 int changed = 0;
2680 again:
2681 if (!PLIsArray(value)) {
2682 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2683 entry->key, "cursor specification");
2684 if (!changed) {
2685 value = entry->plvalue;
2686 changed = 1;
2687 wwarning(_("using default \"%s\" instead"), entry->default_value);
2688 goto again;
2690 return(False);
2692 status = parse_cursor(scr, value, &cursor);
2693 if (!status) {
2694 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2695 if (!changed) {
2696 value = entry->plvalue;
2697 changed = 1;
2698 wwarning(_("using default \"%s\" instead"), entry->default_value);
2699 goto again;
2701 return(False);
2703 if (ret) {
2704 *ret = &cursor;
2706 if (addr) {
2707 *(Cursor *)addr = cursor;
2709 return(True);
2711 #undef CURSOR_ID_NONE
2713 #endif /* DEFINABLE_CURSOR */
2716 /* ---------------- value setting functions --------------- */
2717 static int
2718 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2720 return REFRESH_WINDOW_TITLE_COLOR;
2723 static int
2724 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2726 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2729 static int
2730 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2732 switch (which) {
2733 case WM_DOCK:
2734 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2735 break;
2736 case WM_CLIP:
2737 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2738 break;
2739 default:
2740 break;
2742 return 0;
2746 static int
2747 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2749 if (scr->workspaces) {
2750 wWorkspaceForceChange(scr, scr->current_workspace);
2751 wArrangeIcons(scr, False);
2753 return 0;
2756 #if not_used
2757 static int
2758 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2760 if (*value <= 0)
2761 *(int*)foo = 1;
2763 return 0;
2765 #endif
2769 static int
2770 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2772 Pixmap pixmap;
2773 RImage *img;
2774 int reset = 0;
2776 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2777 wPreferences.icon_size,
2778 ((*texture)->any.type & WREL_BORDER_MASK)
2779 ? WREL_ICON : WREL_FLAT);
2780 if (!img) {
2781 wwarning(_("could not render texture for icon background"));
2782 if (!entry->addr)
2783 wTextureDestroy(scr, *texture);
2784 return 0;
2786 RConvertImage(scr->rcontext, img, &pixmap);
2788 if (scr->icon_tile) {
2789 reset = 1;
2790 RDestroyImage(scr->icon_tile);
2791 XFreePixmap(dpy, scr->icon_tile_pixmap);
2794 scr->icon_tile = img;
2797 /* put the icon in the noticeboard hint */
2798 PropSetIconTileHint(scr, img);
2801 if (!wPreferences.flags.noclip) {
2802 if (scr->clip_tile) {
2803 RDestroyImage(scr->clip_tile);
2805 scr->clip_tile = wClipMakeTile(scr, img);
2808 scr->icon_tile_pixmap = pixmap;
2810 if (scr->def_icon_pixmap) {
2811 XFreePixmap(dpy, scr->def_icon_pixmap);
2812 scr->def_icon_pixmap = None;
2814 if (scr->def_ticon_pixmap) {
2815 XFreePixmap(dpy, scr->def_ticon_pixmap);
2816 scr->def_ticon_pixmap = None;
2819 if (scr->icon_back_texture) {
2820 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2822 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2824 if (scr->clip_balloon)
2825 XSetWindowBackground(dpy, scr->clip_balloon,
2826 (*texture)->any.color.pixel);
2829 * Free the texture as nobody else will use it, nor refer to it.
2831 if (!entry->addr)
2832 wTextureDestroy(scr, *texture);
2834 return (reset ? REFRESH_ICON_TILE : 0);
2839 static int
2840 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2842 if (scr->title_font) {
2843 WMReleaseFont(scr->title_font);
2845 scr->title_font = font;
2847 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2851 static int
2852 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2854 if (scr->menu_title_font) {
2855 WMReleaseFont(scr->menu_title_font);
2858 scr->menu_title_font = font;
2860 return REFRESH_MENU_TITLE_FONT;
2864 static int
2865 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2867 if (scr->menu_entry_font) {
2868 WMReleaseFont(scr->menu_entry_font);
2870 scr->menu_entry_font = font;
2872 return REFRESH_MENU_FONT;
2877 static int
2878 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2880 if (scr->icon_title_font) {
2881 WMReleaseFont(scr->icon_title_font);
2884 scr->icon_title_font = font;
2886 return REFRESH_ICON_FONT;
2890 static int
2891 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2893 if (scr->clip_title_font) {
2894 WMReleaseFont(scr->clip_title_font);
2897 scr->clip_title_font = font;
2899 return REFRESH_ICON_FONT;
2903 static int
2904 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2906 if (scr->workspace_name_font) {
2907 WMReleaseFont(scr->workspace_name_font);
2910 scr->workspace_name_font = font;
2912 return 0;
2916 static int
2917 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2919 if (scr->select_pixel!=scr->white_pixel &&
2920 scr->select_pixel!=scr->black_pixel) {
2921 wFreeColor(scr, scr->select_pixel);
2924 scr->select_pixel = color->pixel;
2926 return REFRESH_MENU_COLOR;
2930 static int
2931 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2933 if (scr->select_text_pixel!=scr->white_pixel &&
2934 scr->select_text_pixel!=scr->black_pixel) {
2935 wFreeColor(scr, scr->select_text_pixel);
2938 scr->select_text_pixel = color->pixel;
2940 return REFRESH_MENU_COLOR;
2944 static int
2945 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2947 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2948 scr->clip_title_pixel[index]!=scr->black_pixel) {
2949 wFreeColor(scr, scr->clip_title_pixel[index]);
2951 scr->clip_title_pixel[index] = color->pixel;
2953 #ifdef GRADIENT_CLIP_ARROW
2954 if (index == CLIP_NORMAL) {
2955 RImage *image;
2956 RColor color1, color2;
2957 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2958 int as = pt - 15; /* 15 = 5+5+5 */
2960 FREE_PIXMAP(scr->clip_arrow_gradient);
2962 color1.red = (color->red >> 8)*6/10;
2963 color1.green = (color->green >> 8)*6/10;
2964 color1.blue = (color->blue >> 8)*6/10;
2966 color2.red = WMIN((color->red >> 8)*20/10, 255);
2967 color2.green = WMIN((color->green >> 8)*20/10, 255);
2968 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2970 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2971 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2972 RDestroyImage(image);
2974 #endif /* GRADIENT_CLIP_ARROW */
2976 return REFRESH_ICON_TITLE_COLOR;
2980 static int
2981 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2983 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2984 scr->window_title_pixel[index]!=scr->black_pixel) {
2985 wFreeColor(scr, scr->window_title_pixel[index]);
2988 scr->window_title_pixel[index] = color->pixel;
2990 if (index == WS_UNFOCUSED)
2991 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2993 return REFRESH_WINDOW_TITLE_COLOR;
2997 static int
2998 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3000 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3001 scr->menu_title_pixel[0]!=scr->black_pixel) {
3002 wFreeColor(scr, scr->menu_title_pixel[0]);
3005 scr->menu_title_pixel[0] = color->pixel;
3006 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3008 return REFRESH_MENU_TITLE_COLOR;
3012 static int
3013 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3015 XGCValues gcv;
3016 #define gcm (GCForeground|GCBackground|GCFillStyle)
3018 if (scr->mtext_pixel!=scr->white_pixel &&
3019 scr->mtext_pixel!=scr->black_pixel) {
3020 wFreeColor(scr, scr->mtext_pixel);
3023 scr->mtext_pixel = color->pixel;
3025 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3028 if (scr->dtext_pixel == scr->mtext_pixel) {
3029 gcv.foreground = scr->white_pixel;
3030 gcv.background = scr->black_pixel;
3031 gcv.fill_style = FillStippled;
3032 } else {
3033 gcv.foreground = scr->dtext_pixel;
3034 gcv.fill_style = FillSolid;
3036 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3038 return REFRESH_MENU_COLOR;
3039 #undef gcm
3043 static int
3044 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3046 XGCValues gcv;
3047 #define gcm (GCForeground|GCBackground|GCFillStyle)
3049 if (scr->dtext_pixel!=scr->white_pixel &&
3050 scr->dtext_pixel!=scr->black_pixel) {
3051 wFreeColor(scr, scr->dtext_pixel);
3054 scr->dtext_pixel = color->pixel;
3056 if (scr->dtext_pixel == scr->mtext_pixel) {
3057 gcv.foreground = scr->white_pixel;
3058 gcv.background = scr->black_pixel;
3059 gcv.fill_style = FillStippled;
3060 } else {
3061 gcv.foreground = scr->dtext_pixel;
3062 gcv.fill_style = FillSolid;
3064 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3066 return REFRESH_MENU_COLOR;
3067 #undef gcm
3070 static int
3071 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3073 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3075 return REFRESH_ICON_TITLE_COLOR;
3079 static int
3080 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3082 if (scr->icon_title_texture) {
3083 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3085 XQueryColor (dpy, scr->w_colormap, color);
3086 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3088 return REFRESH_ICON_TITLE_BACK;
3092 static void
3093 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3095 close(scr->helper_fd);
3096 scr->helper_fd = 0;
3097 scr->helper_pid = 0;
3098 scr->flags.backimage_helper_launched = 0;
3102 static int
3103 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3104 void *bar)
3106 int i;
3107 proplist_t val;
3108 char *str;
3110 if (scr->flags.backimage_helper_launched) {
3111 if (PLGetNumberOfElements(value)==0) {
3112 SendHelperMessage(scr, 'C', 0, NULL);
3113 SendHelperMessage(scr, 'K', 0, NULL);
3115 PLRelease(value);
3116 return 0;
3118 } else {
3119 pid_t pid;
3120 int filedes[2];
3122 if (PLGetNumberOfElements(value) == 0)
3123 return 0;
3125 if (pipe(filedes) < 0) {
3126 wsyserror("pipe() failed:can't set workspace specific background image");
3128 PLRelease(value);
3129 return 0;
3132 pid = fork();
3133 if (pid < 0) {
3134 wsyserror("fork() failed:can't set workspace specific background image");
3135 if (close(filedes[0]) < 0)
3136 wsyserror("could not close pipe");
3137 if (close(filedes[1]) < 0)
3138 wsyserror("could not close pipe");
3140 } else if (pid == 0) {
3141 char *dither;
3143 SetupEnvironment(scr);
3145 if (close(0) < 0)
3146 wsyserror("could not close pipe");
3147 if (dup(filedes[0]) < 0) {
3148 wsyserror("dup() failed:can't set workspace specific background image");
3150 dither = wPreferences.no_dithering ? "-m" : "-d";
3151 if (wPreferences.smooth_workspace_back)
3152 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3153 else
3154 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3155 wsyserror("could not execute wmsetbg");
3156 exit(1);
3157 } else {
3159 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3160 wsyserror("error setting close-on-exec flag");
3162 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3163 wsyserror("error setting close-on-exec flag");
3166 scr->helper_fd = filedes[1];
3167 scr->helper_pid = pid;
3168 scr->flags.backimage_helper_launched = 1;
3170 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3172 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3177 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3178 val = PLGetArrayElement(value, i);
3179 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3180 str = PLGetDescription(val);
3182 SendHelperMessage(scr, 'S', i+1, str);
3184 wfree(str);
3185 } else {
3186 SendHelperMessage(scr, 'U', i+1, NULL);
3189 sleep(1);
3191 PLRelease(value);
3192 return 0;
3196 static int
3197 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3198 void *bar)
3200 if (scr->flags.backimage_helper_launched) {
3201 char *str;
3203 if (PLGetNumberOfElements(value)==0) {
3204 SendHelperMessage(scr, 'U', 0, NULL);
3205 } else {
3206 /* set the default workspace background to this one */
3207 str = PLGetDescription(value);
3208 if (str) {
3209 SendHelperMessage(scr, 'S', 0, str);
3210 wfree(str);
3211 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3212 } else {
3213 SendHelperMessage(scr, 'U', 0, NULL);
3216 } else if (PLGetNumberOfElements(value) > 0) {
3217 char *command;
3218 char *text;
3219 char *dither;
3221 SetupEnvironment(scr);
3222 text = PLGetDescription(value);
3223 command = wmalloc(strlen(text)+40);
3224 dither = wPreferences.no_dithering ? "-m" : "-d";
3225 if (wPreferences.smooth_workspace_back)
3226 sprintf(command, "wmsetbg %s -S -p '%s' &", dither, text);
3227 else
3228 sprintf(command, "wmsetbg %s -p '%s' &", dither, text);
3229 wfree(text);
3230 system(command);
3231 wfree(command);
3233 PLRelease(value);
3235 return 0;
3239 static int
3240 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3242 if (scr->widget_texture) {
3243 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3245 scr->widget_texture = *(WTexSolid**)texture;
3247 return 0;
3251 static int
3252 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3254 if (scr->window_title_texture[WS_FOCUSED]) {
3255 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3257 scr->window_title_texture[WS_FOCUSED] = *texture;
3259 return REFRESH_WINDOW_TEXTURES;
3263 static int
3264 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3266 if (scr->window_title_texture[WS_PFOCUSED]) {
3267 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3269 scr->window_title_texture[WS_PFOCUSED] = *texture;
3271 return REFRESH_WINDOW_TEXTURES;
3275 static int
3276 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3278 if (scr->window_title_texture[WS_UNFOCUSED]) {
3279 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3281 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3283 return REFRESH_WINDOW_TEXTURES;
3287 static int
3288 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3290 if (scr->resizebar_texture[0]) {
3291 wTextureDestroy(scr, scr->resizebar_texture[0]);
3293 scr->resizebar_texture[0] = *texture;
3295 return REFRESH_WINDOW_TEXTURES;
3299 static int
3300 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3302 if (scr->menu_title_texture[0]) {
3303 wTextureDestroy(scr, scr->menu_title_texture[0]);
3305 scr->menu_title_texture[0] = *texture;
3307 return REFRESH_MENU_TITLE_TEXTURE;
3311 static int
3312 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3314 if (scr->menu_item_texture) {
3315 wTextureDestroy(scr, scr->menu_item_texture);
3316 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3318 scr->menu_item_texture = *texture;
3320 scr->menu_item_auxtexture
3321 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3323 return REFRESH_MENU_TEXTURE;
3327 static int
3328 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3330 WWindow *wwin;
3331 wKeyBindings[index] = *shortcut;
3333 wwin = scr->focused_window;
3335 while (wwin!=NULL) {
3336 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3338 if (!WFLAGP(wwin, no_bind_keys)) {
3339 wWindowSetKeyGrabs(wwin);
3341 wwin = wwin->prev;
3344 return 0;
3348 static int
3349 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3351 wArrangeIcons(scr, True);
3353 return 0;
3357 static int
3358 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3360 wScreenUpdateUsableArea(scr);
3362 return 0;
3366 static int
3367 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3369 return REFRESH_MENU_TEXTURE;
3374 static int
3375 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3377 return REFRESH_BUTTON_IMAGES;
3382 * Very ugly kluge.
3383 * Need access to the double click variables, so that all widgets in
3384 * wmaker panels will have the same dbl-click values.
3385 * TODO: figure a better way of dealing with it.
3387 #include <WINGs/WINGsP.h>
3389 static int
3390 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3392 extern _WINGsConfiguration WINGsConfiguration;
3394 if (*value <= 0)
3395 *(int*)foo = 1;
3397 WINGsConfiguration.doubleClickDelay = *value;
3399 return 0;
3403 #if 0
3404 static int
3405 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3407 extern _WINGsConfiguration WINGsConfiguration;
3409 WINGsConfiguration.useMultiByte = *value;
3411 return 0;
3413 #endif
3415 #ifdef DEFINABLE_CURSOR
3416 static int
3417 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3419 if (None != wCursor[index])
3421 XFreeCursor(dpy, wCursor[index]);
3424 wCursor[index] = *cursor;
3426 if ((WCUR_ROOT == index) && (None != *cursor))
3428 XDefineCursor(dpy, scr->root_win, *cursor);
3431 return 0;
3433 #endif /* DEFINABLE_CURSOR*/