remove drawstring plugins
[wmaker-crm.git] / src / defaults.c
blobc08658bd0164a4f935a7efce8ad2c96fc570e6a1
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 static int getWSBackground();
133 static int getWSSpecificBackground();
134 static int getFont();
135 static int getColor();
136 static int getKeybind();
137 static int getModMask();
138 #ifdef NEWSTUFF
139 static int getRImage();
140 #endif
143 /* value setting functions */
144 static int setJustify();
145 static int setClearance();
146 static int setIfDockPresent();
147 static int setStickyIcons();
149 static int setPositive();
151 static int setWidgetColor();
152 static int setIconTile();
153 static int setWinTitleFont();
154 static int setMenuTitleFont();
155 static int setMenuTextFont();
156 static int setIconTitleFont();
157 static int setIconTitleColor();
158 static int setIconTitleBack();
159 static int setLargeDisplayFont();
160 static int setWTitleColor();
161 static int setFTitleBack();
162 static int setPTitleBack();
163 static int setUTitleBack();
164 static int setResizebarBack();
165 static int setWorkspaceBack();
166 static int setWorkspaceSpecificBack();
167 static int setMenuTitleColor();
168 static int setMenuTextColor();
169 static int setMenuDisabledColor();
170 static int setMenuTitleBack();
171 static int setMenuTextBack();
172 static int setHightlight();
173 static int setHightlightText();
174 static int setKeyGrab();
175 static int setDoubleClick();
176 static int setIconPosition();
178 static int setClipTitleFont();
179 static int setClipTitleColor();
181 static int setMenuStyle();
182 #if 0
183 static int setMultiByte();
184 #endif
185 static int updateUsableArea();
187 #ifdef DEFINABLE_CURSOR
188 extern Cursor wCursor[WCUR_LAST];
189 static int getCursor();
190 static int setCursor();
191 #endif
195 * Tables to convert strings to enumeration values.
196 * Values stored are char
200 /* WARNING: sum of length of all value strings must not exceed
201 * this value */
202 #define TOTAL_VALUES_LENGTH 80
207 #define REFRESH_WINDOW_TEXTURES (1<<0)
208 #define REFRESH_MENU_TEXTURE (1<<1)
209 #define REFRESH_MENU_FONT (1<<2)
210 #define REFRESH_MENU_COLOR (1<<3)
211 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
212 #define REFRESH_MENU_TITLE_FONT (1<<5)
213 #define REFRESH_MENU_TITLE_COLOR (1<<6)
214 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
215 #define REFRESH_WINDOW_FONT (1<<8)
216 #define REFRESH_ICON_TILE (1<<9)
217 #define REFRESH_ICON_FONT (1<<10)
218 #define REFRESH_WORKSPACE_BACK (1<<11)
220 #define REFRESH_BUTTON_IMAGES (1<<12)
222 #define REFRESH_ICON_TITLE_COLOR (1<<13)
223 #define REFRESH_ICON_TITLE_BACK (1<<14)
227 static WOptionEnumeration seFocusModes[] = {
228 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
229 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
230 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1},
231 {NULL, 0, 0}
234 static WOptionEnumeration seColormapModes[] = {
235 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
236 {"Auto", WKF_POINTER, 0}, {"FocusFollowMouse", WKF_POINTER, 1},
237 {NULL, 0, 0}
240 static WOptionEnumeration sePlacements[] = {
241 {"Auto", WPM_AUTO, 0},
242 {"Smart", WPM_SMART, 0},
243 {"Cascade", WPM_CASCADE, 0},
244 {"Random", WPM_RANDOM, 0},
245 {"Manual", WPM_MANUAL, 0},
246 {NULL, 0, 0}
249 static WOptionEnumeration seGeomDisplays[] = {
250 {"Center", WDIS_CENTER, 0},
251 {"Corner", WDIS_TOPLEFT, 0},
252 {"Floating", WDIS_FRAME_CENTER, 0},
253 {"Line", WDIS_NEW, 0},
254 {NULL, 0, 0}
257 static WOptionEnumeration seSpeeds[] = {
258 {"UltraFast", SPEED_ULTRAFAST, 0},
259 {"Fast", SPEED_FAST, 0},
260 {"Medium", SPEED_MEDIUM, 0},
261 {"Slow", SPEED_SLOW, 0},
262 {"UltraSlow", SPEED_ULTRASLOW, 0},
263 {NULL, 0, 0}
266 static WOptionEnumeration seMouseButtons[] = {
267 {"None", -1, 0},
268 {"Left", Button1, 0}, {"Button1", Button1, 1},
269 {"Middle", Button2, 0}, {"Button2", Button2, 1},
270 {"Right", Button3, 0}, {"Button3", Button3, 1},
271 {"Button4", Button4, 0},
272 {"Button5", Button5, 0},
273 {NULL, 0, 0}
276 static WOptionEnumeration seIconificationStyles[] = {
277 {"Zoom", WIS_ZOOM, 0},
278 {"Twist", WIS_TWIST, 0},
279 {"Flip", WIS_FLIP, 0},
280 {"None", WIS_NONE, 0},
281 {"random", WIS_RANDOM, 0},
282 {NULL, 0, 0}
285 static WOptionEnumeration seJustifications[] = {
286 {"Left", WTJ_LEFT, 0},
287 {"Center", WTJ_CENTER, 0},
288 {"Right", WTJ_RIGHT, 0},
289 {NULL, 0, 0}
292 static WOptionEnumeration seIconPositions[] = {
293 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
294 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
295 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
296 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
297 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
298 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
299 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
300 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
301 {NULL, 0, 0}
304 static WOptionEnumeration seMenuStyles[] = {
305 {"normal", MS_NORMAL, 0},
306 {"singletexture", MS_SINGLE_TEXTURE, 0},
307 {"flat", MS_FLAT, 0},
308 {NULL, 0, 0}
312 static WOptionEnumeration seDisplayPositions[] = {
313 {"none", WD_NONE, 0},
314 {"center", WD_CENTER, 0},
315 {"top", WD_TOP, 0},
316 {"bottom", WD_BOTTOM, 0},
317 {"topleft", WD_TOPLEFT, 0},
318 {"topright", WD_TOPRIGHT, 0},
319 {"bottomleft", WD_BOTTOMLEFT, 0},
320 {"bottomright", WD_BOTTOMRIGHT, 0},
321 {NULL, 0, 0}
324 static WOptionEnumeration seWorkspaceBorder[] = {
325 {"None", WB_NONE, 0},
326 {"LeftRight", WB_LEFTRIGHT, 0},
327 {"TopBottom", WB_TOPBOTTOM, 0},
328 {"AllDirections", WB_ALLDIRS, 0},
329 {NULL, 0, 0}
334 * ALL entries in the tables bellow, NEED to have a default value
335 * defined, and this value needs to be correct.
338 /* these options will only affect the window manager on startup
340 * static defaults can't access the screen data, because it is
341 * created after these defaults are read
343 WDefaultEntry staticOptionList[] = {
345 {"ColormapSize", "4", NULL,
346 &wPreferences.cmap_size, getInt, NULL
348 {"DisableDithering", "NO", NULL,
349 &wPreferences.no_dithering, getBool, NULL
351 /* static by laziness */
352 {"IconSize", "64", NULL,
353 &wPreferences.icon_size, getInt, NULL
355 {"ModifierKey", "Mod1", NULL,
356 &wPreferences.modifier_mask, getModMask, NULL
358 {"DisableWSMouseActions", "NO", NULL,
359 &wPreferences.disable_root_mouse, getBool, NULL
361 {"FocusMode", "manual", seFocusModes,
362 &wPreferences.focus_mode, getEnum, NULL
363 }, /* have a problem when switching from manual to sloppy without restart */
364 {"NewStyle", "NO", NULL,
365 &wPreferences.new_style, getBool, NULL
367 {"DisableDock", "NO", (void*) WM_DOCK,
368 NULL, getBool, setIfDockPresent
370 {"DisableClip", "NO", (void*) WM_CLIP,
371 NULL, getBool, setIfDockPresent
373 {"DisableMiniwindows", "NO", NULL,
374 &wPreferences.disable_miniwindows, getBool, NULL
376 #if 0
377 ,{"MultiByteText", "NO", NULL,
378 &wPreferences.multi_byte_text, getBool, setMultiByte
380 #endif
385 WDefaultEntry optionList[] = {
386 /* dynamic options */
387 {"IconPosition", "blh", seIconPositions,
388 &wPreferences.icon_yard, getEnum, setIconPosition
390 {"IconificationStyle", "Zoom", seIconificationStyles,
391 &wPreferences.iconification_style, getEnum, NULL
393 {"SelectWindowsMouseButton", "Left", seMouseButtons,
394 &wPreferences.select_button, getEnum, NULL
396 {"WindowListMouseButton", "Middle", seMouseButtons,
397 &wPreferences.windowl_button, getEnum, NULL
399 {"ApplicationMenuMouseButton", "Right", seMouseButtons,
400 &wPreferences.menu_button, getEnum, NULL
402 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
403 &wPreferences.pixmap_path, getPathList, NULL
405 {"IconPath", DEF_ICON_PATHS, NULL,
406 &wPreferences.icon_path, getPathList, NULL
408 {"ColormapMode", "auto", seColormapModes,
409 &wPreferences.colormap_mode, getEnum, NULL
411 {"AutoFocus", "NO", NULL,
412 &wPreferences.auto_focus, getBool, NULL
414 {"RaiseDelay", "0", NULL,
415 &wPreferences.raise_delay, getInt, NULL
417 {"WindozeCycling", "YES", NULL,
418 &wPreferences.windows_cycling,getBool, NULL
420 {"CirculateRaise", "NO", NULL,
421 &wPreferences.circ_raise, getBool, NULL
423 {"Superfluous", "NO", NULL,
424 &wPreferences.superfluous, getBool, NULL
426 {"AdvanceToNewWorkspace", "NO", NULL,
427 &wPreferences.ws_advance, getBool, NULL
429 {"CycleWorkspaces", "NO", NULL,
430 &wPreferences.ws_cycle, getBool, NULL
432 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
433 &wPreferences.workspace_name_display_position, getEnum, NULL
435 {"WorkspaceBorder", "None", seWorkspaceBorder,
436 &wPreferences.workspace_border_position, getEnum, updateUsableArea
438 {"WorkspaceBorderSize", "0", NULL,
439 &wPreferences.workspace_border_size, getInt, updateUsableArea
441 #ifdef VIRTUAL_DESKTOP
442 {"VirtualEdgeThickness", "1", NULL,
443 &wPreferences.vedge_thickness, getInt, NULL
445 {"VirtualEdgeHorizonScrollSpeed", "1", NULL,
446 &wPreferences.vedge_hscrollspeed, getInt, NULL
448 {"VirtualEdgeVerticalScrollSpeed", "1", NULL,
449 &wPreferences.vedge_vscrollspeed, getInt, NULL
451 {"VirtualEdgeMaximumWidth", "3000", NULL,
452 &wPreferences.vedge_maxwidth, getInt, NULL
454 {"VirtualEdgeMaximumHeight", "3000", NULL,
455 &wPreferences.vedge_maxheight, getInt, NULL
457 #endif
458 {"StickyIcons", "NO", NULL,
459 &wPreferences.sticky_icons, getBool, setStickyIcons
461 {"SaveSessionOnExit", "NO", NULL,
462 &wPreferences.save_session_on_exit, getBool, NULL
464 {"WrapMenus", "NO", NULL,
465 &wPreferences.wrap_menus, getBool, NULL
467 {"ScrollableMenus", "NO", NULL,
468 &wPreferences.scrollable_menus, getBool, NULL
470 {"MenuScrollSpeed", "medium", seSpeeds,
471 &wPreferences.menu_scroll_speed, getEnum, NULL
473 {"IconSlideSpeed", "medium", seSpeeds,
474 &wPreferences.icon_slide_speed, getEnum, NULL
476 {"ShadeSpeed", "medium", seSpeeds,
477 &wPreferences.shade_speed, getEnum, NULL
479 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
480 &wPreferences.dblclick_time, getInt, setDoubleClick,
482 {"AlignSubmenus", "NO", NULL,
483 &wPreferences.align_menus, getBool, NULL
485 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
486 &wPreferences.open_transients_with_parent, getBool, NULL
488 {"WindowPlacement", "auto", sePlacements,
489 &wPreferences.window_placement, getEnum, NULL
491 {"IgnoreFocusClick","NO", NULL,
492 &wPreferences.ignore_focus_click, getBool, NULL
494 {"UseSaveUnders", "NO", NULL,
495 &wPreferences.use_saveunders, getBool, NULL
497 {"OpaqueMove", "NO", NULL,
498 &wPreferences.opaque_move, getBool, NULL
500 {"DisableSound", "NO", NULL,
501 &wPreferences.no_sound, getBool, NULL
503 {"DisableAnimations", "NO", NULL,
504 &wPreferences.no_animations, getBool, NULL
506 {"DontLinkWorkspaces","NO", NULL,
507 &wPreferences.no_autowrap, getBool, NULL
509 {"AutoArrangeIcons", "NO", NULL,
510 &wPreferences.auto_arrange_icons, getBool, NULL
512 {"NoWindowOverDock", "NO", NULL,
513 &wPreferences.no_window_over_dock, getBool, updateUsableArea
515 {"NoWindowOverIcons", "NO", NULL,
516 &wPreferences.no_window_over_icons, getBool, updateUsableArea
518 {"WindowPlaceOrigin", "(0, 0)", NULL,
519 &wPreferences.window_place_origin, getCoord, NULL
521 {"ResizeDisplay", "corner", seGeomDisplays,
522 &wPreferences.size_display, getEnum, NULL
524 {"MoveDisplay", "corner", seGeomDisplays,
525 &wPreferences.move_display, getEnum, NULL
527 {"DontConfirmKill", "NO", NULL,
528 &wPreferences.dont_confirm_kill, getBool,NULL
530 {"WindowTitleBalloons", "NO", NULL,
531 &wPreferences.window_balloon, getBool, NULL
533 {"MiniwindowTitleBalloons", "NO", NULL,
534 &wPreferences.miniwin_balloon,getBool, NULL
536 {"AppIconBalloons", "NO", NULL,
537 &wPreferences.appicon_balloon,getBool, NULL
539 {"HelpBalloons", "NO", NULL,
540 &wPreferences.help_balloon, getBool, NULL
542 {"EdgeResistance", "30", NULL,
543 &wPreferences.edge_resistance,getInt, NULL
545 {"Attraction", "NO", NULL,
546 &wPreferences.attract, getBool, NULL
548 {"DisableBlinking", "NO", NULL,
549 &wPreferences.dont_blink, getBool, NULL
551 /* style options */
552 {"MenuStyle", "normal", seMenuStyles,
553 &wPreferences.menu_style, getEnum, setMenuStyle
555 {"WidgetColor", "(solid, gray)", NULL,
556 NULL, getTexture, setWidgetColor,
558 {"WorkspaceSpecificBack","()", NULL,
559 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
561 /* WorkspaceBack must come after WorkspaceSpecificBack or
562 * WorkspaceBack wont know WorkspaceSpecificBack was also
563 * specified and 2 copies of wmsetbg will be launched */
564 {"WorkspaceBack", "(solid, black)", NULL,
565 NULL, getWSBackground,setWorkspaceBack
567 {"SmoothWorkspaceBack", "NO", NULL,
568 NULL, getBool, NULL
570 {"IconBack", "(solid, gray)", NULL,
571 NULL, getTexture, setIconTile
573 {"TitleJustify", "center", seJustifications,
574 &wPreferences.title_justification, getEnum, setJustify
576 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
577 NULL, getFont, setWinTitleFont,
579 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
580 &wPreferences.window_title_clearance, getInt, setClearance
582 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
583 &wPreferences.menu_title_clearance, getInt, setClearance
585 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
586 &wPreferences.menu_text_clearance, getInt, setClearance
588 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
589 NULL, getFont, setMenuTitleFont
591 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
592 NULL, getFont, setMenuTextFont
594 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
595 NULL, getFont, setIconTitleFont
597 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
598 NULL, getFont, setClipTitleFont
600 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
601 NULL, getFont, setLargeDisplayFont
603 {"HighlightColor", "white", NULL,
604 NULL, getColor, setHightlight
606 {"HighlightTextColor", "black", NULL,
607 NULL, getColor, setHightlightText
609 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
610 NULL, getColor, setClipTitleColor
612 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
613 NULL, getColor, setClipTitleColor
615 {"FTitleColor", "white", (void*)WS_FOCUSED,
616 NULL, getColor, setWTitleColor
618 {"PTitleColor", "white", (void*)WS_PFOCUSED,
619 NULL, getColor, setWTitleColor
621 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
622 NULL, getColor, setWTitleColor
624 {"FTitleBack", "(solid, black)", NULL,
625 NULL, getTexture, setFTitleBack
627 {"PTitleBack", "(solid, \"#616161\")", NULL,
628 NULL, getTexture, setPTitleBack
630 {"UTitleBack", "(solid, gray)", NULL,
631 NULL, getTexture, setUTitleBack
633 {"ResizebarBack", "(solid, gray)", NULL,
634 NULL, getTexture, setResizebarBack
636 {"MenuTitleColor", "white", NULL,
637 NULL, getColor, setMenuTitleColor
639 {"MenuTextColor", "black", NULL,
640 NULL, getColor, setMenuTextColor
642 {"MenuDisabledColor", "\"#616161\"", NULL,
643 NULL, getColor, setMenuDisabledColor
645 {"MenuTitleBack", "(solid, black)", NULL,
646 NULL, getTexture, setMenuTitleBack
648 {"MenuTextBack", "(solid, gray)", NULL,
649 NULL, getTexture, setMenuTextBack
651 {"IconTitleColor", "white", NULL,
652 NULL, getColor, setIconTitleColor
654 {"IconTitleBack", "black", NULL,
655 NULL, getColor, setIconTitleBack
657 /* keybindings */
658 #ifndef LITE
659 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
660 NULL, getKeybind, setKeyGrab
662 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
663 NULL, getKeybind, setKeyGrab
665 #endif /* LITE */
666 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
667 NULL, getKeybind, setKeyGrab
669 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
670 NULL, getKeybind, setKeyGrab
672 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
673 NULL, getKeybind, setKeyGrab
675 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
676 NULL, getKeybind, setKeyGrab
678 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
679 NULL, getKeybind, setKeyGrab
681 {"HideKey", "None", (void*)WKBD_HIDE,
682 NULL, getKeybind, setKeyGrab
684 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
685 NULL, getKeybind, setKeyGrab
687 {"CloseKey", "None", (void*)WKBD_CLOSE,
688 NULL, getKeybind, setKeyGrab
690 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
691 NULL, getKeybind, setKeyGrab
693 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
694 NULL, getKeybind, setKeyGrab
696 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
697 NULL, getKeybind, setKeyGrab
699 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
700 NULL, getKeybind, setKeyGrab
702 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
703 NULL, getKeybind, setKeyGrab
705 {"ShadeKey", "None", (void*)WKBD_SHADE,
706 NULL, getKeybind, setKeyGrab
708 {"SelectKey", "None", (void*)WKBD_SELECT,
709 NULL, getKeybind, setKeyGrab
711 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
712 NULL, getKeybind, setKeyGrab
714 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
715 NULL, getKeybind, setKeyGrab
717 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
718 NULL, getKeybind, setKeyGrab
720 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
721 NULL, getKeybind, setKeyGrab
723 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
724 NULL, getKeybind, setKeyGrab
726 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
727 NULL, getKeybind, setKeyGrab
729 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
730 NULL, getKeybind, setKeyGrab
732 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
733 NULL, getKeybind, setKeyGrab
735 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
757 NULL, getKeybind, setKeyGrab
759 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
760 NULL, getKeybind, setKeyGrab
762 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
763 NULL, getKeybind, setKeyGrab
765 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
766 NULL, getKeybind, setKeyGrab
768 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
769 NULL, getKeybind, setKeyGrab
771 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
772 NULL, getKeybind, setKeyGrab
774 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
787 NULL, getKeybind, setKeyGrab
789 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
790 NULL, getKeybind, setKeyGrab
793 #ifdef KEEP_XKB_LOCK_STATUS
794 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
795 NULL, getKeybind, setKeyGrab
797 {"KbdModeLock", "NO", NULL,
798 &wPreferences.modelock, getBool, NULL
800 #endif /* KEEP_XKB_LOCK_STATUS */
801 #ifdef DEFINABLE_CURSOR
802 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
803 NULL, getCursor, setCursor
805 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
806 NULL, getCursor, setCursor
808 #if 0
809 {"TopLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPLEFTRESIZE,
810 NULL, getCursor, setCursor
812 {"TopRightResizeCursor", "(builtin, sizing)", (void*)WCUR_TOPRIGHTRESIZE,
813 NULL, getCursor, setCursor
815 {"BottomLeftResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMLEFTRESIZE,
816 NULL, getCursor, setCursor
818 {"BottomRightResizeCursor", "(builtin, sizing)", (void*)WCUR_BOTTOMRIGHTRESIZE,
819 NULL, getCursor, setCursor
821 {"VerticalResizeCursor", "(builtin, sizing)", (void*)WCUR_VERTICALRESIZE,
822 NULL, getCursor, setCursor
824 {"HorizonResizeCursor", "(builtin, sizing)", (void*)WCUR_HORIZONRESIZE,
825 NULL, getCursor, setCursor
827 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
828 NULL, getCursor, setCursor
830 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
831 NULL, getCursor, setCursor
833 #endif
834 #endif /* DEFINABLE_CURSOR */
838 #if 0
839 static void rereadDefaults(void);
840 #endif
842 #if 0
843 static void
844 rereadDefaults(void)
846 /* must defer the update because accessing X data from a
847 * signal handler can mess up Xlib */
850 #endif
852 static void
853 initDefaults()
855 int i;
856 WDefaultEntry *entry;
858 PLSetStringCmpHook(StringCompareHook);
860 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
861 entry = &optionList[i];
863 entry->plkey = PLMakeString(entry->key);
864 if (entry->default_value)
865 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
866 else
867 entry->plvalue = NULL;
870 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
871 entry = &staticOptionList[i];
873 entry->plkey = PLMakeString(entry->key);
874 if (entry->default_value)
875 entry->plvalue = PLGetProplistWithDescription(entry->default_value);
876 else
877 entry->plvalue = NULL;
881 wDomainName = PLMakeString(WMDOMAIN_NAME);
882 wAttributeDomainName = PLMakeString(WMATTRIBUTE_DOMAIN_NAME);
884 PLRegister(wDomainName, rereadDefaults);
885 PLRegister(wAttributeDomainName, rereadDefaults);
892 #if 0
893 proplist_t
894 wDefaultsInit(int screen_number)
896 static int defaults_inited = 0;
897 proplist_t dict;
899 if (!defaults_inited) {
900 initDefaults();
903 dict = PLGetDomain(wDomainName);
904 if (!dict) {
905 wwarning(_("could not read domain \"%s\" from defaults database"),
906 PLGetString(wDomainName));
909 return dict;
911 #endif
914 void
915 wDefaultsDestroyDomain(WDDomain *domain)
917 if (domain->dictionary)
918 PLRelease(domain->dictionary);
919 wfree(domain->path);
920 wfree(domain);
924 WDDomain*
925 wDefaultsInitDomain(char *domain, Bool requireDictionary)
927 WDDomain *db;
928 struct stat stbuf;
929 static int inited = 0;
930 char path[PATH_MAX];
931 char *the_path;
932 proplist_t shared_dict=NULL;
934 if (!inited) {
935 inited = 1;
936 initDefaults();
939 db = wmalloc(sizeof(WDDomain));
940 memset(db, 0, sizeof(WDDomain));
941 db->domain_name = domain;
942 db->path = wdefaultspathfordomain(domain);
943 the_path = db->path;
945 if (the_path && stat(the_path, &stbuf)>=0) {
946 db->dictionary = ReadProplistFromFile(the_path);
947 if (db->dictionary) {
948 if (requireDictionary && !PLIsDictionary(db->dictionary)) {
949 PLRelease(db->dictionary);
950 db->dictionary = NULL;
951 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
952 domain, the_path);
954 db->timestamp = stbuf.st_mtime;
955 } else {
956 wwarning(_("could not load domain %s from user defaults database"),
957 domain);
961 /* global system dictionary */
962 sprintf(path, "%s/WindowMaker/%s", SYSCONFDIR, domain);
963 if (stat(path, &stbuf)>=0) {
964 shared_dict = ReadProplistFromFile(path);
965 if (shared_dict) {
966 if (requireDictionary && !PLIsDictionary(shared_dict)) {
967 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
968 domain, path);
969 PLRelease(shared_dict);
970 shared_dict = NULL;
971 } else {
972 if (db->dictionary && PLIsDictionary(shared_dict) &&
973 PLIsDictionary(db->dictionary)) {
974 PLMergeDictionaries(shared_dict, db->dictionary);
975 PLRelease(db->dictionary);
976 db->dictionary = shared_dict;
977 if (stbuf.st_mtime > db->timestamp)
978 db->timestamp = stbuf.st_mtime;
979 } else if (!db->dictionary) {
980 db->dictionary = shared_dict;
981 if (stbuf.st_mtime > db->timestamp)
982 db->timestamp = stbuf.st_mtime;
985 } else {
986 wwarning(_("could not load domain %s from global defaults database (%s)"),
987 domain, path);
991 /* set to save it in user's directory, no matter from where it was read */
992 if (db->dictionary) {
993 proplist_t tmp = PLMakeString(db->path);
995 PLSetFilename(db->dictionary, tmp);
996 PLRelease(tmp);
999 return db;
1003 void
1004 wReadStaticDefaults(proplist_t dict)
1006 proplist_t plvalue;
1007 WDefaultEntry *entry;
1008 int i;
1009 void *tdata;
1012 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1013 entry = &staticOptionList[i];
1015 if (dict)
1016 plvalue = PLGetDictionaryEntry(dict, entry->plkey);
1017 else
1018 plvalue = NULL;
1020 if (!plvalue) {
1021 /* no default in the DB. Use builtin default */
1022 plvalue = entry->plvalue;
1025 if (plvalue) {
1026 /* convert data */
1027 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1028 if (entry->update) {
1029 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1036 void
1037 wDefaultsCheckDomains(void *foo)
1039 WScreen *scr;
1040 struct stat stbuf;
1041 proplist_t dict;
1042 int i;
1043 char path[PATH_MAX];
1045 #ifdef HEARTBEAT
1046 puts("Checking domains...");
1047 #endif
1048 if (stat(WDWindowMaker->path, &stbuf)>=0
1049 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1050 proplist_t shared_dict = NULL;
1051 #ifdef HEARTBEAT
1052 puts("Checking WindowMaker domain");
1053 #endif
1054 WDWindowMaker->timestamp = stbuf.st_mtime;
1056 /* global dictionary */
1057 sprintf(path, "%s/WindowMaker/WindowMaker", SYSCONFDIR);
1058 if (stat(path, &stbuf)>=0) {
1059 shared_dict = ReadProplistFromFile(path);
1060 if (shared_dict && !PLIsDictionary(shared_dict)) {
1061 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1062 "WindowMaker", path);
1063 PLRelease(shared_dict);
1064 shared_dict = NULL;
1065 } else if (!shared_dict) {
1066 wwarning(_("could not load domain %s from global defaults database"),
1067 "WindowMaker");
1070 /* user dictionary */
1071 dict = ReadProplistFromFile(WDWindowMaker->path);
1072 if (dict) {
1073 if (!PLIsDictionary(dict)) {
1074 PLRelease(dict);
1075 dict = NULL;
1076 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1077 "WindowMaker", WDWindowMaker->path);
1078 } else {
1079 if (shared_dict) {
1080 PLSetFilename(shared_dict, PLGetFilename(dict));
1081 PLMergeDictionaries(shared_dict, dict);
1082 PLRelease(dict);
1083 dict = shared_dict;
1084 shared_dict = NULL;
1086 for (i=0; i<wScreenCount; i++) {
1087 scr = wScreenWithNumber(i);
1088 if (scr)
1089 wReadDefaults(scr, dict);
1091 if (WDWindowMaker->dictionary) {
1092 PLRelease(WDWindowMaker->dictionary);
1094 WDWindowMaker->dictionary = dict;
1096 } else {
1097 wwarning(_("could not load domain %s from user defaults database"),
1098 "WindowMaker");
1100 if (shared_dict) {
1101 PLRelease(shared_dict);
1105 if (stat(WDWindowAttributes->path, &stbuf)>=0
1106 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1107 #ifdef HEARTBEAT
1108 puts("Checking WMWindowAttributes domain");
1109 #endif
1110 dict = ReadProplistFromFile(WDWindowAttributes->path);
1111 if (dict) {
1112 if (!PLIsDictionary(dict)) {
1113 PLRelease(dict);
1114 dict = NULL;
1115 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1116 "WMWindowAttributes", WDWindowAttributes->path);
1117 } else {
1118 if (WDWindowAttributes->dictionary)
1119 PLRelease(WDWindowAttributes->dictionary);
1120 WDWindowAttributes->dictionary = dict;
1121 for (i=0; i<wScreenCount; i++) {
1122 scr = wScreenWithNumber(i);
1123 if (scr)
1124 wDefaultUpdateIcons(scr);
1127 } else {
1128 wwarning(_("could not load domain %s from user defaults database"),
1129 "WMWindowAttributes");
1131 WDWindowAttributes->timestamp = stbuf.st_mtime;
1134 #ifndef LITE
1135 if (stat(WDRootMenu->path, &stbuf)>=0
1136 && WDRootMenu->timestamp < stbuf.st_mtime) {
1137 dict = ReadProplistFromFile(WDRootMenu->path);
1138 #ifdef HEARTBEAT
1139 puts("Checking WMRootMenu domain");
1140 #endif
1141 if (dict) {
1142 if (!PLIsArray(dict) && !PLIsString(dict)) {
1143 PLRelease(dict);
1144 dict = NULL;
1145 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1146 "WMRootMenu", WDRootMenu->path);
1147 } else {
1148 if (WDRootMenu->dictionary) {
1149 PLRelease(WDRootMenu->dictionary);
1151 WDRootMenu->dictionary = dict;
1153 } else {
1154 wwarning(_("could not load domain %s from user defaults database"),
1155 "WMRootMenu");
1157 WDRootMenu->timestamp = stbuf.st_mtime;
1159 #endif /* !LITE */
1161 if (!foo)
1162 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1166 void
1167 wReadDefaults(WScreen *scr, proplist_t new_dict)
1169 proplist_t plvalue, old_value;
1170 WDefaultEntry *entry;
1171 int i, must_update;
1172 int update_workspace_back = 0; /* kluge :/ */
1173 int needs_refresh;
1174 void *tdata;
1175 proplist_t old_dict = (WDWindowMaker->dictionary!=new_dict
1176 ? WDWindowMaker->dictionary : NULL);
1178 must_update = 0;
1180 needs_refresh = 0;
1182 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1183 entry = &optionList[i];
1185 if (new_dict)
1186 plvalue = PLGetDictionaryEntry(new_dict, entry->plkey);
1187 else
1188 plvalue = NULL;
1190 if (!old_dict)
1191 old_value = NULL;
1192 else
1193 old_value = PLGetDictionaryEntry(old_dict, entry->plkey);
1196 if (!plvalue && !old_value) {
1197 /* no default in the DB. Use builtin default */
1198 plvalue = entry->plvalue;
1199 if (plvalue && new_dict) {
1200 PLInsertDictionaryEntry(new_dict, entry->plkey, plvalue);
1201 must_update = 1;
1203 } else if (!plvalue) {
1204 /* value was deleted from DB. Keep current value */
1205 continue;
1206 } else if (!old_value) {
1207 /* set value for the 1st time */
1208 } else if (!PLIsEqual(plvalue, old_value)) {
1209 /* value has changed */
1210 } else {
1212 if (strcmp(entry->key, "WorkspaceBack") == 0
1213 && update_workspace_back
1214 && scr->flags.backimage_helper_launched) {
1215 } else {
1216 /* value was not changed since last time */
1217 continue;
1221 if (plvalue) {
1222 #ifdef DEBUG
1223 printf("Updating %s to %s\n", entry->key,
1224 PLGetDescription(plvalue));
1225 #endif
1226 /* convert data */
1227 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1229 * If the WorkspaceSpecificBack data has been changed
1230 * so that the helper will be launched now, we must be
1231 * sure to send the default background texture config
1232 * to the helper.
1234 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1235 && !scr->flags.backimage_helper_launched) {
1236 update_workspace_back = 1;
1238 if (entry->update) {
1239 needs_refresh |=
1240 (*entry->update)(scr, entry, tdata, entry->extra_data);
1246 if (needs_refresh!=0 && !scr->flags.startup) {
1247 int foo;
1249 foo = 0;
1250 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1251 foo |= WTextureSettings;
1252 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1253 foo |= WFontSettings;
1254 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1255 foo |= WColorSettings;
1256 if (foo)
1257 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1258 (void*)foo);
1260 foo = 0;
1261 if (needs_refresh & REFRESH_MENU_TEXTURE)
1262 foo |= WTextureSettings;
1263 if (needs_refresh & REFRESH_MENU_FONT)
1264 foo |= WFontSettings;
1265 if (needs_refresh & REFRESH_MENU_COLOR)
1266 foo |= WColorSettings;
1267 if (foo)
1268 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1269 (void*)foo);
1271 foo = 0;
1272 if (needs_refresh & REFRESH_WINDOW_FONT) {
1273 foo |= WFontSettings;
1275 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1276 foo |= WTextureSettings;
1278 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1279 foo |= WColorSettings;
1281 if (foo)
1282 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1283 (void*)foo);
1285 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1286 foo = 0;
1287 if (needs_refresh & REFRESH_ICON_FONT) {
1288 foo |= WFontSettings;
1290 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1291 foo |= WTextureSettings;
1293 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1294 foo |= WTextureSettings;
1296 if (foo)
1297 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1298 (void*)foo);
1300 if (needs_refresh & REFRESH_ICON_TILE)
1301 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1306 void
1307 wDefaultUpdateIcons(WScreen *scr)
1309 WAppIcon *aicon = scr->app_icon_list;
1310 WWindow *wwin = scr->focused_window;
1311 char *file;
1313 while(aicon) {
1314 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1315 False);
1316 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1317 || (file && !aicon->icon->file)) {
1318 RImage *new_image;
1320 if (aicon->icon->file)
1321 wfree(aicon->icon->file);
1322 aicon->icon->file = wstrdup(file);
1324 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1325 aicon->wm_class);
1326 if (new_image) {
1327 wIconChangeImage(aicon->icon, new_image);
1328 wAppIconPaint(aicon);
1331 aicon = aicon->next;
1334 if (!wPreferences.flags.noclip)
1335 wClipIconPaint(scr->clip_icon);
1337 while (wwin) {
1338 if (wwin->icon && wwin->flags.miniaturized) {
1339 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1340 False);
1341 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1342 || (file && !wwin->icon->file)) {
1343 RImage *new_image;
1345 if (wwin->icon->file)
1346 wfree(wwin->icon->file);
1347 wwin->icon->file = wstrdup(file);
1349 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1350 wwin->wm_class);
1351 if (new_image)
1352 wIconChangeImage(wwin->icon, new_image);
1355 wwin = wwin->prev;
1360 /* --------------------------- Local ----------------------- */
1362 #define GET_STRING_OR_DEFAULT(x, var) if (!PLIsString(value)) { \
1363 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1364 entry->key, x); \
1365 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1366 var = entry->default_value;\
1367 } else var = PLGetString(value)\
1373 static int
1374 string2index(proplist_t key, proplist_t val, proplist_t def,
1375 WOptionEnumeration *values)
1377 char *str;
1378 WOptionEnumeration *v;
1379 char buffer[TOTAL_VALUES_LENGTH];
1381 if (PLIsString(val) && (str = PLGetString(val))) {
1382 for (v=values; v->string!=NULL; v++) {
1383 if (strcasecmp(v->string, str)==0)
1384 return v->value;
1388 buffer[0] = 0;
1389 for (v=values; v->string!=NULL; v++) {
1390 if (!v->is_alias) {
1391 if (buffer[0]!=0)
1392 strcat(buffer, ", ");
1393 strcat(buffer, v->string);
1396 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1397 PLGetString(key), buffer);
1399 if (def) {
1400 return string2index(key, val, NULL, values);
1403 return -1;
1410 * value - is the value in the defaults DB
1411 * addr - is the address to store the data
1412 * ret - is the address to store a pointer to a temporary buffer. ret
1413 * must not be freed and is used by the set functions
1415 static int
1416 getBool(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1417 void **ret)
1419 static char data;
1420 char *val;
1421 int second_pass=0;
1423 GET_STRING_OR_DEFAULT("Boolean", val);
1425 again:
1426 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1427 || strcasecmp(val, "YES")==0) {
1429 data = 1;
1430 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1431 || strcasecmp(val, "NO")==0) {
1432 data = 0;
1433 } else {
1434 int i;
1435 if (sscanf(val, "%i", &i)==1) {
1436 if (i!=0)
1437 data = 1;
1438 else
1439 data = 0;
1440 } else {
1441 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1442 val, entry->key);
1443 if (second_pass==0) {
1444 val = PLGetString(entry->plvalue);
1445 second_pass = 1;
1446 wwarning(_("using default \"%s\" instead"), val);
1447 goto again;
1449 return False;
1453 if (ret)
1454 *ret = &data;
1456 if (addr) {
1457 *(char*)addr = data;
1460 return True;
1464 static int
1465 getInt(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1466 void **ret)
1468 static int data;
1469 char *val;
1472 GET_STRING_OR_DEFAULT("Integer", val);
1474 if (sscanf(val, "%i", &data)!=1) {
1475 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1476 val, entry->key);
1477 val = PLGetString(entry->plvalue);
1478 wwarning(_("using default \"%s\" instead"), val);
1479 if (sscanf(val, "%i", &data)!=1) {
1480 return False;
1484 if (ret)
1485 *ret = &data;
1487 if (addr) {
1488 *(int*)addr = data;
1490 return True;
1494 static int
1495 getCoord(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1496 void **ret)
1498 static WCoord data;
1499 char *val_x, *val_y;
1500 int nelem, changed=0;
1501 proplist_t elem_x, elem_y;
1503 again:
1504 if (!PLIsArray(value)) {
1505 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1506 entry->key, "Coordinate");
1507 if (changed==0) {
1508 value = entry->plvalue;
1509 changed = 1;
1510 wwarning(_("using default \"%s\" instead"), entry->default_value);
1511 goto again;
1513 return False;
1516 nelem = PLGetNumberOfElements(value);
1517 if (nelem != 2) {
1518 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1519 entry->key);
1520 if (changed==0) {
1521 value = entry->plvalue;
1522 changed = 1;
1523 wwarning(_("using default \"%s\" instead"), entry->default_value);
1524 goto again;
1526 return False;
1529 elem_x = PLGetArrayElement(value, 0);
1530 elem_y = PLGetArrayElement(value, 1);
1532 if (!elem_x || !elem_y || !PLIsString(elem_x) || !PLIsString(elem_y)) {
1533 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1534 entry->key);
1535 if (changed==0) {
1536 value = entry->plvalue;
1537 changed = 1;
1538 wwarning(_("using default \"%s\" instead"), entry->default_value);
1539 goto again;
1541 return False;
1544 val_x = PLGetString(elem_x);
1545 val_y = PLGetString(elem_y);
1547 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1548 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1549 if (changed==0) {
1550 value = entry->plvalue;
1551 changed = 1;
1552 wwarning(_("using default \"%s\" instead"), entry->default_value);
1553 goto again;
1555 return False;
1558 if (data.x < 0)
1559 data.x = 0;
1560 else if (data.x > scr->scr_width/3)
1561 data.x = scr->scr_width/3;
1562 if (data.y < 0)
1563 data.y = 0;
1564 else if (data.y > scr->scr_height/3)
1565 data.y = scr->scr_height/3;
1567 if (ret)
1568 *ret = &data;
1570 if (addr) {
1571 *(WCoord*)addr = data;
1574 return True;
1578 #if 0
1579 /* This function is not used at the moment. */
1580 static int
1581 getString(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1582 void **ret)
1584 static char *data;
1586 GET_STRING_OR_DEFAULT("String", data);
1588 if (!data) {
1589 data = PLGetString(entry->plvalue);
1590 if (!data)
1591 return False;
1594 if (ret)
1595 *ret = &data;
1597 if (addr)
1598 *(char**)addr = wstrdup(data);
1600 return True;
1602 #endif
1605 static int
1606 getPathList(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1607 void **ret)
1609 static char *data;
1610 int i, count, len;
1611 char *ptr;
1612 proplist_t d;
1613 int changed=0;
1615 again:
1616 if (!PLIsArray(value)) {
1617 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1618 entry->key, "an array of paths");
1619 if (changed==0) {
1620 value = entry->plvalue;
1621 changed = 1;
1622 wwarning(_("using default \"%s\" instead"), entry->default_value);
1623 goto again;
1625 return False;
1628 i = 0;
1629 count = PLGetNumberOfElements(value);
1630 if (count < 1) {
1631 if (changed==0) {
1632 value = entry->plvalue;
1633 changed = 1;
1634 wwarning(_("using default \"%s\" instead"), entry->default_value);
1635 goto again;
1637 return False;
1640 len = 0;
1641 for (i=0; i<count; i++) {
1642 d = PLGetArrayElement(value, i);
1643 if (!d || !PLIsString(d)) {
1644 count = i;
1645 break;
1647 len += strlen(PLGetString(d))+1;
1650 ptr = data = wmalloc(len+1);
1652 for (i=0; i<count; i++) {
1653 d = PLGetArrayElement(value, i);
1654 if (!d || !PLIsString(d)) {
1655 break;
1657 strcpy(ptr, PLGetString(d));
1658 ptr += strlen(PLGetString(d));
1659 *ptr = ':';
1660 ptr++;
1662 ptr--; *(ptr--) = 0;
1664 if (*(char**)addr!=NULL) {
1665 wfree(*(char**)addr);
1667 *(char**)addr = data;
1669 return True;
1673 static int
1674 getEnum(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
1675 void **ret)
1677 static signed char data;
1679 data = string2index(entry->plkey, value, entry->default_value,
1680 (WOptionEnumeration*)entry->extra_data);
1681 if (data < 0)
1682 return False;
1684 if (ret)
1685 *ret = &data;
1687 if (addr)
1688 *(signed char*)addr = data;
1690 return True;
1696 * (solid <color>)
1697 * (hgradient <color> <color>)
1698 * (vgradient <color> <color>)
1699 * (dgradient <color> <color>)
1700 * (mhgradient <color> <color> ...)
1701 * (mvgradient <color> <color> ...)
1702 * (mdgradient <color> <color> ...)
1703 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
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, "igradient")==0) {
1805 RColor colors1[2], colors2[2];
1806 int th1, th2;
1807 XColor xcolor;
1808 int i;
1810 if (nelem != 7) {
1811 wwarning(_("bad number of arguments in gradient specification"));
1812 return NULL;
1815 /* get from color */
1816 for (i = 0; i < 2; i++) {
1817 elem = PLGetArrayElement(pl, 1+i);
1818 if (!elem || !PLIsString(elem))
1819 return NULL;
1820 val = PLGetString(elem);
1822 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1823 wwarning(_("\"%s\" is not a valid color name"), val);
1824 return NULL;
1826 colors1[i].alpha = 255;
1827 colors1[i].red = xcolor.red >> 8;
1828 colors1[i].green = xcolor.green >> 8;
1829 colors1[i].blue = xcolor.blue >> 8;
1831 elem = PLGetArrayElement(pl, 3);
1832 if (!elem || !PLIsString(elem))
1833 return NULL;
1834 val = PLGetString(elem);
1835 th1 = atoi(val);
1838 /* get from color */
1839 for (i = 0; i < 2; i++) {
1840 elem = PLGetArrayElement(pl, 4+i);
1841 if (!elem || !PLIsString(elem))
1842 return NULL;
1843 val = PLGetString(elem);
1845 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1846 wwarning(_("\"%s\" is not a valid color name"), val);
1847 return NULL;
1849 colors2[i].alpha = 255;
1850 colors2[i].red = xcolor.red >> 8;
1851 colors2[i].green = xcolor.green >> 8;
1852 colors2[i].blue = xcolor.blue >> 8;
1854 elem = PLGetArrayElement(pl, 6);
1855 if (!elem || !PLIsString(elem))
1856 return NULL;
1857 val = PLGetString(elem);
1858 th2 = atoi(val);
1860 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1861 th2, colors2);
1863 } else if (strcasecmp(val, "mhgradient")==0
1864 || strcasecmp(val, "mvgradient")==0
1865 || strcasecmp(val, "mdgradient")==0) {
1866 XColor color;
1867 RColor **colors;
1868 int i, count;
1869 int type;
1871 if (nelem < 3) {
1872 wwarning(_("too few arguments in multicolor gradient specification"));
1873 return NULL;
1876 if (val[1]=='h' || val[1]=='H')
1877 type = WTEX_MHGRADIENT;
1878 else if (val[1]=='v' || val[1]=='V')
1879 type = WTEX_MVGRADIENT;
1880 else
1881 type = WTEX_MDGRADIENT;
1883 count = nelem-1;
1885 colors = wmalloc(sizeof(RColor*)*(count+1));
1887 for (i=0; i<count; i++) {
1888 elem = PLGetArrayElement(pl, i+1);
1889 if (!elem || !PLIsString(elem)) {
1890 for (--i; i>=0; --i) {
1891 wfree(colors[i]);
1893 wfree(colors);
1894 return NULL;
1896 val = PLGetString(elem);
1898 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1899 wwarning(_("\"%s\" is not a valid color name"), val);
1900 for (--i; i>=0; --i) {
1901 wfree(colors[i]);
1903 wfree(colors);
1904 return NULL;
1905 } else {
1906 colors[i] = wmalloc(sizeof(RColor));
1907 colors[i]->red = color.red >> 8;
1908 colors[i]->green = color.green >> 8;
1909 colors[i]->blue = color.blue >> 8;
1912 colors[i] = NULL;
1914 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1915 } else if (strcasecmp(val, "spixmap")==0 ||
1916 strcasecmp(val, "cpixmap")==0 ||
1917 strcasecmp(val, "tpixmap")==0) {
1918 XColor color;
1919 int type;
1921 if (nelem != 3)
1922 return NULL;
1924 if (val[0] == 's' || val[0] == 'S')
1925 type = WTP_SCALE;
1926 else if (val[0] == 'c' || val[0] == 'C')
1927 type = WTP_CENTER;
1928 else
1929 type = WTP_TILE;
1931 /* get color */
1932 elem = PLGetArrayElement(pl, 2);
1933 if (!elem || !PLIsString(elem)) {
1934 return NULL;
1936 val = PLGetString(elem);
1938 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1939 wwarning(_("\"%s\" is not a valid color name"), val);
1940 return NULL;
1943 /* file name */
1944 elem = PLGetArrayElement(pl, 1);
1945 if (!elem || !PLIsString(elem))
1946 return NULL;
1947 val = PLGetString(elem);
1949 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
1950 } else if (strcasecmp(val, "thgradient")==0
1951 || strcasecmp(val, "tvgradient")==0
1952 || strcasecmp(val, "tdgradient")==0) {
1953 RColor color1, color2;
1954 XColor xcolor;
1955 int opacity;
1956 int style;
1958 if (val[1]=='h' || val[1]=='H')
1959 style = WTEX_THGRADIENT;
1960 else if (val[1]=='v' || val[1]=='V')
1961 style = WTEX_TVGRADIENT;
1962 else
1963 style = WTEX_TDGRADIENT;
1965 if (nelem != 5) {
1966 wwarning(_("bad number of arguments in textured gradient specification"));
1967 return NULL;
1970 /* get from color */
1971 elem = PLGetArrayElement(pl, 3);
1972 if (!elem || !PLIsString(elem))
1973 return NULL;
1974 val = PLGetString(elem);
1976 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1977 wwarning(_("\"%s\" is not a valid color name"), val);
1978 return NULL;
1980 color1.alpha = 255;
1981 color1.red = xcolor.red >> 8;
1982 color1.green = xcolor.green >> 8;
1983 color1.blue = xcolor.blue >> 8;
1985 /* get to color */
1986 elem = PLGetArrayElement(pl, 4);
1987 if (!elem || !PLIsString(elem)) {
1988 return NULL;
1990 val = PLGetString(elem);
1992 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1993 wwarning(_("\"%s\" is not a valid color name"), val);
1994 return NULL;
1996 color2.alpha = 255;
1997 color2.red = xcolor.red >> 8;
1998 color2.green = xcolor.green >> 8;
1999 color2.blue = xcolor.blue >> 8;
2001 /* get opacity */
2002 elem = PLGetArrayElement(pl, 2);
2003 if (!elem || !PLIsString(elem))
2004 opacity = 128;
2005 else
2006 val = PLGetString(elem);
2008 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2009 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2010 opacity = 128;
2013 /* get file name */
2014 elem = PLGetArrayElement(pl, 1);
2015 if (!elem || !PLIsString(elem))
2016 return NULL;
2017 val = PLGetString(elem);
2019 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2020 val, opacity);
2022 #ifdef TEXTURE_PLUGIN
2023 else if (strcasecmp(val, "function")==0) {
2024 WTexFunction *function;
2025 void (*initFunc) (Display *, Colormap);
2026 char *lib, *func, **argv;
2027 int i, argc;
2029 if (nelem < 3)
2030 return NULL;
2032 /* get the library name */
2033 elem = PLGetArrayElement(pl, 1);
2034 if (!elem || !PLIsString(elem)) {
2035 return NULL;
2037 lib = PLGetString(elem);
2039 /* get the function name */
2040 elem = PLGetArrayElement(pl, 2);
2041 if (!elem || !PLIsString(elem)) {
2042 return NULL;
2044 func = PLGetString(elem);
2046 argc = nelem - 2;
2047 argv = (char **)wmalloc(argc * sizeof(char *));
2049 /* get the parameters */
2050 argv[0] = wstrdup(func);
2051 for (i = 0; i < argc - 1; i++) {
2052 elem = PLGetArrayElement(pl, 3 + i);
2053 if (!elem || !PLIsString(elem)) {
2054 wfree(argv);
2056 return NULL;
2058 argv[i+1] = wstrdup(PLGetString(elem));
2061 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2063 #ifdef HAVE_DLFCN_H
2064 if (function) {
2065 initFunc = dlsym(function->handle, "initWindowMaker");
2066 if (initFunc) {
2067 initFunc(dpy, scr->w_colormap);
2068 } else {
2069 wwarning(_("could not initialize library %s"), lib);
2071 } else {
2072 wwarning(_("could not find function %s::%s"), lib, func);
2074 #endif /* HAVE_DLFCN_H */
2075 texture = (WTexture*)function;
2077 #endif /* TEXTURE_PLUGIN */
2078 else {
2079 wwarning(_("invalid texture type %s"), val);
2080 return NULL;
2082 return texture;
2087 static int
2088 getTexture(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2089 void **ret)
2091 static WTexture *texture;
2092 int changed=0;
2094 again:
2095 if (!PLIsArray(value)) {
2096 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2097 entry->key, "Texture");
2098 if (changed==0) {
2099 value = entry->plvalue;
2100 changed = 1;
2101 wwarning(_("using default \"%s\" instead"), entry->default_value);
2102 goto again;
2104 return False;
2107 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2108 proplist_t pl;
2110 pl = PLGetArrayElement(value, 0);
2111 if (!pl || !PLIsString(pl) || !PLGetString(pl)
2112 || strcasecmp(PLGetString(pl), "solid")!=0) {
2113 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2114 entry->key, "Solid Texture");
2116 value = entry->plvalue;
2117 changed = 1;
2118 wwarning(_("using default \"%s\" instead"), entry->default_value);
2119 goto again;
2123 texture = parse_texture(scr, value);
2125 if (!texture) {
2126 wwarning(_("Error in texture specification for key \"%s\""),
2127 entry->key);
2128 if (changed==0) {
2129 value = entry->plvalue;
2130 changed = 1;
2131 wwarning(_("using default \"%s\" instead"), entry->default_value);
2132 goto again;
2134 return False;
2137 if (ret)
2138 *ret = &texture;
2140 if (addr)
2141 *(WTexture**)addr = texture;
2143 return True;
2147 static int
2148 getWSBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2149 void *addr, void **ret)
2151 proplist_t elem;
2152 int changed = 0;
2153 char *val;
2154 int nelem;
2156 again:
2157 if (!PLIsArray(value)) {
2158 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2159 "WorkspaceBack", "Texture or None");
2160 if (changed==0) {
2161 value = entry->plvalue;
2162 changed = 1;
2163 wwarning(_("using default \"%s\" instead"), entry->default_value);
2164 goto again;
2166 return False;
2169 /* only do basic error checking and verify for None texture */
2171 nelem = PLGetNumberOfElements(value);
2172 if (nelem > 0) {
2173 elem = PLGetArrayElement(value, 0);
2174 if (!elem || !PLIsString(elem)) {
2175 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2176 if (changed==0) {
2177 value = entry->plvalue;
2178 changed = 1;
2179 wwarning(_("using default \"%s\" instead"), entry->default_value);
2180 goto again;
2182 return False;
2184 val = PLGetString(elem);
2186 if (strcasecmp(val, "None")==0)
2187 return True;
2189 *ret = PLRetain(value);
2191 return True;
2195 static int
2196 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2197 void *addr, void **ret)
2199 proplist_t elem;
2200 int nelem;
2201 int changed = 0;
2203 again:
2204 if (!PLIsArray(value)) {
2205 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2206 "WorkspaceSpecificBack", "an array of textures");
2207 if (changed==0) {
2208 value = entry->plvalue;
2209 changed = 1;
2210 wwarning(_("using default \"%s\" instead"), entry->default_value);
2211 goto again;
2213 return False;
2216 /* only do basic error checking and verify for None texture */
2218 nelem = PLGetNumberOfElements(value);
2219 if (nelem > 0) {
2220 while (nelem--) {
2221 elem = PLGetArrayElement(value, nelem);
2222 if (!elem || !PLIsArray(elem)) {
2223 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2224 nelem);
2229 *ret = PLRetain(value);
2231 #ifdef notworking
2233 * Kluge to force wmsetbg helper to set the default background.
2234 * If the WorkspaceSpecificBack is changed once wmaker has started,
2235 * the WorkspaceBack won't be sent to the helper, unless the user
2236 * changes it's value too. So, we must force this by removing the
2237 * value from the defaults DB.
2239 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2240 proplist_t key = PLMakeString("WorkspaceBack");
2242 PLRemoveDictionaryEntry(WDWindowMaker->dictionary, key);
2244 PLRelease(key);
2246 #endif
2247 return True;
2251 static int
2252 getFont(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2253 void **ret)
2255 static WMFont *font;
2256 char *val;
2258 GET_STRING_OR_DEFAULT("Font", val);
2260 font = WMCreateFont(scr->wmscreen, val);
2261 if (!font)
2262 font = WMCreateFont(scr->wmscreen, "fixed");
2264 if (!font) {
2265 wfatal(_("could not load any usable font!!!"));
2266 exit(1);
2269 if (ret)
2270 *ret = font;
2272 /* can't assign font value outside update function */
2273 wassertrv(addr == NULL, True);
2275 return True;
2279 static int
2280 getColor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2281 void **ret)
2283 static XColor color;
2284 char *val;
2285 int second_pass=0;
2287 GET_STRING_OR_DEFAULT("Color", val);
2290 again:
2291 if (!wGetColor(scr, val, &color)) {
2292 wwarning(_("could not get color for key \"%s\""),
2293 entry->key);
2294 if (second_pass==0) {
2295 val = PLGetString(entry->plvalue);
2296 second_pass = 1;
2297 wwarning(_("using default \"%s\" instead"), val);
2298 goto again;
2300 return False;
2303 if (ret)
2304 *ret = &color;
2306 assert(addr==NULL);
2308 if (addr)
2309 *(unsigned long*)addr = pixel;
2312 return True;
2317 static int
2318 getKeybind(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2319 void **ret)
2321 static WShortKey shortcut;
2322 KeySym ksym;
2323 char *val;
2324 char *k;
2325 char buf[128], *b;
2328 GET_STRING_OR_DEFAULT("Key spec", val);
2330 if (!val || strcasecmp(val, "NONE")==0) {
2331 shortcut.keycode = 0;
2332 shortcut.modifier = 0;
2333 if (ret)
2334 *ret = &shortcut;
2335 return True;
2338 strcpy(buf, val);
2340 b = (char*)buf;
2342 /* get modifiers */
2343 shortcut.modifier = 0;
2344 while ((k = strchr(b, '+'))!=NULL) {
2345 int mod;
2347 *k = 0;
2348 mod = wXModifierFromKey(b);
2349 if (mod<0) {
2350 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2351 return False;
2353 shortcut.modifier |= mod;
2355 b = k+1;
2358 /* get key */
2359 ksym = XStringToKeysym(b);
2361 if (ksym==NoSymbol) {
2362 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2363 val);
2364 return False;
2367 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2368 if (shortcut.keycode==0) {
2369 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2370 return False;
2373 if (ret)
2374 *ret = &shortcut;
2376 return True;
2380 static int
2381 getModMask(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2382 void **ret)
2384 static unsigned int mask;
2385 char *str;
2387 GET_STRING_OR_DEFAULT("Modifier Key", str);
2389 if (!str)
2390 return False;
2392 mask = wXModifierFromKey(str);
2393 if (mask < 0) {
2394 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2395 mask = 0;
2396 return False;
2399 if (addr)
2400 *(unsigned int*)addr = mask;
2402 if (ret)
2403 *ret = &mask;
2405 return True;
2409 #ifdef NEWSTUFF
2410 static int
2411 getRImages(WScreen *scr, WDefaultEntry *entry, proplist_t value,
2412 void *addr, void **ret)
2414 unsigned int mask;
2415 char *str;
2416 RImage *image;
2417 int i, n;
2418 int w, h;
2420 GET_STRING_OR_DEFAULT("Image File Path", str);
2421 if (!str)
2422 return False;
2424 image = RLoadImage(scr->rcontext, str, 0);
2425 if (!image) {
2426 wwarning(_("could not load image in option %s: %s"), entry->key,
2427 RMessageForError(RErrorCode));
2428 return False;
2431 if (*(RImage**)addr) {
2432 RDestroyImage(*(RImage**)addr);
2434 if (addr)
2435 *(RImage**)addr = image;
2437 assert(ret == NULL);
2439 if (ret)
2440 *(RImage**)ret = image;
2443 return True;
2445 #endif
2447 #ifdef DEFINABLE_CURSOR
2449 # include <X11/cursorfont.h>
2450 typedef struct
2452 char *name;
2453 int id;
2454 } WCursorLookup;
2456 #define CURSOR_ID_NONE (XC_num_glyphs)
2458 static WCursorLookup cursor_table[] =
2460 { "X_cursor", XC_X_cursor },
2461 { "arrow", XC_arrow },
2462 { "based_arrow_down", XC_based_arrow_down },
2463 { "based_arrow_up", XC_based_arrow_up },
2464 { "boat", XC_boat },
2465 { "bogosity", XC_bogosity },
2466 { "bottom_left_corner", XC_bottom_left_corner },
2467 { "bottom_right_corner", XC_bottom_right_corner },
2468 { "bottom_side", XC_bottom_side },
2469 { "bottom_tee", XC_bottom_tee },
2470 { "box_spiral", XC_box_spiral },
2471 { "center_ptr", XC_center_ptr },
2472 { "circle", XC_circle },
2473 { "clock", XC_clock },
2474 { "coffee_mug", XC_coffee_mug },
2475 { "cross", XC_cross },
2476 { "cross_reverse", XC_cross_reverse },
2477 { "crosshair", XC_crosshair },
2478 { "diamond_cross", XC_diamond_cross },
2479 { "dot", XC_dot },
2480 { "dotbox", XC_dotbox },
2481 { "double_arrow", XC_double_arrow },
2482 { "draft_large", XC_draft_large },
2483 { "draft_small", XC_draft_small },
2484 { "draped_box", XC_draped_box },
2485 { "exchange", XC_exchange },
2486 { "fleur", XC_fleur },
2487 { "gobbler", XC_gobbler },
2488 { "gumby", XC_gumby },
2489 { "hand1", XC_hand1 },
2490 { "hand2", XC_hand2 },
2491 { "heart", XC_heart },
2492 { "icon", XC_icon },
2493 { "iron_cross", XC_iron_cross },
2494 { "left_ptr", XC_left_ptr },
2495 { "left_side", XC_left_side },
2496 { "left_tee", XC_left_tee },
2497 { "leftbutton", XC_leftbutton },
2498 { "ll_angle", XC_ll_angle },
2499 { "lr_angle", XC_lr_angle },
2500 { "man", XC_man },
2501 { "middlebutton", XC_middlebutton },
2502 { "mouse", XC_mouse },
2503 { "pencil", XC_pencil },
2504 { "pirate", XC_pirate },
2505 { "plus", XC_plus },
2506 { "question_arrow", XC_question_arrow },
2507 { "right_ptr", XC_right_ptr },
2508 { "right_side", XC_right_side },
2509 { "right_tee", XC_right_tee },
2510 { "rightbutton", XC_rightbutton },
2511 { "rtl_logo", XC_rtl_logo },
2512 { "sailboat", XC_sailboat },
2513 { "sb_down_arrow", XC_sb_down_arrow },
2514 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2515 { "sb_left_arrow", XC_sb_left_arrow },
2516 { "sb_right_arrow", XC_sb_right_arrow },
2517 { "sb_up_arrow", XC_sb_up_arrow },
2518 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2519 { "shuttle", XC_shuttle },
2520 { "sizing", XC_sizing },
2521 { "spider", XC_spider },
2522 { "spraycan", XC_spraycan },
2523 { "star", XC_star },
2524 { "target", XC_target },
2525 { "tcross", XC_tcross },
2526 { "top_left_arrow", XC_top_left_arrow },
2527 { "top_left_corner", XC_top_left_corner },
2528 { "top_right_corner", XC_top_right_corner },
2529 { "top_side", XC_top_side },
2530 { "top_tee", XC_top_tee },
2531 { "trek", XC_trek },
2532 { "ul_angle", XC_ul_angle },
2533 { "umbrella", XC_umbrella },
2534 { "ur_angle", XC_ur_angle },
2535 { "watch", XC_watch },
2536 { "xterm", XC_xterm },
2537 { NULL, CURSOR_ID_NONE }
2540 static void
2541 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2543 switch(status) {
2544 case BitmapOpenFailed:
2545 wwarning(_("failed to open bitmap file \"%s\""), filename);
2546 break;
2547 case BitmapFileInvalid:
2548 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2549 break;
2550 case BitmapNoMemory:
2551 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2552 break;
2553 case BitmapSuccess:
2554 XFreePixmap(dpy, bitmap);
2555 break;
2560 * (none)
2561 * (builtin, <cursor_name>)
2562 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2564 static int
2565 parse_cursor(WScreen *scr, proplist_t pl, Cursor *cursor)
2567 proplist_t elem;
2568 char *val;
2569 int nelem;
2570 int status = 0;
2572 nelem = PLGetNumberOfElements(pl);
2573 if (nelem < 1) {
2574 return(status);
2576 elem = PLGetArrayElement(pl, 0);
2577 if (!elem || !PLIsString(elem)) {
2578 return(status);
2580 val = PLGetString(elem);
2582 if (0 == strcasecmp(val, "none")) {
2583 status = 1;
2584 *cursor = None;
2585 } else if (0 == strcasecmp(val, "builtin")) {
2586 int i;
2587 int cursor_id = CURSOR_ID_NONE;
2589 if (2 != nelem) {
2590 wwarning(_("bad number of arguments in cursor specification"));
2591 return(status);
2593 elem = PLGetArrayElement(pl, 1);
2594 if (!elem || !PLIsString(elem)) {
2595 return(status);
2597 val = PLGetString(elem);
2599 for (i = 0; NULL != cursor_table[i].name; i++) {
2600 if (0 == strcasecmp(val, cursor_table[i].name)) {
2601 cursor_id = cursor_table[i].id;
2602 break;
2605 if (CURSOR_ID_NONE == cursor_id) {
2606 wwarning(_("unknown builtin cursor name \"%s\""), val);
2607 } else {
2608 *cursor = XCreateFontCursor(dpy, cursor_id);
2609 status = 1;
2611 } else if (0 == strcasecmp(val, "bitmap")) {
2612 char *bitmap_name;
2613 char *mask_name;
2614 int bitmap_status;
2615 int mask_status;
2616 Pixmap bitmap;
2617 Pixmap mask;
2618 unsigned int w, h;
2619 int x, y;
2620 XColor fg, bg;
2622 if (3 != nelem) {
2623 wwarning(_("bad number of arguments in cursor specification"));
2624 return(status);
2626 elem = PLGetArrayElement(pl, 1);
2627 if (!elem || !PLIsString(elem)) {
2628 return(status);
2630 val = PLGetString(elem);
2631 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2632 if (!bitmap_name) {
2633 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2634 return(status);
2636 elem = PLGetArrayElement(pl, 2);
2637 if (!elem || !PLIsString(elem)) {
2638 wfree(bitmap_name);
2639 return(status);
2641 val = PLGetString(elem);
2642 mask_name = FindImage(wPreferences.pixmap_path, val);
2643 if (!mask_name) {
2644 wfree(bitmap_name);
2645 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2646 return(status);
2648 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2649 &mask, &x, &y);
2650 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2651 &bitmap, &x, &y);
2652 if ((BitmapSuccess == bitmap_status) &&
2653 (BitmapSuccess == mask_status)) {
2654 fg.pixel = scr->black_pixel;
2655 bg.pixel = scr->white_pixel;
2656 XQueryColor(dpy, scr->w_colormap, &fg);
2657 XQueryColor(dpy, scr->w_colormap, &bg);
2658 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2659 status = 1;
2661 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2662 check_bitmap_status(mask_status, mask_name, mask);
2663 wfree(bitmap_name);
2664 wfree(mask_name);
2666 return(status);
2670 static int
2671 getCursor(WScreen *scr, WDefaultEntry *entry, proplist_t value, void *addr,
2672 void **ret)
2674 static Cursor cursor;
2675 int status;
2676 int changed = 0;
2678 again:
2679 if (!PLIsArray(value)) {
2680 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2681 entry->key, "cursor specification");
2682 if (!changed) {
2683 value = entry->plvalue;
2684 changed = 1;
2685 wwarning(_("using default \"%s\" instead"), entry->default_value);
2686 goto again;
2688 return(False);
2690 status = parse_cursor(scr, value, &cursor);
2691 if (!status) {
2692 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2693 if (!changed) {
2694 value = entry->plvalue;
2695 changed = 1;
2696 wwarning(_("using default \"%s\" instead"), entry->default_value);
2697 goto again;
2699 return(False);
2701 if (ret) {
2702 *ret = &cursor;
2704 if (addr) {
2705 *(Cursor *)addr = cursor;
2707 return(True);
2709 #undef CURSOR_ID_NONE
2711 #endif /* DEFINABLE_CURSOR */
2714 /* ---------------- value setting functions --------------- */
2715 static int
2716 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2718 return REFRESH_WINDOW_TITLE_COLOR;
2721 static int
2722 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2724 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2727 static int
2728 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2730 switch (which) {
2731 case WM_DOCK:
2732 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2733 break;
2734 case WM_CLIP:
2735 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2736 break;
2737 default:
2738 break;
2740 return 0;
2744 static int
2745 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2747 if (scr->workspaces) {
2748 wWorkspaceForceChange(scr, scr->current_workspace);
2749 wArrangeIcons(scr, False);
2751 return 0;
2754 #if not_used
2755 static int
2756 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2758 if (*value <= 0)
2759 *(int*)foo = 1;
2761 return 0;
2763 #endif
2767 static int
2768 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2770 Pixmap pixmap;
2771 RImage *img;
2772 int reset = 0;
2774 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2775 wPreferences.icon_size,
2776 ((*texture)->any.type & WREL_BORDER_MASK)
2777 ? WREL_ICON : WREL_FLAT);
2778 if (!img) {
2779 wwarning(_("could not render texture for icon background"));
2780 if (!entry->addr)
2781 wTextureDestroy(scr, *texture);
2782 return 0;
2784 RConvertImage(scr->rcontext, img, &pixmap);
2786 if (scr->icon_tile) {
2787 reset = 1;
2788 RDestroyImage(scr->icon_tile);
2789 XFreePixmap(dpy, scr->icon_tile_pixmap);
2792 scr->icon_tile = img;
2795 /* put the icon in the noticeboard hint */
2796 PropSetIconTileHint(scr, img);
2799 if (!wPreferences.flags.noclip) {
2800 if (scr->clip_tile) {
2801 RDestroyImage(scr->clip_tile);
2803 scr->clip_tile = wClipMakeTile(scr, img);
2806 scr->icon_tile_pixmap = pixmap;
2808 if (scr->def_icon_pixmap) {
2809 XFreePixmap(dpy, scr->def_icon_pixmap);
2810 scr->def_icon_pixmap = None;
2812 if (scr->def_ticon_pixmap) {
2813 XFreePixmap(dpy, scr->def_ticon_pixmap);
2814 scr->def_ticon_pixmap = None;
2817 if (scr->icon_back_texture) {
2818 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2820 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2822 if (scr->clip_balloon)
2823 XSetWindowBackground(dpy, scr->clip_balloon,
2824 (*texture)->any.color.pixel);
2827 * Free the texture as nobody else will use it, nor refer to it.
2829 if (!entry->addr)
2830 wTextureDestroy(scr, *texture);
2832 return (reset ? REFRESH_ICON_TILE : 0);
2837 static int
2838 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2840 if (scr->title_font) {
2841 WMReleaseFont(scr->title_font);
2843 scr->title_font = font;
2845 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2849 static int
2850 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2852 if (scr->menu_title_font) {
2853 WMReleaseFont(scr->menu_title_font);
2856 scr->menu_title_font = font;
2858 return REFRESH_MENU_TITLE_FONT;
2862 static int
2863 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2865 if (scr->menu_entry_font) {
2866 WMReleaseFont(scr->menu_entry_font);
2868 scr->menu_entry_font = font;
2870 return REFRESH_MENU_FONT;
2875 static int
2876 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2878 if (scr->icon_title_font) {
2879 WMReleaseFont(scr->icon_title_font);
2882 scr->icon_title_font = font;
2884 return REFRESH_ICON_FONT;
2888 static int
2889 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2891 if (scr->clip_title_font) {
2892 WMReleaseFont(scr->clip_title_font);
2895 scr->clip_title_font = font;
2897 return REFRESH_ICON_FONT;
2901 static int
2902 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2904 if (scr->workspace_name_font) {
2905 WMReleaseFont(scr->workspace_name_font);
2908 scr->workspace_name_font = font;
2910 return 0;
2914 static int
2915 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2917 if (scr->select_pixel!=scr->white_pixel &&
2918 scr->select_pixel!=scr->black_pixel) {
2919 wFreeColor(scr, scr->select_pixel);
2922 scr->select_pixel = color->pixel;
2924 return REFRESH_MENU_COLOR;
2928 static int
2929 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2931 if (scr->select_text_pixel!=scr->white_pixel &&
2932 scr->select_text_pixel!=scr->black_pixel) {
2933 wFreeColor(scr, scr->select_text_pixel);
2936 scr->select_text_pixel = color->pixel;
2938 return REFRESH_MENU_COLOR;
2942 static int
2943 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2945 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2946 scr->clip_title_pixel[index]!=scr->black_pixel) {
2947 wFreeColor(scr, scr->clip_title_pixel[index]);
2949 scr->clip_title_pixel[index] = color->pixel;
2951 #ifdef GRADIENT_CLIP_ARROW
2952 if (index == CLIP_NORMAL) {
2953 RImage *image;
2954 RColor color1, color2;
2955 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
2956 int as = pt - 15; /* 15 = 5+5+5 */
2958 FREE_PIXMAP(scr->clip_arrow_gradient);
2960 color1.red = (color->red >> 8)*6/10;
2961 color1.green = (color->green >> 8)*6/10;
2962 color1.blue = (color->blue >> 8)*6/10;
2964 color2.red = WMIN((color->red >> 8)*20/10, 255);
2965 color2.green = WMIN((color->green >> 8)*20/10, 255);
2966 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
2968 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
2969 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2970 RDestroyImage(image);
2972 #endif /* GRADIENT_CLIP_ARROW */
2974 return REFRESH_ICON_TITLE_COLOR;
2978 static int
2979 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2981 if (scr->window_title_pixel[index]!=scr->white_pixel &&
2982 scr->window_title_pixel[index]!=scr->black_pixel) {
2983 wFreeColor(scr, scr->window_title_pixel[index]);
2986 scr->window_title_pixel[index] = color->pixel;
2988 if (index == WS_UNFOCUSED)
2989 XSetForeground(dpy, scr->info_text_gc, color->pixel);
2991 return REFRESH_WINDOW_TITLE_COLOR;
2995 static int
2996 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2998 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
2999 scr->menu_title_pixel[0]!=scr->black_pixel) {
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 wfree(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 wfree(str);
3206 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3207 } else {
3208 SendHelperMessage(scr, 'U', 0, NULL);
3211 } else if (PLGetNumberOfElements(value) > 0) {
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 wfree(text);
3223 system(command);
3224 wfree(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;
3396 #if 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;
3406 #endif
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*/