Fix buffer overflows in shortcut and workspace name handling
[wmaker-crm.git] / src / defaults.c
blobd7fbb605589687e13523b6ccf048185ab2ca5b0b
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
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 <stdint.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>
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"
72 #define MAX_SHORTCUT_LENGTH 32
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
133 static int getPropList();
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 #ifdef VIRTUAL_DESKTOP
160 static int setVirtualDeskEnable();
161 #endif
162 static int setMenuTitleColor();
163 static int setMenuTextColor();
164 static int setMenuDisabledColor();
165 static int setMenuTitleBack();
166 static int setMenuTextBack();
167 static int setHightlight();
168 static int setHightlightText();
169 static int setKeyGrab();
170 static int setDoubleClick();
171 static int setIconPosition();
173 static int setClipTitleFont();
174 static int setClipTitleColor();
176 static int setMenuStyle();
177 static int setSwPOptions();
178 static int updateUsableArea();
181 extern Cursor wCursor[WCUR_LAST];
182 static int getCursor();
183 static int setCursor();
187 * Tables to convert strings to enumeration values.
188 * Values stored are char
192 /* WARNING: sum of length of all value strings must not exceed
193 * this value */
194 #define TOTAL_VALUES_LENGTH 80
199 #define REFRESH_WINDOW_TEXTURES (1<<0)
200 #define REFRESH_MENU_TEXTURE (1<<1)
201 #define REFRESH_MENU_FONT (1<<2)
202 #define REFRESH_MENU_COLOR (1<<3)
203 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
204 #define REFRESH_MENU_TITLE_FONT (1<<5)
205 #define REFRESH_MENU_TITLE_COLOR (1<<6)
206 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
207 #define REFRESH_WINDOW_FONT (1<<8)
208 #define REFRESH_ICON_TILE (1<<9)
209 #define REFRESH_ICON_FONT (1<<10)
210 #define REFRESH_WORKSPACE_BACK (1<<11)
212 #define REFRESH_BUTTON_IMAGES (1<<12)
214 #define REFRESH_ICON_TITLE_COLOR (1<<13)
215 #define REFRESH_ICON_TITLE_BACK (1<<14)
219 static WOptionEnumeration seFocusModes[] = {
220 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
221 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
222 {NULL, 0, 0}
225 static WOptionEnumeration seColormapModes[] = {
226 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
227 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
228 {NULL, 0, 0}
231 static WOptionEnumeration sePlacements[] = {
232 {"Auto", WPM_AUTO, 0},
233 {"Smart", WPM_SMART, 0},
234 {"Cascade", WPM_CASCADE, 0},
235 {"Random", WPM_RANDOM, 0},
236 {"Manual", WPM_MANUAL, 0},
237 {NULL, 0, 0}
240 static WOptionEnumeration seGeomDisplays[] = {
241 {"None", WDIS_NONE, 0},
242 {"Center", WDIS_CENTER, 0},
243 {"Corner", WDIS_TOPLEFT, 0},
244 {"Floating", WDIS_FRAME_CENTER, 0},
245 {"Line", WDIS_NEW, 0},
246 {NULL, 0, 0}
249 static WOptionEnumeration seSpeeds[] = {
250 {"UltraFast", SPEED_ULTRAFAST, 0},
251 {"Fast", SPEED_FAST, 0},
252 {"Medium", SPEED_MEDIUM, 0},
253 {"Slow", SPEED_SLOW, 0},
254 {"UltraSlow", SPEED_ULTRASLOW, 0},
255 {NULL, 0, 0}
258 static WOptionEnumeration seMouseButtonActions[] = {
259 {"None", WA_NONE, 0},
260 {"SelectWindows", WA_SELECT_WINDOWS, 0},
261 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
262 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
263 {NULL, 0, 0}
266 static WOptionEnumeration seMouseWheelActions[] = {
267 {"None", WA_NONE, 0},
268 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
269 {NULL, 0, 0}
272 static WOptionEnumeration seIconificationStyles[] = {
273 {"Zoom", WIS_ZOOM, 0},
274 {"Twist", WIS_TWIST, 0},
275 {"Flip", WIS_FLIP, 0},
276 {"None", WIS_NONE, 0},
277 {"random", WIS_RANDOM, 0},
278 {NULL, 0, 0}
281 static WOptionEnumeration seJustifications[] = {
282 {"Left", WTJ_LEFT, 0},
283 {"Center", WTJ_CENTER, 0},
284 {"Right", WTJ_RIGHT, 0},
285 {NULL, 0, 0}
288 static WOptionEnumeration seIconPositions[] = {
289 {"blv", IY_BOTTOM|IY_LEFT|IY_VERT, 0},
290 {"blh", IY_BOTTOM|IY_LEFT|IY_HORIZ, 0},
291 {"brv", IY_BOTTOM|IY_RIGHT|IY_VERT, 0},
292 {"brh", IY_BOTTOM|IY_RIGHT|IY_HORIZ, 0},
293 {"tlv", IY_TOP|IY_LEFT|IY_VERT, 0},
294 {"tlh", IY_TOP|IY_LEFT|IY_HORIZ, 0},
295 {"trv", IY_TOP|IY_RIGHT|IY_VERT, 0},
296 {"trh", IY_TOP|IY_RIGHT|IY_HORIZ, 0},
297 {NULL, 0, 0}
300 static WOptionEnumeration seMenuStyles[] = {
301 {"normal", MS_NORMAL, 0},
302 {"singletexture", MS_SINGLE_TEXTURE, 0},
303 {"flat", MS_FLAT, 0},
304 {NULL, 0, 0}
308 static WOptionEnumeration seDisplayPositions[] = {
309 {"none", WD_NONE, 0},
310 {"center", WD_CENTER, 0},
311 {"top", WD_TOP, 0},
312 {"bottom", WD_BOTTOM, 0},
313 {"topleft", WD_TOPLEFT, 0},
314 {"topright", WD_TOPRIGHT, 0},
315 {"bottomleft", WD_BOTTOMLEFT, 0},
316 {"bottomright", WD_BOTTOMRIGHT, 0},
317 {NULL, 0, 0}
320 static WOptionEnumeration seWorkspaceBorder[] = {
321 {"None", WB_NONE, 0},
322 {"LeftRight", WB_LEFTRIGHT, 0},
323 {"TopBottom", WB_TOPBOTTOM, 0},
324 {"AllDirections", WB_ALLDIRS, 0},
325 {NULL, 0, 0}
330 * ALL entries in the tables bellow, NEED to have a default value
331 * defined, and this value needs to be correct.
334 /* these options will only affect the window manager on startup
336 * static defaults can't access the screen data, because it is
337 * created after these defaults are read
339 WDefaultEntry staticOptionList[] = {
341 {"ColormapSize", "4", NULL,
342 &wPreferences.cmap_size, getInt, NULL
344 {"DisableDithering", "NO", NULL,
345 &wPreferences.no_dithering, getBool, NULL
347 /* static by laziness */
348 {"IconSize", "64", NULL,
349 &wPreferences.icon_size, getInt, NULL
351 {"ModifierKey", "Mod1", NULL,
352 &wPreferences.modifier_mask, getModMask, NULL
354 {"DisableWSMouseActions", "NO", NULL,
355 &wPreferences.disable_root_mouse, getBool, NULL
357 {"FocusMode", "manual", seFocusModes,
358 &wPreferences.focus_mode, getEnum, NULL
359 }, /* have a problem when switching from manual to sloppy without restart */
360 {"NewStyle", "NO", NULL,
361 &wPreferences.new_style, getBool, NULL
363 {"DisableDock", "NO", (void*) WM_DOCK,
364 NULL, getBool, setIfDockPresent
366 {"DisableClip", "NO", (void*) WM_CLIP,
367 NULL, getBool, setIfDockPresent
369 {"DisableMiniwindows", "NO", NULL,
370 &wPreferences.disable_miniwindows, getBool, NULL
376 WDefaultEntry optionList[] = {
377 /* dynamic options */
378 {"IconPosition", "blh", seIconPositions,
379 &wPreferences.icon_yard, getEnum, setIconPosition
381 {"IconificationStyle", "Zoom", seIconificationStyles,
382 &wPreferences.iconification_style, getEnum, NULL
384 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
385 &wPreferences.mouse_button1, getEnum, NULL
387 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
388 &wPreferences.mouse_button2, getEnum, NULL
390 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
391 &wPreferences.mouse_button3, getEnum, NULL
393 {"MouseWheelAction", "None", seMouseWheelActions,
394 &wPreferences.mouse_wheel, getEnum, NULL
396 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
397 &wPreferences.pixmap_path, getPathList, NULL
399 {"IconPath", DEF_ICON_PATHS, NULL,
400 &wPreferences.icon_path, getPathList, NULL
402 {"ColormapMode", "auto", seColormapModes,
403 &wPreferences.colormap_mode, getEnum, NULL
405 {"AutoFocus", "NO", NULL,
406 &wPreferences.auto_focus, getBool, NULL
408 {"RaiseDelay", "0", NULL,
409 &wPreferences.raise_delay, getInt, NULL
411 {"CirculateRaise", "NO", NULL,
412 &wPreferences.circ_raise, getBool, NULL
414 {"Superfluous", "NO", NULL,
415 &wPreferences.superfluous, getBool, NULL
417 {"AdvanceToNewWorkspace", "NO", NULL,
418 &wPreferences.ws_advance, getBool, NULL
420 {"CycleWorkspaces", "NO", NULL,
421 &wPreferences.ws_cycle, getBool, NULL
423 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
424 &wPreferences.workspace_name_display_position, getEnum, NULL
426 {"WorkspaceBorder", "None", seWorkspaceBorder,
427 &wPreferences.workspace_border_position, getEnum, updateUsableArea
429 {"WorkspaceBorderSize", "0", NULL,
430 &wPreferences.workspace_border_size, getInt, updateUsableArea
432 #ifdef VIRTUAL_DESKTOP
433 {"EnableVirtualDesktop", "NO", NULL,
434 &wPreferences.vdesk_enable, getBool, setVirtualDeskEnable
436 {"VirtualEdgeExtendSpace", "0", NULL,
437 &wPreferences.vedge_bordersize, getInt, NULL
439 {"VirtualEdgeHorizonScrollSpeed", "30", NULL,
440 &wPreferences.vedge_hscrollspeed, getInt, NULL
442 {"VirtualEdgeVerticalScrollSpeed", "30", NULL,
443 &wPreferences.vedge_vscrollspeed, getInt, NULL
445 {"VirtualEdgeResistance", "30", NULL,
446 &wPreferences.vedge_resistance, getInt, NULL
448 {"VirtualEdgeAttraction", "30", NULL,
449 &wPreferences.vedge_attraction, getInt, NULL
451 {"VirtualEdgeLeftKey", "None", (void*)WKBD_VDESK_LEFT,
452 NULL, getKeybind, setKeyGrab
454 {"VirtualEdgeRightKey", "None", (void*)WKBD_VDESK_RIGHT,
455 NULL, getKeybind, setKeyGrab
457 {"VirtualEdgeUpKey", "None", (void*)WKBD_VDESK_UP,
458 NULL, getKeybind, setKeyGrab
460 {"VirtualEdgeDownKey", "None", (void*)WKBD_VDESK_DOWN,
461 NULL, getKeybind, setKeyGrab
463 #endif
464 {"StickyIcons", "NO", NULL,
465 &wPreferences.sticky_icons, getBool, setStickyIcons
467 {"SaveSessionOnExit", "NO", NULL,
468 &wPreferences.save_session_on_exit, getBool, NULL
470 {"WrapMenus", "NO", NULL,
471 &wPreferences.wrap_menus, getBool, NULL
473 {"ScrollableMenus", "NO", NULL,
474 &wPreferences.scrollable_menus, getBool, NULL
476 {"MenuScrollSpeed", "medium", seSpeeds,
477 &wPreferences.menu_scroll_speed, getEnum, NULL
479 {"IconSlideSpeed", "medium", seSpeeds,
480 &wPreferences.icon_slide_speed, getEnum, NULL
482 {"ShadeSpeed", "medium", seSpeeds,
483 &wPreferences.shade_speed, getEnum, NULL
485 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
486 &wPreferences.dblclick_time, getInt, setDoubleClick,
488 {"AlignSubmenus", "NO", NULL,
489 &wPreferences.align_menus, getBool, NULL
491 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
492 &wPreferences.open_transients_with_parent, getBool, NULL
494 {"WindowPlacement", "auto", sePlacements,
495 &wPreferences.window_placement, getEnum, NULL
497 {"IgnoreFocusClick","NO", NULL,
498 &wPreferences.ignore_focus_click, getBool, NULL
500 {"UseSaveUnders", "NO", NULL,
501 &wPreferences.use_saveunders, getBool, NULL
503 {"OpaqueMove", "NO", NULL,
504 &wPreferences.opaque_move, getBool, NULL
506 {"DisableSound", "NO", NULL,
507 &wPreferences.no_sound, getBool, NULL
509 {"DisableAnimations", "NO", NULL,
510 &wPreferences.no_animations, getBool, NULL
512 {"DontLinkWorkspaces","NO", NULL,
513 &wPreferences.no_autowrap, getBool, NULL
515 {"AutoArrangeIcons", "NO", NULL,
516 &wPreferences.auto_arrange_icons, getBool, NULL
518 {"NoWindowOverDock", "NO", NULL,
519 &wPreferences.no_window_over_dock, getBool, updateUsableArea
521 {"NoWindowOverIcons", "NO", NULL,
522 &wPreferences.no_window_over_icons, getBool, updateUsableArea
524 {"WindowPlaceOrigin", "(0, 0)", NULL,
525 &wPreferences.window_place_origin, getCoord, NULL
527 {"ResizeDisplay", "corner", seGeomDisplays,
528 &wPreferences.size_display, getEnum, NULL
530 {"MoveDisplay", "corner", seGeomDisplays,
531 &wPreferences.move_display, getEnum, NULL
533 {"DontConfirmKill", "NO", NULL,
534 &wPreferences.dont_confirm_kill, getBool,NULL
536 {"WindowTitleBalloons", "NO", NULL,
537 &wPreferences.window_balloon, getBool, NULL
539 {"MiniwindowTitleBalloons", "NO", NULL,
540 &wPreferences.miniwin_balloon,getBool, NULL
542 {"AppIconBalloons", "NO", NULL,
543 &wPreferences.appicon_balloon,getBool, NULL
545 {"HelpBalloons", "NO", NULL,
546 &wPreferences.help_balloon, getBool, NULL
548 {"EdgeResistance", "30", NULL,
549 &wPreferences.edge_resistance,getInt, NULL
551 {"Attraction", "NO", NULL,
552 &wPreferences.attract, getBool, NULL
554 {"DisableBlinking", "NO", NULL,
555 &wPreferences.dont_blink, getBool, NULL
557 /* style options */
558 {"MenuStyle", "normal", seMenuStyles,
559 &wPreferences.menu_style, getEnum, setMenuStyle
561 {"WidgetColor", "(solid, gray)", NULL,
562 NULL, getTexture, setWidgetColor,
564 {"WorkspaceSpecificBack","()", NULL,
565 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
567 /* WorkspaceBack must come after WorkspaceSpecificBack or
568 * WorkspaceBack wont know WorkspaceSpecificBack was also
569 * specified and 2 copies of wmsetbg will be launched */
570 {"WorkspaceBack", "(solid, black)", NULL,
571 NULL, getWSBackground,setWorkspaceBack
573 {"SmoothWorkspaceBack", "NO", NULL,
574 NULL, getBool, NULL
576 {"IconBack", "(solid, gray)", NULL,
577 NULL, getTexture, setIconTile
579 {"TitleJustify", "center", seJustifications,
580 &wPreferences.title_justification, getEnum, setJustify
582 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
583 NULL, getFont, setWinTitleFont,
585 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
586 &wPreferences.window_title_clearance, getInt, setClearance
588 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
589 &wPreferences.menu_title_clearance, getInt, setClearance
591 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
592 &wPreferences.menu_text_clearance, getInt, setClearance
594 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
595 NULL, getFont, setMenuTitleFont
597 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
598 NULL, getFont, setMenuTextFont
600 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
601 NULL, getFont, setIconTitleFont
603 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
604 NULL, getFont, setClipTitleFont
606 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
607 NULL, getFont, setLargeDisplayFont
609 {"HighlightColor", "white", NULL,
610 NULL, getColor, setHightlight
612 {"HighlightTextColor", "black", NULL,
613 NULL, getColor, setHightlightText
615 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
616 NULL, getColor, setClipTitleColor
618 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
619 NULL, getColor, setClipTitleColor
621 {"FTitleColor", "white", (void*)WS_FOCUSED,
622 NULL, getColor, setWTitleColor
624 {"PTitleColor", "white", (void*)WS_PFOCUSED,
625 NULL, getColor, setWTitleColor
627 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
628 NULL, getColor, setWTitleColor
630 {"FTitleBack", "(solid, black)", NULL,
631 NULL, getTexture, setFTitleBack
633 {"PTitleBack", "(solid, \"#616161\")", NULL,
634 NULL, getTexture, setPTitleBack
636 {"UTitleBack", "(solid, gray)", NULL,
637 NULL, getTexture, setUTitleBack
639 {"ResizebarBack", "(solid, gray)", NULL,
640 NULL, getTexture, setResizebarBack
642 {"MenuTitleColor", "white", NULL,
643 NULL, getColor, setMenuTitleColor
645 {"MenuTextColor", "black", NULL,
646 NULL, getColor, setMenuTextColor
648 {"MenuDisabledColor", "\"#616161\"", NULL,
649 NULL, getColor, setMenuDisabledColor
651 {"MenuTitleBack", "(solid, black)", NULL,
652 NULL, getTexture, setMenuTitleBack
654 {"MenuTextBack", "(solid, gray)", NULL,
655 NULL, getTexture, setMenuTextBack
657 {"IconTitleColor", "white", NULL,
658 NULL, getColor, setIconTitleColor
660 {"IconTitleBack", "black", NULL,
661 NULL, getColor, setIconTitleBack
663 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
664 NULL, getPropList, setSwPOptions
666 /* keybindings */
667 #ifndef LITE
668 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
669 NULL, getKeybind, setKeyGrab
671 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
672 NULL, getKeybind, setKeyGrab
674 #endif /* LITE */
675 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
676 NULL, getKeybind, setKeyGrab
678 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
679 NULL, getKeybind, setKeyGrab
681 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
682 NULL, getKeybind, setKeyGrab
684 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
685 NULL, getKeybind, setKeyGrab
687 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
688 NULL, getKeybind, setKeyGrab
690 {"HideKey", "None", (void*)WKBD_HIDE,
691 NULL, getKeybind, setKeyGrab
693 {"HideOthersKey", "None", (void*)WKBD_HIDE_OTHERS,
694 NULL, getKeybind, setKeyGrab
696 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
697 NULL, getKeybind, setKeyGrab
699 {"CloseKey", "None", (void*)WKBD_CLOSE,
700 NULL, getKeybind, setKeyGrab
702 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
703 NULL, getKeybind, setKeyGrab
705 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
706 NULL, getKeybind, setKeyGrab
708 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
709 NULL, getKeybind, setKeyGrab
711 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
712 NULL, getKeybind, setKeyGrab
714 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
715 NULL, getKeybind, setKeyGrab
717 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
718 NULL, getKeybind, setKeyGrab
720 {"ShadeKey", "None", (void*)WKBD_SHADE,
721 NULL, getKeybind, setKeyGrab
723 {"SelectKey", "None", (void*)WKBD_SELECT,
724 NULL, getKeybind, setKeyGrab
726 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
727 NULL, getKeybind, setKeyGrab
729 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
730 NULL, getKeybind, setKeyGrab
732 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
733 NULL, getKeybind, setKeyGrab
735 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
736 NULL, getKeybind, setKeyGrab
738 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
739 NULL, getKeybind, setKeyGrab
741 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
742 NULL, getKeybind, setKeyGrab
744 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
745 NULL, getKeybind, setKeyGrab
747 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
748 NULL, getKeybind, setKeyGrab
750 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
751 NULL, getKeybind, setKeyGrab
753 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
754 NULL, getKeybind, setKeyGrab
756 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
757 NULL, getKeybind, setKeyGrab
759 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
760 NULL, getKeybind, setKeyGrab
762 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
763 NULL, getKeybind, setKeyGrab
765 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
766 NULL, getKeybind, setKeyGrab
768 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
769 NULL, getKeybind, setKeyGrab
771 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
772 NULL, getKeybind, setKeyGrab
774 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
775 NULL, getKeybind, setKeyGrab
777 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
778 NULL, getKeybind, setKeyGrab
780 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
781 NULL, getKeybind, setKeyGrab
783 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
784 NULL, getKeybind, setKeyGrab
786 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
787 NULL, getKeybind, setKeyGrab
789 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
790 NULL, getKeybind, setKeyGrab
792 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
793 NULL, getKeybind, setKeyGrab
795 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
796 NULL, getKeybind, setKeyGrab
798 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
799 NULL, getKeybind, setKeyGrab
801 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
802 NULL, getKeybind, setKeyGrab
804 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
805 NULL, getKeybind, setKeyGrab
808 #ifdef KEEP_XKB_LOCK_STATUS
809 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
810 NULL, getKeybind, setKeyGrab
812 {"KbdModeLock", "NO", NULL,
813 &wPreferences.modelock, getBool, NULL
815 #endif /* KEEP_XKB_LOCK_STATUS */
817 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
818 NULL, getCursor, setCursor
820 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
821 NULL, getCursor, setCursor
823 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
824 NULL, getCursor, setCursor
826 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
827 NULL, getCursor, setCursor
829 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
830 (void*)WCUR_TOPLEFTRESIZE,
831 NULL, getCursor, setCursor
833 {"TopRightResizeCursor", "(builtin, top_right_corner)",
834 (void*)WCUR_TOPRIGHTRESIZE,
835 NULL, getCursor, setCursor
837 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
838 (void*)WCUR_BOTTOMLEFTRESIZE,
839 NULL, getCursor, setCursor
841 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
842 (void*)WCUR_BOTTOMRIGHTRESIZE,
843 NULL, getCursor, setCursor
845 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
846 (void*)WCUR_VERTICALRESIZE,
847 NULL, getCursor, setCursor
849 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
850 (void*)WCUR_HORIZONRESIZE,
851 NULL, getCursor, setCursor
853 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
854 NULL, getCursor, setCursor
856 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
857 NULL, getCursor, setCursor
859 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
860 NULL, getCursor, setCursor
862 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
863 NULL, getCursor, setCursor
868 #if 0
869 static void rereadDefaults(void);
870 #endif
872 #if 0
873 static void
874 rereadDefaults(void)
876 /* must defer the update because accessing X data from a
877 * signal handler can mess up Xlib */
880 #endif
882 static void
883 initDefaults()
885 int i;
886 WDefaultEntry *entry;
888 WMPLSetCaseSensitive(False);
890 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
891 entry = &optionList[i];
893 entry->plkey = WMCreatePLString(entry->key);
894 if (entry->default_value)
895 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
896 else
897 entry->plvalue = NULL;
900 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
901 entry = &staticOptionList[i];
903 entry->plkey = WMCreatePLString(entry->key);
904 if (entry->default_value)
905 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
906 else
907 entry->plvalue = NULL;
911 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
912 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
914 PLRegister(wDomainName, rereadDefaults);
915 PLRegister(wAttributeDomainName, rereadDefaults);
920 static WMPropList*
921 readGlobalDomain(char *domainName, Bool requireDictionary)
923 WMPropList *globalDict = NULL;
924 char path[PATH_MAX];
925 struct stat stbuf;
927 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
928 if (stat(path, &stbuf)>=0) {
929 globalDict = WMReadPropListFromFile(path);
930 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
931 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
932 domainName, path);
933 WMReleasePropList(globalDict);
934 globalDict = NULL;
935 } else if (!globalDict) {
936 wwarning(_("could not load domain %s from global defaults database"),
937 domainName);
941 return globalDict;
945 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
946 static void
947 prependMenu(WMPropList *destarr, WMPropList *array)
949 WMPropList *item;
950 int i;
952 for (i=0; i<WMGetPropListItemCount(array); i++) {
953 item = WMGetFromPLArray(array, i);
954 if (item)
955 WMInsertInPLArray(destarr, i+1, item);
960 static void
961 appendMenu(WMPropList *destarr, WMPropList *array)
963 WMPropList *item;
964 int i;
966 for (i=0; i<WMGetPropListItemCount(array); i++) {
967 item = WMGetFromPLArray(array, i);
968 if (item)
969 WMAddToPLArray(destarr, item);
972 #endif
975 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
976 static Bool
977 fixupCachedPixmapsPaths(WMPropList *dict)
979 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
980 char *path, *fixedpath, *ptr, *search, *replace;
981 int i, len, slen;
982 Bool changed = False;
984 search = "/.AppInfo/WindowMaker/";
985 slen = strlen(search);
987 iconkey = WMCreatePLString("Icon");
988 allApps = WMGetPLDictionaryKeys(dict);
990 for (i=0; i < WMGetPropListItemCount(allApps); i++) {
991 app = WMGetFromPLArray(allApps, i);
992 props = WMGetFromPLDictionary(dict, app);
993 if (!props)
994 continue;
995 icon = WMGetFromPLDictionary(props, iconkey);
996 if (icon && WMIsPLString(icon)) {
997 path = WMGetFromPLString(icon);
998 ptr = strstr(path, search);
999 if (ptr) {
1000 changed = True;
1001 len = (ptr - path);
1002 fixedpath = wmalloc(strlen(path)+32);
1003 strncpy(fixedpath, path, len);
1004 fixedpath[len] = 0;
1005 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
1006 strcat(fixedpath, ptr+slen);
1007 newicon = WMCreatePLString(fixedpath);
1008 WMPutInPLDictionary(props, iconkey, newicon);
1009 WMReleasePropList(newicon);
1010 wfree(fixedpath);
1015 WMReleasePropList(allApps);
1016 WMReleasePropList(iconkey);
1018 return changed;
1022 void
1023 wDefaultsMergeGlobalMenus(WDDomain *menuDomain)
1025 WMPropList *menu = menuDomain->dictionary;
1026 WMPropList *submenu;
1028 if (!menu || !WMIsPLArray(menu))
1029 return;
1031 #ifdef GLOBAL_PREAMBLE_MENU_FILE
1032 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_PREAMBLE_MENU_FILE);
1034 if (submenu && !WMIsPLArray(submenu)) {
1035 wwarning(_("invalid global menu file %s"),
1036 GLOBAL_PREAMBLE_MENU_FILE);
1037 WMReleasePropList(submenu);
1038 submenu = NULL;
1040 if (submenu) {
1041 prependMenu(menu, submenu);
1042 WMReleasePropList(submenu);
1044 #endif
1046 #ifdef GLOBAL_EPILOGUE_MENU_FILE
1047 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_EPILOGUE_MENU_FILE);
1049 if (submenu && !WMIsPLArray(submenu)) {
1050 wwarning(_("invalid global menu file %s"),
1051 GLOBAL_EPILOGUE_MENU_FILE);
1052 WMReleasePropList(submenu);
1053 submenu = NULL;
1055 if (submenu) {
1056 appendMenu(menu, submenu);
1057 WMReleasePropList(submenu);
1059 #endif
1061 menuDomain->dictionary = menu;
1065 #if 0
1066 WMPropList*
1067 wDefaultsInit(int screen_number)
1069 static int defaults_inited = 0;
1070 WMPropList *dict;
1072 if (!defaults_inited) {
1073 initDefaults();
1076 dict = PLGetDomain(wDomainName);
1077 if (!dict) {
1078 wwarning(_("could not read domain \"%s\" from defaults database"),
1079 WMGetFromPLString(wDomainName));
1082 return dict;
1084 #endif
1087 void
1088 wDefaultsDestroyDomain(WDDomain *domain)
1090 if (domain->dictionary)
1091 WMReleasePropList(domain->dictionary);
1092 wfree(domain->path);
1093 wfree(domain);
1097 WDDomain*
1098 wDefaultsInitDomain(char *domain, Bool requireDictionary)
1100 WDDomain *db;
1101 struct stat stbuf;
1102 static int inited = 0;
1103 char path[PATH_MAX];
1104 char *the_path;
1105 WMPropList *shared_dict=NULL;
1107 if (!inited) {
1108 inited = 1;
1109 initDefaults();
1112 db = wmalloc(sizeof(WDDomain));
1113 memset(db, 0, sizeof(WDDomain));
1114 db->domain_name = domain;
1115 db->path = wdefaultspathfordomain(domain);
1116 the_path = db->path;
1118 if (the_path && stat(the_path, &stbuf)>=0) {
1119 db->dictionary = WMReadPropListFromFile(the_path);
1120 if (db->dictionary) {
1121 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
1122 WMReleasePropList(db->dictionary);
1123 db->dictionary = NULL;
1124 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1125 domain, the_path);
1127 if (strcmp(domain, "WMWindowAttributes")==0 && db->dictionary) {
1128 if (fixupCachedPixmapsPaths(db->dictionary)) {
1129 WMWritePropListToFile(db->dictionary, db->path, True);
1130 /* re-read the timestamp. if this fails take current time */
1131 if (stat(db->path, &stbuf)<0) {
1132 stbuf.st_mtime = time(NULL);
1136 db->timestamp = stbuf.st_mtime;
1137 } else {
1138 wwarning(_("could not load domain %s from user defaults database"),
1139 domain);
1143 /* global system dictionary */
1144 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1145 if (stat(path, &stbuf)>=0) {
1146 shared_dict = WMReadPropListFromFile(path);
1147 if (shared_dict) {
1148 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1149 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1150 domain, path);
1151 WMReleasePropList(shared_dict);
1152 shared_dict = NULL;
1153 } else {
1154 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1155 WMIsPLDictionary(db->dictionary)) {
1156 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1157 WMReleasePropList(db->dictionary);
1158 db->dictionary = shared_dict;
1159 if (stbuf.st_mtime > db->timestamp)
1160 db->timestamp = stbuf.st_mtime;
1161 } else if (!db->dictionary) {
1162 db->dictionary = shared_dict;
1163 if (stbuf.st_mtime > db->timestamp)
1164 db->timestamp = stbuf.st_mtime;
1167 } else {
1168 wwarning(_("could not load domain %s from global defaults database (%s)"),
1169 domain, path);
1173 return db;
1177 void
1178 wReadStaticDefaults(WMPropList *dict)
1180 WMPropList *plvalue;
1181 WDefaultEntry *entry;
1182 int i;
1183 void *tdata;
1186 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1187 entry = &staticOptionList[i];
1189 if (dict)
1190 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1191 else
1192 plvalue = NULL;
1194 if (!plvalue) {
1195 /* no default in the DB. Use builtin default */
1196 plvalue = entry->plvalue;
1199 if (plvalue) {
1200 /* convert data */
1201 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1202 if (entry->update) {
1203 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1211 void
1212 wDefaultsCheckDomains(void *foo)
1214 WScreen *scr;
1215 struct stat stbuf;
1216 WMPropList *shared_dict = NULL;
1217 WMPropList *dict;
1218 int i;
1220 #ifdef HEARTBEAT
1221 puts("Checking domains...");
1222 #endif
1223 if (stat(WDWindowMaker->path, &stbuf)>=0
1224 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1225 #ifdef HEARTBEAT
1226 puts("Checking WindowMaker domain");
1227 #endif
1228 WDWindowMaker->timestamp = stbuf.st_mtime;
1230 /* global dictionary */
1231 shared_dict = readGlobalDomain("WindowMaker", True);
1232 /* user dictionary */
1233 dict = WMReadPropListFromFile(WDWindowMaker->path);
1234 if (dict) {
1235 if (!WMIsPLDictionary(dict)) {
1236 WMReleasePropList(dict);
1237 dict = NULL;
1238 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1239 "WindowMaker", WDWindowMaker->path);
1240 } else {
1241 if (shared_dict) {
1242 WMMergePLDictionaries(shared_dict, dict, True);
1243 WMReleasePropList(dict);
1244 dict = shared_dict;
1245 shared_dict = NULL;
1247 for (i=0; i<wScreenCount; i++) {
1248 scr = wScreenWithNumber(i);
1249 if (scr)
1250 wReadDefaults(scr, dict);
1252 if (WDWindowMaker->dictionary) {
1253 WMReleasePropList(WDWindowMaker->dictionary);
1255 WDWindowMaker->dictionary = dict;
1257 } else {
1258 wwarning(_("could not load domain %s from user defaults database"),
1259 "WindowMaker");
1261 if (shared_dict) {
1262 WMReleasePropList(shared_dict);
1266 if (stat(WDWindowAttributes->path, &stbuf)>=0
1267 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1268 #ifdef HEARTBEAT
1269 puts("Checking WMWindowAttributes domain");
1270 #endif
1271 /* global dictionary */
1272 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1273 /* user dictionary */
1274 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1275 if (dict) {
1276 if (!WMIsPLDictionary(dict)) {
1277 WMReleasePropList(dict);
1278 dict = NULL;
1279 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1280 "WMWindowAttributes", WDWindowAttributes->path);
1281 } else {
1282 if (shared_dict) {
1283 WMMergePLDictionaries(shared_dict, dict, True);
1284 WMReleasePropList(dict);
1285 dict = shared_dict;
1286 shared_dict = NULL;
1288 if (WDWindowAttributes->dictionary) {
1289 WMReleasePropList(WDWindowAttributes->dictionary);
1291 WDWindowAttributes->dictionary = dict;
1292 for (i=0; i<wScreenCount; i++) {
1293 scr = wScreenWithNumber(i);
1294 if (scr) {
1295 RImage *image;
1297 wDefaultUpdateIcons(scr);
1299 /* Update the panel image if changed */
1300 /* Don't worry. If the image is the same these
1301 * functions will have no performance impact. */
1302 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1304 if (!image) {
1305 wwarning(_("could not load logo image for panels: %s"),
1306 RMessageForError(RErrorCode));
1307 } else {
1308 WMSetApplicationIconImage(scr->wmscreen, image);
1309 RReleaseImage(image);
1314 } else {
1315 wwarning(_("could not load domain %s from user defaults database"),
1316 "WMWindowAttributes");
1318 WDWindowAttributes->timestamp = stbuf.st_mtime;
1319 if (shared_dict) {
1320 WMReleasePropList(shared_dict);
1324 #ifndef LITE
1325 if (stat(WDRootMenu->path, &stbuf)>=0
1326 && WDRootMenu->timestamp < stbuf.st_mtime) {
1327 dict = WMReadPropListFromFile(WDRootMenu->path);
1328 #ifdef HEARTBEAT
1329 puts("Checking WMRootMenu domain");
1330 #endif
1331 if (dict) {
1332 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1333 WMReleasePropList(dict);
1334 dict = NULL;
1335 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1336 "WMRootMenu", WDRootMenu->path);
1337 } else {
1338 if (WDRootMenu->dictionary) {
1339 WMReleasePropList(WDRootMenu->dictionary);
1341 WDRootMenu->dictionary = dict;
1342 wDefaultsMergeGlobalMenus(WDRootMenu);
1344 } else {
1345 wwarning(_("could not load domain %s from user defaults database"),
1346 "WMRootMenu");
1348 WDRootMenu->timestamp = stbuf.st_mtime;
1350 #endif /* !LITE */
1355 void
1356 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1358 WMPropList *plvalue, *old_value;
1359 WDefaultEntry *entry;
1360 int i, must_update;
1361 int update_workspace_back = 0; /* kluge :/ */
1362 int needs_refresh;
1363 void *tdata;
1364 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1365 ? WDWindowMaker->dictionary : NULL);
1367 must_update = 0;
1369 needs_refresh = 0;
1371 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1372 entry = &optionList[i];
1374 if (new_dict)
1375 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1376 else
1377 plvalue = NULL;
1379 if (!old_dict)
1380 old_value = NULL;
1381 else
1382 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1385 if (!plvalue && !old_value) {
1386 /* no default in the DB. Use builtin default */
1387 plvalue = entry->plvalue;
1388 if (plvalue && new_dict) {
1389 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1390 must_update = 1;
1392 } else if (!plvalue) {
1393 /* value was deleted from DB. Keep current value */
1394 continue;
1395 } else if (!old_value) {
1396 /* set value for the 1st time */
1397 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1398 /* value has changed */
1399 } else {
1401 if (strcmp(entry->key, "WorkspaceBack") == 0
1402 && update_workspace_back
1403 && scr->flags.backimage_helper_launched) {
1404 } else {
1405 /* value was not changed since last time */
1406 continue;
1410 if (plvalue) {
1411 #ifdef DEBUG
1412 printf("Updating %s to %s\n", entry->key,
1413 WMGetPropListDescription(plvalue, False));
1414 #endif
1415 /* convert data */
1416 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1418 * If the WorkspaceSpecificBack data has been changed
1419 * so that the helper will be launched now, we must be
1420 * sure to send the default background texture config
1421 * to the helper.
1423 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1424 && !scr->flags.backimage_helper_launched) {
1425 update_workspace_back = 1;
1427 if (entry->update) {
1428 needs_refresh |=
1429 (*entry->update)(scr, entry, tdata, entry->extra_data);
1435 if (needs_refresh!=0 && !scr->flags.startup) {
1436 int foo;
1438 foo = 0;
1439 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1440 foo |= WTextureSettings;
1441 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1442 foo |= WFontSettings;
1443 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1444 foo |= WColorSettings;
1445 if (foo)
1446 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1447 (void*)(uintptr_t)foo);
1449 foo = 0;
1450 if (needs_refresh & REFRESH_MENU_TEXTURE)
1451 foo |= WTextureSettings;
1452 if (needs_refresh & REFRESH_MENU_FONT)
1453 foo |= WFontSettings;
1454 if (needs_refresh & REFRESH_MENU_COLOR)
1455 foo |= WColorSettings;
1456 if (foo)
1457 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1458 (void*)(uintptr_t)foo);
1460 foo = 0;
1461 if (needs_refresh & REFRESH_WINDOW_FONT) {
1462 foo |= WFontSettings;
1464 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1465 foo |= WTextureSettings;
1467 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1468 foo |= WColorSettings;
1470 if (foo)
1471 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1472 (void*)(uintptr_t)foo);
1474 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1475 foo = 0;
1476 if (needs_refresh & REFRESH_ICON_FONT) {
1477 foo |= WFontSettings;
1479 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1480 foo |= WTextureSettings;
1482 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1483 foo |= WTextureSettings;
1485 if (foo)
1486 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1487 (void*)(uintptr_t)foo);
1489 if (needs_refresh & REFRESH_ICON_TILE)
1490 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1495 void
1496 wDefaultUpdateIcons(WScreen *scr)
1498 WAppIcon *aicon = scr->app_icon_list;
1499 WWindow *wwin = scr->focused_window;
1500 char *file;
1502 while(aicon) {
1503 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1504 False);
1505 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1506 || (file && !aicon->icon->file)) {
1507 RImage *new_image;
1509 if (aicon->icon->file)
1510 wfree(aicon->icon->file);
1511 aicon->icon->file = wstrdup(file);
1513 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1514 aicon->wm_class);
1515 if (new_image) {
1516 wIconChangeImage(aicon->icon, new_image);
1517 wAppIconPaint(aicon);
1520 aicon = aicon->next;
1523 if (!wPreferences.flags.noclip)
1524 wClipIconPaint(scr->clip_icon);
1526 while (wwin) {
1527 if (wwin->icon && wwin->flags.miniaturized) {
1528 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1529 False);
1530 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1531 || (file && !wwin->icon->file)) {
1532 RImage *new_image;
1534 if (wwin->icon->file)
1535 wfree(wwin->icon->file);
1536 wwin->icon->file = wstrdup(file);
1538 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1539 wwin->wm_class);
1540 if (new_image)
1541 wIconChangeImage(wwin->icon, new_image);
1544 wwin = wwin->prev;
1549 /* --------------------------- Local ----------------------- */
1551 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1552 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1553 entry->key, x); \
1554 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1555 var = entry->default_value;\
1556 } else var = WMGetFromPLString(value)\
1562 static int
1563 string2index(WMPropList *key, WMPropList *val, char *def,
1564 WOptionEnumeration *values)
1566 char *str;
1567 WOptionEnumeration *v;
1568 char buffer[TOTAL_VALUES_LENGTH];
1570 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1571 for (v=values; v->string!=NULL; v++) {
1572 if (strcasecmp(v->string, str)==0)
1573 return v->value;
1577 buffer[0] = 0;
1578 for (v=values; v->string!=NULL; v++) {
1579 if (!v->is_alias) {
1580 if (buffer[0]!=0)
1581 strcat(buffer, ", ");
1582 strcat(buffer, v->string);
1585 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1586 WMGetFromPLString(key), buffer);
1588 if (def) {
1589 return string2index(key, val, NULL, values);
1592 return -1;
1599 * value - is the value in the defaults DB
1600 * addr - is the address to store the data
1601 * ret - is the address to store a pointer to a temporary buffer. ret
1602 * must not be freed and is used by the set functions
1604 static int
1605 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1606 void **ret)
1608 static char data;
1609 char *val;
1610 int second_pass=0;
1612 GET_STRING_OR_DEFAULT("Boolean", val);
1614 again:
1615 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1616 || strcasecmp(val, "YES")==0) {
1618 data = 1;
1619 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1620 || strcasecmp(val, "NO")==0) {
1621 data = 0;
1622 } else {
1623 int i;
1624 if (sscanf(val, "%i", &i)==1) {
1625 if (i!=0)
1626 data = 1;
1627 else
1628 data = 0;
1629 } else {
1630 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1631 val, entry->key);
1632 if (second_pass==0) {
1633 val = WMGetFromPLString(entry->plvalue);
1634 second_pass = 1;
1635 wwarning(_("using default \"%s\" instead"), val);
1636 goto again;
1638 return False;
1642 if (ret)
1643 *ret = &data;
1644 if (addr)
1645 *(char*)addr = data;
1647 return True;
1651 static int
1652 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1653 void **ret)
1655 static int data;
1656 char *val;
1659 GET_STRING_OR_DEFAULT("Integer", val);
1661 if (sscanf(val, "%i", &data)!=1) {
1662 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1663 val, entry->key);
1664 val = WMGetFromPLString(entry->plvalue);
1665 wwarning(_("using default \"%s\" instead"), val);
1666 if (sscanf(val, "%i", &data)!=1) {
1667 return False;
1671 if (ret)
1672 *ret = &data;
1673 if (addr)
1674 *(int*)addr = data;
1676 return True;
1680 static int
1681 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1682 void **ret)
1684 static WCoord data;
1685 char *val_x, *val_y;
1686 int nelem, changed=0;
1687 WMPropList *elem_x, *elem_y;
1689 again:
1690 if (!WMIsPLArray(value)) {
1691 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1692 entry->key, "Coordinate");
1693 if (changed==0) {
1694 value = entry->plvalue;
1695 changed = 1;
1696 wwarning(_("using default \"%s\" instead"), entry->default_value);
1697 goto again;
1699 return False;
1702 nelem = WMGetPropListItemCount(value);
1703 if (nelem != 2) {
1704 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1705 entry->key);
1706 if (changed==0) {
1707 value = entry->plvalue;
1708 changed = 1;
1709 wwarning(_("using default \"%s\" instead"), entry->default_value);
1710 goto again;
1712 return False;
1715 elem_x = WMGetFromPLArray(value, 0);
1716 elem_y = WMGetFromPLArray(value, 1);
1718 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1719 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1720 entry->key);
1721 if (changed==0) {
1722 value = entry->plvalue;
1723 changed = 1;
1724 wwarning(_("using default \"%s\" instead"), entry->default_value);
1725 goto again;
1727 return False;
1730 val_x = WMGetFromPLString(elem_x);
1731 val_y = WMGetFromPLString(elem_y);
1733 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1734 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1735 if (changed==0) {
1736 value = entry->plvalue;
1737 changed = 1;
1738 wwarning(_("using default \"%s\" instead"), entry->default_value);
1739 goto again;
1741 return False;
1744 if (data.x < 0)
1745 data.x = 0;
1746 else if (data.x > scr->scr_width/3)
1747 data.x = scr->scr_width/3;
1748 if (data.y < 0)
1749 data.y = 0;
1750 else if (data.y > scr->scr_height/3)
1751 data.y = scr->scr_height/3;
1753 if (ret)
1754 *ret = &data;
1755 if (addr)
1756 *(WCoord*)addr = data;
1758 return True;
1762 static int
1763 getPropList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1764 void **ret)
1766 WMRetainPropList(value);
1768 *ret= value;
1770 return True;
1773 #if 0
1774 /* This function is not used at the moment. */
1775 static int
1776 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1777 void **ret)
1779 static char *data;
1781 GET_STRING_OR_DEFAULT("String", data);
1783 if (!data) {
1784 data = WMGetFromPLString(entry->plvalue);
1785 if (!data)
1786 return False;
1789 if (ret)
1790 *ret = &data;
1791 if (addr)
1792 *(char**)addr = wstrdup(data);
1794 return True;
1796 #endif
1799 static int
1800 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1801 void **ret)
1803 static char *data;
1804 int i, count, len;
1805 char *ptr;
1806 WMPropList *d;
1807 int changed=0;
1809 again:
1810 if (!WMIsPLArray(value)) {
1811 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1812 entry->key, "an array of paths");
1813 if (changed==0) {
1814 value = entry->plvalue;
1815 changed = 1;
1816 wwarning(_("using default \"%s\" instead"), entry->default_value);
1817 goto again;
1819 return False;
1822 i = 0;
1823 count = WMGetPropListItemCount(value);
1824 if (count < 1) {
1825 if (changed==0) {
1826 value = entry->plvalue;
1827 changed = 1;
1828 wwarning(_("using default \"%s\" instead"), entry->default_value);
1829 goto again;
1831 return False;
1834 len = 0;
1835 for (i=0; i<count; i++) {
1836 d = WMGetFromPLArray(value, i);
1837 if (!d || !WMIsPLString(d)) {
1838 count = i;
1839 break;
1841 len += strlen(WMGetFromPLString(d))+1;
1844 ptr = data = wmalloc(len+1);
1846 for (i=0; i<count; i++) {
1847 d = WMGetFromPLArray(value, i);
1848 if (!d || !WMIsPLString(d)) {
1849 break;
1851 strcpy(ptr, WMGetFromPLString(d));
1852 ptr += strlen(WMGetFromPLString(d));
1853 *ptr = ':';
1854 ptr++;
1856 ptr--; *(ptr--) = 0;
1858 if (*(char**)addr!=NULL) {
1859 wfree(*(char**)addr);
1861 *(char**)addr = data;
1863 return True;
1867 static int
1868 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1869 void **ret)
1871 static signed char data;
1873 data = string2index(entry->plkey, value, entry->default_value,
1874 (WOptionEnumeration*)entry->extra_data);
1875 if (data < 0)
1876 return False;
1878 if (ret)
1879 *ret = &data;
1880 if (addr)
1881 *(signed char*)addr = data;
1883 return True;
1889 * (solid <color>)
1890 * (hgradient <color> <color>)
1891 * (vgradient <color> <color>)
1892 * (dgradient <color> <color>)
1893 * (mhgradient <color> <color> ...)
1894 * (mvgradient <color> <color> ...)
1895 * (mdgradient <color> <color> ...)
1896 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1897 * (tpixmap <file> <color>)
1898 * (spixmap <file> <color>)
1899 * (cpixmap <file> <color>)
1900 * (thgradient <file> <opaqueness> <color> <color>)
1901 * (tvgradient <file> <opaqueness> <color> <color>)
1902 * (tdgradient <file> <opaqueness> <color> <color>)
1903 * (function <lib> <function> ...)
1906 static WTexture*
1907 parse_texture(WScreen *scr, WMPropList *pl)
1909 WMPropList *elem;
1910 char *val;
1911 int nelem;
1912 WTexture *texture=NULL;
1914 nelem = WMGetPropListItemCount(pl);
1915 if (nelem < 1)
1916 return NULL;
1919 elem = WMGetFromPLArray(pl, 0);
1920 if (!elem || !WMIsPLString(elem))
1921 return NULL;
1922 val = WMGetFromPLString(elem);
1925 if (strcasecmp(val, "solid")==0) {
1926 XColor color;
1928 if (nelem != 2)
1929 return NULL;
1931 /* get color */
1933 elem = WMGetFromPLArray(pl, 1);
1934 if (!elem || !WMIsPLString(elem))
1935 return NULL;
1936 val = WMGetFromPLString(elem);
1938 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1939 wwarning(_("\"%s\" is not a valid color name"), val);
1940 return NULL;
1943 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1944 } else if (strcasecmp(val, "dgradient")==0
1945 || strcasecmp(val, "vgradient")==0
1946 || strcasecmp(val, "hgradient")==0) {
1947 RColor color1, color2;
1948 XColor xcolor;
1949 int type;
1951 if (nelem != 3) {
1952 wwarning(_("bad number of arguments in gradient specification"));
1953 return NULL;
1956 if (val[0]=='d' || val[0]=='D')
1957 type = WTEX_DGRADIENT;
1958 else if (val[0]=='h' || val[0]=='H')
1959 type = WTEX_HGRADIENT;
1960 else
1961 type = WTEX_VGRADIENT;
1964 /* get from color */
1965 elem = WMGetFromPLArray(pl, 1);
1966 if (!elem || !WMIsPLString(elem))
1967 return NULL;
1968 val = WMGetFromPLString(elem);
1970 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1971 wwarning(_("\"%s\" is not a valid color name"), val);
1972 return NULL;
1974 color1.alpha = 255;
1975 color1.red = xcolor.red >> 8;
1976 color1.green = xcolor.green >> 8;
1977 color1.blue = xcolor.blue >> 8;
1979 /* get to color */
1980 elem = WMGetFromPLArray(pl, 2);
1981 if (!elem || !WMIsPLString(elem)) {
1982 return NULL;
1984 val = WMGetFromPLString(elem);
1986 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1987 wwarning(_("\"%s\" is not a valid color name"), val);
1988 return NULL;
1990 color2.alpha = 255;
1991 color2.red = xcolor.red >> 8;
1992 color2.green = xcolor.green >> 8;
1993 color2.blue = xcolor.blue >> 8;
1995 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1997 } else if (strcasecmp(val, "igradient")==0) {
1998 RColor colors1[2], colors2[2];
1999 int th1, th2;
2000 XColor xcolor;
2001 int i;
2003 if (nelem != 7) {
2004 wwarning(_("bad number of arguments in gradient specification"));
2005 return NULL;
2008 /* get from color */
2009 for (i = 0; i < 2; i++) {
2010 elem = WMGetFromPLArray(pl, 1+i);
2011 if (!elem || !WMIsPLString(elem))
2012 return NULL;
2013 val = WMGetFromPLString(elem);
2015 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2016 wwarning(_("\"%s\" is not a valid color name"), val);
2017 return NULL;
2019 colors1[i].alpha = 255;
2020 colors1[i].red = xcolor.red >> 8;
2021 colors1[i].green = xcolor.green >> 8;
2022 colors1[i].blue = xcolor.blue >> 8;
2024 elem = WMGetFromPLArray(pl, 3);
2025 if (!elem || !WMIsPLString(elem))
2026 return NULL;
2027 val = WMGetFromPLString(elem);
2028 th1 = atoi(val);
2031 /* get from color */
2032 for (i = 0; i < 2; i++) {
2033 elem = WMGetFromPLArray(pl, 4+i);
2034 if (!elem || !WMIsPLString(elem))
2035 return NULL;
2036 val = WMGetFromPLString(elem);
2038 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2039 wwarning(_("\"%s\" is not a valid color name"), val);
2040 return NULL;
2042 colors2[i].alpha = 255;
2043 colors2[i].red = xcolor.red >> 8;
2044 colors2[i].green = xcolor.green >> 8;
2045 colors2[i].blue = xcolor.blue >> 8;
2047 elem = WMGetFromPLArray(pl, 6);
2048 if (!elem || !WMIsPLString(elem))
2049 return NULL;
2050 val = WMGetFromPLString(elem);
2051 th2 = atoi(val);
2053 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
2054 th2, colors2);
2056 } else if (strcasecmp(val, "mhgradient")==0
2057 || strcasecmp(val, "mvgradient")==0
2058 || strcasecmp(val, "mdgradient")==0) {
2059 XColor color;
2060 RColor **colors;
2061 int i, count;
2062 int type;
2064 if (nelem < 3) {
2065 wwarning(_("too few arguments in multicolor gradient specification"));
2066 return NULL;
2069 if (val[1]=='h' || val[1]=='H')
2070 type = WTEX_MHGRADIENT;
2071 else if (val[1]=='v' || val[1]=='V')
2072 type = WTEX_MVGRADIENT;
2073 else
2074 type = WTEX_MDGRADIENT;
2076 count = nelem-1;
2078 colors = wmalloc(sizeof(RColor*)*(count+1));
2080 for (i=0; i<count; i++) {
2081 elem = WMGetFromPLArray(pl, i+1);
2082 if (!elem || !WMIsPLString(elem)) {
2083 for (--i; i>=0; --i) {
2084 wfree(colors[i]);
2086 wfree(colors);
2087 return NULL;
2089 val = WMGetFromPLString(elem);
2091 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2092 wwarning(_("\"%s\" is not a valid color name"), val);
2093 for (--i; i>=0; --i) {
2094 wfree(colors[i]);
2096 wfree(colors);
2097 return NULL;
2098 } else {
2099 colors[i] = wmalloc(sizeof(RColor));
2100 colors[i]->red = color.red >> 8;
2101 colors[i]->green = color.green >> 8;
2102 colors[i]->blue = color.blue >> 8;
2105 colors[i] = NULL;
2107 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
2108 } else if (strcasecmp(val, "spixmap")==0 ||
2109 strcasecmp(val, "cpixmap")==0 ||
2110 strcasecmp(val, "tpixmap")==0) {
2111 XColor color;
2112 int type;
2114 if (nelem != 3)
2115 return NULL;
2117 if (val[0] == 's' || val[0] == 'S')
2118 type = WTP_SCALE;
2119 else if (val[0] == 'c' || val[0] == 'C')
2120 type = WTP_CENTER;
2121 else
2122 type = WTP_TILE;
2124 /* get color */
2125 elem = WMGetFromPLArray(pl, 2);
2126 if (!elem || !WMIsPLString(elem)) {
2127 return NULL;
2129 val = WMGetFromPLString(elem);
2131 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2132 wwarning(_("\"%s\" is not a valid color name"), val);
2133 return NULL;
2136 /* file name */
2137 elem = WMGetFromPLArray(pl, 1);
2138 if (!elem || !WMIsPLString(elem))
2139 return NULL;
2140 val = WMGetFromPLString(elem);
2142 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2143 } else if (strcasecmp(val, "thgradient")==0
2144 || strcasecmp(val, "tvgradient")==0
2145 || strcasecmp(val, "tdgradient")==0) {
2146 RColor color1, color2;
2147 XColor xcolor;
2148 int opacity;
2149 int style;
2151 if (val[1]=='h' || val[1]=='H')
2152 style = WTEX_THGRADIENT;
2153 else if (val[1]=='v' || val[1]=='V')
2154 style = WTEX_TVGRADIENT;
2155 else
2156 style = WTEX_TDGRADIENT;
2158 if (nelem != 5) {
2159 wwarning(_("bad number of arguments in textured gradient specification"));
2160 return NULL;
2163 /* get from color */
2164 elem = WMGetFromPLArray(pl, 3);
2165 if (!elem || !WMIsPLString(elem))
2166 return NULL;
2167 val = WMGetFromPLString(elem);
2169 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2170 wwarning(_("\"%s\" is not a valid color name"), val);
2171 return NULL;
2173 color1.alpha = 255;
2174 color1.red = xcolor.red >> 8;
2175 color1.green = xcolor.green >> 8;
2176 color1.blue = xcolor.blue >> 8;
2178 /* get to color */
2179 elem = WMGetFromPLArray(pl, 4);
2180 if (!elem || !WMIsPLString(elem)) {
2181 return NULL;
2183 val = WMGetFromPLString(elem);
2185 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2186 wwarning(_("\"%s\" is not a valid color name"), val);
2187 return NULL;
2189 color2.alpha = 255;
2190 color2.red = xcolor.red >> 8;
2191 color2.green = xcolor.green >> 8;
2192 color2.blue = xcolor.blue >> 8;
2194 /* get opacity */
2195 elem = WMGetFromPLArray(pl, 2);
2196 if (!elem || !WMIsPLString(elem))
2197 opacity = 128;
2198 else
2199 val = WMGetFromPLString(elem);
2201 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2202 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2203 opacity = 128;
2206 /* get file name */
2207 elem = WMGetFromPLArray(pl, 1);
2208 if (!elem || !WMIsPLString(elem))
2209 return NULL;
2210 val = WMGetFromPLString(elem);
2212 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2213 val, opacity);
2215 #ifdef TEXTURE_PLUGIN
2216 else if (strcasecmp(val, "function")==0) {
2217 WTexFunction *function;
2218 void (*initFunc) (Display *, Colormap);
2219 char *lib, *func, **argv;
2220 int i, argc;
2222 if (nelem < 3)
2223 return NULL;
2225 /* get the library name */
2226 elem = WMGetFromPLArray(pl, 1);
2227 if (!elem || !WMIsPLString(elem)) {
2228 return NULL;
2230 lib = WMGetFromPLString(elem);
2232 /* get the function name */
2233 elem = WMGetFromPLArray(pl, 2);
2234 if (!elem || !WMIsPLString(elem)) {
2235 return NULL;
2237 func = WMGetFromPLString(elem);
2239 argc = nelem - 2;
2240 argv = (char **)wmalloc(argc * sizeof(char *));
2242 /* get the parameters */
2243 argv[0] = wstrdup(func);
2244 for (i = 0; i < argc - 1; i++) {
2245 elem = WMGetFromPLArray(pl, 3 + i);
2246 if (!elem || !WMIsPLString(elem)) {
2247 wfree(argv);
2249 return NULL;
2251 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2254 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2256 #ifdef HAVE_DLFCN_H
2257 if (function) {
2258 initFunc = dlsym(function->handle, "initWindowMaker");
2259 if (initFunc) {
2260 initFunc(dpy, scr->w_colormap);
2261 } else {
2262 wwarning(_("could not initialize library %s"), lib);
2264 } else {
2265 wwarning(_("could not find function %s::%s"), lib, func);
2267 #endif /* HAVE_DLFCN_H */
2268 texture = (WTexture*)function;
2270 #endif /* TEXTURE_PLUGIN */
2271 else {
2272 wwarning(_("invalid texture type %s"), val);
2273 return NULL;
2275 return texture;
2280 static int
2281 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2282 void **ret)
2284 static WTexture *texture;
2285 int changed=0;
2287 again:
2288 if (!WMIsPLArray(value)) {
2289 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2290 entry->key, "Texture");
2291 if (changed==0) {
2292 value = entry->plvalue;
2293 changed = 1;
2294 wwarning(_("using default \"%s\" instead"), entry->default_value);
2295 goto again;
2297 return False;
2300 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2301 WMPropList *pl;
2303 pl = WMGetFromPLArray(value, 0);
2304 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2305 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2306 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2307 entry->key, "Solid Texture");
2309 value = entry->plvalue;
2310 changed = 1;
2311 wwarning(_("using default \"%s\" instead"), entry->default_value);
2312 goto again;
2316 texture = parse_texture(scr, value);
2318 if (!texture) {
2319 wwarning(_("Error in texture specification for key \"%s\""),
2320 entry->key);
2321 if (changed==0) {
2322 value = entry->plvalue;
2323 changed = 1;
2324 wwarning(_("using default \"%s\" instead"), entry->default_value);
2325 goto again;
2327 return False;
2330 if (ret)
2331 *ret = &texture;
2333 if (addr)
2334 *(WTexture**)addr = texture;
2336 return True;
2340 static int
2341 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2342 void *addr, void **ret)
2344 WMPropList *elem;
2345 int changed = 0;
2346 char *val;
2347 int nelem;
2349 again:
2350 if (!WMIsPLArray(value)) {
2351 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2352 "WorkspaceBack", "Texture or None");
2353 if (changed==0) {
2354 value = entry->plvalue;
2355 changed = 1;
2356 wwarning(_("using default \"%s\" instead"), entry->default_value);
2357 goto again;
2359 return False;
2362 /* only do basic error checking and verify for None texture */
2364 nelem = WMGetPropListItemCount(value);
2365 if (nelem > 0) {
2366 elem = WMGetFromPLArray(value, 0);
2367 if (!elem || !WMIsPLString(elem)) {
2368 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2369 if (changed==0) {
2370 value = entry->plvalue;
2371 changed = 1;
2372 wwarning(_("using default \"%s\" instead"), entry->default_value);
2373 goto again;
2375 return False;
2377 val = WMGetFromPLString(elem);
2379 if (strcasecmp(val, "None")==0)
2380 return True;
2382 *ret = WMRetainPropList(value);
2384 return True;
2388 static int
2389 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2390 void *addr, void **ret)
2392 WMPropList *elem;
2393 int nelem;
2394 int changed = 0;
2396 again:
2397 if (!WMIsPLArray(value)) {
2398 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2399 "WorkspaceSpecificBack", "an array of textures");
2400 if (changed==0) {
2401 value = entry->plvalue;
2402 changed = 1;
2403 wwarning(_("using default \"%s\" instead"), entry->default_value);
2404 goto again;
2406 return False;
2409 /* only do basic error checking and verify for None texture */
2411 nelem = WMGetPropListItemCount(value);
2412 if (nelem > 0) {
2413 while (nelem--) {
2414 elem = WMGetFromPLArray(value, nelem);
2415 if (!elem || !WMIsPLArray(elem)) {
2416 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2417 nelem);
2422 *ret = WMRetainPropList(value);
2424 #ifdef notworking
2426 * Kluge to force wmsetbg helper to set the default background.
2427 * If the WorkspaceSpecificBack is changed once wmaker has started,
2428 * the WorkspaceBack won't be sent to the helper, unless the user
2429 * changes it's value too. So, we must force this by removing the
2430 * value from the defaults DB.
2432 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2433 WMPropList *key = WMCreatePLString("WorkspaceBack");
2435 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2437 WMReleasePropList(key);
2439 #endif
2440 return True;
2444 static int
2445 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2446 void **ret)
2448 static WMFont *font;
2449 char *val;
2451 GET_STRING_OR_DEFAULT("Font", val);
2453 font = WMCreateFont(scr->wmscreen, val);
2454 if (!font)
2455 font = WMCreateFont(scr->wmscreen, "fixed");
2457 if (!font) {
2458 wfatal(_("could not load any usable font!!!"));
2459 exit(1);
2462 if (ret)
2463 *ret = font;
2465 /* can't assign font value outside update function */
2466 wassertrv(addr == NULL, True);
2468 return True;
2472 static int
2473 getColor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2474 void **ret)
2476 static XColor color;
2477 char *val;
2478 int second_pass=0;
2480 GET_STRING_OR_DEFAULT("Color", val);
2483 again:
2484 if (!wGetColor(scr, val, &color)) {
2485 wwarning(_("could not get color for key \"%s\""),
2486 entry->key);
2487 if (second_pass==0) {
2488 val = WMGetFromPLString(entry->plvalue);
2489 second_pass = 1;
2490 wwarning(_("using default \"%s\" instead"), val);
2491 goto again;
2493 return False;
2496 if (ret)
2497 *ret = &color;
2499 assert(addr==NULL);
2501 if (addr)
2502 *(unsigned long*)addr = pixel;
2505 return True;
2510 static int
2511 getKeybind(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2512 void **ret)
2514 static WShortKey shortcut;
2515 KeySym ksym;
2516 char *val;
2517 char *k;
2518 char buf[MAX_SHORTCUT_LENGTH], *b;
2521 GET_STRING_OR_DEFAULT("Key spec", val);
2523 if (!val || strcasecmp(val, "NONE")==0) {
2524 shortcut.keycode = 0;
2525 shortcut.modifier = 0;
2526 if (ret)
2527 *ret = &shortcut;
2528 return True;
2531 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2533 b = (char*)buf;
2535 /* get modifiers */
2536 shortcut.modifier = 0;
2537 while ((k = strchr(b, '+'))!=NULL) {
2538 int mod;
2540 *k = 0;
2541 mod = wXModifierFromKey(b);
2542 if (mod<0) {
2543 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2544 return False;
2546 shortcut.modifier |= mod;
2548 b = k+1;
2551 /* get key */
2552 ksym = XStringToKeysym(b);
2554 if (ksym==NoSymbol) {
2555 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2556 val);
2557 return False;
2560 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2561 if (shortcut.keycode==0) {
2562 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2563 return False;
2566 if (ret)
2567 *ret = &shortcut;
2569 return True;
2573 static int
2574 getModMask(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2575 void **ret)
2577 static unsigned int mask;
2578 char *str;
2580 GET_STRING_OR_DEFAULT("Modifier Key", str);
2582 if (!str)
2583 return False;
2585 mask = wXModifierFromKey(str);
2586 if (mask < 0) {
2587 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2588 mask = 0;
2589 return False;
2592 if (addr)
2593 *(unsigned int*)addr = mask;
2595 if (ret)
2596 *ret = &mask;
2598 return True;
2602 #ifdef NEWSTUFF
2603 static int
2604 getRImages(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2605 void *addr, void **ret)
2607 unsigned int mask;
2608 char *str;
2609 RImage *image;
2610 int i, n;
2611 int w, h;
2613 GET_STRING_OR_DEFAULT("Image File Path", str);
2614 if (!str)
2615 return False;
2617 image = RLoadImage(scr->rcontext, str, 0);
2618 if (!image) {
2619 wwarning(_("could not load image in option %s: %s"), entry->key,
2620 RMessageForError(RErrorCode));
2621 return False;
2624 if (*(RImage**)addr) {
2625 RReleaseImage(*(RImage**)addr);
2627 if (addr)
2628 *(RImage**)addr = image;
2630 assert(ret == NULL);
2632 if (ret)
2633 *(RImage**)ret = image;
2636 return True;
2638 #endif
2640 # include <X11/cursorfont.h>
2641 typedef struct
2643 char *name;
2644 int id;
2645 } WCursorLookup;
2647 #define CURSOR_ID_NONE (XC_num_glyphs)
2649 static WCursorLookup cursor_table[] =
2651 { "X_cursor", XC_X_cursor },
2652 { "arrow", XC_arrow },
2653 { "based_arrow_down", XC_based_arrow_down },
2654 { "based_arrow_up", XC_based_arrow_up },
2655 { "boat", XC_boat },
2656 { "bogosity", XC_bogosity },
2657 { "bottom_left_corner", XC_bottom_left_corner },
2658 { "bottom_right_corner", XC_bottom_right_corner },
2659 { "bottom_side", XC_bottom_side },
2660 { "bottom_tee", XC_bottom_tee },
2661 { "box_spiral", XC_box_spiral },
2662 { "center_ptr", XC_center_ptr },
2663 { "circle", XC_circle },
2664 { "clock", XC_clock },
2665 { "coffee_mug", XC_coffee_mug },
2666 { "cross", XC_cross },
2667 { "cross_reverse", XC_cross_reverse },
2668 { "crosshair", XC_crosshair },
2669 { "diamond_cross", XC_diamond_cross },
2670 { "dot", XC_dot },
2671 { "dotbox", XC_dotbox },
2672 { "double_arrow", XC_double_arrow },
2673 { "draft_large", XC_draft_large },
2674 { "draft_small", XC_draft_small },
2675 { "draped_box", XC_draped_box },
2676 { "exchange", XC_exchange },
2677 { "fleur", XC_fleur },
2678 { "gobbler", XC_gobbler },
2679 { "gumby", XC_gumby },
2680 { "hand1", XC_hand1 },
2681 { "hand2", XC_hand2 },
2682 { "heart", XC_heart },
2683 { "icon", XC_icon },
2684 { "iron_cross", XC_iron_cross },
2685 { "left_ptr", XC_left_ptr },
2686 { "left_side", XC_left_side },
2687 { "left_tee", XC_left_tee },
2688 { "leftbutton", XC_leftbutton },
2689 { "ll_angle", XC_ll_angle },
2690 { "lr_angle", XC_lr_angle },
2691 { "man", XC_man },
2692 { "middlebutton", XC_middlebutton },
2693 { "mouse", XC_mouse },
2694 { "pencil", XC_pencil },
2695 { "pirate", XC_pirate },
2696 { "plus", XC_plus },
2697 { "question_arrow", XC_question_arrow },
2698 { "right_ptr", XC_right_ptr },
2699 { "right_side", XC_right_side },
2700 { "right_tee", XC_right_tee },
2701 { "rightbutton", XC_rightbutton },
2702 { "rtl_logo", XC_rtl_logo },
2703 { "sailboat", XC_sailboat },
2704 { "sb_down_arrow", XC_sb_down_arrow },
2705 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2706 { "sb_left_arrow", XC_sb_left_arrow },
2707 { "sb_right_arrow", XC_sb_right_arrow },
2708 { "sb_up_arrow", XC_sb_up_arrow },
2709 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2710 { "shuttle", XC_shuttle },
2711 { "sizing", XC_sizing },
2712 { "spider", XC_spider },
2713 { "spraycan", XC_spraycan },
2714 { "star", XC_star },
2715 { "target", XC_target },
2716 { "tcross", XC_tcross },
2717 { "top_left_arrow", XC_top_left_arrow },
2718 { "top_left_corner", XC_top_left_corner },
2719 { "top_right_corner", XC_top_right_corner },
2720 { "top_side", XC_top_side },
2721 { "top_tee", XC_top_tee },
2722 { "trek", XC_trek },
2723 { "ul_angle", XC_ul_angle },
2724 { "umbrella", XC_umbrella },
2725 { "ur_angle", XC_ur_angle },
2726 { "watch", XC_watch },
2727 { "xterm", XC_xterm },
2728 { NULL, CURSOR_ID_NONE }
2731 static void
2732 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2734 switch(status) {
2735 case BitmapOpenFailed:
2736 wwarning(_("failed to open bitmap file \"%s\""), filename);
2737 break;
2738 case BitmapFileInvalid:
2739 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2740 break;
2741 case BitmapNoMemory:
2742 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2743 break;
2744 case BitmapSuccess:
2745 XFreePixmap(dpy, bitmap);
2746 break;
2751 * (none)
2752 * (builtin, <cursor_name>)
2753 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2755 static int
2756 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2758 WMPropList *elem;
2759 char *val;
2760 int nelem;
2761 int status = 0;
2763 nelem = WMGetPropListItemCount(pl);
2764 if (nelem < 1) {
2765 return(status);
2767 elem = WMGetFromPLArray(pl, 0);
2768 if (!elem || !WMIsPLString(elem)) {
2769 return(status);
2771 val = WMGetFromPLString(elem);
2773 if (0 == strcasecmp(val, "none")) {
2774 status = 1;
2775 *cursor = None;
2776 } else if (0 == strcasecmp(val, "builtin")) {
2777 int i;
2778 int cursor_id = CURSOR_ID_NONE;
2780 if (2 != nelem) {
2781 wwarning(_("bad number of arguments in cursor specification"));
2782 return(status);
2784 elem = WMGetFromPLArray(pl, 1);
2785 if (!elem || !WMIsPLString(elem)) {
2786 return(status);
2788 val = WMGetFromPLString(elem);
2790 for (i = 0; NULL != cursor_table[i].name; i++) {
2791 if (0 == strcasecmp(val, cursor_table[i].name)) {
2792 cursor_id = cursor_table[i].id;
2793 break;
2796 if (CURSOR_ID_NONE == cursor_id) {
2797 wwarning(_("unknown builtin cursor name \"%s\""), val);
2798 } else {
2799 *cursor = XCreateFontCursor(dpy, cursor_id);
2800 status = 1;
2802 } else if (0 == strcasecmp(val, "bitmap")) {
2803 char *bitmap_name;
2804 char *mask_name;
2805 int bitmap_status;
2806 int mask_status;
2807 Pixmap bitmap;
2808 Pixmap mask;
2809 unsigned int w, h;
2810 int x, y;
2811 XColor fg, bg;
2813 if (3 != nelem) {
2814 wwarning(_("bad number of arguments in cursor specification"));
2815 return(status);
2817 elem = WMGetFromPLArray(pl, 1);
2818 if (!elem || !WMIsPLString(elem)) {
2819 return(status);
2821 val = WMGetFromPLString(elem);
2822 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2823 if (!bitmap_name) {
2824 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2825 return(status);
2827 elem = WMGetFromPLArray(pl, 2);
2828 if (!elem || !WMIsPLString(elem)) {
2829 wfree(bitmap_name);
2830 return(status);
2832 val = WMGetFromPLString(elem);
2833 mask_name = FindImage(wPreferences.pixmap_path, val);
2834 if (!mask_name) {
2835 wfree(bitmap_name);
2836 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2837 return(status);
2839 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2840 &mask, &x, &y);
2841 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2842 &bitmap, &x, &y);
2843 if ((BitmapSuccess == bitmap_status) &&
2844 (BitmapSuccess == mask_status)) {
2845 fg.pixel = scr->black_pixel;
2846 bg.pixel = scr->white_pixel;
2847 XQueryColor(dpy, scr->w_colormap, &fg);
2848 XQueryColor(dpy, scr->w_colormap, &bg);
2849 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2850 status = 1;
2852 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2853 check_bitmap_status(mask_status, mask_name, mask);
2854 wfree(bitmap_name);
2855 wfree(mask_name);
2857 return(status);
2861 static int
2862 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2863 void **ret)
2865 static Cursor cursor;
2866 int status;
2867 int changed = 0;
2869 again:
2870 if (!WMIsPLArray(value)) {
2871 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2872 entry->key, "cursor specification");
2873 if (!changed) {
2874 value = entry->plvalue;
2875 changed = 1;
2876 wwarning(_("using default \"%s\" instead"), entry->default_value);
2877 goto again;
2879 return(False);
2881 status = parse_cursor(scr, value, &cursor);
2882 if (!status) {
2883 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2884 if (!changed) {
2885 value = entry->plvalue;
2886 changed = 1;
2887 wwarning(_("using default \"%s\" instead"), entry->default_value);
2888 goto again;
2890 return(False);
2892 if (ret) {
2893 *ret = &cursor;
2895 if (addr) {
2896 *(Cursor *)addr = cursor;
2898 return(True);
2900 #undef CURSOR_ID_NONE
2903 /* ---------------- value setting functions --------------- */
2904 static int
2905 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2907 return REFRESH_WINDOW_TITLE_COLOR;
2910 static int
2911 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2913 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2916 static int
2917 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2919 switch (which) {
2920 case WM_DOCK:
2921 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2922 break;
2923 case WM_CLIP:
2924 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2925 break;
2926 default:
2927 break;
2929 return 0;
2933 static int
2934 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2936 if (scr->workspaces) {
2937 wWorkspaceForceChange(scr, scr->current_workspace);
2938 wArrangeIcons(scr, False);
2940 return 0;
2943 #if not_used
2944 static int
2945 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2947 if (*value <= 0)
2948 *(int*)foo = 1;
2950 return 0;
2952 #endif
2956 static int
2957 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2959 Pixmap pixmap;
2960 RImage *img;
2961 int reset = 0;
2963 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2964 wPreferences.icon_size,
2965 ((*texture)->any.type & WREL_BORDER_MASK)
2966 ? WREL_ICON : WREL_FLAT);
2967 if (!img) {
2968 wwarning(_("could not render texture for icon background"));
2969 if (!entry->addr)
2970 wTextureDestroy(scr, *texture);
2971 return 0;
2973 RConvertImage(scr->rcontext, img, &pixmap);
2975 if (scr->icon_tile) {
2976 reset = 1;
2977 RReleaseImage(scr->icon_tile);
2978 XFreePixmap(dpy, scr->icon_tile_pixmap);
2981 scr->icon_tile = img;
2984 /* put the icon in the noticeboard hint */
2985 PropSetIconTileHint(scr, img);
2988 if (!wPreferences.flags.noclip) {
2989 if (scr->clip_tile) {
2990 RReleaseImage(scr->clip_tile);
2992 scr->clip_tile = wClipMakeTile(scr, img);
2995 scr->icon_tile_pixmap = pixmap;
2997 if (scr->def_icon_pixmap) {
2998 XFreePixmap(dpy, scr->def_icon_pixmap);
2999 scr->def_icon_pixmap = None;
3001 if (scr->def_ticon_pixmap) {
3002 XFreePixmap(dpy, scr->def_ticon_pixmap);
3003 scr->def_ticon_pixmap = None;
3006 if (scr->icon_back_texture) {
3007 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
3009 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
3011 if (scr->clip_balloon)
3012 XSetWindowBackground(dpy, scr->clip_balloon,
3013 (*texture)->any.color.pixel);
3016 * Free the texture as nobody else will use it, nor refer to it.
3018 if (!entry->addr)
3019 wTextureDestroy(scr, *texture);
3021 return (reset ? REFRESH_ICON_TILE : 0);
3026 static int
3027 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3029 if (scr->title_font) {
3030 WMReleaseFont(scr->title_font);
3032 scr->title_font = font;
3034 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
3038 static int
3039 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3041 if (scr->menu_title_font) {
3042 WMReleaseFont(scr->menu_title_font);
3045 scr->menu_title_font = font;
3047 return REFRESH_MENU_TITLE_FONT;
3051 static int
3052 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3054 if (scr->menu_entry_font) {
3055 WMReleaseFont(scr->menu_entry_font);
3057 scr->menu_entry_font = font;
3059 return REFRESH_MENU_FONT;
3064 static int
3065 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3067 if (scr->icon_title_font) {
3068 WMReleaseFont(scr->icon_title_font);
3071 scr->icon_title_font = font;
3073 return REFRESH_ICON_FONT;
3077 static int
3078 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3080 if (scr->clip_title_font) {
3081 WMReleaseFont(scr->clip_title_font);
3084 scr->clip_title_font = font;
3086 return REFRESH_ICON_FONT;
3090 static int
3091 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3093 if (scr->workspace_name_font) {
3094 WMReleaseFont(scr->workspace_name_font);
3097 scr->workspace_name_font = font;
3099 return 0;
3103 static int
3104 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3106 if (scr->select_color)
3107 WMReleaseColor(scr->select_color);
3109 scr->select_color =
3110 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3111 color->blue, True);
3113 wFreeColor(scr, color->pixel);
3115 return REFRESH_MENU_COLOR;
3119 static int
3120 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3122 if (scr->select_text_color)
3123 WMReleaseColor(scr->select_text_color);
3125 scr->select_text_color =
3126 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3127 color->blue, True);
3129 wFreeColor(scr, color->pixel);
3131 return REFRESH_MENU_COLOR;
3135 static int
3136 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3138 if (scr->clip_title_color[index])
3139 WMReleaseColor(scr->clip_title_color[index]);
3140 scr->clip_title_color[index] = WMCreateRGBColor(scr->wmscreen, color->red,
3141 color->green, color->blue,
3142 True);
3143 #ifdef GRADIENT_CLIP_ARROW
3144 if (index == CLIP_NORMAL) {
3145 RImage *image;
3146 RColor color1, color2;
3147 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3148 int as = pt - 15; /* 15 = 5+5+5 */
3150 FREE_PIXMAP(scr->clip_arrow_gradient);
3152 color1.red = (color->red >> 8)*6/10;
3153 color1.green = (color->green >> 8)*6/10;
3154 color1.blue = (color->blue >> 8)*6/10;
3156 color2.red = WMIN((color->red >> 8)*20/10, 255);
3157 color2.green = WMIN((color->green >> 8)*20/10, 255);
3158 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3160 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3161 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3162 RReleaseImage(image);
3164 #endif /* GRADIENT_CLIP_ARROW */
3166 wFreeColor(scr, color->pixel);
3168 return REFRESH_ICON_TITLE_COLOR;
3172 static int
3173 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3175 if (scr->window_title_color[index])
3176 WMReleaseColor(scr->window_title_color[index]);
3178 scr->window_title_color[index] =
3179 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue,
3180 True);
3182 wFreeColor(scr, color->pixel);
3184 return REFRESH_WINDOW_TITLE_COLOR;
3188 static int
3189 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3191 if (scr->menu_title_color[0])
3192 WMReleaseColor(scr->menu_title_color[0]);
3194 scr->menu_title_color[0] =
3195 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3196 color->blue, True);
3198 wFreeColor(scr, color->pixel);
3200 return REFRESH_MENU_TITLE_COLOR;
3204 static int
3205 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3207 if (scr->mtext_color)
3208 WMReleaseColor(scr->mtext_color);
3210 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3211 color->green, color->blue, True);
3213 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3214 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3215 } else {
3216 WMSetColorAlpha(scr->dtext_color, 0xffff);
3219 wFreeColor(scr, color->pixel);
3221 return REFRESH_MENU_COLOR;
3225 static int
3226 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3228 if (scr->dtext_color)
3229 WMReleaseColor(scr->dtext_color);
3231 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3232 color->green, color->blue, True);
3234 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3235 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3236 } else {
3237 WMSetColorAlpha(scr->dtext_color, 0xffff);
3240 wFreeColor(scr, color->pixel);
3242 return REFRESH_MENU_COLOR;
3246 static int
3247 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3249 if (scr->icon_title_color)
3250 WMReleaseColor(scr->icon_title_color);
3251 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red,
3252 color->green, color->blue,
3253 True);
3255 wFreeColor(scr, color->pixel);
3257 return REFRESH_ICON_TITLE_COLOR;
3261 static int
3262 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3264 if (scr->icon_title_texture) {
3265 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3267 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3269 return REFRESH_ICON_TITLE_BACK;
3273 static void
3274 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3276 close(scr->helper_fd);
3277 scr->helper_fd = 0;
3278 scr->helper_pid = 0;
3279 scr->flags.backimage_helper_launched = 0;
3283 static int
3284 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3285 void *bar)
3287 WMPropList *val;
3288 char *str;
3289 int i;
3291 if (scr->flags.backimage_helper_launched) {
3292 if (WMGetPropListItemCount(value)==0) {
3293 SendHelperMessage(scr, 'C', 0, NULL);
3294 SendHelperMessage(scr, 'K', 0, NULL);
3296 WMReleasePropList(value);
3297 return 0;
3299 } else {
3300 pid_t pid;
3301 int filedes[2];
3303 if (WMGetPropListItemCount(value) == 0)
3304 return 0;
3306 if (pipe(filedes) < 0) {
3307 wsyserror("pipe() failed:can't set workspace specific background image");
3309 WMReleasePropList(value);
3310 return 0;
3313 pid = fork();
3314 if (pid < 0) {
3315 wsyserror("fork() failed:can't set workspace specific background image");
3316 if (close(filedes[0]) < 0)
3317 wsyserror("could not close pipe");
3318 if (close(filedes[1]) < 0)
3319 wsyserror("could not close pipe");
3321 } else if (pid == 0) {
3322 char *dither;
3324 SetupEnvironment(scr);
3326 if (close(0) < 0)
3327 wsyserror("could not close pipe");
3328 if (dup(filedes[0]) < 0) {
3329 wsyserror("dup() failed:can't set workspace specific background image");
3331 dither = wPreferences.no_dithering ? "-m" : "-d";
3332 if (wPreferences.smooth_workspace_back)
3333 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3334 else
3335 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3336 wsyserror("could not execute wmsetbg");
3337 exit(1);
3338 } else {
3340 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3341 wsyserror("error setting close-on-exec flag");
3343 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3344 wsyserror("error setting close-on-exec flag");
3347 scr->helper_fd = filedes[1];
3348 scr->helper_pid = pid;
3349 scr->flags.backimage_helper_launched = 1;
3351 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3353 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3358 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3359 val = WMGetFromPLArray(value, i);
3360 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3361 str = WMGetPropListDescription(val, False);
3363 SendHelperMessage(scr, 'S', i+1, str);
3365 wfree(str);
3366 } else {
3367 SendHelperMessage(scr, 'U', i+1, NULL);
3370 sleep(1);
3372 WMReleasePropList(value);
3373 return 0;
3377 static int
3378 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3379 void *bar)
3381 if (scr->flags.backimage_helper_launched) {
3382 char *str;
3384 if (WMGetPropListItemCount(value)==0) {
3385 SendHelperMessage(scr, 'U', 0, NULL);
3386 } else {
3387 /* set the default workspace background to this one */
3388 str = WMGetPropListDescription(value, False);
3389 if (str) {
3390 SendHelperMessage(scr, 'S', 0, str);
3391 wfree(str);
3392 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3393 } else {
3394 SendHelperMessage(scr, 'U', 0, NULL);
3397 } else if (WMGetPropListItemCount(value) > 0) {
3398 char *command;
3399 char *text;
3400 char *dither;
3401 int len;
3403 SetupEnvironment(scr);
3404 text = WMGetPropListDescription(value, False);
3405 len = strlen(text)+40;
3406 command = wmalloc(len);
3407 dither = wPreferences.no_dithering ? "-m" : "-d";
3408 if (wPreferences.smooth_workspace_back)
3409 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3410 else
3411 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3412 wfree(text);
3413 system(command);
3414 wfree(command);
3416 WMReleasePropList(value);
3418 return 0;
3422 #ifdef VIRTUAL_DESKTOP
3423 static int
3424 setVirtualDeskEnable(WScreen *scr, WDefaultEntry *entry, void *foo, void *bar)
3426 wWorkspaceUpdateEdge(scr);
3427 return 0;
3429 #endif
3432 static int
3433 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3435 if (scr->widget_texture) {
3436 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3438 scr->widget_texture = *(WTexSolid**)texture;
3440 return 0;
3444 static int
3445 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3447 if (scr->window_title_texture[WS_FOCUSED]) {
3448 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3450 scr->window_title_texture[WS_FOCUSED] = *texture;
3452 return REFRESH_WINDOW_TEXTURES;
3456 static int
3457 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3459 if (scr->window_title_texture[WS_PFOCUSED]) {
3460 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3462 scr->window_title_texture[WS_PFOCUSED] = *texture;
3464 return REFRESH_WINDOW_TEXTURES;
3468 static int
3469 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3471 if (scr->window_title_texture[WS_UNFOCUSED]) {
3472 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3474 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3476 return REFRESH_WINDOW_TEXTURES;
3480 static int
3481 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3483 if (scr->resizebar_texture[0]) {
3484 wTextureDestroy(scr, scr->resizebar_texture[0]);
3486 scr->resizebar_texture[0] = *texture;
3488 return REFRESH_WINDOW_TEXTURES;
3492 static int
3493 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3495 if (scr->menu_title_texture[0]) {
3496 wTextureDestroy(scr, scr->menu_title_texture[0]);
3498 scr->menu_title_texture[0] = *texture;
3500 return REFRESH_MENU_TITLE_TEXTURE;
3504 static int
3505 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3507 if (scr->menu_item_texture) {
3508 wTextureDestroy(scr, scr->menu_item_texture);
3509 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3511 scr->menu_item_texture = *texture;
3513 scr->menu_item_auxtexture
3514 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3516 return REFRESH_MENU_TEXTURE;
3520 static int
3521 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3523 WWindow *wwin;
3524 wKeyBindings[index] = *shortcut;
3526 wwin = scr->focused_window;
3528 while (wwin!=NULL) {
3529 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3531 if (!WFLAGP(wwin, no_bind_keys)) {
3532 wWindowSetKeyGrabs(wwin);
3534 wwin = wwin->prev;
3537 return 0;
3541 static int
3542 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3544 wScreenUpdateUsableArea(scr);
3545 wArrangeIcons(scr, True);
3547 return 0;
3551 static int
3552 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3554 wScreenUpdateUsableArea(scr);
3556 return 0;
3560 static int
3561 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3563 return REFRESH_MENU_TEXTURE;
3567 static RImage *chopOffImage(RImage *image, int x, int y, int w, int h)
3569 RImage *img= RCreateImage(w, h, image->format == RRGBAFormat);
3571 RCopyArea(img, image, x, y, w, h, 0, 0);
3573 return img;
3576 static int
3577 setSwPOptions(WScreen *scr, WDefaultEntry *entry, WMPropList *array, void *foo)
3579 char *path;
3580 RImage *bgimage;
3581 int cwidth, cheight;
3582 WPreferences *prefs= (WPreferences*)foo;
3584 if (!WMIsPLArray(array) || WMGetPropListItemCount(array)==0) {
3585 if (prefs->swtileImage) RReleaseImage(prefs->swtileImage);
3586 prefs->swtileImage= NULL;
3588 WMReleasePropList(array);
3589 return 0;
3592 switch (WMGetPropListItemCount(array))
3594 case 4:
3595 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3596 wwarning(_("Invalid arguments for option \"%s\""),
3597 entry->key);
3598 break;
3599 } else
3600 path= FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3602 if (!path) {
3603 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3604 WMGetFromPLString(WMGetFromPLArray(array, 1)),
3605 entry->key);
3606 } else {
3607 bgimage= RLoadImage(scr->rcontext, path, 0);
3608 if (!bgimage) {
3609 wwarning(_("Could not load image \"%s\" for option \"%s\""),
3610 path, entry->key);
3611 wfree(path);
3612 } else {
3613 wfree(path);
3615 cwidth= atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3616 cheight= atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3618 if (cwidth <= 0 || cheight <= 0 ||
3619 cwidth >= bgimage->width - 2 ||
3620 cheight >= bgimage->height - 2)
3621 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3622 else {
3623 int i;
3624 int swidth, theight;
3625 for (i= 0; i < 9; i++) {
3626 if (prefs->swbackImage[i])
3627 RReleaseImage(prefs->swbackImage[i]);
3628 prefs->swbackImage[i]= NULL;
3630 swidth= (bgimage->width - cwidth) / 2;
3631 theight= (bgimage->height - cheight) / 2;
3633 prefs->swbackImage[0]= chopOffImage(bgimage, 0, 0,
3634 swidth, theight);
3635 prefs->swbackImage[1]= chopOffImage(bgimage, swidth, 0,
3636 cwidth, theight);
3637 prefs->swbackImage[2]= chopOffImage(bgimage, swidth+cwidth, 0,
3638 swidth, theight);
3640 prefs->swbackImage[3]= chopOffImage(bgimage, 0, theight,
3641 swidth, cheight);
3642 prefs->swbackImage[4]= chopOffImage(bgimage, swidth, theight,
3643 cwidth, cheight);
3644 prefs->swbackImage[5]= chopOffImage(bgimage, swidth+cwidth, theight,
3645 swidth, cheight);
3647 prefs->swbackImage[6]= chopOffImage(bgimage, 0, theight+cheight,
3648 swidth, theight);
3649 prefs->swbackImage[7]= chopOffImage(bgimage, swidth, theight+cheight,
3650 cwidth, theight);
3651 prefs->swbackImage[8]= chopOffImage(bgimage, swidth+cwidth, theight+cheight,
3652 swidth, theight);
3654 // check if anything failed
3655 for (i= 0; i < 9; i++) {
3656 if (!prefs->swbackImage[i]) {
3657 for (; i>=0; --i) {
3658 RReleaseImage(prefs->swbackImage[i]);
3659 prefs->swbackImage[i]= NULL;
3661 break;
3665 RReleaseImage(bgimage);
3669 case 1:
3670 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3671 wwarning(_("Invalid arguments for option \"%s\""),
3672 entry->key);
3673 break;
3674 } else
3675 path= FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3677 if (!path) {
3678 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3679 WMGetFromPLString(WMGetFromPLArray(array, 0)),
3680 entry->key);
3681 } else {
3682 if (prefs->swtileImage) RReleaseImage(prefs->swtileImage);
3684 prefs->swtileImage= RLoadImage(scr->rcontext, path, 0);
3685 if (!prefs->swtileImage) {
3686 wwarning(_("Could not load image \"%s\" for option \"%s\""),
3687 path, entry->key);
3689 wfree(path);
3691 break;
3693 default:
3694 wwarning(_("Invalid number of arguments for option \"%s\""),
3695 entry->key);
3696 break;
3699 WMReleasePropList(array);
3701 return 0;
3706 static int
3707 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3709 return REFRESH_BUTTON_IMAGES;
3714 * Very ugly kluge.
3715 * Need access to the double click variables, so that all widgets in
3716 * wmaker panels will have the same dbl-click values.
3717 * TODO: figure a better way of dealing with it.
3719 #include <WINGs/WINGsP.h>
3721 static int
3722 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3724 extern _WINGsConfiguration WINGsConfiguration;
3726 if (*value <= 0)
3727 *(int*)foo = 1;
3729 WINGsConfiguration.doubleClickDelay = *value;
3731 return 0;
3735 static int
3736 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3738 if (wCursor[index] != None) {
3739 XFreeCursor(dpy, wCursor[index]);
3742 wCursor[index] = *cursor;
3744 if (index==WCUR_ROOT && *cursor!=None) {
3745 XDefineCursor(dpy, scr->root_win, *cursor);
3748 return 0;