added shortcut to switch screens
[wmaker-crm.git] / src / defaults.c
blob7d902ed7d28209ad257bcbc1e07dc9dca62ec64d
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;
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 #ifdef DRAWSTRING_PLUGIN
132 static int getTextRenderer();
133 #endif
134 static int getWSBackground();
135 static int getWSSpecificBackground();
136 static int getFont();
137 static int getColor();
138 static int getKeybind();
139 static int getModMask();
140 #ifdef NEWSTUFF
141 static int getRImage();
142 #endif
145 /* value setting functions */
146 static int setJustify();
147 static int setClearance();
148 static int setIfDockPresent();
149 static int setStickyIcons();
151 static int setPositive();
153 static int setWidgetColor();
154 static int setIconTile();
155 static int setWinTitleFont();
156 static int setMenuTitleFont();
157 static int setMenuTextFont();
158 static int setIconTitleFont();
159 static int setIconTitleColor();
160 static int setIconTitleBack();
161 static int setLargeDisplayFont();
162 static int setWTitleColor();
163 static int setFTitleBack();
164 static int setPTitleBack();
165 static int setUTitleBack();
166 static int setResizebarBack();
167 static int setWorkspaceBack();
168 static int setWorkspaceSpecificBack();
169 static int setMenuTitleColor();
170 static int setMenuTextColor();
171 static int setMenuDisabledColor();
172 static int setMenuTitleBack();
173 static int setMenuTextBack();
174 static int setHightlight();
175 static int setHightlightText();
176 static int setKeyGrab();
177 static int setDoubleClick();
178 static int setIconPosition();
180 static int setClipTitleFont();
181 static int setClipTitleColor();
183 static int setMenuStyle();
184 #if 0
185 static int setMultiByte();
186 #endif
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},
323 {NULL, 0, 0}
326 static WOptionEnumeration seWorkspaceBorder[] = {
327 {"None", WB_NONE, 0},
328 {"LeftRight", WB_LEFTRIGHT, 0},
329 {"TopBottom", WB_TOPBOTTOM, 0},
330 {"AllDirections", WB_ALLDIRS, 0},
331 {NULL, 0, 0}
336 * ALL entries in the tables bellow, NEED to have a default value
337 * defined, and this value needs to be correct.
340 /* these options will only affect the window manager on startup
342 * static defaults can't access the screen data, because it is
343 * created after these defaults are read
345 WDefaultEntry staticOptionList[] = {
347 {"ColormapSize", "4", NULL,
348 &wPreferences.cmap_size, getInt, NULL
350 {"DisableDithering", "NO", NULL,
351 &wPreferences.no_dithering, getBool, NULL
353 /* static by laziness */
354 {"IconSize", "64", NULL,
355 &wPreferences.icon_size, getInt, NULL
357 {"ModifierKey", "Mod1", NULL,
358 &wPreferences.modifier_mask, getModMask, NULL
360 {"DisableWSMouseActions", "NO", NULL,
361 &wPreferences.disable_root_mouse, getBool, NULL
363 {"FocusMode", "manual", seFocusModes,
364 &wPreferences.focus_mode, getEnum, NULL
365 }, /* have a problem when switching from manual to sloppy without restart */
366 {"NewStyle", "NO", NULL,
367 &wPreferences.new_style, getBool, NULL
369 {"DisableDock", "NO", (void*) WM_DOCK,
370 NULL, getBool, setIfDockPresent
372 {"DisableClip", "NO", (void*) WM_CLIP,
373 NULL, getBool, setIfDockPresent
375 {"DisableMiniwindows", "NO", NULL,
376 &wPreferences.disable_miniwindows, getBool, NULL
378 #if 0
379 ,{"MultiByteText", "NO", NULL,
380 &wPreferences.multi_byte_text, getBool, setMultiByte
382 #endif
387 WDefaultEntry optionList[] = {
388 /* dynamic options */
389 {"IconPosition", "blh", seIconPositions,
390 &wPreferences.icon_yard, getEnum, setIconPosition
392 {"IconificationStyle", "Zoom", seIconificationStyles,
393 &wPreferences.iconification_style, getEnum, NULL
395 {"SelectWindowsMouseButton", "Left", seMouseButtons,
396 &wPreferences.select_button, getEnum, NULL
398 {"WindowListMouseButton", "Middle", seMouseButtons,
399 &wPreferences.windowl_button, getEnum, NULL
401 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
402 &wPreferences.menu_button, getEnum, NULL
404 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
405 &wPreferences.pixmap_path, getPathList, NULL
407 {"IconPath", DEF_ICON_PATHS, NULL,
408 &wPreferences.icon_path, getPathList, NULL
410 {"ColormapMode", "auto", seColormapModes,
411 &wPreferences.colormap_mode, getEnum, NULL
413 {"AutoFocus", "NO", NULL,
414 &wPreferences.auto_focus, getBool, NULL
416 {"RaiseDelay", "0", NULL,
417 &wPreferences.raise_delay, getInt, NULL
419 {"WindozeCycling", "YES", NULL,
420 &wPreferences.windows_cycling,getBool, NULL
422 {"CirculateRaise", "NO", NULL,
423 &wPreferences.circ_raise, getBool, NULL
425 {"Superfluous", "NO", NULL,
426 &wPreferences.superfluous, getBool, NULL
428 {"AdvanceToNewWorkspace", "NO", NULL,
429 &wPreferences.ws_advance, getBool, NULL
431 {"CycleWorkspaces", "NO", NULL,
432 &wPreferences.ws_cycle, getBool, NULL
434 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
435 &wPreferences.workspace_name_display_position, getEnum, NULL
437 {"WorkspaceBorder", "None", seWorkspaceBorder,
438 &wPreferences.workspace_border_position, getEnum, updateUsableArea
440 {"WorkspaceBorderSize", "0", NULL,
441 &wPreferences.workspace_border_size, getInt, updateUsableArea
443 #ifdef VIRTUAL_DESKTOP
444 {"VirtualEdgeThickness", "1", NULL,
445 &wPreferences.vedge_thickness, getInt, NULL
447 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
448 &wPreferences.vedge_hscrollspeed, getInt, NULL
450 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
451 &wPreferences.vedge_vscrollspeed, getInt, NULL
453 {"VirtualEdgeWidth", "2000", NULL,
454 &wPreferences.vedge_width, getInt, NULL
456 {"VirtualEdgeHeight", "2000", NULL,
457 &wPreferences.vedge_height, 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 #ifdef DRAWSTRING_PLUGIN
618 {"FTitleColor", "white", (void*)WS_FOCUSED,
619 NULL, getTextRenderer, setWTitleColor
621 {"PTitleColor", "white", (void*)WS_PFOCUSED,
622 NULL, getTextRenderer, setWTitleColor
624 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
625 NULL, getTextRenderer, setWTitleColor
627 #else
628 {"FTitleColor", "white", (void*)WS_FOCUSED,
629 NULL, getColor, setWTitleColor
631 {"PTitleColor", "white", (void*)WS_PFOCUSED,
632 NULL, getColor, setWTitleColor
634 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
635 NULL, getColor, setWTitleColor
637 #endif
638 {"FTitleBack", "(solid, black)", NULL,
639 NULL, getTexture, setFTitleBack
641 {"PTitleBack", "(solid, \"#616161\")", NULL,
642 NULL, getTexture, setPTitleBack
644 {"UTitleBack", "(solid, gray)", NULL,
645 NULL, getTexture, setUTitleBack
647 {"ResizebarBack", "(solid, gray)", NULL,
648 NULL, getTexture, setResizebarBack
650 #ifdef DRAWSTRING_PLUGIN
651 {"MenuTitleColor", "white", NULL,
652 NULL, getTextRenderer, setMenuTitleColor
654 #else
655 {"MenuTitleColor", "white", NULL,
656 NULL, getColor, setMenuTitleColor
658 #endif
659 {"MenuTextColor", "black", NULL,
660 NULL, getColor, setMenuTextColor
662 {"MenuDisabledColor", "\"#616161\"", NULL,
663 NULL, getColor, setMenuDisabledColor
665 {"MenuTitleBack", "(solid, black)", NULL,
666 NULL, getTexture, setMenuTitleBack
668 {"MenuTextBack", "(solid, gray)", NULL,
669 NULL, getTexture, setMenuTextBack
671 {"IconTitleColor", "white", NULL,
672 NULL, getColor, setIconTitleColor
674 {"IconTitleBack", "black", NULL,
675 NULL, getColor, setIconTitleBack
677 /* keybindings */
678 #ifndef LITE
679 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
680 NULL, getKeybind, setKeyGrab
682 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
683 NULL, getKeybind, setKeyGrab
685 #endif /* LITE */
686 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
687 NULL, getKeybind, setKeyGrab
689 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
690 NULL, getKeybind, setKeyGrab
692 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
693 NULL, getKeybind, setKeyGrab
695 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
696 NULL, getKeybind, setKeyGrab
698 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
699 NULL, getKeybind, setKeyGrab
701 {"HideKey", "None", (void*)WKBD_HIDE,
702 NULL, getKeybind, setKeyGrab
704 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
705 NULL, getKeybind, setKeyGrab
707 {"CloseKey", "None", (void*)WKBD_CLOSE,
708 NULL, getKeybind, setKeyGrab
710 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
711 NULL, getKeybind, setKeyGrab
713 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
714 NULL, getKeybind, setKeyGrab
716 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
717 NULL, getKeybind, setKeyGrab
719 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
720 NULL, getKeybind, setKeyGrab
722 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
723 NULL, getKeybind, setKeyGrab
725 {"ShadeKey", "None", (void*)WKBD_SHADE,
726 NULL, getKeybind, setKeyGrab
728 {"SelectKey", "None", (void*)WKBD_SELECT,
729 NULL, getKeybind, setKeyGrab
731 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
732 NULL, getKeybind, setKeyGrab
734 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
735 NULL, getKeybind, setKeyGrab
737 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
738 NULL, getKeybind, setKeyGrab
740 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
741 NULL, getKeybind, setKeyGrab
743 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
744 NULL, getKeybind, setKeyGrab
746 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
756 NULL, getKeybind, setKeyGrab
758 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
759 NULL, getKeybind, setKeyGrab
761 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
762 NULL, getKeybind, setKeyGrab
764 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
765 NULL, getKeybind, setKeyGrab
767 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
768 NULL, getKeybind, setKeyGrab
770 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
771 NULL, getKeybind, setKeyGrab
773 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
774 NULL, getKeybind, setKeyGrab
776 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
783 NULL, getKeybind, setKeyGrab
785 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
786 NULL, getKeybind, setKeyGrab
788 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
789 NULL, getKeybind, setKeyGrab
791 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
792 NULL, getKeybind, setKeyGrab
794 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
795 NULL, getKeybind, setKeyGrab
797 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
798 NULL, getKeybind, setKeyGrab
800 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
801 NULL, getKeybind, setKeyGrab
803 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
804 NULL, getKeybind, setKeyGrab
806 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
807 NULL, getKeybind, setKeyGrab
809 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
810 NULL, getKeybind, setKeyGrab
813 #ifdef KEEP_XKB_LOCK_STATUS
814 ,{"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
815 NULL, getKeybind, setKeyGrab
817 {"KbdModeLock", "NO", NULL,
818 &wPreferences.modelock, getBool, NULL
820 #endif /* KEEP_XKB_LOCK_STATUS */
821 #ifdef DEFINABLE_CURSOR
822 ,{"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
823 NULL, getCursor, setCursor
825 ,{"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
826 NULL, getCursor, setCursor
828 #if 0
829 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
830 NULL, getCursor, setCursor
832 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
833 NULL, getCursor, setCursor
835 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
836 NULL, getCursor, setCursor
838 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
839 NULL, getCursor, setCursor
841 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
842 NULL, getCursor, setCursor
844 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
845 NULL, getCursor, setCursor
847 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
848 NULL, getCursor, setCursor
850 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
851 NULL, getCursor, setCursor
853 #endif
854 #endif /* DEFINABLE_CURSOR */
858 #if 0
859 static void rereadDefaults(void);
860 #endif
862 #if 0
863 static void
864 rereadDefaults(void)
866 /* must defer the update because accessing X data from a
867 * signal handler can mess up Xlib */
870 #endif
872 static void
873 initDefaults()
875 int i;
876 WDefaultEntry *entry;
878 PLSetStringCmpHook(StringCompareHook);
880 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
881 entry = &optionList[i];
883 entry->plkey = PLMakeString(entry->key);
884 if (entry->default_value)
885 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
886 else
887 entry->plvalue = NULL;
890 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
891 entry = &staticOptionList[i];
893 entry->plkey = PLMakeString(entry->key);
894 if (entry->default_value)
895 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
896 else
897 entry->plvalue = NULL;
901 wDomainName = PLMakeString(WMDOMAIN_NAME);
902 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
904 PLRegister(wDomainName, rereadDefaults);
905 PLRegister(wAttributeDomainName, rereadDefaults);
912 #if 0
913 proplist_t
914 wDefaultsInit(int screen_number)
916 static int defaults_inited = 0;
917 proplist_t dict;
919 if (!defaults_inited) {
920 initDefaults();
923 dict = PLGetDomain(wDomainName);
924 if (!dict) {
925 wwarning(_("could not read domain \"%s\" from defaults database"),
926 PLGetString(wDomainName));
929 return dict;
931 #endif
934 void
935 wDefaultsDestroyDomain(WDDomain *domain)
937 if (domain->dictionary)
938 PLRelease(domain->dictionary);
939 wfree(domain->path);
940 wfree(domain);
944 WDDomain*
945 wDefaultsInitDomain(char *domain, Bool requireDictionary)
947 WDDomain *db;
948 struct stat stbuf;
949 static int inited = 0;
950 char path[PATH_MAX];
951 char *the_path;
952 proplist_t shared_dict=NULL;
954 if (!inited) {
955 inited = 1;
956 initDefaults();
959 db = wmalloc(sizeof(WDDomain));
960 memset(db, 0, sizeof(WDDomain));
961 db->domain_name = domain;
962 db->path = wdefaultspathfordomain(domain);
963 the_path = db->path;
965 if (the_path && stat(the_path, &stbuf)>=0) {
966 db->dictionary = ReadProplistFromFile(the_path);
967 if (db->dictionary) {
968 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
969 PLRelease(db->dictionary);
970 db->dictionary = NULL;
971 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
972 domain, the_path);
974 db->timestamp = stbuf.st_mtime;
975 } else {
976 wwarning(_("could not load domain %s from user defaults database"),
977 domain);
981 /* global system dictionary */
982 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
983 if (stat(path, &stbuf)>=0) {
984 shared_dict = ReadProplistFromFile(path);
985 if (shared_dict) {
986 if (requireDictionary && !PLIsDictionary(shared_dict)) {
987 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
988 domain, path);
989 PLRelease(shared_dict);
990 shared_dict = NULL;
991 } else {
992 if (db->dictionary && PLIsDictionary(shared_dict) &&
993 PLIsDictionary(db->dictionary)) {
994 PLMergeDictionaries(shared_dict, db->dictionary);
995 PLRelease(db->dictionary);
996 db->dictionary = shared_dict;
997 if (stbuf.st_mtime > db->timestamp)
998 db->timestamp = stbuf.st_mtime;
999 } else if (!db->dictionary) {
1000 db->dictionary = shared_dict;
1001 if (stbuf.st_mtime > db->timestamp)
1002 db->timestamp = stbuf.st_mtime;
1005 } else {
1006 wwarning(_("could not load domain %s from global defaults database (%s)"),
1007 domain, path);
1011 /* set to save it in user's directory, no matter from where it was read */
1012 if (db->dictionary) {
1013 proplist_t tmp = PLMakeString(db->path);
1015 PLSetFilename(db->dictionary, tmp);
1016 PLRelease(tmp);
1019 return db;
1023 void
1024 wReadStaticDefaults(proplist_t dict)
1026 proplist_t plvalue;
1027 WDefaultEntry *entry;
1028 int i;
1029 void *tdata;
1032 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1033 entry = &staticOptionList[i];
1035 if (dict)
1036 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1037 else
1038 plvalue = NULL;
1040 if (!plvalue) {
1041 /* no default in the DB. Use builtin default */
1042 plvalue = entry->plvalue;
1045 if (plvalue) {
1046 /* convert data */
1047 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1048 if (entry->update) {
1049 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1056 void
1057 wDefaultsCheckDomains(void *foo)
1059 WScreen *scr;
1060 struct stat stbuf;
1061 proplist_t dict;
1062 int i;
1063 char path[PATH_MAX];
1065 #ifdef HEARTBEAT
1066 puts("Checking domains...");
1067 #endif
1068 if (stat(WDWindowMaker->path, &stbuf)>=0
1069 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1070 proplist_t shared_dict = NULL;
1071 #ifdef HEARTBEAT
1072 puts("Checking WindowMaker domain");
1073 #endif
1074 WDWindowMaker->timestamp = stbuf.st_mtime;
1076 /* global dictionary */
1077 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1078 if (stat(path, &stbuf)>=0) {
1079 shared_dict = ReadProplistFromFile(path);
1080 if (shared_dict && !PLIsDictionary(shared_dict)) {
1081 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1082 "WindowMaker", path);
1083 PLRelease(shared_dict);
1084 shared_dict = NULL;
1085 } else if (!shared_dict) {
1086 wwarning(_("could not load domain %s from global defaults database"),
1087 "WindowMaker");
1090 /* user dictionary */
1091 dict = ReadProplistFromFile(WDWindowMaker->path);
1092 if (dict) {
1093 if (!PLIsDictionary(dict)) {
1094 PLRelease(dict);
1095 dict = NULL;
1096 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1097 "WindowMaker", WDWindowMaker->path);
1098 } else {
1099 if (shared_dict) {
1100 PLSetFilename(shared_dict, PLGetFilename(dict));
1101 PLMergeDictionaries(shared_dict, dict);
1102 PLRelease(dict);
1103 dict = shared_dict;
1104 shared_dict = NULL;
1106 for (i=0; i<wScreenCount; i++) {
1107 scr = wScreenWithNumber(i);
1108 if (scr)
1109 wReadDefaults(scr, dict);
1111 if (WDWindowMaker->dictionary) {
1112 PLRelease(WDWindowMaker->dictionary);
1114 WDWindowMaker->dictionary = dict;
1116 } else {
1117 wwarning(_("could not load domain %s from user defaults database"),
1118 "WindowMaker");
1120 if (shared_dict) {
1121 PLRelease(shared_dict);
1125 if (stat(WDWindowAttributes->path, &stbuf)>=0
1126 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1127 #ifdef HEARTBEAT
1128 puts("Checking WMWindowAttributes domain");
1129 #endif
1130 dict = ReadProplistFromFile(WDWindowAttributes->path);
1131 if (dict) {
1132 if (!PLIsDictionary(dict)) {
1133 PLRelease(dict);
1134 dict = NULL;
1135 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1136 "WMWindowAttributes", WDWindowAttributes->path);
1137 } else {
1138 if (WDWindowAttributes->dictionary)
1139 PLRelease(WDWindowAttributes->dictionary);
1140 WDWindowAttributes->dictionary = dict;
1141 for (i=0; i<wScreenCount; i++) {
1142 scr = wScreenWithNumber(i);
1143 if (scr)
1144 wDefaultUpdateIcons(scr);
1147 } else {
1148 wwarning(_("could not load domain %s from user defaults database"),
1149 "WMWindowAttributes");
1151 WDWindowAttributes->timestamp = stbuf.st_mtime;
1154 if (!foo)
1155 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1159 void
1160 wReadDefaults(WScreen *scr, proplist_t new_dict)
1162 proplist_t plvalue, old_value;
1163 WDefaultEntry *entry;
1164 int i, must_update;
1165 int update_workspace_back = 0; /* kluge :/ */
1166 int needs_refresh;
1167 void *tdata;
1168 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1169 ? WDWindowMaker->dictionary : NULL);
1171 must_update = 0;
1173 needs_refresh = 0;
1175 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1176 entry = &optionList[i];
1178 if (new_dict)
1179 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1180 else
1181 plvalue = NULL;
1183 if (!old_dict)
1184 old_value = NULL;
1185 else
1186 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1189 if (!plvalue && !old_value) {
1190 /* no default in the DB. Use builtin default */
1191 plvalue = entry->plvalue;
1192 if (plvalue && new_dict) {
1193 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1194 must_update = 1;
1196 } else if (!plvalue) {
1197 /* value was deleted from DB. Keep current value */
1198 continue;
1199 } else if (!old_value) {
1200 /* set value for the 1st time */
1201 } else if (!PLIsEqual(plvalue, old_value)) {
1202 /* value has changed */
1203 } else {
1205 if (strcmp(entry->key, "WorkspaceBack") == 0
1206 && update_workspace_back
1207 && scr->flags.backimage_helper_launched) {
1208 } else {
1209 /* value was not changed since last time */
1210 continue;
1214 if (plvalue) {
1215 #ifdef DEBUG
1216 printf("Updating %s to %s\n", entry->key,
1217 PLGetDescription(plvalue));
1218 #endif
1219 /* convert data */
1220 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1222 * If the WorkspaceSpecificBack data has been changed
1223 * so that the helper will be launched now, we must be
1224 * sure to send the default background texture config
1225 * to the helper.
1227 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1228 && !scr->flags.backimage_helper_launched) {
1229 update_workspace_back = 1;
1231 if (entry->update) {
1232 needs_refresh |=
1233 (*entry->update)(scr, entry, tdata, entry->extra_data);
1239 if (needs_refresh!=0 && !scr->flags.startup) {
1240 int foo;
1242 foo = 0;
1243 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1244 foo |= WTextureSettings;
1245 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1246 foo |= WFontSettings;
1247 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1248 foo |= WColorSettings;
1249 if (foo)
1250 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1251 (void*)foo);
1253 foo = 0;
1254 if (needs_refresh & REFRESH_MENU_TEXTURE)
1255 foo |= WTextureSettings;
1256 if (needs_refresh & REFRESH_MENU_FONT)
1257 foo |= WFontSettings;
1258 if (needs_refresh & REFRESH_MENU_COLOR)
1259 foo |= WColorSettings;
1260 if (foo)
1261 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1262 (void*)foo);
1264 foo = 0;
1265 if (needs_refresh & REFRESH_WINDOW_FONT) {
1266 foo |= WFontSettings;
1268 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1269 foo |= WTextureSettings;
1271 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1272 foo |= WColorSettings;
1274 if (foo)
1275 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1276 (void*)foo);
1278 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1279 foo = 0;
1280 if (needs_refresh & REFRESH_ICON_FONT) {
1281 foo |= WFontSettings;
1283 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1284 foo |= WTextureSettings;
1286 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1287 foo |= WTextureSettings;
1289 if (foo)
1290 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1291 (void*)foo);
1293 if (needs_refresh & REFRESH_ICON_TILE)
1294 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1299 void
1300 wDefaultUpdateIcons(WScreen *scr)
1302 WAppIcon *aicon = scr->app_icon_list;
1303 WWindow *wwin = scr->focused_window;
1304 char *file;
1306 while(aicon) {
1307 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1308 False);
1309 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1310 || (file && !aicon->icon->file)) {
1311 RImage *new_image;
1313 if (aicon->icon->file)
1314 wfree(aicon->icon->file);
1315 aicon->icon->file = wstrdup(file);
1317 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1318 aicon->wm_class);
1319 if (new_image) {
1320 wIconChangeImage(aicon->icon, new_image);
1321 wAppIconPaint(aicon);
1324 aicon = aicon->next;
1327 if (!wPreferences.flags.noclip)
1328 wClipIconPaint(scr->clip_icon);
1330 while (wwin) {
1331 if (wwin->icon && wwin->flags.miniaturized) {
1332 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1333 False);
1334 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1335 || (file && !wwin->icon->file)) {
1336 RImage *new_image;
1338 if (wwin->icon->file)
1339 wfree(wwin->icon->file);
1340 wwin->icon->file = wstrdup(file);
1342 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1343 wwin->wm_class);
1344 if (new_image)
1345 wIconChangeImage(wwin->icon, new_image);
1348 wwin = wwin->prev;
1353 /* --------------------------- Local ----------------------- */
1355 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1356 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1357 entry->key, x); \
1358 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1359 var = entry->default_value;\
1360 } else var = PLGetString(value)\
1366 static int
1367 string2index(proplist_t key, proplist_t val, proplist_t def,
1368 WOptionEnumeration *values)
1370 char *str;
1371 WOptionEnumeration *v;
1372 char buffer[TOTAL_VALUES_LENGTH];
1374 if (PLIsString(val) && (str = PLGetString(val))) {
1375 for (v=values; v->string!=NULL; v++) {
1376 if (strcasecmp(v->string, str)==0)
1377 return v->value;
1381 buffer[0] = 0;
1382 for (v=values; v->string!=NULL; v++) {
1383 if (!v->is_alias) {
1384 if (buffer[0]!=0)
1385 strcat(buffer, ", ");
1386 strcat(buffer, v->string);
1389 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1390 PLGetString(key), buffer);
1392 if (def) {
1393 return string2index(key, val, NULL, values);
1396 return -1;
1403 * value - is the value in the defaults DB
1404 * addr - is the address to store the data
1405 * ret - is the address to store a pointer to a temporary buffer. ret
1406 * must not be freed and is used by the set functions
1408 static int
1409 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1410 void **ret)
1412 static char data;
1413 char *val;
1414 int second_pass=0;
1416 GET_STRING_OR_DEFAULT("Boolean", val);
1418 again:
1419 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1420 || strcasecmp(val, "YES")==0) {
1422 data = 1;
1423 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1424 || strcasecmp(val, "NO")==0) {
1425 data = 0;
1426 } else {
1427 int i;
1428 if (sscanf(val, "%i", &i)==1) {
1429 if (i!=0)
1430 data = 1;
1431 else
1432 data = 0;
1433 } else {
1434 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1435 val, entry->key);
1436 if (second_pass==0) {
1437 val = PLGetString(entry->plvalue);
1438 second_pass = 1;
1439 wwarning(_("using default \"%s\" instead"), val);
1440 goto again;
1442 return False;
1446 if (ret)
1447 *ret = &data;
1449 if (addr) {
1450 *(char*)addr = data;
1453 return True;
1457 static int
1458 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1459 void **ret)
1461 static int data;
1462 char *val;
1465 GET_STRING_OR_DEFAULT("Integer", val);
1467 if (sscanf(val, "%i", &data)!=1) {
1468 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1469 val, entry->key);
1470 val = PLGetString(entry->plvalue);
1471 wwarning(_("using default \"%s\" instead"), val);
1472 if (sscanf(val, "%i", &data)!=1) {
1473 return False;
1477 if (ret)
1478 *ret = &data;
1480 if (addr) {
1481 *(int*)addr = data;
1483 return True;
1487 static int
1488 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1489 void **ret)
1491 static WCoord data;
1492 char *val_x, *val_y;
1493 int nelem, changed=0;
1494 proplist_t elem_x, elem_y;
1496 again:
1497 if (!PLIsArray(value)) {
1498 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1499 entry->key, "Coordinate");
1500 if (changed==0) {
1501 value = entry->plvalue;
1502 changed = 1;
1503 wwarning(_("using default \"%s\" instead"), entry->default_value);
1504 goto again;
1506 return False;
1509 nelem = PLGetNumberOfElements(value);
1510 if (nelem != 2) {
1511 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1512 entry->key);
1513 if (changed==0) {
1514 value = entry->plvalue;
1515 changed = 1;
1516 wwarning(_("using default \"%s\" instead"), entry->default_value);
1517 goto again;
1519 return False;
1522 elem_x = PLGetArrayElement(value, 0);
1523 elem_y = PLGetArrayElement(value, 1);
1525 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1526 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1527 entry->key);
1528 if (changed==0) {
1529 value = entry->plvalue;
1530 changed = 1;
1531 wwarning(_("using default \"%s\" instead"), entry->default_value);
1532 goto again;
1534 return False;
1537 val_x = PLGetString(elem_x);
1538 val_y = PLGetString(elem_y);
1540 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1541 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1542 if (changed==0) {
1543 value = entry->plvalue;
1544 changed = 1;
1545 wwarning(_("using default \"%s\" instead"), entry->default_value);
1546 goto again;
1548 return False;
1551 if (data.x < 0)
1552 data.x = 0;
1553 else if (data.x > scr->scr_width/3)
1554 data.x = scr->scr_width/3;
1555 if (data.y < 0)
1556 data.y = 0;
1557 else if (data.y > scr->scr_height/3)
1558 data.y = scr->scr_height/3;
1560 if (ret)
1561 *ret = &data;
1563 if (addr) {
1564 *(WCoord*)addr = data;
1567 return True;
1571 #if 0
1572 /* This function is not used at the moment. */
1573 static int
1574 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1575 void **ret)
1577 static char *data;
1579 GET_STRING_OR_DEFAULT("String", data);
1581 if (!data) {
1582 data = PLGetString(entry->plvalue);
1583 if (!data)
1584 return False;
1587 if (ret)
1588 *ret = &data;
1590 if (addr)
1591 *(char**)addr = wstrdup(data);
1593 return True;
1595 #endif
1598 static int
1599 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1600 void **ret)
1602 static char *data;
1603 int i, count, len;
1604 char *ptr;
1605 proplist_t d;
1606 int changed=0;
1608 again:
1609 if (!PLIsArray(value)) {
1610 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1611 entry->key, "an array of paths");
1612 if (changed==0) {
1613 value = entry->plvalue;
1614 changed = 1;
1615 wwarning(_("using default \"%s\" instead"), entry->default_value);
1616 goto again;
1618 return False;
1621 i = 0;
1622 count = PLGetNumberOfElements(value);
1623 if (count < 1) {
1624 if (changed==0) {
1625 value = entry->plvalue;
1626 changed = 1;
1627 wwarning(_("using default \"%s\" instead"), entry->default_value);
1628 goto again;
1630 return False;
1633 len = 0;
1634 for (i=0; i<count; i++) {
1635 d = PLGetArrayElement(value, i);
1636 if (!d || !PLIsString(d)) {
1637 count = i;
1638 break;
1640 len += strlen(PLGetString(d))+1;
1643 ptr = data = wmalloc(len+1);
1645 for (i=0; i<count; i++) {
1646 d = PLGetArrayElement(value, i);
1647 if (!d || !PLIsString(d)) {
1648 break;
1650 strcpy(ptr, PLGetString(d));
1651 ptr += strlen(PLGetString(d));
1652 *ptr = ':';
1653 ptr++;
1655 ptr--; *(ptr--) = 0;
1657 if (*(char**)addr!=NULL) {
1658 wfree(*(char**)addr);
1660 *(char**)addr = data;
1662 return True;
1666 static int
1667 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1668 void **ret)
1670 static signed char data;
1672 data = string2index(entry->plkey, value, entry->default_value,
1673 (WOptionEnumeration*)entry->extra_data);
1674 if (data < 0)
1675 return False;
1677 if (ret)
1678 *ret = &data;
1680 if (addr)
1681 *(signed char*)addr = data;
1683 return True;
1689 * (solid <color>)
1690 * (hgradient <color> <color>)
1691 * (vgradient <color> <color>)
1692 * (dgradient <color> <color>)
1693 * (mhgradient <color> <color> ...)
1694 * (mvgradient <color> <color> ...)
1695 * (mdgradient <color> <color> ...)
1696 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1697 * (tpixmap <file> <color>)
1698 * (spixmap <file> <color>)
1699 * (cpixmap <file> <color>)
1700 * (thgradient <file> <opaqueness> <color> <color>)
1701 * (tvgradient <file> <opaqueness> <color> <color>)
1702 * (tdgradient <file> <opaqueness> <color> <color>)
1703 * (function <lib> <function> ...)
1706 static WTexture*
1707 parse_texture(WScreen *scr, proplist_t pl)
1709 proplist_t elem;
1710 char *val;
1711 int nelem;
1712 WTexture *texture=NULL;
1714 nelem = PLGetNumberOfElements(pl);
1715 if (nelem < 1)
1716 return NULL;
1719 elem = PLGetArrayElement(pl, 0);
1720 if (!elem || !PLIsString(elem))
1721 return NULL;
1722 val = PLGetString(elem);
1725 if (strcasecmp(val, "solid")==0) {
1726 XColor color;
1728 if (nelem != 2)
1729 return NULL;
1731 /* get color */
1733 elem = PLGetArrayElement(pl, 1);
1734 if (!elem || !PLIsString(elem))
1735 return NULL;
1736 val = PLGetString(elem);
1738 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1739 wwarning(_("\"%s\" is not a valid color name"), val);
1740 return NULL;
1743 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1744 } else if (strcasecmp(val, "dgradient")==0
1745 || strcasecmp(val, "vgradient")==0
1746 || strcasecmp(val, "hgradient")==0) {
1747 RColor color1, color2;
1748 XColor xcolor;
1749 int type;
1751 if (nelem != 3) {
1752 wwarning(_("bad number of arguments in gradient specification"));
1753 return NULL;
1756 if (val[0]=='d' || val[0]=='D')
1757 type = WTEX_DGRADIENT;
1758 else if (val[0]=='h' || val[0]=='H')
1759 type = WTEX_HGRADIENT;
1760 else
1761 type = WTEX_VGRADIENT;
1764 /* get from color */
1765 elem = PLGetArrayElement(pl, 1);
1766 if (!elem || !PLIsString(elem))
1767 return NULL;
1768 val = PLGetString(elem);
1770 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1771 wwarning(_("\"%s\" is not a valid color name"), val);
1772 return NULL;
1774 color1.alpha = 255;
1775 color1.red = xcolor.red >> 8;
1776 color1.green = xcolor.green >> 8;
1777 color1.blue = xcolor.blue >> 8;
1779 /* get to color */
1780 elem = PLGetArrayElement(pl, 2);
1781 if (!elem || !PLIsString(elem)) {
1782 return NULL;
1784 val = PLGetString(elem);
1786 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1787 wwarning(_("\"%s\" is not a valid color name"), val);
1788 return NULL;
1790 color2.alpha = 255;
1791 color2.red = xcolor.red >> 8;
1792 color2.green = xcolor.green >> 8;
1793 color2.blue = xcolor.blue >> 8;
1795 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1797 } else if (strcasecmp(val, "igradient")==0) {
1798 RColor colors1[2], colors2[2];
1799 int th1, th2;
1800 XColor xcolor;
1801 int i;
1803 if (nelem != 7) {
1804 wwarning(_("bad number of arguments in gradient specification"));
1805 return NULL;
1808 /* get from color */
1809 for (i = 0; i < 2; i++) {
1810 elem = PLGetArrayElement(pl, 1+i);
1811 if (!elem || !PLIsString(elem))
1812 return NULL;
1813 val = PLGetString(elem);
1815 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1816 wwarning(_("\"%s\" is not a valid color name"), val);
1817 return NULL;
1819 colors1[i].alpha = 255;
1820 colors1[i].red = xcolor.red >> 8;
1821 colors1[i].green = xcolor.green >> 8;
1822 colors1[i].blue = xcolor.blue >> 8;
1824 elem = PLGetArrayElement(pl, 3);
1825 if (!elem || !PLIsString(elem))
1826 return NULL;
1827 val = PLGetString(elem);
1828 th1 = atoi(val);
1831 /* get from color */
1832 for (i = 0; i < 2; i++) {
1833 elem = PLGetArrayElement(pl, 4+i);
1834 if (!elem || !PLIsString(elem))
1835 return NULL;
1836 val = PLGetString(elem);
1838 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1839 wwarning(_("\"%s\" is not a valid color name"), val);
1840 return NULL;
1842 colors2[i].alpha = 255;
1843 colors2[i].red = xcolor.red >> 8;
1844 colors2[i].green = xcolor.green >> 8;
1845 colors2[i].blue = xcolor.blue >> 8;
1847 elem = PLGetArrayElement(pl, 6);
1848 if (!elem || !PLIsString(elem))
1849 return NULL;
1850 val = PLGetString(elem);
1851 th2 = atoi(val);
1853 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1854 th2, colors2);
1856 } else if (strcasecmp(val, "mhgradient")==0
1857 || strcasecmp(val, "mvgradient")==0
1858 || strcasecmp(val, "mdgradient")==0) {
1859 XColor color;
1860 RColor **colors;
1861 int i, count;
1862 int type;
1864 if (nelem < 3) {
1865 wwarning(_("too few arguments in multicolor gradient specification"));
1866 return NULL;
1869 if (val[1]=='h' || val[1]=='H')
1870 type = WTEX_MHGRADIENT;
1871 else if (val[1]=='v' || val[1]=='V')
1872 type = WTEX_MVGRADIENT;
1873 else
1874 type = WTEX_MDGRADIENT;
1876 count = nelem-1;
1878 colors = wmalloc(sizeof(RColor*)*(count+1));
1880 for (i=0; i<count; i++) {
1881 elem = PLGetArrayElement(pl, i+1);
1882 if (!elem || !PLIsString(elem)) {
1883 for (--i; i>=0; --i) {
1884 wfree(colors[i]);
1886 wfree(colors);
1887 return NULL;
1889 val = PLGetString(elem);
1891 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1892 wwarning(_("\"%s\" is not a valid color name"), val);
1893 for (--i; i>=0; --i) {
1894 wfree(colors[i]);
1896 wfree(colors);
1897 return NULL;
1898 } else {
1899 colors[i] = wmalloc(sizeof(RColor));
1900 colors[i]->red = color.red >> 8;
1901 colors[i]->green = color.green >> 8;
1902 colors[i]->blue = color.blue >> 8;
1905 colors[i] = NULL;
1907 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1908 } else if (strcasecmp(val, "spixmap")==0 ||
1909 strcasecmp(val, "cpixmap")==0 ||
1910 strcasecmp(val, "tpixmap")==0) {
1911 XColor color;
1912 int type;
1914 if (nelem != 3)
1915 return NULL;
1917 if (val[0] == 's' || val[0] == 'S')
1918 type = WTP_SCALE;
1919 else if (val[0] == 'c' || val[0] == 'C')
1920 type = WTP_CENTER;
1921 else
1922 type = WTP_TILE;
1924 /* get color */
1925 elem = PLGetArrayElement(pl, 2);
1926 if (!elem || !PLIsString(elem)) {
1927 return NULL;
1929 val = PLGetString(elem);
1931 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1932 wwarning(_("\"%s\" is not a valid color name"), val);
1933 return NULL;
1936 /* file name */
1937 elem = PLGetArrayElement(pl, 1);
1938 if (!elem || !PLIsString(elem))
1939 return NULL;
1940 val = PLGetString(elem);
1942 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1943 } else if (strcasecmp(val, "thgradient")==0
1944 || strcasecmp(val, "tvgradient")==0
1945 || strcasecmp(val, "tdgradient")==0) {
1946 RColor color1, color2;
1947 XColor xcolor;
1948 int opacity;
1949 int style;
1951 if (val[1]=='h' || val[1]=='H')
1952 style = WTEX_THGRADIENT;
1953 else if (val[1]=='v' || val[1]=='V')
1954 style = WTEX_TVGRADIENT;
1955 else
1956 style = WTEX_TDGRADIENT;
1958 if (nelem != 5) {
1959 wwarning(_("bad number of arguments in textured gradient specification"));
1960 return NULL;
1963 /* get from color */
1964 elem = PLGetArrayElement(pl, 3);
1965 if (!elem || !PLIsString(elem))
1966 return NULL;
1967 val = PLGetString(elem);
1969 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1970 wwarning(_("\"%s\" is not a valid color name"), val);
1971 return NULL;
1973 color1.alpha = 255;
1974 color1.red = xcolor.red >> 8;
1975 color1.green = xcolor.green >> 8;
1976 color1.blue = xcolor.blue >> 8;
1978 /* get to color */
1979 elem = PLGetArrayElement(pl, 4);
1980 if (!elem || !PLIsString(elem)) {
1981 return NULL;
1983 val = PLGetString(elem);
1985 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1986 wwarning(_("\"%s\" is not a valid color name"), val);
1987 return NULL;
1989 color2.alpha = 255;
1990 color2.red = xcolor.red >> 8;
1991 color2.green = xcolor.green >> 8;
1992 color2.blue = xcolor.blue >> 8;
1994 /* get opacity */
1995 elem = PLGetArrayElement(pl, 2);
1996 if (!elem || !PLIsString(elem))
1997 opacity = 128;
1998 else
1999 val = PLGetString(elem);
2001 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2002 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2003 opacity = 128;
2006 /* get file name */
2007 elem = PLGetArrayElement(pl, 1);
2008 if (!elem || !PLIsString(elem))
2009 return NULL;
2010 val = PLGetString(elem);
2012 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2013 val, opacity);
2015 #ifdef TEXTURE_PLUGIN
2016 else if (strcasecmp(val, "function")==0) {
2017 WTexFunction *function;
2018 void (*initFunc) (Display *, Colormap);
2019 char *lib, *func, **argv;
2020 int i, argc;
2022 if (nelem < 3)
2023 return NULL;
2025 /* get the library name */
2026 elem = PLGetArrayElement(pl, 1);
2027 if (!elem || !PLIsString(elem)) {
2028 return NULL;
2030 lib = PLGetString(elem);
2032 /* get the function name */
2033 elem = PLGetArrayElement(pl, 2);
2034 if (!elem || !PLIsString(elem)) {
2035 return NULL;
2037 func = PLGetString(elem);
2039 argc = nelem - 2;
2040 argv = (char **)wmalloc(argc * sizeof(char *));
2042 /* get the parameters */
2043 argv[0] = wstrdup(func);
2044 for (i = 0; i < argc - 1; i++) {
2045 elem = PLGetArrayElement(pl, 3 + i);
2046 if (!elem || !PLIsString(elem)) {
2047 wfree(argv);
2049 return NULL;
2051 argv[i+1] = wstrdup(PLGetString(elem));
2054 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2056 #ifdef HAVE_DLFCN_H
2057 if (function) {
2058 initFunc = dlsym(function->handle, "initWindowMaker");
2059 if (initFunc) {
2060 initFunc(dpy, scr->w_colormap);
2061 } else {
2062 wwarning(_("could not initialize library %s"), lib);
2064 } else {
2065 wwarning(_("could not find function %s::%s"), lib, func);
2067 #endif /* HAVE_DLFCN_H */
2068 texture = (WTexture*)function;
2070 #endif /* TEXTURE_PLUGIN */
2071 else {
2072 wwarning(_("invalid texture type %s"), val);
2073 return NULL;
2075 return texture;
2080 static int
2081 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2082 void **ret)
2084 static WTexture *texture;
2085 int changed=0;
2087 again:
2088 if (!PLIsArray(value)) {
2089 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2090 entry->key, "Texture");
2091 if (changed==0) {
2092 value = entry->plvalue;
2093 changed = 1;
2094 wwarning(_("using default \"%s\" instead"), entry->default_value);
2095 goto again;
2097 return False;
2100 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2101 proplist_t pl;
2103 pl = PLGetArrayElement(value, 0);
2104 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2105 || strcasecmp(PLGetString(pl), "solid")!=0) {
2106 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2107 entry->key, "Solid Texture");
2109 value = entry->plvalue;
2110 changed = 1;
2111 wwarning(_("using default \"%s\" instead"), entry->default_value);
2112 goto again;
2116 texture = parse_texture(scr, value);
2118 if (!texture) {
2119 wwarning(_("Error in texture specification for key \"%s\""),
2120 entry->key);
2121 if (changed==0) {
2122 value = entry->plvalue;
2123 changed = 1;
2124 wwarning(_("using default \"%s\" instead"), entry->default_value);
2125 goto again;
2127 return False;
2130 if (ret)
2131 *ret = &texture;
2133 if (addr)
2134 *(WTexture**)addr = texture;
2136 return True;
2141 #ifdef DRAWSTRING_PLUGIN
2142 static int
2143 getTextRenderer(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2144 void *addr, void **ret)
2146 proplist_t elem;
2147 char *val, *lib, *func, **argv;
2148 int argc, changed;
2150 if (strcmp(entry->key, "FTitleColor")==0) {
2151 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_FTITLE]);
2152 scr->drawstring_func[W_STRING_FTITLE] = NULL;
2153 } else if (strcmp(entry->key, "UTitleColor")==0) {
2154 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_UTITLE]);
2155 scr->drawstring_func[W_STRING_UTITLE] = NULL;
2156 } else if (strcmp(entry->key, "PTitleColor")==0) {
2157 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_PTITLE]);
2158 scr->drawstring_func[W_STRING_PTITLE] = NULL;
2159 } else if (strcmp(entry->key, "MenuTitleColor")==0) {
2160 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTITLE]);
2161 scr->drawstring_func[W_STRING_MTITLE] = NULL;
2162 } else if (strcmp(entry->key, "MenuPluginColor")==0) {
2163 wPluginDestroyFunction(scr->drawstring_func[changed = W_STRING_MTEXT]);
2164 scr->drawstring_func[W_STRING_MTEXT] = NULL;
2167 if (PLIsArray(value)) {
2168 if ((argc = PLGetNumberOfElements(value)) < 4) return False;
2169 argc -= 2;
2170 argv = (char **)wmalloc(argc * sizeof(char *));
2172 elem = PLGetArrayElement(value,0);
2173 if (!elem || !PLIsString(elem)) return False;
2174 val = PLGetString(elem);
2175 if (strcasecmp(val, "function")==0) {
2176 elem = PLGetArrayElement(value, 1); /* library name */
2177 if (!elem || !PLIsString(elem)) return False;
2178 lib = PLGetString(elem);
2179 elem = PLGetArrayElement(value, 2); /* function name */
2180 if (!elem || !PLIsString(elem)) return False;
2181 func = PLGetString(elem);
2182 scr->drawstring_func[changed] = wPluginCreateFunction (W_FUNCTION_DRAWSTRING,
2183 lib, "initDrawString", func, NULL, value,
2184 wPluginPackInitData(3, dpy, scr->w_colormap,"-DATA-"));
2187 return getColor(scr, entry, PLGetArrayElement(value,3), addr, ret);
2188 } else if (PLIsString(value)) {
2189 return getColor(scr, entry, value, addr, ret);
2192 return False;
2194 #endif /* DRAWSTRING_PLUGIN */
2198 static int
2199 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2200 void *addr, void **ret)
2202 proplist_t elem;
2203 int changed = 0;
2204 char *val;
2205 int nelem;
2207 again:
2208 if (!PLIsArray(value)) {
2209 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2210 "WorkspaceBack", "Texture or None");
2211 if (changed==0) {
2212 value = entry->plvalue;
2213 changed = 1;
2214 wwarning(_("using default \"%s\" instead"), entry->default_value);
2215 goto again;
2217 return False;
2220 /* only do basic error checking and verify for None texture */
2222 nelem = PLGetNumberOfElements(value);
2223 if (nelem > 0) {
2224 elem = PLGetArrayElement(value, 0);
2225 if (!elem || !PLIsString(elem)) {
2226 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2227 if (changed==0) {
2228 value = entry->plvalue;
2229 changed = 1;
2230 wwarning(_("using default \"%s\" instead"), entry->default_value);
2231 goto again;
2233 return False;
2235 val = PLGetString(elem);
2237 if (strcasecmp(val, "None")==0)
2238 return True;
2240 *ret = PLRetain(value);
2242 return True;
2246 static int
2247 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2248 void *addr, void **ret)
2250 proplist_t elem;
2251 int nelem;
2252 int changed = 0;
2254 again:
2255 if (!PLIsArray(value)) {
2256 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2257 "WorkspaceSpecificBack", "an array of textures");
2258 if (changed==0) {
2259 value = entry->plvalue;
2260 changed = 1;
2261 wwarning(_("using default \"%s\" instead"), entry->default_value);
2262 goto again;
2264 return False;
2267 /* only do basic error checking and verify for None texture */
2269 nelem = PLGetNumberOfElements(value);
2270 if (nelem > 0) {
2271 while (nelem--) {
2272 elem = PLGetArrayElement(value, nelem);
2273 if (!elem || !PLIsArray(elem)) {
2274 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2275 nelem);
2280 *ret = PLRetain(value);
2282 #ifdef notworking
2284 * Kluge to force wmsetbg helper to set the default background.
2285 * If the WorkspaceSpecificBack is changed once wmaker has started,
2286 * the WorkspaceBack won't be sent to the helper, unless the user
2287 * changes it's value too. So, we must force this by removing the
2288 * value from the defaults DB.
2290 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2291 proplist_t key = PLMakeString("WorkspaceBack");
2293 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2295 PLRelease(key);
2297 #endif
2298 return True;
2302 static int
2303 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2304 void **ret)
2306 static WMFont *font;
2307 char *val;
2309 GET_STRING_OR_DEFAULT("Font", val);
2311 font = WMCreateFont(scr->wmscreen, val);
2312 if (!font)
2313 font = WMCreateFont(scr->wmscreen, "fixed");
2315 if (!font) {
2316 wfatal(_("could not load any usable font!!!"));
2317 exit(1);
2320 if (ret)
2321 *ret = font;
2323 /* can't assign font value outside update function */
2324 wassertrv(addr == NULL, True);
2326 return True;
2330 static int
2331 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2332 void **ret)
2334 static XColor color;
2335 char *val;
2336 int second_pass=0;
2338 GET_STRING_OR_DEFAULT("Color", val);
2341 again:
2342 if (!wGetColor(scr, val, &color)) {
2343 wwarning(_("could not get color for key \"%s\""),
2344 entry->key);
2345 if (second_pass==0) {
2346 val = PLGetString(entry->plvalue);
2347 second_pass = 1;
2348 wwarning(_("using default \"%s\" instead"), val);
2349 goto again;
2351 return False;
2354 if (ret)
2355 *ret = &color;
2357 assert(addr==NULL);
2359 if (addr)
2360 *(unsigned long*)addr = pixel;
2363 return True;
2368 static int
2369 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2370 void **ret)
2372 static WShortKey shortcut;
2373 KeySym ksym;
2374 char *val;
2375 char *k;
2376 char buf[128], *b;
2379 GET_STRING_OR_DEFAULT("Key spec", val);
2381 if (!val || strcasecmp(val, "NONE")==0) {
2382 shortcut.keycode = 0;
2383 shortcut.modifier = 0;
2384 if (ret)
2385 *ret = &shortcut;
2386 return True;
2389 strcpy(buf, val);
2391 b = (char*)buf;
2393 /* get modifiers */
2394 shortcut.modifier = 0;
2395 while ((k = strchr(b, '+'))!=NULL) {
2396 int mod;
2398 *k = 0;
2399 mod = wXModifierFromKey(b);
2400 if (mod<0) {
2401 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2402 return False;
2404 shortcut.modifier |= mod;
2406 b = k+1;
2409 /* get key */
2410 ksym = XStringToKeysym(b);
2412 if (ksym==NoSymbol) {
2413 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2414 val);
2415 return False;
2418 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2419 if (shortcut.keycode==0) {
2420 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2421 return False;
2424 if (ret)
2425 *ret = &shortcut;
2427 return True;
2431 static int
2432 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2433 void **ret)
2435 static unsigned int mask;
2436 char *str;
2438 GET_STRING_OR_DEFAULT("Modifier Key", str);
2440 if (!str)
2441 return False;
2443 mask = wXModifierFromKey(str);
2444 if (mask < 0) {
2445 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2446 mask = 0;
2447 return False;
2450 if (addr)
2451 *(unsigned int*)addr = mask;
2453 if (ret)
2454 *ret = &mask;
2456 return True;
2460 #ifdef NEWSTUFF
2461 static int
2462 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2463 void *addr, void **ret)
2465 unsigned int mask;
2466 char *str;
2467 RImage *image;
2468 int i, n;
2469 int w, h;
2471 GET_STRING_OR_DEFAULT("Image File Path", str);
2472 if (!str)
2473 return False;
2475 image = RLoadImage(scr->rcontext, str, 0);
2476 if (!image) {
2477 wwarning(_("could not load image in option %s: %s"), entry->key,
2478 RMessageForError(RErrorCode));
2479 return False;
2482 if (*(RImage**)addr) {
2483 RDestroyImage(*(RImage**)addr);
2485 if (addr)
2486 *(RImage**)addr = image;
2488 assert(ret == NULL);
2490 if (ret)
2491 *(RImage**)ret = image;
2494 return True;
2496 #endif
2498 #ifdef DEFINABLE_CURSOR
2500 # include <X11/cursorfont.h>
2501 typedef struct
2503 char *name;
2504 int id;
2505 } WCursorLookup;
2507 #define CURSOR_ID_NONE (XC_num_glyphs)
2509 static WCursorLookup cursor_table[] =
2511 { "X_cursor", XC_X_cursor },
2512 { "arrow", XC_arrow },
2513 { "based_arrow_down", XC_based_arrow_down },
2514 { "based_arrow_up", XC_based_arrow_up },
2515 { "boat", XC_boat },
2516 { "bogosity", XC_bogosity },
2517 { "bottom_left_corner", XC_bottom_left_corner },
2518 { "bottom_right_corner", XC_bottom_right_corner },
2519 { "bottom_side", XC_bottom_side },
2520 { "bottom_tee", XC_bottom_tee },
2521 { "box_spiral", XC_box_spiral },
2522 { "center_ptr", XC_center_ptr },
2523 { "circle", XC_circle },
2524 { "clock", XC_clock },
2525 { "coffee_mug", XC_coffee_mug },
2526 { "cross", XC_cross },
2527 { "cross_reverse", XC_cross_reverse },
2528 { "crosshair", XC_crosshair },
2529 { "diamond_cross", XC_diamond_cross },
2530 { "dot", XC_dot },
2531 { "dotbox", XC_dotbox },
2532 { "double_arrow", XC_double_arrow },
2533 { "draft_large", XC_draft_large },
2534 { "draft_small", XC_draft_small },
2535 { "draped_box", XC_draped_box },
2536 { "exchange", XC_exchange },
2537 { "fleur", XC_fleur },
2538 { "gobbler", XC_gobbler },
2539 { "gumby", XC_gumby },
2540 { "hand1", XC_hand1 },
2541 { "hand2", XC_hand2 },
2542 { "heart", XC_heart },
2543 { "icon", XC_icon },
2544 { "iron_cross", XC_iron_cross },
2545 { "left_ptr", XC_left_ptr },
2546 { "left_side", XC_left_side },
2547 { "left_tee", XC_left_tee },
2548 { "leftbutton", XC_leftbutton },
2549 { "ll_angle", XC_ll_angle },
2550 { "lr_angle", XC_lr_angle },
2551 { "man", XC_man },
2552 { "middlebutton", XC_middlebutton },
2553 { "mouse", XC_mouse },
2554 { "pencil", XC_pencil },
2555 { "pirate", XC_pirate },
2556 { "plus", XC_plus },
2557 { "question_arrow", XC_question_arrow },
2558 { "right_ptr", XC_right_ptr },
2559 { "right_side", XC_right_side },
2560 { "right_tee", XC_right_tee },
2561 { "rightbutton", XC_rightbutton },
2562 { "rtl_logo", XC_rtl_logo },
2563 { "sailboat", XC_sailboat },
2564 { "sb_down_arrow", XC_sb_down_arrow },
2565 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2566 { "sb_left_arrow", XC_sb_left_arrow },
2567 { "sb_right_arrow", XC_sb_right_arrow },
2568 { "sb_up_arrow", XC_sb_up_arrow },
2569 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2570 { "shuttle", XC_shuttle },
2571 { "sizing", XC_sizing },
2572 { "spider", XC_spider },
2573 { "spraycan", XC_spraycan },
2574 { "star", XC_star },
2575 { "target", XC_target },
2576 { "tcross", XC_tcross },
2577 { "top_left_arrow", XC_top_left_arrow },
2578 { "top_left_corner", XC_top_left_corner },
2579 { "top_right_corner", XC_top_right_corner },
2580 { "top_side", XC_top_side },
2581 { "top_tee", XC_top_tee },
2582 { "trek", XC_trek },
2583 { "ul_angle", XC_ul_angle },
2584 { "umbrella", XC_umbrella },
2585 { "ur_angle", XC_ur_angle },
2586 { "watch", XC_watch },
2587 { "xterm", XC_xterm },
2588 { NULL, CURSOR_ID_NONE }
2591 static void
2592 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2594 switch(status) {
2595 case BitmapOpenFailed:
2596 wwarning(_("failed to open bitmap file \"%s\""), filename);
2597 break;
2598 case BitmapFileInvalid:
2599 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2600 break;
2601 case BitmapNoMemory:
2602 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2603 break;
2604 case BitmapSuccess:
2605 XFreePixmap(dpy, bitmap);
2606 break;
2611 * (none)
2612 * (builtin, <cursor_name>)
2613 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2615 static int
2616 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2618 proplist_t elem;
2619 char *val;
2620 int nelem;
2621 int status = 0;
2623 nelem = PLGetNumberOfElements(pl);
2624 if (nelem < 1) {
2625 return(status);
2627 elem = PLGetArrayElement(pl, 0);
2628 if (!elem || !PLIsString(elem)) {
2629 return(status);
2631 val = PLGetString(elem);
2633 if (0 == strcasecmp(val, "none")) {
2634 status = 1;
2635 *cursor = None;
2636 } else if (0 == strcasecmp(val, "builtin")) {
2637 int i;
2638 int cursor_id = CURSOR_ID_NONE;
2640 if (2 != nelem) {
2641 wwarning(_("bad number of arguments in cursor specification"));
2642 return(status);
2644 elem = PLGetArrayElement(pl, 1);
2645 if (!elem || !PLIsString(elem)) {
2646 return(status);
2648 val = PLGetString(elem);
2650 for (i = 0; NULL != cursor_table[i].name; i++) {
2651 if (0 == strcasecmp(val, cursor_table[i].name)) {
2652 cursor_id = cursor_table[i].id;
2653 break;
2656 if (CURSOR_ID_NONE == cursor_id) {
2657 wwarning(_("unknown builtin cursor name \"%s\""), val);
2658 } else {
2659 *cursor = XCreateFontCursor(dpy, cursor_id);
2660 status = 1;
2662 } else if (0 == strcasecmp(val, "bitmap")) {
2663 char *bitmap_name;
2664 char *mask_name;
2665 int bitmap_status;
2666 int mask_status;
2667 Pixmap bitmap;
2668 Pixmap mask;
2669 unsigned int w, h;
2670 int x, y;
2671 XColor fg, bg;
2673 if (3 != nelem) {
2674 wwarning(_("bad number of arguments in cursor specification"));
2675 return(status);
2677 elem = PLGetArrayElement(pl, 1);
2678 if (!elem || !PLIsString(elem)) {
2679 return(status);
2681 val = PLGetString(elem);
2682 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2683 if (!bitmap_name) {
2684 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2685 return(status);
2687 elem = PLGetArrayElement(pl, 2);
2688 if (!elem || !PLIsString(elem)) {
2689 wfree(bitmap_name);
2690 return(status);
2692 val = PLGetString(elem);
2693 mask_name = FindImage(wPreferences.pixmap_path, val);
2694 if (!mask_name) {
2695 wfree(bitmap_name);
2696 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2697 return(status);
2699 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2700 &mask, &x, &y);
2701 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2702 &bitmap, &x, &y);
2703 if ((BitmapSuccess == bitmap_status) &&
2704 (BitmapSuccess == mask_status)) {
2705 fg.pixel = scr->black_pixel;
2706 bg.pixel = scr->white_pixel;
2707 XQueryColor(dpy, scr->w_colormap, &fg);
2708 XQueryColor(dpy, scr->w_colormap, &bg);
2709 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2710 status = 1;
2712 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2713 check_bitmap_status(mask_status, mask_name, mask);
2714 wfree(bitmap_name);
2715 wfree(mask_name);
2717 return(status);
2721 static int
2722 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2723 void **ret)
2725 static Cursor cursor;
2726 int status;
2727 int changed = 0;
2729 again:
2730 if (!PLIsArray(value)) {
2731 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2732 entry->key, "cursor specification");
2733 if (!changed) {
2734 value = entry->plvalue;
2735 changed = 1;
2736 wwarning(_("using default \"%s\" instead"), entry->default_value);
2737 goto again;
2739 return(False);
2741 status = parse_cursor(scr, value, &cursor);
2742 if (!status) {
2743 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2744 if (!changed) {
2745 value = entry->plvalue;
2746 changed = 1;
2747 wwarning(_("using default \"%s\" instead"), entry->default_value);
2748 goto again;
2750 return(False);
2752 if (ret) {
2753 *ret = &cursor;
2755 if (addr) {
2756 *(Cursor *)addr = cursor;
2758 return(True);
2760 #undef CURSOR_ID_NONE
2762 #endif /* DEFINABLE_CURSOR */
2765 /* ---------------- value setting functions --------------- */
2766 static int
2767 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2769 return REFRESH_WINDOW_TITLE_COLOR;
2772 static int
2773 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2775 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2778 static int
2779 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2781 switch (which) {
2782 case WM_DOCK:
2783 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2784 break;
2785 case WM_CLIP:
2786 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2787 break;
2788 default:
2789 break;
2791 return 0;
2795 static int
2796 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2798 if (scr->workspaces) {
2799 wWorkspaceForceChange(scr, scr->current_workspace);
2800 wArrangeIcons(scr, False);
2802 return 0;
2805 #if not_used
2806 static int
2807 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2809 if (*value <= 0)
2810 *(int*)foo = 1;
2812 return 0;
2814 #endif
2818 static int
2819 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2821 Pixmap pixmap;
2822 RImage *img;
2823 int reset = 0;
2825 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2826 wPreferences.icon_size,
2827 ((*texture)->any.type & WREL_BORDER_MASK)
2828 ? WREL_ICON : WREL_FLAT);
2829 if (!img) {
2830 wwarning(_("could not render texture for icon background"));
2831 if (!entry->addr)
2832 wTextureDestroy(scr, *texture);
2833 return 0;
2835 RConvertImage(scr->rcontext, img, &pixmap);
2837 if (scr->icon_tile) {
2838 reset = 1;
2839 RDestroyImage(scr->icon_tile);
2840 XFreePixmap(dpy, scr->icon_tile_pixmap);
2843 scr->icon_tile = img;
2846 /* put the icon in the noticeboard hint */
2847 PropSetIconTileHint(scr, img);
2850 if (!wPreferences.flags.noclip) {
2851 if (scr->clip_tile) {
2852 RDestroyImage(scr->clip_tile);
2854 scr->clip_tile = wClipMakeTile(scr, img);
2857 scr->icon_tile_pixmap = pixmap;
2859 if (scr->def_icon_pixmap) {
2860 XFreePixmap(dpy, scr->def_icon_pixmap);
2861 scr->def_icon_pixmap = None;
2863 if (scr->def_ticon_pixmap) {
2864 XFreePixmap(dpy, scr->def_ticon_pixmap);
2865 scr->def_ticon_pixmap = None;
2868 if (scr->icon_back_texture) {
2869 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2871 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2873 if (scr->clip_balloon)
2874 XSetWindowBackground(dpy, scr->clip_balloon,
2875 (*texture)->any.color.pixel);
2878 * Free the texture as nobody else will use it, nor refer to it.
2880 if (!entry->addr)
2881 wTextureDestroy(scr, *texture);
2883 return (reset ? REFRESH_ICON_TILE : 0);
2888 static int
2889 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2891 if (scr->title_font) {
2892 WMReleaseFont(scr->title_font);
2894 scr->title_font = font;
2896 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2900 static int
2901 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2903 if (scr->menu_title_font) {
2904 WMReleaseFont(scr->menu_title_font);
2907 scr->menu_title_font = font;
2909 return REFRESH_MENU_TITLE_FONT;
2913 static int
2914 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2916 if (scr->menu_entry_font) {
2917 WMReleaseFont(scr->menu_entry_font);
2919 scr->menu_entry_font = font;
2921 return REFRESH_MENU_FONT;
2926 static int
2927 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2929 if (scr->icon_title_font) {
2930 WMReleaseFont(scr->icon_title_font);
2933 scr->icon_title_font = font;
2935 return REFRESH_ICON_FONT;
2939 static int
2940 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2942 if (scr->clip_title_font) {
2943 WMReleaseFont(scr->clip_title_font);
2946 scr->clip_title_font = font;
2948 return REFRESH_ICON_FONT;
2952 static int
2953 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2955 if (scr->workspace_name_font) {
2956 WMReleaseFont(scr->workspace_name_font);
2959 scr->workspace_name_font = font;
2961 return 0;
2965 static int
2966 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2968 if (scr->select_pixel!=scr->white_pixel &&
2969 scr->select_pixel!=scr->black_pixel) {
2970 wFreeColor(scr, scr->select_pixel);
2973 scr->select_pixel = color->pixel;
2975 return REFRESH_MENU_COLOR;
2979 static int
2980 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2982 if (scr->select_text_pixel!=scr->white_pixel &&
2983 scr->select_text_pixel!=scr->black_pixel) {
2984 wFreeColor(scr, scr->select_text_pixel);
2987 scr->select_text_pixel = color->pixel;
2989 return REFRESH_MENU_COLOR;
2993 static int
2994 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2996 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2997 scr->clip_title_pixel[index]!=scr->black_pixel) {
2998 wFreeColor(scr, scr->clip_title_pixel[index]);
3000 scr->clip_title_pixel[index] = color->pixel;
3002 #ifdef GRADIENT_CLIP_ARROW
3003 if (index == CLIP_NORMAL) {
3004 RImage *image;
3005 RColor color1, color2;
3006 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3007 int as = pt - 15; /* 15 = 5+5+5 */
3009 FREE_PIXMAP(scr->clip_arrow_gradient);
3011 color1.red = (color->red >> 8)*6/10;
3012 color1.green = (color->green >> 8)*6/10;
3013 color1.blue = (color->blue >> 8)*6/10;
3015 color2.red = WMIN((color->red >> 8)*20/10, 255);
3016 color2.green = WMIN((color->green >> 8)*20/10, 255);
3017 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3019 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3020 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3021 RDestroyImage(image);
3023 #endif /* GRADIENT_CLIP_ARROW */
3025 return REFRESH_ICON_TITLE_COLOR;
3029 static int
3030 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3032 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3033 scr->window_title_pixel[index]!=scr->black_pixel) {
3034 wFreeColor(scr, scr->window_title_pixel[index]);
3037 scr->window_title_pixel[index] = color->pixel;
3039 if (index == WS_UNFOCUSED)
3040 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3042 return REFRESH_WINDOW_TITLE_COLOR;
3046 static int
3047 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3049 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3050 scr->menu_title_pixel[0]!=scr->black_pixel) {
3051 #ifdef DRAWSTRING_PLUGIN
3052 if(!scr->drawstring_func[W_STRING_MTITLE])
3053 #endif
3054 wFreeColor(scr, scr->menu_title_pixel[0]);
3057 scr->menu_title_pixel[0] = color->pixel;
3058 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3060 return REFRESH_MENU_TITLE_COLOR;
3064 static int
3065 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3067 XGCValues gcv;
3068 #define gcm (GCForeground|GCBackground|GCFillStyle)
3070 if (scr->mtext_pixel!=scr->white_pixel &&
3071 scr->mtext_pixel!=scr->black_pixel) {
3072 wFreeColor(scr, scr->mtext_pixel);
3075 scr->mtext_pixel = color->pixel;
3077 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3080 if (scr->dtext_pixel == scr->mtext_pixel) {
3081 gcv.foreground = scr->white_pixel;
3082 gcv.background = scr->black_pixel;
3083 gcv.fill_style = FillStippled;
3084 } else {
3085 gcv.foreground = scr->dtext_pixel;
3086 gcv.fill_style = FillSolid;
3088 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3090 return REFRESH_MENU_COLOR;
3091 #undef gcm
3095 static int
3096 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3098 XGCValues gcv;
3099 #define gcm (GCForeground|GCBackground|GCFillStyle)
3101 if (scr->dtext_pixel!=scr->white_pixel &&
3102 scr->dtext_pixel!=scr->black_pixel) {
3103 wFreeColor(scr, scr->dtext_pixel);
3106 scr->dtext_pixel = color->pixel;
3108 if (scr->dtext_pixel == scr->mtext_pixel) {
3109 gcv.foreground = scr->white_pixel;
3110 gcv.background = scr->black_pixel;
3111 gcv.fill_style = FillStippled;
3112 } else {
3113 gcv.foreground = scr->dtext_pixel;
3114 gcv.fill_style = FillSolid;
3116 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3118 return REFRESH_MENU_COLOR;
3119 #undef gcm
3122 static int
3123 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3125 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3127 return REFRESH_ICON_TITLE_COLOR;
3131 static int
3132 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3134 if (scr->icon_title_texture) {
3135 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3137 XQueryColor (dpy, scr->w_colormap, color);
3138 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3140 return REFRESH_ICON_TITLE_BACK;
3144 static void
3145 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3147 close(scr->helper_fd);
3148 scr->helper_fd = 0;
3149 scr->helper_pid = 0;
3150 scr->flags.backimage_helper_launched = 0;
3154 static int
3155 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3156 void *bar)
3158 int i;
3159 proplist_t val;
3160 char *str;
3162 if (scr->flags.backimage_helper_launched) {
3163 if (PLGetNumberOfElements(value)==0) {
3164 SendHelperMessage(scr, 'C', 0, NULL);
3165 SendHelperMessage(scr, 'K', 0, NULL);
3167 PLRelease(value);
3168 return 0;
3170 } else {
3171 pid_t pid;
3172 int filedes[2];
3174 if (PLGetNumberOfElements(value) == 0)
3175 return 0;
3177 if (pipe(filedes) < 0) {
3178 wsyserror("pipe() failed:can't set workspace specific background image");
3180 PLRelease(value);
3181 return 0;
3184 pid = fork();
3185 if (pid < 0) {
3186 wsyserror("fork() failed:can't set workspace specific background image");
3187 if (close(filedes[0]) < 0)
3188 wsyserror("could not close pipe");
3189 if (close(filedes[1]) < 0)
3190 wsyserror("could not close pipe");
3192 } else if (pid == 0) {
3193 SetupEnvironment(scr);
3195 if (close(0) < 0)
3196 wsyserror("could not close pipe");
3197 if (dup(filedes[0]) < 0) {
3198 wsyserror("dup() failed:can't set workspace specific background image");
3200 if (wPreferences.smooth_workspace_back)
3201 execlp("wmsetbg", "wmsetbg", "-helper", "-S", "-d", NULL);
3202 else
3203 execlp("wmsetbg", "wmsetbg", "-helper", "-d", NULL);
3204 wsyserror("could not execute wmsetbg");
3205 exit(1);
3206 } else {
3208 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3209 wsyserror("error setting close-on-exec flag");
3211 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3212 wsyserror("error setting close-on-exec flag");
3215 scr->helper_fd = filedes[1];
3216 scr->helper_pid = pid;
3217 scr->flags.backimage_helper_launched = 1;
3219 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3221 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3226 for (i = 0; i < PLGetNumberOfElements(value); i++) {
3227 val = PLGetArrayElement(value, i);
3228 if (val && PLIsArray(val) && PLGetNumberOfElements(val)>0) {
3229 str = PLGetDescription(val);
3231 SendHelperMessage(scr, 'S', i+1, str);
3233 wfree(str);
3234 } else {
3235 SendHelperMessage(scr, 'U', i+1, NULL);
3238 sleep(1);
3240 PLRelease(value);
3241 return 0;
3245 static int
3246 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, proplist_t value,
3247 void *bar)
3249 if (scr->flags.backimage_helper_launched) {
3250 char *str;
3252 if (PLGetNumberOfElements(value)==0) {
3253 SendHelperMessage(scr, 'U', 0, NULL);
3254 } else {
3255 /* set the default workspace background to this one */
3256 str = PLGetDescription(value);
3257 if (str) {
3258 SendHelperMessage(scr, 'S', 0, str);
3259 wfree(str);
3260 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3261 } else {
3262 SendHelperMessage(scr, 'U', 0, NULL);
3265 } else if (PLGetNumberOfElements(value) > 0) {
3266 char *command;
3267 char *text;
3269 SetupEnvironment(scr);
3270 text = PLGetDescription(value);
3271 command = wmalloc(strlen(text)+40);
3272 if (wPreferences.smooth_workspace_back)
3273 sprintf(command, "wmsetbg -d -S -p '%s' &", text);
3274 else
3275 sprintf(command, "wmsetbg -d -p '%s' &", text);
3276 wfree(text);
3277 system(command);
3278 wfree(command);
3280 PLRelease(value);
3282 return 0;
3286 static int
3287 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3289 if (scr->widget_texture) {
3290 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3292 scr->widget_texture = *(WTexSolid**)texture;
3294 return 0;
3298 static int
3299 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3301 if (scr->window_title_texture[WS_FOCUSED]) {
3302 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3304 scr->window_title_texture[WS_FOCUSED] = *texture;
3306 return REFRESH_WINDOW_TEXTURES;
3310 static int
3311 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3313 if (scr->window_title_texture[WS_PFOCUSED]) {
3314 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3316 scr->window_title_texture[WS_PFOCUSED] = *texture;
3318 return REFRESH_WINDOW_TEXTURES;
3322 static int
3323 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3325 if (scr->window_title_texture[WS_UNFOCUSED]) {
3326 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3328 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3330 return REFRESH_WINDOW_TEXTURES;
3334 static int
3335 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3337 if (scr->resizebar_texture[0]) {
3338 wTextureDestroy(scr, scr->resizebar_texture[0]);
3340 scr->resizebar_texture[0] = *texture;
3342 return REFRESH_WINDOW_TEXTURES;
3346 static int
3347 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3349 if (scr->menu_title_texture[0]) {
3350 wTextureDestroy(scr, scr->menu_title_texture[0]);
3352 scr->menu_title_texture[0] = *texture;
3354 return REFRESH_MENU_TITLE_TEXTURE;
3358 static int
3359 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3361 if (scr->menu_item_texture) {
3362 wTextureDestroy(scr, scr->menu_item_texture);
3363 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3365 scr->menu_item_texture = *texture;
3367 scr->menu_item_auxtexture
3368 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3370 return REFRESH_MENU_TEXTURE;
3374 static int
3375 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3377 WWindow *wwin;
3378 wKeyBindings[index] = *shortcut;
3380 wwin = scr->focused_window;
3382 while (wwin!=NULL) {
3383 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3385 if (!WFLAGP(wwin, no_bind_keys)) {
3386 wWindowSetKeyGrabs(wwin);
3388 wwin = wwin->prev;
3391 return 0;
3395 static int
3396 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3398 wArrangeIcons(scr, True);
3400 return 0;
3404 static int
3405 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3407 wScreenUpdateUsableArea(scr);
3409 return 0;
3413 static int
3414 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3416 return REFRESH_MENU_TEXTURE;
3421 static int
3422 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3424 return REFRESH_BUTTON_IMAGES;
3429 * Very ugly kluge.
3430 * Need access to the double click variables, so that all widgets in
3431 * wmaker panels will have the same dbl-click values.
3432 * TODO: figure a better way of dealing with it.
3434 #include "WINGsP.h"
3436 static int
3437 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3439 extern _WINGsConfiguration WINGsConfiguration;
3441 if (*value <= 0)
3442 *(int*)foo = 1;
3444 WINGsConfiguration.doubleClickDelay = *value;
3446 return 0;
3450 #if 0
3451 static int
3452 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3454 extern _WINGsConfiguration WINGsConfiguration;
3456 WINGsConfiguration.useMultiByte = *value;
3458 return 0;
3460 #endif
3462 #ifdef DEFINABLE_CURSOR
3463 static int
3464 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3466 if (None != wCursor[index])
3468 XFreeCursor(dpy, wCursor[index]);
3471 wCursor[index] = *cursor;
3473 if ((WCUR_ROOT == index) && (None != *cursor))
3475 XDefineCursor(dpy, scr->root_win, *cursor);
3478 return 0;
3480 #endif /* DEFINABLE_CURSOR*/