updated get/setstyle for new options
[wmaker-crm.git] / src / defaults.c
blobf34029e9974dda63d1df1969e810de0350936c9a
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1998 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
25 #include "plugin.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
45 #ifndef PATH_MAX
46 #define PATH_MAX DEFAULT_PATH_MAX
47 #endif
49 #include <X11/Xlib.h>
50 #include <X11/Xutil.h>
51 #include <X11/keysym.h>
53 #include <wraster.h>
56 #include "WindowMaker.h"
57 #include "wcore.h"
58 #include "framewin.h"
59 #include "window.h"
60 #include "texture.h"
61 #include "screen.h"
62 #include "resources.h"
63 #include "defaults.h"
64 #include "keybind.h"
65 #include "xmodifier.h"
66 #include "icon.h"
67 #include "funcs.h"
68 #include "actions.h"
69 #include "dock.h"
70 #include "workspace.h"
71 #include "properties.h"
75 * Our own proplist reader parser. This one will not accept any
76 * syntax errors and is more descriptive in the error messages.
77 * It also doesn't seem to crash.
79 extern proplist_t ReadProplistFromFile(char *file);
82 /***** Global *****/
84 extern WDDomain *WDWindowMaker;
85 extern WDDomain *WDWindowAttributes;
86 extern WDDomain *WDRootMenu;
88 extern int wScreenCount;
90 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
91 extern Atom _XA_WINDOWMAKER_ICON_TILE;
94 extern proplist_t wDomainName;
95 extern proplist_t wAttributeDomainName;
97 extern WPreferences wPreferences;
99 extern WShortKey wKeyBindings[WKBD_LAST];
101 typedef struct {
102 char *key;
103 char *default_value;
104 void *extra_data;
105 void *addr;
106 int (*convert)();
107 int (*update)();
108 proplist_t plkey;
109 proplist_t plvalue; /* default value */
110 } WDefaultEntry;
113 /* used to map strings to integers */
114 typedef struct {
115 char *string;
116 short value;
117 char is_alias;
118 } WOptionEnumeration;
121 /* type converters */
122 static int getBool();
123 static int getInt();
124 static int getCoord();
125 #if 0
126 /* this is not used yet */
127 static int getString();
128 #endif
129 static int getPathList();
130 static int getEnum();
131 static int getTexture();
132 #ifdef DRAWSTRING_PLUGIN
133 static int getTextRenderer();
134 #endif
135 static int getWSBackground();
136 static int getWSSpecificBackground();
137 static int getFont();
138 static int getColor();
139 static int getKeybind();
140 static int getModMask();
141 #ifdef NEWSTUFF
142 static int getRImage();
143 #endif
146 /* value setting functions */
147 static int setJustify();
148 static int setClearance();
149 static int setIfDockPresent();
150 static int setStickyIcons();
152 static int setPositive();
154 static int setWidgetColor();
155 static int setIconTile();
156 static int setWinTitleFont();
157 static int setMenuTitleFont();
158 static int setMenuTextFont();
159 static int setIconTitleFont();
160 static int setIconTitleColor();
161 static int setIconTitleBack();
162 static int setLargeDisplayFont();
163 static int setWTitleColor();
164 static int setFTitleBack();
165 static int setPTitleBack();
166 static int setUTitleBack();
167 static int setResizebarBack();
168 static int setWorkspaceBack();
169 static int setWorkspaceSpecificBack();
170 static int setMenuTitleColor();
171 static int setMenuTextColor();
172 static int setMenuDisabledColor();
173 static int setMenuTitleBack();
174 static int setMenuTextBack();
175 static int setHightlight();
176 static int setHightlightText();
177 static int setKeyGrab();
178 static int setDoubleClick();
179 static int setIconPosition();
181 static int setClipTitleFont();
182 static int setClipTitleColor();
184 static int setMenuStyle();
185 static int setMultiByte();
187 static int updateUsableArea();
189 #ifdef DEFINABLE_CURSOR
190 extern Cursor wCursor[WCUR_LAST];
191 static int getCursor();
192 static int setCursor();
193 #endif
197 * Tables to convert strings to enumeration values.
198 * Values stored are char
202 /* WARNING: sum of length of all value strings must not exceed
203 * this value */
204 #define TOTAL_VALUES_LENGTH 80
209 #define REFRESH_WINDOW_TEXTURES (1<<0)
210 #define REFRESH_MENU_TEXTURE (1<<1)
211 #define REFRESH_MENU_FONT (1<<2)
212 #define REFRESH_MENU_COLOR (1<<3)
213 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
214 #define REFRESH_MENU_TITLE_FONT (1<<5)
215 #define REFRESH_MENU_TITLE_COLOR (1<<6)
216 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
217 #define REFRESH_WINDOW_FONT (1<<8)
218 #define REFRESH_ICON_TILE (1<<9)
219 #define REFRESH_ICON_FONT (1<<10)
220 #define REFRESH_WORKSPACE_BACK (1<<11)
222 #define REFRESH_BUTTON_IMAGES (1<<12)
224 #define REFRESH_ICON_TITLE_COLOR (1<<13)
225 #define REFRESH_ICON_TITLE_BACK (1<<14)
229 static WOptionEnumeration seFocusModes[] = {
230 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
231 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
232 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
233 {NULL, 0, 0}
236 static WOptionEnumeration seColormapModes[] = {
237 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
238 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
239 {NULL, 0, 0}
242 static WOptionEnumeration sePlacements[] = {
243 {"Auto", WPM_AUTO, 0},
244 {"Smart", WPM_SMART, 0},
245 {"Cascade", WPM_CASCADE, 0},
246 {"Random", WPM_RANDOM, 0},
247 {"Manual", WPM_MANUAL, 0},
248 {NULL, 0, 0}
251 static WOptionEnumeration seGeomDisplays[] = {
252 {"Center", WDIS_CENTER, 0},
253 {"Corner", WDIS_TOPLEFT, 0},
254 {"Floating", WDIS_FRAME_CENTER, 0},
255 {"Line", WDIS_NEW, 0},
256 {NULL, 0, 0}
259 static WOptionEnumeration seSpeeds[] = {
260 {"UltraFast", SPEED_ULTRAFAST, 0},
261 {"Fast", SPEED_FAST, 0},
262 {"Medium", SPEED_MEDIUM, 0},
263 {"Slow", SPEED_SLOW, 0},
264 {"UltraSlow", SPEED_ULTRASLOW, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seMouseButtons[] = {
269 {"None", -1, 0},
270 {"Left", Button1, 0}, {"Button1", Button1, 1},
271 {"Middle", Button2, 0}, {"Button2", Button2, 1},
272 {"Right", Button3, 0}, {"Button3", Button3, 1},
273 {"Button4", Button4, 0},
274 {"Button5", Button5, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seIconificationStyles[] = {
279 {"Zoom", WIS_ZOOM, 0},
280 {"Twist", WIS_TWIST, 0},
281 {"Flip", WIS_FLIP, 0},
282 {"None", WIS_NONE, 0},
283 {"random", WIS_RANDOM, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seJustifications[] = {
288 {"Left", WTJ_LEFT, 0},
289 {"Center", WTJ_CENTER, 0},
290 {"Right", WTJ_RIGHT, 0},
291 {NULL, 0, 0}
294 static WOptionEnumeration seIconPositions[] = {
295 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
296 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
297 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
298 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
299 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
300 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
301 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
302 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
303 {NULL, 0, 0}
306 static WOptionEnumeration seMenuStyles[] = {
307 {"normal", MS_NORMAL, 0},
308 {"singletexture", MS_SINGLE_TEXTURE, 0},
309 {"flat", MS_FLAT, 0},
310 {NULL, 0, 0}
314 static WOptionEnumeration seDisplayPositions[] = {
315 {"none", WD_NONE, 0},
316 {"center", WD_CENTER, 0},
317 {"top", WD_TOP, 0},
318 {"bottom", WD_BOTTOM, 0},
319 {"topleft", WD_TOPLEFT, 0},
320 {"topright", WD_TOPRIGHT, 0},
321 {"bottomleft", WD_BOTTOMLEFT, 0},
322 {"bottomright", WD_BOTTOMRIGHT, 0}
327 * ALL entries in the tables bellow, NEED to have a default value
328 * defined, and this value needs to be correct.
331 /* these options will only affect the window manager on startup
333 * static defaults can't access the screen data, because it is
334 * created after these defaults are read
336 WDefaultEntry staticOptionList[] = {
338 {"ColormapSize", "4", NULL,
339 &wPreferences.cmap_size, getInt, NULL
341 {"DisableDithering", "NO", NULL,
342 &wPreferences.no_dithering, getBool, NULL
344 /* static by laziness */
345 {"IconSize", "64", NULL,
346 &wPreferences.icon_size, getInt, NULL
348 {"ModifierKey", "Mod1", NULL,
349 &wPreferences.modifier_mask, getModMask, NULL
351 {"DisableWSMouseActions", "NO", NULL,
352 &wPreferences.disable_root_mouse, getBool, NULL
354 {"FocusMode", "manual", seFocusModes,
355 &wPreferences.focus_mode, getEnum, NULL
356 }, /* have a problem when switching from manual to sloppy without restart */
357 {"NewStyle", "NO", NULL,
358 &wPreferences.new_style, getBool, NULL
360 {"DisableDock", "NO", (void*) WM_DOCK,
361 NULL, getBool, setIfDockPresent
363 {"DisableClip", "NO", (void*) WM_CLIP,
364 NULL, getBool, setIfDockPresent
366 {"DisableMiniwindows", "NO", NULL,
367 &wPreferences.disable_miniwindows, getBool, NULL
369 {"MultiByteText", "NO", NULL,
370 &wPreferences.multi_byte_text, getBool, setMultiByte
376 WDefaultEntry optionList[] = {
377 /* dynamic options */
378 {"IconPosition", "blh", seIconPositions,
379 &wPreferences.icon_yard, getEnum, setIconPosition
381 {"IconificationStyle", "Zoom", seIconificationStyles,
382 &wPreferences.iconification_style, getEnum, NULL
384 {"SelectWindowsMouseButton", "Left", seMouseButtons,
385 &wPreferences.select_button, getEnum, NULL
387 {"WindowListMouseButton", "Middle", seMouseButtons,
388 &wPreferences.windowl_button, getEnum, NULL
390 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
391 &wPreferences.menu_button, getEnum, NULL
393 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
394 &wPreferences.pixmap_path, getPathList, NULL
396 {"IconPath", DEF_ICON_PATHS, NULL,
397 &wPreferences.icon_path, getPathList, NULL
399 {"ColormapMode", "auto", seColormapModes,
400 &wPreferences.colormap_mode, getEnum, NULL
402 {"AutoFocus", "NO", NULL,
403 &wPreferences.auto_focus, getBool, NULL
405 {"RaiseDelay", "0", NULL,
406 &wPreferences.raise_delay, getInt, NULL
408 {"WindowsCycling", "YES", NULL,
409 &wPreferences.windows_cycling,getBool, NULL
411 {"CirculateRaise", "NO", NULL,
412 &wPreferences.circ_raise, getBool, NULL
414 {"Superfluous", "NO", NULL,
415 &wPreferences.superfluous, getBool, NULL
417 {"AdvanceToNewWorkspace", "NO", NULL,
418 &wPreferences.ws_advance, getBool, NULL
420 {"CycleWorkspaces", "NO", NULL,
421 &wPreferences.ws_cycle, getBool, NULL
423 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
424 &wPreferences.workspace_name_display_position, getEnum, NULL
426 #ifdef VIRTUAL_DESKTOP
427 {"VirtualEdgeThickness", "1", NULL,
428 &wPreferences.vedge_thickness, getInt, NULL
430 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
431 &wPreferences.vedge_hscrollspeed, getInt, NULL
433 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
434 &wPreferences.vedge_vscrollspeed, getInt, NULL
436 {"VirtualEdgeWidth", "2000", NULL,
437 &wPreferences.vedge_width, getInt, NULL
439 {"VirtualEdgeHeight", "2000", NULL,
440 &wPreferences.vedge_height, getInt, NULL
442 #endif
443 {"StickyIcons", "NO", NULL,
444 &wPreferences.sticky_icons, getBool, setStickyIcons
446 {"SaveSessionOnExit", "NO", NULL,
447 &wPreferences.save_session_on_exit, getBool, NULL
449 {"WrapMenus", "NO", NULL,
450 &wPreferences.wrap_menus, getBool, NULL
452 {"ScrollableMenus", "NO", NULL,
453 &wPreferences.scrollable_menus, getBool, NULL
455 {"MenuScrollSpeed", "medium", seSpeeds,
456 &wPreferences.menu_scroll_speed, getEnum, NULL
458 {"IconSlideSpeed", "medium", seSpeeds,
459 &wPreferences.icon_slide_speed, getEnum, NULL
461 {"ShadeSpeed", "medium", seSpeeds,
462 &wPreferences.shade_speed, getEnum, NULL
464 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
465 &wPreferences.dblclick_time, getInt, setDoubleClick,
467 {"AlignSubmenus", "NO", NULL,
468 &wPreferences.align_menus, getBool, NULL
470 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
471 &wPreferences.open_transients_with_parent, getBool, NULL
473 {"WindowPlacement", "auto", sePlacements,
474 &wPreferences.window_placement, getEnum, NULL
476 {"IgnoreFocusClick","NO", NULL,
477 &wPreferences.ignore_focus_click, getBool, NULL
479 {"UseSaveUnders", "NO", NULL,
480 &wPreferences.use_saveunders, getBool, NULL
482 {"OpaqueMove", "NO", NULL,
483 &wPreferences.opaque_move, getBool, NULL
485 {"DisableSound", "NO", NULL,
486 &wPreferences.no_sound, getBool, NULL
488 {"DisableAnimations", "NO", NULL,
489 &wPreferences.no_animations, getBool, NULL
491 {"DontLinkWorkspaces","NO", NULL,
492 &wPreferences.no_autowrap, getBool, NULL
494 {"AutoArrangeIcons", "NO", NULL,
495 &wPreferences.auto_arrange_icons, getBool, NULL
497 {"NoWindowOverDock", "NO", NULL,
498 &wPreferences.no_window_over_dock, getBool, updateUsableArea
500 {"NoWindowOverIcons", "NO", NULL,
501 &wPreferences.no_window_over_icons, getBool, updateUsableArea
503 {"WindowPlaceOrigin", "(0, 0)", NULL,
504 &wPreferences.window_place_origin, getCoord, NULL
506 {"ResizeDisplay", "corner", seGeomDisplays,
507 &wPreferences.size_display, getEnum, NULL
509 {"MoveDisplay", "corner", seGeomDisplays,
510 &wPreferences.move_display, getEnum, NULL
512 {"DontConfirmKill", "NO", NULL,
513 &wPreferences.dont_confirm_kill, getBool,NULL
515 {"WindowTitleBalloons", "NO", NULL,
516 &wPreferences.window_balloon, getBool, NULL
518 {"MiniwindowTitleBalloons", "NO", NULL,
519 &wPreferences.miniwin_balloon,getBool, NULL
521 {"AppIconBalloons", "NO", NULL,
522 &wPreferences.appicon_balloon,getBool, NULL
524 {"HelpBalloons", "NO", NULL,
525 &wPreferences.help_balloon, getBool, NULL
527 {"EdgeResistance", "30", NULL,
528 &wPreferences.edge_resistance,getInt, NULL
530 {"Attraction", "NO", NULL,
531 &wPreferences.attract, getBool, NULL
533 {"DisableBlinking", "NO", NULL,
534 &wPreferences.dont_blink, getBool, NULL
536 /* style options */
537 {"MenuStyle", "normal", seMenuStyles,
538 &wPreferences.menu_style, getEnum, setMenuStyle
540 {"WidgetColor", "(solid, gray)", NULL,
541 NULL, getTexture, setWidgetColor,
543 {"WorkspaceSpecificBack","()", NULL,
544 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
546 /* WorkspaceBack must come after WorkspaceSpecificBack or
547 * WorkspaceBack wont know WorkspaceSpecificBack was also
548 * specified and 2 copies of wmsetbg will be launched */
549 {"WorkspaceBack", "(solid, black)", NULL,
550 NULL, getWSBackground,setWorkspaceBack
552 {"SmoothWorkspaceBack", "NO", NULL,
553 NULL, getBool, NULL
555 {"IconBack", "(solid, gray)", NULL,
556 NULL, getTexture, setIconTile
558 {"TitleJustify", "center", seJustifications,
559 &wPreferences.title_justification, getEnum, setJustify
561 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
562 NULL, getFont, setWinTitleFont,
564 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
565 &wPreferences.window_title_clearance, getInt, setClearance
567 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
568 &wPreferences.menu_title_clearance, getInt, setClearance
570 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
571 &wPreferences.menu_text_clearance, getInt, setClearance
573 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
574 NULL, getFont, setMenuTitleFont
576 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
577 NULL, getFont, setMenuTextFont
579 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
580 NULL, getFont, setIconTitleFont
582 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
583 NULL, getFont, setClipTitleFont
585 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
586 NULL, getFont, setLargeDisplayFont
588 {"HighlightColor", "white", NULL,
589 NULL, getColor, setHightlight
591 {"HighlightTextColor", "black", NULL,
592 NULL, getColor, setHightlightText
594 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
595 NULL, getColor, setClipTitleColor
597 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
598 NULL, getColor, setClipTitleColor
600 #ifdef DRAWSTRING_PLUGIN
601 {"FTitleColor", "white", (void*)WS_FOCUSED,
602 NULL, getTextRenderer, setWTitleColor
604 {"PTitleColor", "white", (void*)WS_PFOCUSED,
605 NULL, getTextRenderer, setWTitleColor
607 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
608 NULL, getTextRenderer, setWTitleColor
610 #else
611 {"FTitleColor", "white", (void*)WS_FOCUSED,
612 NULL, getColor, setWTitleColor
614 {"PTitleColor", "white", (void*)WS_PFOCUSED,
615 NULL, getColor, setWTitleColor
617 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
618 NULL, getColor, setWTitleColor
620 #endif
621 {"FTitleBack", "(solid, black)", NULL,
622 NULL, getTexture, setFTitleBack
624 {"PTitleBack", "(solid, \"#616161\")", NULL,
625 NULL, getTexture, setPTitleBack
627 {"UTitleBack", "(solid, gray)", NULL,
628 NULL, getTexture, setUTitleBack
630 {"ResizebarBack", "(solid, gray)", NULL,
631 NULL, getTexture, setResizebarBack
633 #ifdef DRAWSTRING_PLUGIN
634 {"MenuTitleColor", "white", NULL,
635 NULL, getTextRenderer, setMenuTitleColor
637 #else
638 {"MenuTitleColor", "white", NULL,
639 NULL, getColor, setMenuTitleColor
641 #endif
642 {"MenuTextColor", "black", NULL,
643 NULL, getColor, setMenuTextColor
645 {"MenuDisabledColor", "\"#616161\"", NULL,
646 NULL, getColor, setMenuDisabledColor
648 {"MenuTitleBack", "(solid, black)", NULL,
649 NULL, getTexture, setMenuTitleBack
651 {"MenuTextBack", "(solid, gray)", NULL,
652 NULL, getTexture, setMenuTextBack
654 {"IconTitleColor", "white", NULL,
655 NULL, getColor, setIconTitleColor
657 {"IconTitleBack", "black", NULL,
658 NULL, getColor, setIconTitleBack
660 /* keybindings */
661 #ifndef LITE
662 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
663 NULL, getKeybind, setKeyGrab
665 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
666 NULL, getKeybind, setKeyGrab
668 #endif /* LITE */
669 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
670 NULL, getKeybind, setKeyGrab
672 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
673 NULL, getKeybind, setKeyGrab
675 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
676 NULL, getKeybind, setKeyGrab
678 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
679 NULL, getKeybind, setKeyGrab
681 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
682 NULL, getKeybind, setKeyGrab
684 {"HideKey", "None", (void*)WKBD_HIDE,
685 NULL, getKeybind, setKeyGrab
687 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
688 NULL, getKeybind, setKeyGrab
690 {"CloseKey", "None", (void*)WKBD_CLOSE,
691 NULL, getKeybind, setKeyGrab
693 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
694 NULL, getKeybind, setKeyGrab
696 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
697 NULL, getKeybind, setKeyGrab
699 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
700 NULL, getKeybind, setKeyGrab
702 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
703 NULL, getKeybind, setKeyGrab
705 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
706 NULL, getKeybind, setKeyGrab
708 {"ShadeKey", "None", (void*)WKBD_SHADE,
709 NULL, getKeybind, setKeyGrab
711 {"SelectKey", "None", (void*)WKBD_SELECT,
712 NULL, getKeybind, setKeyGrab
714 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
715 NULL, getKeybind, setKeyGrab
717 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
718 NULL, getKeybind, setKeyGrab
720 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
721 NULL, getKeybind, setKeyGrab
723 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
724 NULL, getKeybind, setKeyGrab
726 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
727 NULL, getKeybind, setKeyGrab
729 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
730 NULL, getKeybind, setKeyGrab
732 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
733 NULL, getKeybind, setKeyGrab
735 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
760 NULL, getKeybind, setKeyGrab
762 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
763 NULL, getKeybind, setKeyGrab
765 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
766 NULL, getKeybind, setKeyGrab
768 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
772 NULL, getKeybind, setKeyGrab
774 #ifdef EXTEND_WINDOWSHORTCUT
775 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
776 NULL, getKeybind, setKeyGrab
778 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
779 NULL, getKeybind, setKeyGrab
781 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
782 NULL, getKeybind, setKeyGrab
784 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
785 NULL, getKeybind, setKeyGrab
787 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
788 NULL, getKeybind, setKeyGrab
790 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
791 NULL, getKeybind, setKeyGrab
793 #endif /* EXTEND_WINDOWSHORTCUT */
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 free(domain->path);
922 free(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 free(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 free(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 free(*(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 * (tpixmap <file> <color>)
1705 * (spixmap <file> <color>)
1706 * (cpixmap <file> <color>)
1707 * (thgradient <file> <opaqueness> <color> <color>)
1708 * (tvgradient <file> <opaqueness> <color> <color>)
1709 * (tdgradient <file> <opaqueness> <color> <color>)
1710 * (function <lib> <function> ...)
1713 static WTexture*
1714 parse_texture(WScreen *scr, proplist_t pl)
1716 proplist_t elem;
1717 char *val;
1718 int nelem;
1719 WTexture *texture=NULL;
1721 nelem = PLGetNumberOfElements(pl);
1722 if (nelem < 1)
1723 return NULL;
1726 elem = PLGetArrayElement(pl, 0);
1727 if (!elem || !PLIsString(elem))
1728 return NULL;
1729 val = PLGetString(elem);
1732 if (strcasecmp(val, "solid")==0) {
1733 XColor color;
1735 if (nelem != 2)
1736 return NULL;
1738 /* get color */
1740 elem = PLGetArrayElement(pl, 1);
1741 if (!elem || !PLIsString(elem))
1742 return NULL;
1743 val = PLGetString(elem);
1745 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1746 wwarning(_("\"%s\" is not a valid color name"), val);
1747 return NULL;
1750 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1751 } else if (strcasecmp(val, "dgradient")==0
1752 || strcasecmp(val, "vgradient")==0
1753 || strcasecmp(val, "hgradient")==0) {
1754 RColor color1, color2;
1755 XColor xcolor;
1756 int type;
1758 if (nelem != 3) {
1759 wwarning(_("bad number of arguments in gradient specification"));
1760 return NULL;
1763 if (val[0]=='d' || val[0]=='D')
1764 type = WTEX_DGRADIENT;
1765 else if (val[0]=='h' || val[0]=='H')
1766 type = WTEX_HGRADIENT;
1767 else
1768 type = WTEX_VGRADIENT;
1771 /* get from color */
1772 elem = PLGetArrayElement(pl, 1);
1773 if (!elem || !PLIsString(elem))
1774 return NULL;
1775 val = PLGetString(elem);
1777 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1778 wwarning(_("\"%s\" is not a valid color name"), val);
1779 return NULL;
1781 color1.alpha = 255;
1782 color1.red = xcolor.red >> 8;
1783 color1.green = xcolor.green >> 8;
1784 color1.blue = xcolor.blue >> 8;
1786 /* get to color */
1787 elem = PLGetArrayElement(pl, 2);
1788 if (!elem || !PLIsString(elem)) {
1789 return NULL;
1791 val = PLGetString(elem);
1793 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1794 wwarning(_("\"%s\" is not a valid color name"), val);
1795 return NULL;
1797 color2.alpha = 255;
1798 color2.red = xcolor.red >> 8;
1799 color2.green = xcolor.green >> 8;
1800 color2.blue = xcolor.blue >> 8;
1802 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1804 } else if (strcasecmp(val, "mhgradient")==0
1805 || strcasecmp(val, "mvgradient")==0
1806 || strcasecmp(val, "mdgradient")==0) {
1807 XColor color;
1808 RColor **colors;
1809 int i, count;
1810 int type;
1812 if (nelem < 3) {
1813 wwarning(_("too few arguments in multicolor gradient specification"));
1814 return NULL;
1817 if (val[1]=='h' || val[1]=='H')
1818 type = WTEX_MHGRADIENT;
1819 else if (val[1]=='v' || val[1]=='V')
1820 type = WTEX_MVGRADIENT;
1821 else
1822 type = WTEX_MDGRADIENT;
1824 count = nelem-1;
1826 colors = wmalloc(sizeof(RColor*)*(count+1));
1828 for (i=0; i<count; i++) {
1829 elem = PLGetArrayElement(pl, i+1);
1830 if (!elem || !PLIsString(elem)) {
1831 for (--i; i>=0; --i) {
1832 free(colors[i]);
1834 free(colors);
1835 return NULL;
1837 val = PLGetString(elem);
1839 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1840 wwarning(_("\"%s\" is not a valid color name"), val);
1841 for (--i; i>=0; --i) {
1842 free(colors[i]);
1844 free(colors);
1845 return NULL;
1846 } else {
1847 colors[i] = wmalloc(sizeof(RColor));
1848 colors[i]->red = color.red >> 8;
1849 colors[i]->green = color.green >> 8;
1850 colors[i]->blue = color.blue >> 8;
1853 colors[i] = NULL;
1855 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1856 } else if (strcasecmp(val, "spixmap")==0 ||
1857 strcasecmp(val, "cpixmap")==0 ||
1858 strcasecmp(val, "tpixmap")==0) {
1859 XColor color;
1860 int type;
1862 if (nelem != 3)
1863 return NULL;
1865 if (val[0] == 's' || val[0] == 'S')
1866 type = WTP_SCALE;
1867 else if (val[0] == 'c' || val[0] == 'C')
1868 type = WTP_CENTER;
1869 else
1870 type = WTP_TILE;
1872 /* get color */
1873 elem = PLGetArrayElement(pl, 2);
1874 if (!elem || !PLIsString(elem)) {
1875 return NULL;
1877 val = PLGetString(elem);
1879 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1880 wwarning(_("\"%s\" is not a valid color name"), val);
1881 return NULL;
1884 /* file name */
1885 elem = PLGetArrayElement(pl, 1);
1886 if (!elem || !PLIsString(elem))
1887 return NULL;
1888 val = PLGetString(elem);
1890 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1891 } else if (strcasecmp(val, "thgradient")==0
1892 || strcasecmp(val, "tvgradient")==0
1893 || strcasecmp(val, "tdgradient")==0) {
1894 RColor color1, color2;
1895 XColor xcolor;
1896 int opacity;
1897 int style;
1899 if (val[1]=='h' || val[1]=='H')
1900 style = WTEX_THGRADIENT;
1901 else if (val[1]=='v' || val[1]=='V')
1902 style = WTEX_TVGRADIENT;
1903 else
1904 style = WTEX_TDGRADIENT;
1906 if (nelem != 5) {
1907 wwarning(_("bad number of arguments in textured gradient specification"));
1908 return NULL;
1911 /* get from color */
1912 elem = PLGetArrayElement(pl, 3);
1913 if (!elem || !PLIsString(elem))
1914 return NULL;
1915 val = PLGetString(elem);
1917 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1918 wwarning(_("\"%s\" is not a valid color name"), val);
1919 return NULL;
1921 color1.alpha = 255;
1922 color1.red = xcolor.red >> 8;
1923 color1.green = xcolor.green >> 8;
1924 color1.blue = xcolor.blue >> 8;
1926 /* get to color */
1927 elem = PLGetArrayElement(pl, 4);
1928 if (!elem || !PLIsString(elem)) {
1929 return NULL;
1931 val = PLGetString(elem);
1933 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1934 wwarning(_("\"%s\" is not a valid color name"), val);
1935 return NULL;
1937 color2.alpha = 255;
1938 color2.red = xcolor.red >> 8;
1939 color2.green = xcolor.green >> 8;
1940 color2.blue = xcolor.blue >> 8;
1942 /* get opacity */
1943 elem = PLGetArrayElement(pl, 2);
1944 if (!elem || !PLIsString(elem))
1945 opacity = 128;
1946 else
1947 val = PLGetString(elem);
1949 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1950 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1951 opacity = 128;
1954 /* get file name */
1955 elem = PLGetArrayElement(pl, 1);
1956 if (!elem || !PLIsString(elem))
1957 return NULL;
1958 val = PLGetString(elem);
1960 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
1961 val, opacity);
1963 #ifdef TEXTURE_PLUGIN
1964 else if (strcasecmp(val, "function")==0) {
1965 WTexFunction *function;
1966 void (*initFunc) (Display *, Colormap);
1967 char *lib, *func, **argv;
1968 int i, argc;
1970 if (nelem < 3)
1971 return NULL;
1973 /* get the library name */
1974 elem = PLGetArrayElement(pl, 1);
1975 if (!elem || !PLIsString(elem)) {
1976 return NULL;
1978 lib = PLGetString(elem);
1980 /* get the function name */
1981 elem = PLGetArrayElement(pl, 2);
1982 if (!elem || !PLIsString(elem)) {
1983 return NULL;
1985 func = PLGetString(elem);
1987 argc = nelem - 2;
1988 argv = (char **)wmalloc(argc * sizeof(char *));
1990 /* get the parameters */
1991 argv[0] = wstrdup(func);
1992 for (i = 0; i < argc - 1; i++) {
1993 elem = PLGetArrayElement(pl, 3 + i);
1994 if (!elem || !PLIsString(elem)) {
1995 free(argv);
1997 return NULL;
1999 argv[i+1] = wstrdup(PLGetString(elem));
2002 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2004 #ifdef HAVE_DLFCN_H
2005 if (function) {
2006 initFunc = dlsym(function->handle, "initWindowMaker");
2007 if (initFunc) {
2008 initFunc(dpy, scr->w_colormap);
2009 } else {
2010 wwarning(_("could not initialize library %s"), lib);
2012 } else {
2013 wwarning(_("could not find function %s::%s"), lib, func);
2015 #endif /* HAVE_DLFCN_H */
2016 texture = (WTexture*)function;
2018 #endif /* TEXTURE_PLUGIN */
2019 else {
2020 wwarning(_("invalid texture type %s"), val);
2021 return NULL;
2023 return texture;
2028 static int
2029 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2030 void **ret)
2032 static WTexture *texture;
2033 int changed=0;
2035 again:
2036 if (!PLIsArray(value)) {
2037 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2038 entry->key, "Texture");
2039 if (changed==0) {
2040 value = entry->plvalue;
2041 changed = 1;
2042 wwarning(_("using default \"%s\" instead"), entry->default_value);
2043 goto again;
2045 return False;
2048 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2049 proplist_t pl;
2051 pl = PLGetArrayElement(value, 0);
2052 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2053 || strcasecmp(PLGetString(pl), "solid")!=0) {
2054 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2055 entry->key, "Solid Texture");
2057 value = entry->plvalue;
2058 changed = 1;
2059 wwarning(_("using default \"%s\" instead"), entry->default_value);
2060 goto again;
2064 texture = parse_texture(scr, value);
2066 if (!texture) {
2067 wwarning(_("Error in texture specification for key \"%s\""),
2068 entry->key);
2069 if (changed==0) {
2070 value = entry->plvalue;
2071 changed = 1;
2072 wwarning(_("using default \"%s\" instead"), entry->default_value);
2073 goto again;
2075 return False;
2078 if (ret)
2079 *ret = &texture;
2081 if (addr)
2082 *(WTexture**)addr = texture;
2084 return True;
2089 #ifdef DRAWSTRING_PLUGIN
2090 static int
2091 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2092 void *addr, void **ret)
2094 proplist_t elem;
2095 char *val, *lib, *func, **argv;
2096 int argc, changed;
2098 if (strcmp(entry->key, "FTitleColor")==0) {
2099 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2100 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2101 } else if (strcmp(entry->key, "UTitleColor")==0) {
2102 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2103 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2104 } else if (strcmp(entry->key, "PTitleColor")==0) {
2105 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2106 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2107 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2108 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2109 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2110 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2111 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2112 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2115 if (PLIsArray(value)) {
2116 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2117 argc -= 2;
2118 argv = (char **)wmalloc(argc * sizeof(char *));
2120 elem = PLGetArrayElement(value,0);
2121 if (!elem || !PLIsString(elem)) return False;
2122 val = PLGetString(elem);
2123 if (strcasecmp(val, "function")==0) {
2124 elem = PLGetArrayElement(value, 1); /* library name */
2125 if (!elem || !PLIsString(elem)) return False;
2126 lib = PLGetString(elem);
2127 elem = PLGetArrayElement(value, 2); /* function name */
2128 if (!elem || !PLIsString(elem)) return False;
2129 func = PLGetString(elem);
2130 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2131 lib, "initDrawString", func, NULL, value,
2132 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2135 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2136 } else if (PLIsString(value)) {
2137 return getColor(scr, entry, value, addr, ret);
2140 return False;
2142 #endif /* DRAWSTRING_PLUGIN */
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 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2541 switch(status) {
2542 case BitmapOpenFailed:
2543 wwarning(_("failed to open bitmap file \"%s\""), filename);
2544 break;
2545 case BitmapFileInvalid:
2546 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2547 break;
2548 case BitmapNoMemory:
2549 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2550 break;
2551 case BitmapSuccess:
2552 XFreePixmap(dpy, bitmap);
2553 break;
2558 * (none)
2559 * (builtin, <cursor_name>)
2560 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2562 static int parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2564 proplist_t elem;
2565 char *val;
2566 int nelem;
2567 int status = 0;
2569 nelem = PLGetNumberOfElements(pl);
2570 if (nelem < 1) {
2571 return(status);
2573 elem = PLGetArrayElement(pl, 0);
2574 if (!elem || !PLIsString(elem)) {
2575 return(status);
2577 val = PLGetString(elem);
2579 if (0 == strcasecmp(val, "none")) {
2580 status = 1;
2581 *cursor = None;
2582 } else if (0 == strcasecmp(val, "builtin")) {
2583 int i;
2584 int cursor_id = CURSOR_ID_NONE;
2586 if (2 != nelem) {
2587 wwarning(_("bad number of arguments in cursor specification"));
2588 return(status);
2590 elem = PLGetArrayElement(pl, 1);
2591 if (!elem || !PLIsString(elem)) {
2592 return(status);
2594 val = PLGetString(elem);
2596 for (i = 0; NULL != cursor_table[i].name; i++) {
2597 if (0 == strcasecmp(val, cursor_table[i].name)) {
2598 cursor_id = cursor_table[i].id;
2599 break;
2602 if (CURSOR_ID_NONE == cursor_id) {
2603 wwarning(_("unknown builtin cursor name \"%s\""), val);
2604 } else {
2605 *cursor = XCreateFontCursor(dpy, cursor_id);
2606 status = 1;
2608 } else if (0 == strcasecmp(val, "bitmap")) {
2609 char *bitmap_name;
2610 char *mask_name;
2611 int bitmap_status;
2612 int mask_status;
2613 Pixmap bitmap;
2614 Pixmap mask;
2615 unsigned int w, h;
2616 int x, y;
2617 XColor fg, bg;
2619 if (3 != nelem) {
2620 wwarning(_("bad number of arguments in cursor specification"));
2621 return(status);
2623 elem = PLGetArrayElement(pl, 1);
2624 if (!elem || !PLIsString(elem)) {
2625 return(status);
2627 val = PLGetString(elem);
2628 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2629 if (!bitmap_name) {
2630 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2631 return(status);
2633 elem = PLGetArrayElement(pl, 2);
2634 if (!elem || !PLIsString(elem)) {
2635 free(bitmap_name);
2636 return(status);
2638 val = PLGetString(elem);
2639 mask_name = FindImage(wPreferences.pixmap_path, val);
2640 if (!mask_name) {
2641 free(bitmap_name);
2642 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2643 return(status);
2645 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2646 &mask, &x, &y);
2647 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2648 &bitmap, &x, &y);
2649 if ((BitmapSuccess == bitmap_status) &&
2650 (BitmapSuccess == mask_status)) {
2651 fg.pixel = scr->black_pixel;
2652 bg.pixel = scr->white_pixel;
2653 XQueryColor(dpy, scr->w_colormap, &fg);
2654 XQueryColor(dpy, scr->w_colormap, &bg);
2655 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2656 status = 1;
2658 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2659 check_bitmap_status(mask_status, mask_name, mask);
2660 free(bitmap_name);
2661 free(mask_name);
2663 return(status);
2667 static int
2668 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2669 void **ret)
2671 static Cursor cursor;
2672 int status;
2673 int changed = 0;
2675 again:
2676 if (!PLIsArray(value)) {
2677 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2678 entry->key, "cursor specification");
2679 if (!changed) {
2680 value = entry->plvalue;
2681 changed = 1;
2682 wwarning(_("using default \"%s\" instead"), entry->default_value);
2683 goto again;
2685 return(False);
2687 status = parse_cursor(scr, value, &cursor);
2688 if (!status) {
2689 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2690 if (!changed) {
2691 value = entry->plvalue;
2692 changed = 1;
2693 wwarning(_("using default \"%s\" instead"), entry->default_value);
2694 goto again;
2696 return(False);
2698 if (ret) {
2699 *ret = &cursor;
2701 if (addr) {
2702 *(Cursor *)addr = cursor;
2704 return(True);
2706 #undef CURSOR_ID_NONE
2708 #endif /* DEFINABLE_CURSOR */
2711 /* ---------------- value setting functions --------------- */
2712 static int
2713 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2715 return REFRESH_WINDOW_TITLE_COLOR;
2718 static int
2719 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2721 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2724 static int
2725 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2727 switch (which) {
2728 case WM_DOCK:
2729 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2730 break;
2731 case WM_CLIP:
2732 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2733 break;
2734 default:
2735 break;
2737 return 0;
2741 static int
2742 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2744 if (scr->workspaces) {
2745 wWorkspaceForceChange(scr, scr->current_workspace);
2746 wArrangeIcons(scr, False);
2748 return 0;
2751 #if not_used
2752 static int
2753 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2755 if (*value <= 0)
2756 *(int*)foo = 1;
2758 return 0;
2760 #endif
2764 static int
2765 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2767 Pixmap pixmap;
2768 RImage *img;
2769 int reset = 0;
2771 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2772 wPreferences.icon_size,
2773 ((*texture)->any.type & WREL_BORDER_MASK)
2774 ? WREL_ICON : WREL_FLAT);
2775 if (!img) {
2776 wwarning(_("could not render texture for icon background"));
2777 if (!entry->addr)
2778 wTextureDestroy(scr, *texture);
2779 return 0;
2781 RConvertImage(scr->rcontext, img, &pixmap);
2783 if (scr->icon_tile) {
2784 reset = 1;
2785 RDestroyImage(scr->icon_tile);
2786 XFreePixmap(dpy, scr->icon_tile_pixmap);
2789 scr->icon_tile = img;
2792 /* put the icon in the noticeboard hint */
2793 PropSetIconTileHint(scr, img);
2796 if (!wPreferences.flags.noclip) {
2797 if (scr->clip_tile) {
2798 RDestroyImage(scr->clip_tile);
2800 scr->clip_tile = wClipMakeTile(scr, img);
2803 scr->icon_tile_pixmap = pixmap;
2805 if (scr->def_icon_pixmap) {
2806 XFreePixmap(dpy, scr->def_icon_pixmap);
2807 scr->def_icon_pixmap = None;
2809 if (scr->def_ticon_pixmap) {
2810 XFreePixmap(dpy, scr->def_ticon_pixmap);
2811 scr->def_ticon_pixmap = None;
2814 if (scr->icon_back_texture) {
2815 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2817 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2819 if (scr->clip_balloon)
2820 XSetWindowBackground(dpy, scr->clip_balloon,
2821 (*texture)->any.color.pixel);
2824 * Free the texture as nobody else will use it, nor refer to it.
2826 if (!entry->addr)
2827 wTextureDestroy(scr, *texture);
2829 return (reset ? REFRESH_ICON_TILE : 0);
2834 static int
2835 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2837 if (scr->title_font) {
2838 WMReleaseFont(scr->title_font);
2840 scr->title_font = font;
2842 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2846 static int
2847 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2849 if (scr->menu_title_font) {
2850 WMReleaseFont(scr->menu_title_font);
2853 scr->menu_title_font = font;
2855 return REFRESH_MENU_TITLE_FONT;
2859 static int
2860 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2862 if (scr->menu_entry_font) {
2863 WMReleaseFont(scr->menu_entry_font);
2865 scr->menu_entry_font = font;
2867 return REFRESH_MENU_FONT;
2872 static int
2873 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2875 if (scr->icon_title_font) {
2876 WMReleaseFont(scr->icon_title_font);
2879 scr->icon_title_font = font;
2881 return REFRESH_ICON_FONT;
2885 static int
2886 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2888 if (scr->clip_title_font) {
2889 WMReleaseFont(scr->clip_title_font);
2892 scr->clip_title_font = font;
2894 return REFRESH_ICON_FONT;
2898 static int
2899 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2901 if (scr->workspace_name_font) {
2902 WMReleaseFont(scr->workspace_name_font);
2905 scr->workspace_name_font = font;
2907 return 0;
2911 static int
2912 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2914 if (scr->select_pixel!=scr->white_pixel &&
2915 scr->select_pixel!=scr->black_pixel) {
2916 wFreeColor(scr, scr->select_pixel);
2919 scr->select_pixel = color->pixel;
2921 return REFRESH_MENU_COLOR;
2925 static int
2926 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2928 if (scr->select_text_pixel!=scr->white_pixel &&
2929 scr->select_text_pixel!=scr->black_pixel) {
2930 wFreeColor(scr, scr->select_text_pixel);
2933 scr->select_text_pixel = color->pixel;
2935 return REFRESH_MENU_COLOR;
2939 static int
2940 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2942 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2943 scr->clip_title_pixel[index]!=scr->black_pixel) {
2944 wFreeColor(scr, scr->clip_title_pixel[index]);
2946 scr->clip_title_pixel[index] = color->pixel;
2948 #ifdef GRADIENT_CLIP_ARROW
2949 if (index == CLIP_NORMAL) {
2950 RImage *image;
2951 RColor color1, color2;
2952 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2953 int as = pt - 15; /* 15 = 5+5+5 */
2955 FREE_PIXMAP(scr->clip_arrow_gradient);
2957 color1.red = (color->red >> 8)*6/10;
2958 color1.green = (color->green >> 8)*6/10;
2959 color1.blue = (color->blue >> 8)*6/10;
2961 color2.red = WMIN((color->red >> 8)*20/10, 255);
2962 color2.green = WMIN((color->green >> 8)*20/10, 255);
2963 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2965 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2966 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2967 RDestroyImage(image);
2969 #endif /* GRADIENT_CLIP_ARROW */
2971 return REFRESH_ICON_TITLE_COLOR;
2975 static int
2976 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2978 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2979 scr->window_title_pixel[index]!=scr->black_pixel) {
2980 wFreeColor(scr, scr->window_title_pixel[index]);
2983 scr->window_title_pixel[index] = color->pixel;
2985 if (index == WS_UNFOCUSED)
2986 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2988 return REFRESH_WINDOW_TITLE_COLOR;
2992 static int
2993 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2995 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2996 scr->menu_title_pixel[0]!=scr->black_pixel) {
2997 #ifdef DRAWSTRING_PLUGIN
2998 if(!scr->drawstring_func[W_STRING_MTITLE])
2999 #endif
3000 wFreeColor(scr, scr->menu_title_pixel[0]);
3003 scr->menu_title_pixel[0] = color->pixel;
3004 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3006 return REFRESH_MENU_TITLE_COLOR;
3010 static int
3011 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3013 XGCValues gcv;
3014 #define gcm (GCForeground|GCBackground|GCFillStyle)
3016 if (scr->mtext_pixel!=scr->white_pixel &&
3017 scr->mtext_pixel!=scr->black_pixel) {
3018 wFreeColor(scr, scr->mtext_pixel);
3021 scr->mtext_pixel = color->pixel;
3023 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3026 if (scr->dtext_pixel == scr->mtext_pixel) {
3027 gcv.foreground = scr->white_pixel;
3028 gcv.background = scr->black_pixel;
3029 gcv.fill_style = FillStippled;
3030 } else {
3031 gcv.foreground = scr->dtext_pixel;
3032 gcv.fill_style = FillSolid;
3034 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3036 return REFRESH_MENU_COLOR;
3037 #undef gcm
3041 static int
3042 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3044 XGCValues gcv;
3045 #define gcm (GCForeground|GCBackground|GCFillStyle)
3047 if (scr->dtext_pixel!=scr->white_pixel &&
3048 scr->dtext_pixel!=scr->black_pixel) {
3049 wFreeColor(scr, scr->dtext_pixel);
3052 scr->dtext_pixel = color->pixel;
3054 if (scr->dtext_pixel == scr->mtext_pixel) {
3055 gcv.foreground = scr->white_pixel;
3056 gcv.background = scr->black_pixel;
3057 gcv.fill_style = FillStippled;
3058 } else {
3059 gcv.foreground = scr->dtext_pixel;
3060 gcv.fill_style = FillSolid;
3062 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3064 return REFRESH_MENU_COLOR;
3065 #undef gcm
3068 static int
3069 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3071 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3073 return REFRESH_ICON_TITLE_COLOR;
3077 static int
3078 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3080 if (scr->icon_title_texture) {
3081 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3083 XQueryColor (dpy, scr->w_colormap, color);
3084 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3086 return REFRESH_ICON_TITLE_BACK;
3090 static void
3091 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3093 close(scr->helper_fd);
3094 scr->helper_fd = 0;
3095 scr->helper_pid = 0;
3096 scr->flags.backimage_helper_launched = 0;
3100 static int
3101 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3102 void *bar)
3104 int i;
3105 proplist_t val;
3106 char *str;
3108 if (scr->flags.backimage_helper_launched) {
3109 if (PLGetNumberOfElements(value)==0) {
3110 SendHelperMessage(scr, 'C', 0, NULL);
3111 SendHelperMessage(scr, 'K', 0, NULL);
3113 PLRelease(value);
3114 return 0;
3116 } else {
3117 pid_t pid;
3118 int filedes[2];
3120 if (PLGetNumberOfElements(value) == 0)
3121 return 0;
3123 if (pipe(filedes) < 0) {
3124 wsyserror("pipe() failed:can't set workspace specific background image");
3126 PLRelease(value);
3127 return 0;
3130 pid = fork();
3131 if (pid < 0) {
3132 wsyserror("fork() failed:can't set workspace specific background image");
3133 if (close(filedes[0]) < 0)
3134 wsyserror("could not close pipe");
3135 if (close(filedes[1]) < 0)
3136 wsyserror("could not close pipe");
3138 } else if (pid == 0) {
3139 SetupEnvironment(scr);
3141 if (close(0) < 0)
3142 wsyserror("could not close pipe");
3143 if (dup(filedes[0]) < 0) {
3144 wsyserror("dup() failed:can't set workspace specific background image");
3146 if (wPreferences.smooth_workspace_back)
3147 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3148 else
3149 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3150 wsyserror("could not execute wmsetbg");
3151 exit(1);
3152 } else {
3154 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3155 wsyserror("error setting close-on-exec flag");
3157 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3158 wsyserror("error setting close-on-exec flag");
3161 scr->helper_fd = filedes[1];
3162 scr->helper_pid = pid;
3163 scr->flags.backimage_helper_launched = 1;
3165 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3167 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3172 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3173 val = PLGetArrayElement(value, i);
3174 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3175 str = PLGetDescription(val);
3177 SendHelperMessage(scr, 'S', i+1, str);
3179 free(str);
3180 } else {
3181 SendHelperMessage(scr, 'U', i+1, NULL);
3184 sleep(1);
3186 PLRelease(value);
3187 return 0;
3191 static int
3192 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3193 void *bar)
3195 if (scr->flags.backimage_helper_launched) {
3196 char *str;
3198 if (PLGetNumberOfElements(value)==0) {
3199 SendHelperMessage(scr, 'U', 0, NULL);
3200 } else {
3201 /* set the default workspace background to this one */
3202 str = PLGetDescription(value);
3203 if (str) {
3204 SendHelperMessage(scr, 'S', 0, str);
3205 free(str);
3206 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3207 } else {
3208 SendHelperMessage(scr, 'U', 0, NULL);
3211 } else {
3212 char *command;
3213 char *text;
3215 SetupEnvironment(scr);
3216 text = PLGetDescription(value);
3217 command = wmalloc(strlen(text)+40);
3218 if (wPreferences.smooth_workspace_back)
3219 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3220 else
3221 sprintf(command, "wmsetbg -d -p '%s' &", text);
3222 free(text);
3223 system(command);
3224 free(command);
3226 PLRelease(value);
3228 return 0;
3232 static int
3233 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3235 if (scr->widget_texture) {
3236 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3238 scr->widget_texture = *(WTexSolid**)texture;
3240 return 0;
3244 static int
3245 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3247 if (scr->window_title_texture[WS_FOCUSED]) {
3248 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3250 scr->window_title_texture[WS_FOCUSED] = *texture;
3252 return REFRESH_WINDOW_TEXTURES;
3256 static int
3257 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3259 if (scr->window_title_texture[WS_PFOCUSED]) {
3260 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3262 scr->window_title_texture[WS_PFOCUSED] = *texture;
3264 return REFRESH_WINDOW_TEXTURES;
3268 static int
3269 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3271 if (scr->window_title_texture[WS_UNFOCUSED]) {
3272 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3274 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3276 return REFRESH_WINDOW_TEXTURES;
3280 static int
3281 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3283 if (scr->resizebar_texture[0]) {
3284 wTextureDestroy(scr, scr->resizebar_texture[0]);
3286 scr->resizebar_texture[0] = *texture;
3288 return REFRESH_WINDOW_TEXTURES;
3292 static int
3293 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3295 if (scr->menu_title_texture[0]) {
3296 wTextureDestroy(scr, scr->menu_title_texture[0]);
3298 scr->menu_title_texture[0] = *texture;
3300 return REFRESH_MENU_TITLE_TEXTURE;
3304 static int
3305 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3307 if (scr->menu_item_texture) {
3308 wTextureDestroy(scr, scr->menu_item_texture);
3309 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3311 scr->menu_item_texture = *texture;
3313 scr->menu_item_auxtexture
3314 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3316 return REFRESH_MENU_TEXTURE;
3320 static int
3321 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3323 WWindow *wwin;
3324 wKeyBindings[index] = *shortcut;
3326 wwin = scr->focused_window;
3328 while (wwin!=NULL) {
3329 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3331 if (!WFLAGP(wwin, no_bind_keys)) {
3332 wWindowSetKeyGrabs(wwin);
3334 wwin = wwin->prev;
3337 return 0;
3341 static int
3342 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3344 wArrangeIcons(scr, True);
3346 return 0;
3350 static int
3351 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3353 wScreenUpdateUsableArea(scr);
3355 return 0;
3359 static int
3360 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3362 return REFRESH_MENU_TEXTURE;
3367 static int
3368 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3370 return REFRESH_BUTTON_IMAGES;
3375 * Very ugly kluge.
3376 * Need access to the double click variables, so that all widgets in
3377 * wmaker panels will have the same dbl-click values.
3378 * TODO: figure a better way of dealing with it.
3380 #include "WINGsP.h"
3382 static int
3383 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3385 extern _WINGsConfiguration WINGsConfiguration;
3387 if (*value <= 0)
3388 *(int*)foo = 1;
3390 WINGsConfiguration.doubleClickDelay = *value;
3392 return 0;
3397 static int
3398 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3400 extern _WINGsConfiguration WINGsConfiguration;
3402 WINGsConfiguration.useMultiByte = *value;
3404 return 0;
3408 #ifdef DEFINABLE_CURSOR
3409 static int
3410 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3412 if (None != wCursor[index])
3414 XFreeCursor(dpy, wCursor[index]);
3417 wCursor[index] = *cursor;
3419 if ((WCUR_ROOT == index) && (None != *cursor))
3421 XDefineCursor(dpy, scr->root_win, *cursor);
3424 return 0;
3426 #endif /* DEFINABLE_CURSOR*/