- Fixed text in info panel for multibyte (Seiichi SATO <ssato@sh.rim.or.jp>)
[wmaker-crm.git] / src / defaults.c
blob4eb8536ea482a008731d98fabd0bbaa8d55af01f
1 /* defaults.c - manage configuration through defaults db
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
55 #include "WindowMaker.h"
56 #include "wcore.h"
57 #include "framewin.h"
58 #include "window.h"
59 #include "texture.h"
60 #include "screen.h"
61 #include "resources.h"
62 #include "defaults.h"
63 #include "keybind.h"
64 #include "xmodifier.h"
65 #include "icon.h"
66 #include "funcs.h"
67 #include "actions.h"
68 #include "dock.h"
69 #include "workspace.h"
70 #include "properties.h"
74 /***** Global *****/
76 extern WDDomain *WDWindowMaker;
77 extern WDDomain *WDWindowAttributes;
78 extern WDDomain *WDRootMenu;
80 extern int wScreenCount;
82 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
83 extern Atom _XA_WINDOWMAKER_ICON_TILE;
86 extern WMPropList *wDomainName;
87 extern WMPropList *wAttributeDomainName;
89 extern WPreferences wPreferences;
91 extern WShortKey wKeyBindings[WKBD_LAST];
93 typedef struct {
94 char *key;
95 char *default_value;
96 void *extra_data;
97 void *addr;
98 int (*convert)();
99 int (*update)();
100 WMPropList *plkey;
101 WMPropList *plvalue; /* default value */
102 } WDefaultEntry;
105 /* used to map strings to integers */
106 typedef struct {
107 char *string;
108 short value;
109 char is_alias;
110 } WOptionEnumeration;
113 /* type converters */
114 static int getBool();
115 static int getInt();
116 static int getCoord();
117 #if 0
118 /* this is not used yet */
119 static int getString();
120 #endif
121 static int getPathList();
122 static int getEnum();
123 static int getTexture();
124 static int getWSBackground();
125 static int getWSSpecificBackground();
126 static int getFont();
127 static int getColor();
128 static int getKeybind();
129 static int getModMask();
130 #ifdef NEWSTUFF
131 static int getRImage();
132 #endif
135 /* value setting functions */
136 static int setJustify();
137 static int setClearance();
138 static int setIfDockPresent();
139 static int setStickyIcons();
141 static int setPositive();
143 static int setWidgetColor();
144 static int setIconTile();
145 static int setWinTitleFont();
146 static int setMenuTitleFont();
147 static int setMenuTextFont();
148 static int setIconTitleFont();
149 static int setIconTitleColor();
150 static int setIconTitleBack();
151 static int setLargeDisplayFont();
152 static int setWTitleColor();
153 static int setFTitleBack();
154 static int setPTitleBack();
155 static int setUTitleBack();
156 static int setResizebarBack();
157 static int setWorkspaceBack();
158 static int setWorkspaceSpecificBack();
159 static int setMenuTitleColor();
160 static int setMenuTextColor();
161 static int setMenuDisabledColor();
162 static int setMenuTitleBack();
163 static int setMenuTextBack();
164 static int setHightlight();
165 static int setHightlightText();
166 static int setKeyGrab();
167 static int setDoubleClick();
168 static int setIconPosition();
170 static int setClipTitleFont();
171 static int setClipTitleColor();
173 static int setMenuStyle();
174 #if 0
175 static int setMultiByte();
176 #endif
177 static int updateUsableArea();
179 extern Cursor wCursor[WCUR_LAST];
180 static int getCursor();
181 static int setCursor();
185 * Tables to convert strings to enumeration values.
186 * Values stored are char
190 /* WARNING: sum of length of all value strings must not exceed
191 * this value */
192 #define TOTAL_VALUES_LENGTH 80
197 #define REFRESH_WINDOW_TEXTURES (1<<0)
198 #define REFRESH_MENU_TEXTURE (1<<1)
199 #define REFRESH_MENU_FONT (1<<2)
200 #define REFRESH_MENU_COLOR (1<<3)
201 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
202 #define REFRESH_MENU_TITLE_FONT (1<<5)
203 #define REFRESH_MENU_TITLE_COLOR (1<<6)
204 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
205 #define REFRESH_WINDOW_FONT (1<<8)
206 #define REFRESH_ICON_TILE (1<<9)
207 #define REFRESH_ICON_FONT (1<<10)
208 #define REFRESH_WORKSPACE_BACK (1<<11)
210 #define REFRESH_BUTTON_IMAGES (1<<12)
212 #define REFRESH_ICON_TITLE_COLOR (1<<13)
213 #define REFRESH_ICON_TITLE_BACK (1<<14)
217 static WOptionEnumeration seFocusModes[] = {
218 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
219 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
220 {NULL, 0, 0}
223 static WOptionEnumeration seColormapModes[] = {
224 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
225 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
226 {NULL, 0, 0}
229 static WOptionEnumeration sePlacements[] = {
230 {"Auto", WPM_AUTO, 0},
231 {"Smart", WPM_SMART, 0},
232 {"Cascade", WPM_CASCADE, 0},
233 {"Random", WPM_RANDOM, 0},
234 {"Manual", WPM_MANUAL, 0},
235 {NULL, 0, 0}
238 static WOptionEnumeration seGeomDisplays[] = {
239 {"None", WDIS_NONE, 0},
240 {"Center", WDIS_CENTER, 0},
241 {"Corner", WDIS_TOPLEFT, 0},
242 {"Floating", WDIS_FRAME_CENTER, 0},
243 {"Line", WDIS_NEW, 0},
244 {NULL, 0, 0}
247 static WOptionEnumeration seSpeeds[] = {
248 {"UltraFast", SPEED_ULTRAFAST, 0},
249 {"Fast", SPEED_FAST, 0},
250 {"Medium", SPEED_MEDIUM, 0},
251 {"Slow", SPEED_SLOW, 0},
252 {"UltraSlow", SPEED_ULTRASLOW, 0},
253 {NULL, 0, 0}
256 static WOptionEnumeration seMouseButtonActions[] = {
257 {"None", WA_NONE, 0},
258 {"SelectWindows", WA_SELECT_WINDOWS, 0},
259 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
260 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
261 {NULL, 0, 0}
264 static WOptionEnumeration seMouseWheelActions[] = {
265 {"None", WA_NONE, 0},
266 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
267 {NULL, 0, 0}
270 static WOptionEnumeration seIconificationStyles[] = {
271 {"Zoom", WIS_ZOOM, 0},
272 {"Twist", WIS_TWIST, 0},
273 {"Flip", WIS_FLIP, 0},
274 {"None", WIS_NONE, 0},
275 {"random", WIS_RANDOM, 0},
276 {NULL, 0, 0}
279 static WOptionEnumeration seJustifications[] = {
280 {"Left", WTJ_LEFT, 0},
281 {"Center", WTJ_CENTER, 0},
282 {"Right", WTJ_RIGHT, 0},
283 {NULL, 0, 0}
286 static WOptionEnumeration seIconPositions[] = {
287 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
288 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
289 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
290 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
291 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
292 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
293 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
294 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
295 {NULL, 0, 0}
298 static WOptionEnumeration seMenuStyles[] = {
299 {"normal", MS_NORMAL, 0},
300 {"singletexture", MS_SINGLE_TEXTURE, 0},
301 {"flat", MS_FLAT, 0},
302 {NULL, 0, 0}
306 static WOptionEnumeration seDisplayPositions[] = {
307 {"none", WD_NONE, 0},
308 {"center", WD_CENTER, 0},
309 {"top", WD_TOP, 0},
310 {"bottom", WD_BOTTOM, 0},
311 {"topleft", WD_TOPLEFT, 0},
312 {"topright", WD_TOPRIGHT, 0},
313 {"bottomleft", WD_BOTTOMLEFT, 0},
314 {"bottomright", WD_BOTTOMRIGHT, 0},
315 {NULL, 0, 0}
318 static WOptionEnumeration seWorkspaceBorder[] = {
319 {"None", WB_NONE, 0},
320 {"LeftRight", WB_LEFTRIGHT, 0},
321 {"TopBottom", WB_TOPBOTTOM, 0},
322 {"AllDirections", WB_ALLDIRS, 0},
323 {NULL, 0, 0}
328 * ALL entries in the tables bellow, NEED to have a default value
329 * defined, and this value needs to be correct.
332 /* these options will only affect the window manager on startup
334 * static defaults can't access the screen data, because it is
335 * created after these defaults are read
337 WDefaultEntry staticOptionList[] = {
339 {"ColormapSize", "4", NULL,
340 &wPreferences.cmap_size, getInt, NULL
342 {"DisableDithering", "NO", NULL,
343 &wPreferences.no_dithering, getBool, NULL
345 /* static by laziness */
346 {"IconSize", "64", NULL,
347 &wPreferences.icon_size, getInt, NULL
349 {"ModifierKey", "Mod1", NULL,
350 &wPreferences.modifier_mask, getModMask, NULL
352 {"DisableWSMouseActions", "NO", NULL,
353 &wPreferences.disable_root_mouse, getBool, NULL
355 {"FocusMode", "manual", seFocusModes,
356 &wPreferences.focus_mode, getEnum, NULL
357 }, /* have a problem when switching from manual to sloppy without restart */
358 {"NewStyle", "NO", NULL,
359 &wPreferences.new_style, getBool, NULL
361 {"DisableDock", "NO", (void*) WM_DOCK,
362 NULL, getBool, setIfDockPresent
364 {"DisableClip", "NO", (void*) WM_CLIP,
365 NULL, getBool, setIfDockPresent
367 {"DisableMiniwindows", "NO", NULL,
368 &wPreferences.disable_miniwindows, getBool, NULL
370 #if 0
371 ,{"MultiByteText", "NO", NULL,
372 &wPreferences.multi_byte_text, getBool, setMultiByte
374 #endif
379 WDefaultEntry optionList[] = {
380 /* dynamic options */
381 {"IconPosition", "blh", seIconPositions,
382 &wPreferences.icon_yard, getEnum, setIconPosition
384 {"IconificationStyle", "Zoom", seIconificationStyles,
385 &wPreferences.iconification_style, getEnum, NULL
387 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
388 &wPreferences.mouse_button1, getEnum, NULL
390 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
391 &wPreferences.mouse_button2, getEnum, NULL
393 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
394 &wPreferences.mouse_button3, getEnum, NULL
396 {"MouseWheelAction", "None", seMouseWheelActions,
397 &wPreferences.mouse_wheel, getEnum, NULL
399 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
400 &wPreferences.pixmap_path, getPathList, NULL
402 {"IconPath", DEF_ICON_PATHS, NULL,
403 &wPreferences.icon_path, getPathList, NULL
405 {"ColormapMode", "auto", seColormapModes,
406 &wPreferences.colormap_mode, getEnum, NULL
408 {"AutoFocus", "NO", NULL,
409 &wPreferences.auto_focus, getBool, NULL
411 {"RaiseDelay", "0", NULL,
412 &wPreferences.raise_delay, getInt, NULL
414 {"WindozeCycling", "NO", NULL,
415 &wPreferences.windows_cycling,getBool, NULL
417 {"CirculateRaise", "NO", NULL,
418 &wPreferences.circ_raise, getBool, NULL
420 {"Superfluous", "NO", NULL,
421 &wPreferences.superfluous, getBool, NULL
423 {"AdvanceToNewWorkspace", "NO", NULL,
424 &wPreferences.ws_advance, getBool, NULL
426 {"CycleWorkspaces", "NO", NULL,
427 &wPreferences.ws_cycle, getBool, NULL
429 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
430 &wPreferences.workspace_name_display_position, getEnum, NULL
432 {"WorkspaceBorder", "None", seWorkspaceBorder,
433 &wPreferences.workspace_border_position, getEnum, updateUsableArea
435 {"WorkspaceBorderSize", "0", NULL,
436 &wPreferences.workspace_border_size, getInt, updateUsableArea
438 #ifdef VIRTUAL_DESKTOP
439 {"VirtualEdgeThickness", "1", NULL,
440 &wPreferences.vedge_thickness, getInt, NULL
442 {"VirtualEdgeExtendSpace", "0", NULL,
443 &wPreferences.vedge_bordersize, 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 {"HideOthersKey", "None", (void*)WKBD_HIDE_OTHERS,
685 NULL, getKeybind, setKeyGrab
687 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
688 NULL, getKeybind, setKeyGrab
690 {"CloseKey", "None", (void*)WKBD_CLOSE,
691 NULL, getKeybind, setKeyGrab
693 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
694 NULL, getKeybind, setKeyGrab
696 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
697 NULL, getKeybind, setKeyGrab
699 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
700 NULL, getKeybind, setKeyGrab
702 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
703 NULL, getKeybind, setKeyGrab
705 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
706 NULL, getKeybind, setKeyGrab
708 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
709 NULL, getKeybind, setKeyGrab
711 {"ShadeKey", "None", (void*)WKBD_SHADE,
712 NULL, getKeybind, setKeyGrab
714 {"SelectKey", "None", (void*)WKBD_SELECT,
715 NULL, getKeybind, setKeyGrab
717 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
718 NULL, getKeybind, setKeyGrab
720 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
721 NULL, getKeybind, setKeyGrab
723 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
724 NULL, getKeybind, setKeyGrab
726 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
727 NULL, getKeybind, setKeyGrab
729 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
730 NULL, getKeybind, setKeyGrab
732 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
733 NULL, getKeybind, setKeyGrab
735 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
736 NULL, getKeybind, setKeyGrab
738 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
739 NULL, getKeybind, setKeyGrab
741 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
763 NULL, getKeybind, setKeyGrab
765 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
766 NULL, getKeybind, setKeyGrab
768 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
769 NULL, getKeybind, setKeyGrab
771 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
772 NULL, getKeybind, setKeyGrab
774 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
775 NULL, getKeybind, setKeyGrab
777 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
784 NULL, getKeybind, setKeyGrab
786 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
790 NULL, getKeybind, setKeyGrab
792 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
793 NULL, getKeybind, setKeyGrab
795 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
796 NULL, getKeybind, setKeyGrab
799 #ifdef KEEP_XKB_LOCK_STATUS
800 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
801 NULL, getKeybind, setKeyGrab
803 {"KbdModeLock", "NO", NULL,
804 &wPreferences.modelock, getBool, NULL
806 #endif /* KEEP_XKB_LOCK_STATUS */
808 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
809 NULL, getCursor, setCursor
811 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
812 NULL, getCursor, setCursor
814 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
815 NULL, getCursor, setCursor
817 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
818 NULL, getCursor, setCursor
820 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
821 (void*)WCUR_TOPLEFTRESIZE,
822 NULL, getCursor, setCursor
824 {"TopRightResizeCursor", "(builtin, top_right_corner)",
825 (void*)WCUR_TOPRIGHTRESIZE,
826 NULL, getCursor, setCursor
828 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
829 (void*)WCUR_BOTTOMLEFTRESIZE,
830 NULL, getCursor, setCursor
832 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
833 (void*)WCUR_BOTTOMRIGHTRESIZE,
834 NULL, getCursor, setCursor
836 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
837 (void*)WCUR_VERTICALRESIZE,
838 NULL, getCursor, setCursor
840 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
841 (void*)WCUR_HORIZONRESIZE,
842 NULL, getCursor, setCursor
844 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
845 NULL, getCursor, setCursor
847 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
848 NULL, getCursor, setCursor
850 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
851 NULL, getCursor, setCursor
853 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
854 NULL, getCursor, setCursor
859 #if 0
860 static void rereadDefaults(void);
861 #endif
863 #if 0
864 static void
865 rereadDefaults(void)
867 /* must defer the update because accessing X data from a
868 * signal handler can mess up Xlib */
871 #endif
873 static void
874 initDefaults()
876 int i;
877 WDefaultEntry *entry;
879 WMPLSetCaseSensitive(False);
881 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
882 entry = &optionList[i];
884 entry->plkey = WMCreatePLString(entry->key);
885 if (entry->default_value)
886 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
887 else
888 entry->plvalue = NULL;
891 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
892 entry = &staticOptionList[i];
894 entry->plkey = WMCreatePLString(entry->key);
895 if (entry->default_value)
896 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
897 else
898 entry->plvalue = NULL;
902 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
903 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
905 PLRegister(wDomainName, rereadDefaults);
906 PLRegister(wAttributeDomainName, rereadDefaults);
911 static WMPropList*
912 readGlobalDomain(char *domainName, Bool requireDictionary)
914 WMPropList *globalDict = NULL;
915 char path[PATH_MAX];
916 struct stat stbuf;
918 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
919 if (stat(path, &stbuf)>=0) {
920 globalDict = WMReadPropListFromFile(path);
921 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
922 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
923 domainName, path);
924 WMReleasePropList(globalDict);
925 globalDict = NULL;
926 } else if (!globalDict) {
927 wwarning(_("could not load domain %s from global defaults database"),
928 domainName);
932 return globalDict;
936 #if 0
937 WMPropList*
938 wDefaultsInit(int screen_number)
940 static int defaults_inited = 0;
941 WMPropList *dict;
943 if (!defaults_inited) {
944 initDefaults();
947 dict = PLGetDomain(wDomainName);
948 if (!dict) {
949 wwarning(_("could not read domain \"%s\" from defaults database"),
950 WMGetFromPLString(wDomainName));
953 return dict;
955 #endif
958 void
959 wDefaultsDestroyDomain(WDDomain *domain)
961 if (domain->dictionary)
962 WMReleasePropList(domain->dictionary);
963 wfree(domain->path);
964 wfree(domain);
968 WDDomain*
969 wDefaultsInitDomain(char *domain, Bool requireDictionary)
971 WDDomain *db;
972 struct stat stbuf;
973 static int inited = 0;
974 char path[PATH_MAX];
975 char *the_path;
976 WMPropList *shared_dict=NULL;
978 if (!inited) {
979 inited = 1;
980 initDefaults();
983 db = wmalloc(sizeof(WDDomain));
984 memset(db, 0, sizeof(WDDomain));
985 db->domain_name = domain;
986 db->path = wdefaultspathfordomain(domain);
987 the_path = db->path;
989 if (the_path && stat(the_path, &stbuf)>=0) {
990 db->dictionary = WMReadPropListFromFile(the_path);
991 if (db->dictionary) {
992 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
993 WMReleasePropList(db->dictionary);
994 db->dictionary = NULL;
995 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
996 domain, the_path);
998 db->timestamp = stbuf.st_mtime;
999 } else {
1000 wwarning(_("could not load domain %s from user defaults database"),
1001 domain);
1005 /* global system dictionary */
1006 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1007 if (stat(path, &stbuf)>=0) {
1008 shared_dict = WMReadPropListFromFile(path);
1009 if (shared_dict) {
1010 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1011 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1012 domain, path);
1013 WMReleasePropList(shared_dict);
1014 shared_dict = NULL;
1015 } else {
1016 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1017 WMIsPLDictionary(db->dictionary)) {
1018 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1019 WMReleasePropList(db->dictionary);
1020 db->dictionary = shared_dict;
1021 if (stbuf.st_mtime > db->timestamp)
1022 db->timestamp = stbuf.st_mtime;
1023 } else if (!db->dictionary) {
1024 db->dictionary = shared_dict;
1025 if (stbuf.st_mtime > db->timestamp)
1026 db->timestamp = stbuf.st_mtime;
1029 } else {
1030 wwarning(_("could not load domain %s from global defaults database (%s)"),
1031 domain, path);
1035 return db;
1039 void
1040 wReadStaticDefaults(WMPropList *dict)
1042 WMPropList *plvalue;
1043 WDefaultEntry *entry;
1044 int i;
1045 void *tdata;
1048 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1049 entry = &staticOptionList[i];
1051 if (dict)
1052 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1053 else
1054 plvalue = NULL;
1056 if (!plvalue) {
1057 /* no default in the DB. Use builtin default */
1058 plvalue = entry->plvalue;
1061 if (plvalue) {
1062 /* convert data */
1063 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1064 if (entry->update) {
1065 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1072 void
1073 wDefaultsCheckDomains(void *foo)
1075 WScreen *scr;
1076 struct stat stbuf;
1077 WMPropList *shared_dict = NULL;
1078 WMPropList *dict;
1079 int i;
1081 #ifdef HEARTBEAT
1082 puts("Checking domains...");
1083 #endif
1084 if (stat(WDWindowMaker->path, &stbuf)>=0
1085 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1086 #ifdef HEARTBEAT
1087 puts("Checking WindowMaker domain");
1088 #endif
1089 WDWindowMaker->timestamp = stbuf.st_mtime;
1091 /* global dictionary */
1092 shared_dict = readGlobalDomain("WindowMaker", True);
1093 /* user dictionary */
1094 dict = WMReadPropListFromFile(WDWindowMaker->path);
1095 if (dict) {
1096 if (!WMIsPLDictionary(dict)) {
1097 WMReleasePropList(dict);
1098 dict = NULL;
1099 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1100 "WindowMaker", WDWindowMaker->path);
1101 } else {
1102 if (shared_dict) {
1103 WMMergePLDictionaries(shared_dict, dict, True);
1104 WMReleasePropList(dict);
1105 dict = shared_dict;
1106 shared_dict = NULL;
1108 for (i=0; i<wScreenCount; i++) {
1109 scr = wScreenWithNumber(i);
1110 if (scr)
1111 wReadDefaults(scr, dict);
1113 if (WDWindowMaker->dictionary) {
1114 WMReleasePropList(WDWindowMaker->dictionary);
1116 WDWindowMaker->dictionary = dict;
1118 } else {
1119 wwarning(_("could not load domain %s from user defaults database"),
1120 "WindowMaker");
1122 if (shared_dict) {
1123 WMReleasePropList(shared_dict);
1127 if (stat(WDWindowAttributes->path, &stbuf)>=0
1128 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1129 #ifdef HEARTBEAT
1130 puts("Checking WMWindowAttributes domain");
1131 #endif
1132 /* global dictionary */
1133 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1134 /* user dictionary */
1135 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1136 if (dict) {
1137 if (!WMIsPLDictionary(dict)) {
1138 WMReleasePropList(dict);
1139 dict = NULL;
1140 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1141 "WMWindowAttributes", WDWindowAttributes->path);
1142 } else {
1143 if (shared_dict) {
1144 WMMergePLDictionaries(shared_dict, dict, True);
1145 WMReleasePropList(dict);
1146 dict = shared_dict;
1147 shared_dict = NULL;
1149 if (WDWindowAttributes->dictionary) {
1150 WMReleasePropList(WDWindowAttributes->dictionary);
1152 WDWindowAttributes->dictionary = dict;
1153 for (i=0; i<wScreenCount; i++) {
1154 scr = wScreenWithNumber(i);
1155 if (scr) {
1156 RImage *image;
1158 wDefaultUpdateIcons(scr);
1160 /* Update the panel image if changed */
1161 /* Don't worry. If the image is the same these
1162 * functions will have no performance impact. */
1163 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1165 if (!image) {
1166 wwarning(_("could not load logo image for panels: %s"),
1167 RMessageForError(RErrorCode));
1168 } else {
1169 WMSetApplicationIconImage(scr->wmscreen, image);
1170 RReleaseImage(image);
1175 } else {
1176 wwarning(_("could not load domain %s from user defaults database"),
1177 "WMWindowAttributes");
1179 WDWindowAttributes->timestamp = stbuf.st_mtime;
1180 if (shared_dict) {
1181 WMReleasePropList(shared_dict);
1185 #ifndef LITE
1186 if (stat(WDRootMenu->path, &stbuf)>=0
1187 && WDRootMenu->timestamp < stbuf.st_mtime) {
1188 dict = WMReadPropListFromFile(WDRootMenu->path);
1189 #ifdef HEARTBEAT
1190 puts("Checking WMRootMenu domain");
1191 #endif
1192 if (dict) {
1193 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1194 WMReleasePropList(dict);
1195 dict = NULL;
1196 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1197 "WMRootMenu", WDRootMenu->path);
1198 } else {
1199 if (WDRootMenu->dictionary) {
1200 WMReleasePropList(WDRootMenu->dictionary);
1202 WDRootMenu->dictionary = dict;
1204 } else {
1205 wwarning(_("could not load domain %s from user defaults database"),
1206 "WMRootMenu");
1208 WDRootMenu->timestamp = stbuf.st_mtime;
1210 #endif /* !LITE */
1212 if (!foo)
1213 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1217 void
1218 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1220 WMPropList *plvalue, *old_value;
1221 WDefaultEntry *entry;
1222 int i, must_update;
1223 int update_workspace_back = 0; /* kluge :/ */
1224 int needs_refresh;
1225 void *tdata;
1226 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1227 ? WDWindowMaker->dictionary : NULL);
1229 must_update = 0;
1231 needs_refresh = 0;
1233 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1234 entry = &optionList[i];
1236 if (new_dict)
1237 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1238 else
1239 plvalue = NULL;
1241 if (!old_dict)
1242 old_value = NULL;
1243 else
1244 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1247 if (!plvalue && !old_value) {
1248 /* no default in the DB. Use builtin default */
1249 plvalue = entry->plvalue;
1250 if (plvalue && new_dict) {
1251 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1252 must_update = 1;
1254 } else if (!plvalue) {
1255 /* value was deleted from DB. Keep current value */
1256 continue;
1257 } else if (!old_value) {
1258 /* set value for the 1st time */
1259 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1260 /* value has changed */
1261 } else {
1263 if (strcmp(entry->key, "WorkspaceBack") == 0
1264 && update_workspace_back
1265 && scr->flags.backimage_helper_launched) {
1266 } else {
1267 /* value was not changed since last time */
1268 continue;
1272 if (plvalue) {
1273 #ifdef DEBUG
1274 printf("Updating %s to %s\n", entry->key,
1275 WMGetPropListDescription(plvalue, False));
1276 #endif
1277 /* convert data */
1278 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1280 * If the WorkspaceSpecificBack data has been changed
1281 * so that the helper will be launched now, we must be
1282 * sure to send the default background texture config
1283 * to the helper.
1285 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1286 && !scr->flags.backimage_helper_launched) {
1287 update_workspace_back = 1;
1289 if (entry->update) {
1290 needs_refresh |=
1291 (*entry->update)(scr, entry, tdata, entry->extra_data);
1297 if (needs_refresh!=0 && !scr->flags.startup) {
1298 int foo;
1300 foo = 0;
1301 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1302 foo |= WTextureSettings;
1303 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1304 foo |= WFontSettings;
1305 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1306 foo |= WColorSettings;
1307 if (foo)
1308 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1309 (void*)foo);
1311 foo = 0;
1312 if (needs_refresh & REFRESH_MENU_TEXTURE)
1313 foo |= WTextureSettings;
1314 if (needs_refresh & REFRESH_MENU_FONT)
1315 foo |= WFontSettings;
1316 if (needs_refresh & REFRESH_MENU_COLOR)
1317 foo |= WColorSettings;
1318 if (foo)
1319 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1320 (void*)foo);
1322 foo = 0;
1323 if (needs_refresh & REFRESH_WINDOW_FONT) {
1324 foo |= WFontSettings;
1326 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1327 foo |= WTextureSettings;
1329 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1330 foo |= WColorSettings;
1332 if (foo)
1333 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1334 (void*)foo);
1336 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1337 foo = 0;
1338 if (needs_refresh & REFRESH_ICON_FONT) {
1339 foo |= WFontSettings;
1341 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1342 foo |= WTextureSettings;
1344 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1345 foo |= WTextureSettings;
1347 if (foo)
1348 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1349 (void*)foo);
1351 if (needs_refresh & REFRESH_ICON_TILE)
1352 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1357 void
1358 wDefaultUpdateIcons(WScreen *scr)
1360 WAppIcon *aicon = scr->app_icon_list;
1361 WWindow *wwin = scr->focused_window;
1362 char *file;
1364 while(aicon) {
1365 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1366 False);
1367 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1368 || (file && !aicon->icon->file)) {
1369 RImage *new_image;
1371 if (aicon->icon->file)
1372 wfree(aicon->icon->file);
1373 aicon->icon->file = wstrdup(file);
1375 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1376 aicon->wm_class);
1377 if (new_image) {
1378 wIconChangeImage(aicon->icon, new_image);
1379 wAppIconPaint(aicon);
1382 aicon = aicon->next;
1385 if (!wPreferences.flags.noclip)
1386 wClipIconPaint(scr->clip_icon);
1388 while (wwin) {
1389 if (wwin->icon && wwin->flags.miniaturized) {
1390 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1391 False);
1392 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1393 || (file && !wwin->icon->file)) {
1394 RImage *new_image;
1396 if (wwin->icon->file)
1397 wfree(wwin->icon->file);
1398 wwin->icon->file = wstrdup(file);
1400 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1401 wwin->wm_class);
1402 if (new_image)
1403 wIconChangeImage(wwin->icon, new_image);
1406 wwin = wwin->prev;
1411 /* --------------------------- Local ----------------------- */
1413 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1414 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1415 entry->key, x); \
1416 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1417 var = entry->default_value;\
1418 } else var = WMGetFromPLString(value)\
1424 static int
1425 string2index(WMPropList *key, WMPropList *val, char *def,
1426 WOptionEnumeration *values)
1428 char *str;
1429 WOptionEnumeration *v;
1430 char buffer[TOTAL_VALUES_LENGTH];
1432 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1433 for (v=values; v->string!=NULL; v++) {
1434 if (strcasecmp(v->string, str)==0)
1435 return v->value;
1439 buffer[0] = 0;
1440 for (v=values; v->string!=NULL; v++) {
1441 if (!v->is_alias) {
1442 if (buffer[0]!=0)
1443 strcat(buffer, ", ");
1444 strcat(buffer, v->string);
1447 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1448 WMGetFromPLString(key), buffer);
1450 if (def) {
1451 return string2index(key, val, NULL, values);
1454 return -1;
1461 * value - is the value in the defaults DB
1462 * addr - is the address to store the data
1463 * ret - is the address to store a pointer to a temporary buffer. ret
1464 * must not be freed and is used by the set functions
1466 static int
1467 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1468 void **ret)
1470 static char data;
1471 char *val;
1472 int second_pass=0;
1474 GET_STRING_OR_DEFAULT("Boolean", val);
1476 again:
1477 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1478 || strcasecmp(val, "YES")==0) {
1480 data = 1;
1481 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1482 || strcasecmp(val, "NO")==0) {
1483 data = 0;
1484 } else {
1485 int i;
1486 if (sscanf(val, "%i", &i)==1) {
1487 if (i!=0)
1488 data = 1;
1489 else
1490 data = 0;
1491 } else {
1492 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1493 val, entry->key);
1494 if (second_pass==0) {
1495 val = WMGetFromPLString(entry->plvalue);
1496 second_pass = 1;
1497 wwarning(_("using default \"%s\" instead"), val);
1498 goto again;
1500 return False;
1504 if (ret)
1505 *ret = &data;
1507 if (addr) {
1508 *(char*)addr = data;
1511 return True;
1515 static int
1516 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1517 void **ret)
1519 static int data;
1520 char *val;
1523 GET_STRING_OR_DEFAULT("Integer", val);
1525 if (sscanf(val, "%i", &data)!=1) {
1526 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1527 val, entry->key);
1528 val = WMGetFromPLString(entry->plvalue);
1529 wwarning(_("using default \"%s\" instead"), val);
1530 if (sscanf(val, "%i", &data)!=1) {
1531 return False;
1535 if (ret)
1536 *ret = &data;
1538 if (addr) {
1539 *(int*)addr = data;
1541 return True;
1545 static int
1546 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1547 void **ret)
1549 static WCoord data;
1550 char *val_x, *val_y;
1551 int nelem, changed=0;
1552 WMPropList *elem_x, *elem_y;
1554 again:
1555 if (!WMIsPLArray(value)) {
1556 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1557 entry->key, "Coordinate");
1558 if (changed==0) {
1559 value = entry->plvalue;
1560 changed = 1;
1561 wwarning(_("using default \"%s\" instead"), entry->default_value);
1562 goto again;
1564 return False;
1567 nelem = WMGetPropListItemCount(value);
1568 if (nelem != 2) {
1569 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1570 entry->key);
1571 if (changed==0) {
1572 value = entry->plvalue;
1573 changed = 1;
1574 wwarning(_("using default \"%s\" instead"), entry->default_value);
1575 goto again;
1577 return False;
1580 elem_x = WMGetFromPLArray(value, 0);
1581 elem_y = WMGetFromPLArray(value, 1);
1583 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1584 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1585 entry->key);
1586 if (changed==0) {
1587 value = entry->plvalue;
1588 changed = 1;
1589 wwarning(_("using default \"%s\" instead"), entry->default_value);
1590 goto again;
1592 return False;
1595 val_x = WMGetFromPLString(elem_x);
1596 val_y = WMGetFromPLString(elem_y);
1598 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1599 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1600 if (changed==0) {
1601 value = entry->plvalue;
1602 changed = 1;
1603 wwarning(_("using default \"%s\" instead"), entry->default_value);
1604 goto again;
1606 return False;
1609 if (data.x < 0)
1610 data.x = 0;
1611 else if (data.x > scr->scr_width/3)
1612 data.x = scr->scr_width/3;
1613 if (data.y < 0)
1614 data.y = 0;
1615 else if (data.y > scr->scr_height/3)
1616 data.y = scr->scr_height/3;
1618 if (ret)
1619 *ret = &data;
1621 if (addr) {
1622 *(WCoord*)addr = data;
1625 return True;
1629 #if 0
1630 /* This function is not used at the moment. */
1631 static int
1632 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1633 void **ret)
1635 static char *data;
1637 GET_STRING_OR_DEFAULT("String", data);
1639 if (!data) {
1640 data = WMGetFromPLString(entry->plvalue);
1641 if (!data)
1642 return False;
1645 if (ret)
1646 *ret = &data;
1648 if (addr)
1649 *(char**)addr = wstrdup(data);
1651 return True;
1653 #endif
1656 static int
1657 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1658 void **ret)
1660 static char *data;
1661 int i, count, len;
1662 char *ptr;
1663 WMPropList *d;
1664 int changed=0;
1666 again:
1667 if (!WMIsPLArray(value)) {
1668 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1669 entry->key, "an array of paths");
1670 if (changed==0) {
1671 value = entry->plvalue;
1672 changed = 1;
1673 wwarning(_("using default \"%s\" instead"), entry->default_value);
1674 goto again;
1676 return False;
1679 i = 0;
1680 count = WMGetPropListItemCount(value);
1681 if (count < 1) {
1682 if (changed==0) {
1683 value = entry->plvalue;
1684 changed = 1;
1685 wwarning(_("using default \"%s\" instead"), entry->default_value);
1686 goto again;
1688 return False;
1691 len = 0;
1692 for (i=0; i<count; i++) {
1693 d = WMGetFromPLArray(value, i);
1694 if (!d || !WMIsPLString(d)) {
1695 count = i;
1696 break;
1698 len += strlen(WMGetFromPLString(d))+1;
1701 ptr = data = wmalloc(len+1);
1703 for (i=0; i<count; i++) {
1704 d = WMGetFromPLArray(value, i);
1705 if (!d || !WMIsPLString(d)) {
1706 break;
1708 strcpy(ptr, WMGetFromPLString(d));
1709 ptr += strlen(WMGetFromPLString(d));
1710 *ptr = ':';
1711 ptr++;
1713 ptr--; *(ptr--) = 0;
1715 if (*(char**)addr!=NULL) {
1716 wfree(*(char**)addr);
1718 *(char**)addr = data;
1720 return True;
1724 static int
1725 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1726 void **ret)
1728 static signed char data;
1730 data = string2index(entry->plkey, value, entry->default_value,
1731 (WOptionEnumeration*)entry->extra_data);
1732 if (data < 0)
1733 return False;
1735 if (ret)
1736 *ret = &data;
1738 if (addr)
1739 *(signed char*)addr = data;
1741 return True;
1747 * (solid <color>)
1748 * (hgradient <color> <color>)
1749 * (vgradient <color> <color>)
1750 * (dgradient <color> <color>)
1751 * (mhgradient <color> <color> ...)
1752 * (mvgradient <color> <color> ...)
1753 * (mdgradient <color> <color> ...)
1754 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1755 * (tpixmap <file> <color>)
1756 * (spixmap <file> <color>)
1757 * (cpixmap <file> <color>)
1758 * (thgradient <file> <opaqueness> <color> <color>)
1759 * (tvgradient <file> <opaqueness> <color> <color>)
1760 * (tdgradient <file> <opaqueness> <color> <color>)
1761 * (function <lib> <function> ...)
1764 static WTexture*
1765 parse_texture(WScreen *scr, WMPropList *pl)
1767 WMPropList *elem;
1768 char *val;
1769 int nelem;
1770 WTexture *texture=NULL;
1772 nelem = WMGetPropListItemCount(pl);
1773 if (nelem < 1)
1774 return NULL;
1777 elem = WMGetFromPLArray(pl, 0);
1778 if (!elem || !WMIsPLString(elem))
1779 return NULL;
1780 val = WMGetFromPLString(elem);
1783 if (strcasecmp(val, "solid")==0) {
1784 XColor color;
1786 if (nelem != 2)
1787 return NULL;
1789 /* get color */
1791 elem = WMGetFromPLArray(pl, 1);
1792 if (!elem || !WMIsPLString(elem))
1793 return NULL;
1794 val = WMGetFromPLString(elem);
1796 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1797 wwarning(_("\"%s\" is not a valid color name"), val);
1798 return NULL;
1801 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1802 } else if (strcasecmp(val, "dgradient")==0
1803 || strcasecmp(val, "vgradient")==0
1804 || strcasecmp(val, "hgradient")==0) {
1805 RColor color1, color2;
1806 XColor xcolor;
1807 int type;
1809 if (nelem != 3) {
1810 wwarning(_("bad number of arguments in gradient specification"));
1811 return NULL;
1814 if (val[0]=='d' || val[0]=='D')
1815 type = WTEX_DGRADIENT;
1816 else if (val[0]=='h' || val[0]=='H')
1817 type = WTEX_HGRADIENT;
1818 else
1819 type = WTEX_VGRADIENT;
1822 /* get from color */
1823 elem = WMGetFromPLArray(pl, 1);
1824 if (!elem || !WMIsPLString(elem))
1825 return NULL;
1826 val = WMGetFromPLString(elem);
1828 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1829 wwarning(_("\"%s\" is not a valid color name"), val);
1830 return NULL;
1832 color1.alpha = 255;
1833 color1.red = xcolor.red >> 8;
1834 color1.green = xcolor.green >> 8;
1835 color1.blue = xcolor.blue >> 8;
1837 /* get to color */
1838 elem = WMGetFromPLArray(pl, 2);
1839 if (!elem || !WMIsPLString(elem)) {
1840 return NULL;
1842 val = WMGetFromPLString(elem);
1844 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1845 wwarning(_("\"%s\" is not a valid color name"), val);
1846 return NULL;
1848 color2.alpha = 255;
1849 color2.red = xcolor.red >> 8;
1850 color2.green = xcolor.green >> 8;
1851 color2.blue = xcolor.blue >> 8;
1853 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1855 } else if (strcasecmp(val, "igradient")==0) {
1856 RColor colors1[2], colors2[2];
1857 int th1, th2;
1858 XColor xcolor;
1859 int i;
1861 if (nelem != 7) {
1862 wwarning(_("bad number of arguments in gradient specification"));
1863 return NULL;
1866 /* get from color */
1867 for (i = 0; i < 2; i++) {
1868 elem = WMGetFromPLArray(pl, 1+i);
1869 if (!elem || !WMIsPLString(elem))
1870 return NULL;
1871 val = WMGetFromPLString(elem);
1873 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1874 wwarning(_("\"%s\" is not a valid color name"), val);
1875 return NULL;
1877 colors1[i].alpha = 255;
1878 colors1[i].red = xcolor.red >> 8;
1879 colors1[i].green = xcolor.green >> 8;
1880 colors1[i].blue = xcolor.blue >> 8;
1882 elem = WMGetFromPLArray(pl, 3);
1883 if (!elem || !WMIsPLString(elem))
1884 return NULL;
1885 val = WMGetFromPLString(elem);
1886 th1 = atoi(val);
1889 /* get from color */
1890 for (i = 0; i < 2; i++) {
1891 elem = WMGetFromPLArray(pl, 4+i);
1892 if (!elem || !WMIsPLString(elem))
1893 return NULL;
1894 val = WMGetFromPLString(elem);
1896 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1897 wwarning(_("\"%s\" is not a valid color name"), val);
1898 return NULL;
1900 colors2[i].alpha = 255;
1901 colors2[i].red = xcolor.red >> 8;
1902 colors2[i].green = xcolor.green >> 8;
1903 colors2[i].blue = xcolor.blue >> 8;
1905 elem = WMGetFromPLArray(pl, 6);
1906 if (!elem || !WMIsPLString(elem))
1907 return NULL;
1908 val = WMGetFromPLString(elem);
1909 th2 = atoi(val);
1911 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1912 th2, colors2);
1914 } else if (strcasecmp(val, "mhgradient")==0
1915 || strcasecmp(val, "mvgradient")==0
1916 || strcasecmp(val, "mdgradient")==0) {
1917 XColor color;
1918 RColor **colors;
1919 int i, count;
1920 int type;
1922 if (nelem < 3) {
1923 wwarning(_("too few arguments in multicolor gradient specification"));
1924 return NULL;
1927 if (val[1]=='h' || val[1]=='H')
1928 type = WTEX_MHGRADIENT;
1929 else if (val[1]=='v' || val[1]=='V')
1930 type = WTEX_MVGRADIENT;
1931 else
1932 type = WTEX_MDGRADIENT;
1934 count = nelem-1;
1936 colors = wmalloc(sizeof(RColor*)*(count+1));
1938 for (i=0; i<count; i++) {
1939 elem = WMGetFromPLArray(pl, i+1);
1940 if (!elem || !WMIsPLString(elem)) {
1941 for (--i; i>=0; --i) {
1942 wfree(colors[i]);
1944 wfree(colors);
1945 return NULL;
1947 val = WMGetFromPLString(elem);
1949 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1950 wwarning(_("\"%s\" is not a valid color name"), val);
1951 for (--i; i>=0; --i) {
1952 wfree(colors[i]);
1954 wfree(colors);
1955 return NULL;
1956 } else {
1957 colors[i] = wmalloc(sizeof(RColor));
1958 colors[i]->red = color.red >> 8;
1959 colors[i]->green = color.green >> 8;
1960 colors[i]->blue = color.blue >> 8;
1963 colors[i] = NULL;
1965 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
1966 } else if (strcasecmp(val, "spixmap")==0 ||
1967 strcasecmp(val, "cpixmap")==0 ||
1968 strcasecmp(val, "tpixmap")==0) {
1969 XColor color;
1970 int type;
1972 if (nelem != 3)
1973 return NULL;
1975 if (val[0] == 's' || val[0] == 'S')
1976 type = WTP_SCALE;
1977 else if (val[0] == 'c' || val[0] == 'C')
1978 type = WTP_CENTER;
1979 else
1980 type = WTP_TILE;
1982 /* get color */
1983 elem = WMGetFromPLArray(pl, 2);
1984 if (!elem || !WMIsPLString(elem)) {
1985 return NULL;
1987 val = WMGetFromPLString(elem);
1989 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1990 wwarning(_("\"%s\" is not a valid color name"), val);
1991 return NULL;
1994 /* file name */
1995 elem = WMGetFromPLArray(pl, 1);
1996 if (!elem || !WMIsPLString(elem))
1997 return NULL;
1998 val = WMGetFromPLString(elem);
2000 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2001 } else if (strcasecmp(val, "thgradient")==0
2002 || strcasecmp(val, "tvgradient")==0
2003 || strcasecmp(val, "tdgradient")==0) {
2004 RColor color1, color2;
2005 XColor xcolor;
2006 int opacity;
2007 int style;
2009 if (val[1]=='h' || val[1]=='H')
2010 style = WTEX_THGRADIENT;
2011 else if (val[1]=='v' || val[1]=='V')
2012 style = WTEX_TVGRADIENT;
2013 else
2014 style = WTEX_TDGRADIENT;
2016 if (nelem != 5) {
2017 wwarning(_("bad number of arguments in textured gradient specification"));
2018 return NULL;
2021 /* get from color */
2022 elem = WMGetFromPLArray(pl, 3);
2023 if (!elem || !WMIsPLString(elem))
2024 return NULL;
2025 val = WMGetFromPLString(elem);
2027 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2028 wwarning(_("\"%s\" is not a valid color name"), val);
2029 return NULL;
2031 color1.alpha = 255;
2032 color1.red = xcolor.red >> 8;
2033 color1.green = xcolor.green >> 8;
2034 color1.blue = xcolor.blue >> 8;
2036 /* get to color */
2037 elem = WMGetFromPLArray(pl, 4);
2038 if (!elem || !WMIsPLString(elem)) {
2039 return NULL;
2041 val = WMGetFromPLString(elem);
2043 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2044 wwarning(_("\"%s\" is not a valid color name"), val);
2045 return NULL;
2047 color2.alpha = 255;
2048 color2.red = xcolor.red >> 8;
2049 color2.green = xcolor.green >> 8;
2050 color2.blue = xcolor.blue >> 8;
2052 /* get opacity */
2053 elem = WMGetFromPLArray(pl, 2);
2054 if (!elem || !WMIsPLString(elem))
2055 opacity = 128;
2056 else
2057 val = WMGetFromPLString(elem);
2059 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2060 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2061 opacity = 128;
2064 /* get file name */
2065 elem = WMGetFromPLArray(pl, 1);
2066 if (!elem || !WMIsPLString(elem))
2067 return NULL;
2068 val = WMGetFromPLString(elem);
2070 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2071 val, opacity);
2073 #ifdef TEXTURE_PLUGIN
2074 else if (strcasecmp(val, "function")==0) {
2075 WTexFunction *function;
2076 void (*initFunc) (Display *, Colormap);
2077 char *lib, *func, **argv;
2078 int i, argc;
2080 if (nelem < 3)
2081 return NULL;
2083 /* get the library name */
2084 elem = WMGetFromPLArray(pl, 1);
2085 if (!elem || !WMIsPLString(elem)) {
2086 return NULL;
2088 lib = WMGetFromPLString(elem);
2090 /* get the function name */
2091 elem = WMGetFromPLArray(pl, 2);
2092 if (!elem || !WMIsPLString(elem)) {
2093 return NULL;
2095 func = WMGetFromPLString(elem);
2097 argc = nelem - 2;
2098 argv = (char **)wmalloc(argc * sizeof(char *));
2100 /* get the parameters */
2101 argv[0] = wstrdup(func);
2102 for (i = 0; i < argc - 1; i++) {
2103 elem = WMGetFromPLArray(pl, 3 + i);
2104 if (!elem || !WMIsPLString(elem)) {
2105 wfree(argv);
2107 return NULL;
2109 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2112 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2114 #ifdef HAVE_DLFCN_H
2115 if (function) {
2116 initFunc = dlsym(function->handle, "initWindowMaker");
2117 if (initFunc) {
2118 initFunc(dpy, scr->w_colormap);
2119 } else {
2120 wwarning(_("could not initialize library %s"), lib);
2122 } else {
2123 wwarning(_("could not find function %s::%s"), lib, func);
2125 #endif /* HAVE_DLFCN_H */
2126 texture = (WTexture*)function;
2128 #endif /* TEXTURE_PLUGIN */
2129 else {
2130 wwarning(_("invalid texture type %s"), val);
2131 return NULL;
2133 return texture;
2138 static int
2139 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2140 void **ret)
2142 static WTexture *texture;
2143 int changed=0;
2145 again:
2146 if (!WMIsPLArray(value)) {
2147 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2148 entry->key, "Texture");
2149 if (changed==0) {
2150 value = entry->plvalue;
2151 changed = 1;
2152 wwarning(_("using default \"%s\" instead"), entry->default_value);
2153 goto again;
2155 return False;
2158 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2159 WMPropList *pl;
2161 pl = WMGetFromPLArray(value, 0);
2162 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2163 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2164 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2165 entry->key, "Solid Texture");
2167 value = entry->plvalue;
2168 changed = 1;
2169 wwarning(_("using default \"%s\" instead"), entry->default_value);
2170 goto again;
2174 texture = parse_texture(scr, value);
2176 if (!texture) {
2177 wwarning(_("Error in texture specification for key \"%s\""),
2178 entry->key);
2179 if (changed==0) {
2180 value = entry->plvalue;
2181 changed = 1;
2182 wwarning(_("using default \"%s\" instead"), entry->default_value);
2183 goto again;
2185 return False;
2188 if (ret)
2189 *ret = &texture;
2191 if (addr)
2192 *(WTexture**)addr = texture;
2194 return True;
2198 static int
2199 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2200 void *addr, void **ret)
2202 WMPropList *elem;
2203 int changed = 0;
2204 char *val;
2205 int nelem;
2207 again:
2208 if (!WMIsPLArray(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 = WMGetPropListItemCount(value);
2223 if (nelem > 0) {
2224 elem = WMGetFromPLArray(value, 0);
2225 if (!elem || !WMIsPLString(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 = WMGetFromPLString(elem);
2237 if (strcasecmp(val, "None")==0)
2238 return True;
2240 *ret = WMRetainPropList(value);
2242 return True;
2246 static int
2247 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2248 void *addr, void **ret)
2250 WMPropList *elem;
2251 int nelem;
2252 int changed = 0;
2254 again:
2255 if (!WMIsPLArray(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 = WMGetPropListItemCount(value);
2270 if (nelem > 0) {
2271 while (nelem--) {
2272 elem = WMGetFromPLArray(value, nelem);
2273 if (!elem || !WMIsPLArray(elem)) {
2274 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2275 nelem);
2280 *ret = WMRetainPropList(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 WMPropList *key = WMCreatePLString("WorkspaceBack");
2293 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2295 WMReleasePropList(key);
2297 #endif
2298 return True;
2302 static int
2303 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *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, WMPropList *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 = WMGetFromPLString(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, WMPropList *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, WMPropList *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, WMPropList *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 RReleaseImage(*(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 # include <X11/cursorfont.h>
2499 typedef struct
2501 char *name;
2502 int id;
2503 } WCursorLookup;
2505 #define CURSOR_ID_NONE (XC_num_glyphs)
2507 static WCursorLookup cursor_table[] =
2509 { "X_cursor", XC_X_cursor },
2510 { "arrow", XC_arrow },
2511 { "based_arrow_down", XC_based_arrow_down },
2512 { "based_arrow_up", XC_based_arrow_up },
2513 { "boat", XC_boat },
2514 { "bogosity", XC_bogosity },
2515 { "bottom_left_corner", XC_bottom_left_corner },
2516 { "bottom_right_corner", XC_bottom_right_corner },
2517 { "bottom_side", XC_bottom_side },
2518 { "bottom_tee", XC_bottom_tee },
2519 { "box_spiral", XC_box_spiral },
2520 { "center_ptr", XC_center_ptr },
2521 { "circle", XC_circle },
2522 { "clock", XC_clock },
2523 { "coffee_mug", XC_coffee_mug },
2524 { "cross", XC_cross },
2525 { "cross_reverse", XC_cross_reverse },
2526 { "crosshair", XC_crosshair },
2527 { "diamond_cross", XC_diamond_cross },
2528 { "dot", XC_dot },
2529 { "dotbox", XC_dotbox },
2530 { "double_arrow", XC_double_arrow },
2531 { "draft_large", XC_draft_large },
2532 { "draft_small", XC_draft_small },
2533 { "draped_box", XC_draped_box },
2534 { "exchange", XC_exchange },
2535 { "fleur", XC_fleur },
2536 { "gobbler", XC_gobbler },
2537 { "gumby", XC_gumby },
2538 { "hand1", XC_hand1 },
2539 { "hand2", XC_hand2 },
2540 { "heart", XC_heart },
2541 { "icon", XC_icon },
2542 { "iron_cross", XC_iron_cross },
2543 { "left_ptr", XC_left_ptr },
2544 { "left_side", XC_left_side },
2545 { "left_tee", XC_left_tee },
2546 { "leftbutton", XC_leftbutton },
2547 { "ll_angle", XC_ll_angle },
2548 { "lr_angle", XC_lr_angle },
2549 { "man", XC_man },
2550 { "middlebutton", XC_middlebutton },
2551 { "mouse", XC_mouse },
2552 { "pencil", XC_pencil },
2553 { "pirate", XC_pirate },
2554 { "plus", XC_plus },
2555 { "question_arrow", XC_question_arrow },
2556 { "right_ptr", XC_right_ptr },
2557 { "right_side", XC_right_side },
2558 { "right_tee", XC_right_tee },
2559 { "rightbutton", XC_rightbutton },
2560 { "rtl_logo", XC_rtl_logo },
2561 { "sailboat", XC_sailboat },
2562 { "sb_down_arrow", XC_sb_down_arrow },
2563 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2564 { "sb_left_arrow", XC_sb_left_arrow },
2565 { "sb_right_arrow", XC_sb_right_arrow },
2566 { "sb_up_arrow", XC_sb_up_arrow },
2567 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2568 { "shuttle", XC_shuttle },
2569 { "sizing", XC_sizing },
2570 { "spider", XC_spider },
2571 { "spraycan", XC_spraycan },
2572 { "star", XC_star },
2573 { "target", XC_target },
2574 { "tcross", XC_tcross },
2575 { "top_left_arrow", XC_top_left_arrow },
2576 { "top_left_corner", XC_top_left_corner },
2577 { "top_right_corner", XC_top_right_corner },
2578 { "top_side", XC_top_side },
2579 { "top_tee", XC_top_tee },
2580 { "trek", XC_trek },
2581 { "ul_angle", XC_ul_angle },
2582 { "umbrella", XC_umbrella },
2583 { "ur_angle", XC_ur_angle },
2584 { "watch", XC_watch },
2585 { "xterm", XC_xterm },
2586 { NULL, CURSOR_ID_NONE }
2589 static void
2590 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2592 switch(status) {
2593 case BitmapOpenFailed:
2594 wwarning(_("failed to open bitmap file \"%s\""), filename);
2595 break;
2596 case BitmapFileInvalid:
2597 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2598 break;
2599 case BitmapNoMemory:
2600 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2601 break;
2602 case BitmapSuccess:
2603 XFreePixmap(dpy, bitmap);
2604 break;
2609 * (none)
2610 * (builtin, <cursor_name>)
2611 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2613 static int
2614 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2616 WMPropList *elem;
2617 char *val;
2618 int nelem;
2619 int status = 0;
2621 nelem = WMGetPropListItemCount(pl);
2622 if (nelem < 1) {
2623 return(status);
2625 elem = WMGetFromPLArray(pl, 0);
2626 if (!elem || !WMIsPLString(elem)) {
2627 return(status);
2629 val = WMGetFromPLString(elem);
2631 if (0 == strcasecmp(val, "none")) {
2632 status = 1;
2633 *cursor = None;
2634 } else if (0 == strcasecmp(val, "builtin")) {
2635 int i;
2636 int cursor_id = CURSOR_ID_NONE;
2638 if (2 != nelem) {
2639 wwarning(_("bad number of arguments in cursor specification"));
2640 return(status);
2642 elem = WMGetFromPLArray(pl, 1);
2643 if (!elem || !WMIsPLString(elem)) {
2644 return(status);
2646 val = WMGetFromPLString(elem);
2648 for (i = 0; NULL != cursor_table[i].name; i++) {
2649 if (0 == strcasecmp(val, cursor_table[i].name)) {
2650 cursor_id = cursor_table[i].id;
2651 break;
2654 if (CURSOR_ID_NONE == cursor_id) {
2655 wwarning(_("unknown builtin cursor name \"%s\""), val);
2656 } else {
2657 *cursor = XCreateFontCursor(dpy, cursor_id);
2658 status = 1;
2660 } else if (0 == strcasecmp(val, "bitmap")) {
2661 char *bitmap_name;
2662 char *mask_name;
2663 int bitmap_status;
2664 int mask_status;
2665 Pixmap bitmap;
2666 Pixmap mask;
2667 unsigned int w, h;
2668 int x, y;
2669 XColor fg, bg;
2671 if (3 != nelem) {
2672 wwarning(_("bad number of arguments in cursor specification"));
2673 return(status);
2675 elem = WMGetFromPLArray(pl, 1);
2676 if (!elem || !WMIsPLString(elem)) {
2677 return(status);
2679 val = WMGetFromPLString(elem);
2680 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2681 if (!bitmap_name) {
2682 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2683 return(status);
2685 elem = WMGetFromPLArray(pl, 2);
2686 if (!elem || !WMIsPLString(elem)) {
2687 wfree(bitmap_name);
2688 return(status);
2690 val = WMGetFromPLString(elem);
2691 mask_name = FindImage(wPreferences.pixmap_path, val);
2692 if (!mask_name) {
2693 wfree(bitmap_name);
2694 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2695 return(status);
2697 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2698 &mask, &x, &y);
2699 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2700 &bitmap, &x, &y);
2701 if ((BitmapSuccess == bitmap_status) &&
2702 (BitmapSuccess == mask_status)) {
2703 fg.pixel = scr->black_pixel;
2704 bg.pixel = scr->white_pixel;
2705 XQueryColor(dpy, scr->w_colormap, &fg);
2706 XQueryColor(dpy, scr->w_colormap, &bg);
2707 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2708 status = 1;
2710 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2711 check_bitmap_status(mask_status, mask_name, mask);
2712 wfree(bitmap_name);
2713 wfree(mask_name);
2715 return(status);
2719 static int
2720 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2721 void **ret)
2723 static Cursor cursor;
2724 int status;
2725 int changed = 0;
2727 again:
2728 if (!WMIsPLArray(value)) {
2729 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2730 entry->key, "cursor specification");
2731 if (!changed) {
2732 value = entry->plvalue;
2733 changed = 1;
2734 wwarning(_("using default \"%s\" instead"), entry->default_value);
2735 goto again;
2737 return(False);
2739 status = parse_cursor(scr, value, &cursor);
2740 if (!status) {
2741 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2742 if (!changed) {
2743 value = entry->plvalue;
2744 changed = 1;
2745 wwarning(_("using default \"%s\" instead"), entry->default_value);
2746 goto again;
2748 return(False);
2750 if (ret) {
2751 *ret = &cursor;
2753 if (addr) {
2754 *(Cursor *)addr = cursor;
2756 return(True);
2758 #undef CURSOR_ID_NONE
2761 /* ---------------- value setting functions --------------- */
2762 static int
2763 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2765 return REFRESH_WINDOW_TITLE_COLOR;
2768 static int
2769 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2771 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2774 static int
2775 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2777 switch (which) {
2778 case WM_DOCK:
2779 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2780 break;
2781 case WM_CLIP:
2782 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2783 break;
2784 default:
2785 break;
2787 return 0;
2791 static int
2792 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2794 if (scr->workspaces) {
2795 wWorkspaceForceChange(scr, scr->current_workspace);
2796 wArrangeIcons(scr, False);
2798 return 0;
2801 #if not_used
2802 static int
2803 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2805 if (*value <= 0)
2806 *(int*)foo = 1;
2808 return 0;
2810 #endif
2814 static int
2815 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2817 Pixmap pixmap;
2818 RImage *img;
2819 int reset = 0;
2821 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2822 wPreferences.icon_size,
2823 ((*texture)->any.type & WREL_BORDER_MASK)
2824 ? WREL_ICON : WREL_FLAT);
2825 if (!img) {
2826 wwarning(_("could not render texture for icon background"));
2827 if (!entry->addr)
2828 wTextureDestroy(scr, *texture);
2829 return 0;
2831 RConvertImage(scr->rcontext, img, &pixmap);
2833 if (scr->icon_tile) {
2834 reset = 1;
2835 RReleaseImage(scr->icon_tile);
2836 XFreePixmap(dpy, scr->icon_tile_pixmap);
2839 scr->icon_tile = img;
2842 /* put the icon in the noticeboard hint */
2843 PropSetIconTileHint(scr, img);
2846 if (!wPreferences.flags.noclip) {
2847 if (scr->clip_tile) {
2848 RReleaseImage(scr->clip_tile);
2850 scr->clip_tile = wClipMakeTile(scr, img);
2853 scr->icon_tile_pixmap = pixmap;
2855 if (scr->def_icon_pixmap) {
2856 XFreePixmap(dpy, scr->def_icon_pixmap);
2857 scr->def_icon_pixmap = None;
2859 if (scr->def_ticon_pixmap) {
2860 XFreePixmap(dpy, scr->def_ticon_pixmap);
2861 scr->def_ticon_pixmap = None;
2864 if (scr->icon_back_texture) {
2865 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2867 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2869 if (scr->clip_balloon)
2870 XSetWindowBackground(dpy, scr->clip_balloon,
2871 (*texture)->any.color.pixel);
2874 * Free the texture as nobody else will use it, nor refer to it.
2876 if (!entry->addr)
2877 wTextureDestroy(scr, *texture);
2879 return (reset ? REFRESH_ICON_TILE : 0);
2884 static int
2885 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2887 if (scr->title_font) {
2888 WMReleaseFont(scr->title_font);
2890 scr->title_font = font;
2892 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2896 static int
2897 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2899 if (scr->menu_title_font) {
2900 WMReleaseFont(scr->menu_title_font);
2903 scr->menu_title_font = font;
2905 return REFRESH_MENU_TITLE_FONT;
2909 static int
2910 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2912 if (scr->menu_entry_font) {
2913 WMReleaseFont(scr->menu_entry_font);
2915 scr->menu_entry_font = font;
2917 return REFRESH_MENU_FONT;
2922 static int
2923 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2925 if (scr->icon_title_font) {
2926 WMReleaseFont(scr->icon_title_font);
2929 scr->icon_title_font = font;
2931 return REFRESH_ICON_FONT;
2935 static int
2936 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2938 if (scr->clip_title_font) {
2939 WMReleaseFont(scr->clip_title_font);
2942 scr->clip_title_font = font;
2944 return REFRESH_ICON_FONT;
2948 static int
2949 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2951 if (scr->workspace_name_font) {
2952 WMReleaseFont(scr->workspace_name_font);
2955 scr->workspace_name_font = font;
2957 return 0;
2961 static int
2962 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2964 if (scr->select_pixel!=scr->white_pixel &&
2965 scr->select_pixel!=scr->black_pixel) {
2966 wFreeColor(scr, scr->select_pixel);
2969 scr->select_pixel = color->pixel;
2971 return REFRESH_MENU_COLOR;
2975 static int
2976 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
2978 if (scr->select_text_pixel!=scr->white_pixel &&
2979 scr->select_text_pixel!=scr->black_pixel) {
2980 wFreeColor(scr, scr->select_text_pixel);
2983 scr->select_text_pixel = color->pixel;
2985 return REFRESH_MENU_COLOR;
2989 static int
2990 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
2992 if (scr->clip_title_pixel[index]!=scr->white_pixel &&
2993 scr->clip_title_pixel[index]!=scr->black_pixel) {
2994 wFreeColor(scr, scr->clip_title_pixel[index]);
2996 scr->clip_title_pixel[index] = color->pixel;
2998 #ifdef GRADIENT_CLIP_ARROW
2999 if (index == CLIP_NORMAL) {
3000 RImage *image;
3001 RColor color1, color2;
3002 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3003 int as = pt - 15; /* 15 = 5+5+5 */
3005 FREE_PIXMAP(scr->clip_arrow_gradient);
3007 color1.red = (color->red >> 8)*6/10;
3008 color1.green = (color->green >> 8)*6/10;
3009 color1.blue = (color->blue >> 8)*6/10;
3011 color2.red = WMIN((color->red >> 8)*20/10, 255);
3012 color2.green = WMIN((color->green >> 8)*20/10, 255);
3013 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3015 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3016 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3017 RReleaseImage(image);
3019 #endif /* GRADIENT_CLIP_ARROW */
3021 return REFRESH_ICON_TITLE_COLOR;
3025 static int
3026 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3028 if (scr->window_title_pixel[index]!=scr->white_pixel &&
3029 scr->window_title_pixel[index]!=scr->black_pixel) {
3030 wFreeColor(scr, scr->window_title_pixel[index]);
3033 scr->window_title_pixel[index] = color->pixel;
3035 if (index == WS_UNFOCUSED)
3036 XSetForeground(dpy, scr->info_text_gc, color->pixel);
3038 return REFRESH_WINDOW_TITLE_COLOR;
3042 static int
3043 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3045 if (scr->menu_title_pixel[0]!=scr->white_pixel &&
3046 scr->menu_title_pixel[0]!=scr->black_pixel) {
3047 wFreeColor(scr, scr->menu_title_pixel[0]);
3050 scr->menu_title_pixel[0] = color->pixel;
3051 XSetForeground(dpy, scr->menu_title_gc, color->pixel);
3053 return REFRESH_MENU_TITLE_COLOR;
3057 static int
3058 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3060 XGCValues gcv;
3061 #define gcm (GCForeground|GCBackground|GCFillStyle)
3063 if (scr->mtext_pixel!=scr->white_pixel &&
3064 scr->mtext_pixel!=scr->black_pixel) {
3065 wFreeColor(scr, scr->mtext_pixel);
3068 scr->mtext_pixel = color->pixel;
3070 XSetForeground(dpy, scr->menu_entry_gc, color->pixel);
3073 if (scr->dtext_pixel == scr->mtext_pixel) {
3074 gcv.foreground = scr->white_pixel;
3075 gcv.background = scr->black_pixel;
3076 gcv.fill_style = FillStippled;
3077 } else {
3078 gcv.foreground = scr->dtext_pixel;
3079 gcv.fill_style = FillSolid;
3081 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3083 return REFRESH_MENU_COLOR;
3084 #undef gcm
3088 static int
3089 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3091 XGCValues gcv;
3092 #define gcm (GCForeground|GCBackground|GCFillStyle)
3094 if (scr->dtext_pixel!=scr->white_pixel &&
3095 scr->dtext_pixel!=scr->black_pixel) {
3096 wFreeColor(scr, scr->dtext_pixel);
3099 scr->dtext_pixel = color->pixel;
3101 if (scr->dtext_pixel == scr->mtext_pixel) {
3102 gcv.foreground = scr->white_pixel;
3103 gcv.background = scr->black_pixel;
3104 gcv.fill_style = FillStippled;
3105 } else {
3106 gcv.foreground = scr->dtext_pixel;
3107 gcv.fill_style = FillSolid;
3109 XChangeGC(dpy, scr->disabled_menu_entry_gc, gcm, &gcv);
3111 return REFRESH_MENU_COLOR;
3112 #undef gcm
3115 static int
3116 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3118 XSetForeground(dpy, scr->icon_title_gc, color->pixel);
3120 return REFRESH_ICON_TITLE_COLOR;
3124 static int
3125 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3127 if (scr->icon_title_texture) {
3128 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3130 XQueryColor (dpy, scr->w_colormap, color);
3131 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3133 return REFRESH_ICON_TITLE_BACK;
3137 static void
3138 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3140 close(scr->helper_fd);
3141 scr->helper_fd = 0;
3142 scr->helper_pid = 0;
3143 scr->flags.backimage_helper_launched = 0;
3147 static int
3148 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3149 void *bar)
3151 WMPropList *val;
3152 char *str;
3153 int i;
3155 if (scr->flags.backimage_helper_launched) {
3156 if (WMGetPropListItemCount(value)==0) {
3157 SendHelperMessage(scr, 'C', 0, NULL);
3158 SendHelperMessage(scr, 'K', 0, NULL);
3160 WMReleasePropList(value);
3161 return 0;
3163 } else {
3164 pid_t pid;
3165 int filedes[2];
3167 if (WMGetPropListItemCount(value) == 0)
3168 return 0;
3170 if (pipe(filedes) < 0) {
3171 wsyserror("pipe() failed:can't set workspace specific background image");
3173 WMReleasePropList(value);
3174 return 0;
3177 pid = fork();
3178 if (pid < 0) {
3179 wsyserror("fork() failed:can't set workspace specific background image");
3180 if (close(filedes[0]) < 0)
3181 wsyserror("could not close pipe");
3182 if (close(filedes[1]) < 0)
3183 wsyserror("could not close pipe");
3185 } else if (pid == 0) {
3186 char *dither;
3188 SetupEnvironment(scr);
3190 if (close(0) < 0)
3191 wsyserror("could not close pipe");
3192 if (dup(filedes[0]) < 0) {
3193 wsyserror("dup() failed:can't set workspace specific background image");
3195 dither = wPreferences.no_dithering ? "-m" : "-d";
3196 if (wPreferences.smooth_workspace_back)
3197 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3198 else
3199 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3200 wsyserror("could not execute wmsetbg");
3201 exit(1);
3202 } else {
3204 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3205 wsyserror("error setting close-on-exec flag");
3207 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3208 wsyserror("error setting close-on-exec flag");
3211 scr->helper_fd = filedes[1];
3212 scr->helper_pid = pid;
3213 scr->flags.backimage_helper_launched = 1;
3215 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3217 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3222 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3223 val = WMGetFromPLArray(value, i);
3224 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3225 str = WMGetPropListDescription(val, False);
3227 SendHelperMessage(scr, 'S', i+1, str);
3229 wfree(str);
3230 } else {
3231 SendHelperMessage(scr, 'U', i+1, NULL);
3234 sleep(1);
3236 WMReleasePropList(value);
3237 return 0;
3241 static int
3242 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3243 void *bar)
3245 if (scr->flags.backimage_helper_launched) {
3246 char *str;
3248 if (WMGetPropListItemCount(value)==0) {
3249 SendHelperMessage(scr, 'U', 0, NULL);
3250 } else {
3251 /* set the default workspace background to this one */
3252 str = WMGetPropListDescription(value, False);
3253 if (str) {
3254 SendHelperMessage(scr, 'S', 0, str);
3255 wfree(str);
3256 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3257 } else {
3258 SendHelperMessage(scr, 'U', 0, NULL);
3261 } else if (WMGetPropListItemCount(value) > 0) {
3262 char *command;
3263 char *text;
3264 char *dither;
3265 int len;
3267 SetupEnvironment(scr);
3268 text = WMGetPropListDescription(value, False);
3269 len = strlen(text)+40;
3270 command = wmalloc(len);
3271 dither = wPreferences.no_dithering ? "-m" : "-d";
3272 if (wPreferences.smooth_workspace_back)
3273 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3274 else
3275 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3276 wfree(text);
3277 system(command);
3278 wfree(command);
3280 WMReleasePropList(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 <WINGs/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
3463 static int
3464 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3466 if (wCursor[index] != None) {
3467 XFreeCursor(dpy, wCursor[index]);
3470 wCursor[index] = *cursor;
3472 if (index==WCUR_ROOT && *cursor!=None) {
3473 XDefineCursor(dpy, scr->root_win, *cursor);
3476 return 0;