limit VirtualEdgeThickness values to the 0..10 range
[wmaker-crm.git] / src / defaults.c
blob0a47dbedf71a0de37ef2381fe32d8141d3271556
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 <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <time.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
38 #ifdef HAVE_DLFCN_H
39 # include <dlfcn.h>
40 #endif
44 #ifndef PATH_MAX
45 #define PATH_MAX DEFAULT_PATH_MAX
46 #endif
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
52 #include <wraster.h>
54 #include "WindowMaker.h"
55 #include "wcore.h"
56 #include "framewin.h"
57 #include "window.h"
58 #include "texture.h"
59 #include "screen.h"
60 #include "resources.h"
61 #include "defaults.h"
62 #include "keybind.h"
63 #include "xmodifier.h"
64 #include "icon.h"
65 #include "funcs.h"
66 #include "actions.h"
67 #include "dock.h"
68 #include "workspace.h"
69 #include "properties.h"
73 /***** Global *****/
75 extern WDDomain *WDWindowMaker;
76 extern WDDomain *WDWindowAttributes;
77 extern WDDomain *WDRootMenu;
79 extern int wScreenCount;
81 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
82 extern Atom _XA_WINDOWMAKER_ICON_TILE;
85 extern WMPropList *wDomainName;
86 extern WMPropList *wAttributeDomainName;
88 extern WPreferences wPreferences;
90 extern WShortKey wKeyBindings[WKBD_LAST];
92 typedef struct {
93 char *key;
94 char *default_value;
95 void *extra_data;
96 void *addr;
97 int (*convert)();
98 int (*update)();
99 WMPropList *plkey;
100 WMPropList *plvalue; /* default value */
101 } WDefaultEntry;
104 /* used to map strings to integers */
105 typedef struct {
106 char *string;
107 short value;
108 char is_alias;
109 } WOptionEnumeration;
112 /* type converters */
113 static int getBool();
114 static int getInt();
115 static int getCoord();
116 #if 0
117 /* this is not used yet */
118 static int getString();
119 #endif
120 static int getPathList();
121 static int getEnum();
122 static int getTexture();
123 static int getWSBackground();
124 static int getWSSpecificBackground();
125 static int getFont();
126 static int getColor();
127 static int getKeybind();
128 static int getModMask();
129 #ifdef NEWSTUFF
130 static int getRImage();
131 #endif
134 /* value setting functions */
135 static int setJustify();
136 static int setClearance();
137 static int setIfDockPresent();
138 static int setStickyIcons();
140 static int setPositive();
142 static int setWidgetColor();
143 static int setIconTile();
144 static int setWinTitleFont();
145 static int setMenuTitleFont();
146 static int setMenuTextFont();
147 static int setIconTitleFont();
148 static int setIconTitleColor();
149 static int setIconTitleBack();
150 static int setLargeDisplayFont();
151 static int setWTitleColor();
152 static int setFTitleBack();
153 static int setPTitleBack();
154 static int setUTitleBack();
155 static int setResizebarBack();
156 static int setWorkspaceBack();
157 static int setWorkspaceSpecificBack();
158 #ifdef VIRTUAL_DESKTOP
159 static int setVirtualEdgeThickness();
160 #endif
161 static int setMenuTitleColor();
162 static int setMenuTextColor();
163 static int setMenuDisabledColor();
164 static int setMenuTitleBack();
165 static int setMenuTextBack();
166 static int setHightlight();
167 static int setHightlightText();
168 static int setKeyGrab();
169 static int setDoubleClick();
170 static int setIconPosition();
172 static int setClipTitleFont();
173 static int setClipTitleColor();
175 static int setMenuStyle();
176 #if 0
177 static int setMultiByte();
178 #endif
179 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
372 #if 0
373 ,{"MultiByteText", "NO", NULL,
374 &wPreferences.multi_byte_text, getBool, setMultiByte
376 #endif
381 WDefaultEntry optionList[] = {
382 /* dynamic options */
383 {"IconPosition", "blh", seIconPositions,
384 &wPreferences.icon_yard, getEnum, setIconPosition
386 {"IconificationStyle", "Zoom", seIconificationStyles,
387 &wPreferences.iconification_style, getEnum, NULL
389 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
390 &wPreferences.mouse_button1, getEnum, NULL
392 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
393 &wPreferences.mouse_button2, getEnum, NULL
395 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
396 &wPreferences.mouse_button3, getEnum, NULL
398 {"MouseWheelAction", "None", seMouseWheelActions,
399 &wPreferences.mouse_wheel, getEnum, NULL
401 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
402 &wPreferences.pixmap_path, getPathList, NULL
404 {"IconPath", DEF_ICON_PATHS, NULL,
405 &wPreferences.icon_path, getPathList, NULL
407 {"ColormapMode", "auto", seColormapModes,
408 &wPreferences.colormap_mode, getEnum, NULL
410 {"AutoFocus", "NO", NULL,
411 &wPreferences.auto_focus, getBool, NULL
413 {"RaiseDelay", "0", NULL,
414 &wPreferences.raise_delay, getInt, NULL
416 {"WindozeCycling", "NO", NULL,
417 &wPreferences.windows_cycling,getBool, NULL
419 {"CirculateRaise", "NO", NULL,
420 &wPreferences.circ_raise, getBool, NULL
422 {"Superfluous", "NO", NULL,
423 &wPreferences.superfluous, getBool, NULL
425 {"AdvanceToNewWorkspace", "NO", NULL,
426 &wPreferences.ws_advance, getBool, NULL
428 {"CycleWorkspaces", "NO", NULL,
429 &wPreferences.ws_cycle, getBool, NULL
431 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
432 &wPreferences.workspace_name_display_position, getEnum, NULL
434 {"WorkspaceBorder", "None", seWorkspaceBorder,
435 &wPreferences.workspace_border_position, getEnum, updateUsableArea
437 {"WorkspaceBorderSize", "0", NULL,
438 &wPreferences.workspace_border_size, getInt, updateUsableArea
440 #ifdef VIRTUAL_DESKTOP
441 {"VirtualEdgeThickness", "1", NULL,
442 &wPreferences.vedge_thickness, getInt, setVirtualEdgeThickness
444 {"VirtualEdgeExtendSpace", "0", NULL,
445 &wPreferences.vedge_bordersize, getInt, NULL
447 {"VirtualEdgeHorizonScrollSpeed", "30", NULL,
448 &wPreferences.vedge_hscrollspeed, getInt, NULL
450 {"VirtualEdgeVerticalScrollSpeed", "30", NULL,
451 &wPreferences.vedge_vscrollspeed, getInt, NULL
453 {"VirtualEdgeResistance", "30", NULL,
454 &wPreferences.vedge_resistance, getInt, NULL
456 {"VirtualEdgeAttraction", "30", NULL,
457 &wPreferences.vedge_attraction, getInt, NULL
459 {"VirtualEdgeLeftKey", "None", (void*)WKBD_VDESK_LEFT,
460 NULL, getKeybind, setKeyGrab
462 {"VirtualEdgeRightKey", "None", (void*)WKBD_VDESK_RIGHT,
463 NULL, getKeybind, setKeyGrab
465 {"VirtualEdgeUpKey", "None", (void*)WKBD_VDESK_UP,
466 NULL, getKeybind, setKeyGrab
468 {"VirtualEdgeDownKey", "None", (void*)WKBD_VDESK_DOWN,
469 NULL, getKeybind, setKeyGrab
471 #endif
472 {"StickyIcons", "NO", NULL,
473 &wPreferences.sticky_icons, getBool, setStickyIcons
475 {"SaveSessionOnExit", "NO", NULL,
476 &wPreferences.save_session_on_exit, getBool, NULL
478 {"WrapMenus", "NO", NULL,
479 &wPreferences.wrap_menus, getBool, NULL
481 {"ScrollableMenus", "NO", NULL,
482 &wPreferences.scrollable_menus, getBool, NULL
484 {"MenuScrollSpeed", "medium", seSpeeds,
485 &wPreferences.menu_scroll_speed, getEnum, NULL
487 {"IconSlideSpeed", "medium", seSpeeds,
488 &wPreferences.icon_slide_speed, getEnum, NULL
490 {"ShadeSpeed", "medium", seSpeeds,
491 &wPreferences.shade_speed, getEnum, NULL
493 {"DoubleClickTime", "250", (void*) &wPreferences.dblclick_time,
494 &wPreferences.dblclick_time, getInt, setDoubleClick,
496 {"AlignSubmenus", "NO", NULL,
497 &wPreferences.align_menus, getBool, NULL
499 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
500 &wPreferences.open_transients_with_parent, getBool, NULL
502 {"WindowPlacement", "auto", sePlacements,
503 &wPreferences.window_placement, getEnum, NULL
505 {"IgnoreFocusClick","NO", NULL,
506 &wPreferences.ignore_focus_click, getBool, NULL
508 {"UseSaveUnders", "NO", NULL,
509 &wPreferences.use_saveunders, getBool, NULL
511 {"OpaqueMove", "NO", NULL,
512 &wPreferences.opaque_move, getBool, NULL
514 {"DisableSound", "NO", NULL,
515 &wPreferences.no_sound, getBool, NULL
517 {"DisableAnimations", "NO", NULL,
518 &wPreferences.no_animations, getBool, NULL
520 {"DontLinkWorkspaces","NO", NULL,
521 &wPreferences.no_autowrap, getBool, NULL
523 {"AutoArrangeIcons", "NO", NULL,
524 &wPreferences.auto_arrange_icons, getBool, NULL
526 {"NoWindowOverDock", "NO", NULL,
527 &wPreferences.no_window_over_dock, getBool, updateUsableArea
529 {"NoWindowOverIcons", "NO", NULL,
530 &wPreferences.no_window_over_icons, getBool, updateUsableArea
532 {"WindowPlaceOrigin", "(0, 0)", NULL,
533 &wPreferences.window_place_origin, getCoord, NULL
535 {"ResizeDisplay", "corner", seGeomDisplays,
536 &wPreferences.size_display, getEnum, NULL
538 {"MoveDisplay", "corner", seGeomDisplays,
539 &wPreferences.move_display, getEnum, NULL
541 {"DontConfirmKill", "NO", NULL,
542 &wPreferences.dont_confirm_kill, getBool,NULL
544 {"WindowTitleBalloons", "NO", NULL,
545 &wPreferences.window_balloon, getBool, NULL
547 {"MiniwindowTitleBalloons", "NO", NULL,
548 &wPreferences.miniwin_balloon,getBool, NULL
550 {"AppIconBalloons", "NO", NULL,
551 &wPreferences.appicon_balloon,getBool, NULL
553 {"HelpBalloons", "NO", NULL,
554 &wPreferences.help_balloon, getBool, NULL
556 {"EdgeResistance", "30", NULL,
557 &wPreferences.edge_resistance,getInt, NULL
559 {"Attraction", "NO", NULL,
560 &wPreferences.attract, getBool, NULL
562 {"DisableBlinking", "NO", NULL,
563 &wPreferences.dont_blink, getBool, NULL
565 /* style options */
566 {"MenuStyle", "normal", seMenuStyles,
567 &wPreferences.menu_style, getEnum, setMenuStyle
569 {"WidgetColor", "(solid, gray)", NULL,
570 NULL, getTexture, setWidgetColor,
572 {"WorkspaceSpecificBack","()", NULL,
573 NULL, getWSSpecificBackground, setWorkspaceSpecificBack
575 /* WorkspaceBack must come after WorkspaceSpecificBack or
576 * WorkspaceBack wont know WorkspaceSpecificBack was also
577 * specified and 2 copies of wmsetbg will be launched */
578 {"WorkspaceBack", "(solid, black)", NULL,
579 NULL, getWSBackground,setWorkspaceBack
581 {"SmoothWorkspaceBack", "NO", NULL,
582 NULL, getBool, NULL
584 {"IconBack", "(solid, gray)", NULL,
585 NULL, getTexture, setIconTile
587 {"TitleJustify", "center", seJustifications,
588 &wPreferences.title_justification, getEnum, setJustify
590 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
591 NULL, getFont, setWinTitleFont,
593 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
594 &wPreferences.window_title_clearance, getInt, setClearance
596 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
597 &wPreferences.menu_title_clearance, getInt, setClearance
599 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
600 &wPreferences.menu_text_clearance, getInt, setClearance
602 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
603 NULL, getFont, setMenuTitleFont
605 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
606 NULL, getFont, setMenuTextFont
608 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
609 NULL, getFont, setIconTitleFont
611 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
612 NULL, getFont, setClipTitleFont
614 {"LargeDisplayFont",DEF_WORKSPACE_NAME_FONT, NULL,
615 NULL, getFont, setLargeDisplayFont
617 {"HighlightColor", "white", NULL,
618 NULL, getColor, setHightlight
620 {"HighlightTextColor", "black", NULL,
621 NULL, getColor, setHightlightText
623 {"ClipTitleColor", "black", (void*)CLIP_NORMAL,
624 NULL, getColor, setClipTitleColor
626 {"CClipTitleColor", "\"#454045\"", (void*)CLIP_COLLAPSED,
627 NULL, getColor, setClipTitleColor
629 {"FTitleColor", "white", (void*)WS_FOCUSED,
630 NULL, getColor, setWTitleColor
632 {"PTitleColor", "white", (void*)WS_PFOCUSED,
633 NULL, getColor, setWTitleColor
635 {"UTitleColor", "black", (void*)WS_UNFOCUSED,
636 NULL, getColor, setWTitleColor
638 {"FTitleBack", "(solid, black)", NULL,
639 NULL, getTexture, setFTitleBack
641 {"PTitleBack", "(solid, \"#616161\")", NULL,
642 NULL, getTexture, setPTitleBack
644 {"UTitleBack", "(solid, gray)", NULL,
645 NULL, getTexture, setUTitleBack
647 {"ResizebarBack", "(solid, gray)", NULL,
648 NULL, getTexture, setResizebarBack
650 {"MenuTitleColor", "white", NULL,
651 NULL, getColor, setMenuTitleColor
653 {"MenuTextColor", "black", NULL,
654 NULL, getColor, setMenuTextColor
656 {"MenuDisabledColor", "\"#616161\"", NULL,
657 NULL, getColor, setMenuDisabledColor
659 {"MenuTitleBack", "(solid, black)", NULL,
660 NULL, getTexture, setMenuTitleBack
662 {"MenuTextBack", "(solid, gray)", NULL,
663 NULL, getTexture, setMenuTextBack
665 {"IconTitleColor", "white", NULL,
666 NULL, getColor, setIconTitleColor
668 {"IconTitleBack", "black", NULL,
669 NULL, getColor, setIconTitleBack
671 /* keybindings */
672 #ifndef LITE
673 {"RootMenuKey", "None", (void*)WKBD_ROOTMENU,
674 NULL, getKeybind, setKeyGrab
676 {"WindowListKey", "None", (void*)WKBD_WINDOWLIST,
677 NULL, getKeybind, setKeyGrab
679 #endif /* LITE */
680 {"WindowMenuKey", "None", (void*)WKBD_WINDOWMENU,
681 NULL, getKeybind, setKeyGrab
683 {"ClipLowerKey", "None", (void*)WKBD_CLIPLOWER,
684 NULL, getKeybind, setKeyGrab
686 {"ClipRaiseKey", "None", (void*)WKBD_CLIPRAISE,
687 NULL, getKeybind, setKeyGrab
689 {"ClipRaiseLowerKey", "None", (void*)WKBD_CLIPRAISELOWER,
690 NULL, getKeybind, setKeyGrab
692 {"MiniaturizeKey", "None", (void*)WKBD_MINIATURIZE,
693 NULL, getKeybind, setKeyGrab
695 {"HideKey", "None", (void*)WKBD_HIDE,
696 NULL, getKeybind, setKeyGrab
698 {"HideOthersKey", "None", (void*)WKBD_HIDE_OTHERS,
699 NULL, getKeybind, setKeyGrab
701 {"MoveResizeKey", "None", (void*)WKBD_MOVERESIZE,
702 NULL, getKeybind, setKeyGrab
704 {"CloseKey", "None", (void*)WKBD_CLOSE,
705 NULL, getKeybind, setKeyGrab
707 {"MaximizeKey", "None", (void*)WKBD_MAXIMIZE,
708 NULL, getKeybind, setKeyGrab
710 {"VMaximizeKey", "None", (void*)WKBD_VMAXIMIZE,
711 NULL, getKeybind, setKeyGrab
713 {"HMaximizeKey", "None", (void*)WKBD_HMAXIMIZE,
714 NULL, getKeybind, setKeyGrab
716 {"RaiseKey", "\"Meta+Up\"", (void*)WKBD_RAISE,
717 NULL, getKeybind, setKeyGrab
719 {"LowerKey", "\"Meta+Down\"", (void*)WKBD_LOWER,
720 NULL, getKeybind, setKeyGrab
722 {"RaiseLowerKey", "None", (void*)WKBD_RAISELOWER,
723 NULL, getKeybind, setKeyGrab
725 {"ShadeKey", "None", (void*)WKBD_SHADE,
726 NULL, getKeybind, setKeyGrab
728 {"SelectKey", "None", (void*)WKBD_SELECT,
729 NULL, getKeybind, setKeyGrab
731 {"FocusNextKey", "None", (void*)WKBD_FOCUSNEXT,
732 NULL, getKeybind, setKeyGrab
734 {"FocusPrevKey", "None", (void*)WKBD_FOCUSPREV,
735 NULL, getKeybind, setKeyGrab
737 {"NextWorkspaceKey", "None", (void*)WKBD_NEXTWORKSPACE,
738 NULL, getKeybind, setKeyGrab
740 {"PrevWorkspaceKey", "None", (void*)WKBD_PREVWORKSPACE,
741 NULL, getKeybind, setKeyGrab
743 {"NextWorkspaceLayerKey", "None", (void*)WKBD_NEXTWSLAYER,
744 NULL, getKeybind, setKeyGrab
746 {"PrevWorkspaceLayerKey", "None", (void*)WKBD_PREVWSLAYER,
747 NULL, getKeybind, setKeyGrab
749 {"Workspace1Key", "None", (void*)WKBD_WORKSPACE1,
750 NULL, getKeybind, setKeyGrab
752 {"Workspace2Key", "None", (void*)WKBD_WORKSPACE2,
753 NULL, getKeybind, setKeyGrab
755 {"Workspace3Key", "None", (void*)WKBD_WORKSPACE3,
756 NULL, getKeybind, setKeyGrab
758 {"Workspace4Key", "None", (void*)WKBD_WORKSPACE4,
759 NULL, getKeybind, setKeyGrab
761 {"Workspace5Key", "None", (void*)WKBD_WORKSPACE5,
762 NULL, getKeybind, setKeyGrab
764 {"Workspace6Key", "None", (void*)WKBD_WORKSPACE6,
765 NULL, getKeybind, setKeyGrab
767 {"Workspace7Key", "None", (void*)WKBD_WORKSPACE7,
768 NULL, getKeybind, setKeyGrab
770 {"Workspace8Key", "None", (void*)WKBD_WORKSPACE8,
771 NULL, getKeybind, setKeyGrab
773 {"Workspace9Key", "None", (void*)WKBD_WORKSPACE9,
774 NULL, getKeybind, setKeyGrab
776 {"Workspace10Key", "None", (void*)WKBD_WORKSPACE10,
777 NULL, getKeybind, setKeyGrab
779 {"WindowShortcut1Key","None", (void*)WKBD_WINDOW1,
780 NULL, getKeybind, setKeyGrab
782 {"WindowShortcut2Key","None", (void*)WKBD_WINDOW2,
783 NULL, getKeybind, setKeyGrab
785 {"WindowShortcut3Key","None", (void*)WKBD_WINDOW3,
786 NULL, getKeybind, setKeyGrab
788 {"WindowShortcut4Key","None", (void*)WKBD_WINDOW4,
789 NULL, getKeybind, setKeyGrab
791 ,{"WindowShortcut5Key","None", (void*)WKBD_WINDOW5,
792 NULL, getKeybind, setKeyGrab
794 {"WindowShortcut6Key","None", (void*)WKBD_WINDOW6,
795 NULL, getKeybind, setKeyGrab
797 {"WindowShortcut7Key","None", (void*)WKBD_WINDOW7,
798 NULL, getKeybind, setKeyGrab
800 {"WindowShortcut8Key","None", (void*)WKBD_WINDOW8,
801 NULL, getKeybind, setKeyGrab
803 {"WindowShortcut9Key","None", (void*)WKBD_WINDOW9,
804 NULL, getKeybind, setKeyGrab
806 {"WindowShortcut10Key","None", (void*)WKBD_WINDOW10,
807 NULL, getKeybind, setKeyGrab
809 {"ScreenSwitchKey", "None", (void*)WKBD_SWITCH_SCREEN,
810 NULL, getKeybind, setKeyGrab
813 #ifdef KEEP_XKB_LOCK_STATUS
814 {"ToggleKbdModeKey", "None", (void*)WKBD_TOGGLE,
815 NULL, getKeybind, setKeyGrab
817 {"KbdModeLock", "NO", NULL,
818 &wPreferences.modelock, getBool, NULL
820 #endif /* KEEP_XKB_LOCK_STATUS */
822 {"NormalCursor", "(builtin, left_ptr)", (void*)WCUR_ROOT,
823 NULL, getCursor, setCursor
825 {"ArrowCursor", "(builtin, top_left_arrow)", (void*)WCUR_ARROW,
826 NULL, getCursor, setCursor
828 {"MoveCursor", "(builtin, fleur)", (void*)WCUR_MOVE,
829 NULL, getCursor, setCursor
831 {"ResizeCursor", "(builtin, sizing)", (void*)WCUR_RESIZE,
832 NULL, getCursor, setCursor
834 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
835 (void*)WCUR_TOPLEFTRESIZE,
836 NULL, getCursor, setCursor
838 {"TopRightResizeCursor", "(builtin, top_right_corner)",
839 (void*)WCUR_TOPRIGHTRESIZE,
840 NULL, getCursor, setCursor
842 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
843 (void*)WCUR_BOTTOMLEFTRESIZE,
844 NULL, getCursor, setCursor
846 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
847 (void*)WCUR_BOTTOMRIGHTRESIZE,
848 NULL, getCursor, setCursor
850 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
851 (void*)WCUR_VERTICALRESIZE,
852 NULL, getCursor, setCursor
854 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
855 (void*)WCUR_HORIZONRESIZE,
856 NULL, getCursor, setCursor
858 {"WaitCursor", "(builtin, watch)", (void*)WCUR_WAIT,
859 NULL, getCursor, setCursor
861 {"QuestionCursor", "(builtin, question_arrow)", (void*)WCUR_QUESTION,
862 NULL, getCursor, setCursor
864 {"TextCursor", "(builtin, xterm)", (void*)WCUR_TEXT,
865 NULL, getCursor, setCursor
867 {"SelectCursor", "(builtin, cross)", (void*)WCUR_SELECT,
868 NULL, getCursor, setCursor
873 #if 0
874 static void rereadDefaults(void);
875 #endif
877 #if 0
878 static void
879 rereadDefaults(void)
881 /* must defer the update because accessing X data from a
882 * signal handler can mess up Xlib */
885 #endif
887 static void
888 initDefaults()
890 int i;
891 WDefaultEntry *entry;
893 WMPLSetCaseSensitive(False);
895 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
896 entry = &optionList[i];
898 entry->plkey = WMCreatePLString(entry->key);
899 if (entry->default_value)
900 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
901 else
902 entry->plvalue = NULL;
905 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
906 entry = &staticOptionList[i];
908 entry->plkey = WMCreatePLString(entry->key);
909 if (entry->default_value)
910 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
911 else
912 entry->plvalue = NULL;
916 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
917 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
919 PLRegister(wDomainName, rereadDefaults);
920 PLRegister(wAttributeDomainName, rereadDefaults);
925 static WMPropList*
926 readGlobalDomain(char *domainName, Bool requireDictionary)
928 WMPropList *globalDict = NULL;
929 char path[PATH_MAX];
930 struct stat stbuf;
932 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
933 if (stat(path, &stbuf)>=0) {
934 globalDict = WMReadPropListFromFile(path);
935 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
936 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
937 domainName, path);
938 WMReleasePropList(globalDict);
939 globalDict = NULL;
940 } else if (!globalDict) {
941 wwarning(_("could not load domain %s from global defaults database"),
942 domainName);
946 return globalDict;
950 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
951 static void
952 prependMenu(WMPropList *destarr, WMPropList *array)
954 WMPropList *item;
955 int i;
957 for (i=0; i<WMGetPropListItemCount(array); i++) {
958 item = WMGetFromPLArray(array, i);
959 if (item)
960 WMInsertInPLArray(destarr, i+1, item);
965 static void
966 appendMenu(WMPropList *destarr, WMPropList *array)
968 WMPropList *item;
969 int i;
971 for (i=0; i<WMGetPropListItemCount(array); i++) {
972 item = WMGetFromPLArray(array, i);
973 if (item)
974 WMAddToPLArray(destarr, item);
977 #endif
980 void
981 wDefaultsMergeGlobalMenus(WDDomain *menuDomain)
983 WMPropList *menu = menuDomain->dictionary;
984 WMPropList *submenu;
986 if (!menu || !WMIsPLArray(menu))
987 return;
989 #ifdef GLOBAL_PREAMBLE_MENU_FILE
990 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_PREAMBLE_MENU_FILE);
992 if (submenu && !WMIsPLArray(submenu)) {
993 wwarning(_("invalid global menu file %s"),
994 GLOBAL_PREAMBLE_MENU_FILE);
995 WMReleasePropList(submenu);
996 submenu = NULL;
998 if (submenu) {
999 prependMenu(menu, submenu);
1000 WMReleasePropList(submenu);
1002 #endif
1004 #ifdef GLOBAL_EPILOGUE_MENU_FILE
1005 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_EPILOGUE_MENU_FILE);
1007 if (submenu && !WMIsPLArray(submenu)) {
1008 wwarning(_("invalid global menu file %s"),
1009 GLOBAL_EPILOGUE_MENU_FILE);
1010 WMReleasePropList(submenu);
1011 submenu = NULL;
1013 if (submenu) {
1014 appendMenu(menu, submenu);
1015 WMReleasePropList(submenu);
1017 #endif
1019 menuDomain->dictionary = menu;
1023 #if 0
1024 WMPropList*
1025 wDefaultsInit(int screen_number)
1027 static int defaults_inited = 0;
1028 WMPropList *dict;
1030 if (!defaults_inited) {
1031 initDefaults();
1034 dict = PLGetDomain(wDomainName);
1035 if (!dict) {
1036 wwarning(_("could not read domain \"%s\" from defaults database"),
1037 WMGetFromPLString(wDomainName));
1040 return dict;
1042 #endif
1045 void
1046 wDefaultsDestroyDomain(WDDomain *domain)
1048 if (domain->dictionary)
1049 WMReleasePropList(domain->dictionary);
1050 wfree(domain->path);
1051 wfree(domain);
1055 WDDomain*
1056 wDefaultsInitDomain(char *domain, Bool requireDictionary)
1058 WDDomain *db;
1059 struct stat stbuf;
1060 static int inited = 0;
1061 char path[PATH_MAX];
1062 char *the_path;
1063 WMPropList *shared_dict=NULL;
1065 if (!inited) {
1066 inited = 1;
1067 initDefaults();
1070 db = wmalloc(sizeof(WDDomain));
1071 memset(db, 0, sizeof(WDDomain));
1072 db->domain_name = domain;
1073 db->path = wdefaultspathfordomain(domain);
1074 the_path = db->path;
1076 if (the_path && stat(the_path, &stbuf)>=0) {
1077 db->dictionary = WMReadPropListFromFile(the_path);
1078 if (db->dictionary) {
1079 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
1080 WMReleasePropList(db->dictionary);
1081 db->dictionary = NULL;
1082 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1083 domain, the_path);
1085 db->timestamp = stbuf.st_mtime;
1086 } else {
1087 wwarning(_("could not load domain %s from user defaults database"),
1088 domain);
1092 /* global system dictionary */
1093 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1094 if (stat(path, &stbuf)>=0) {
1095 shared_dict = WMReadPropListFromFile(path);
1096 if (shared_dict) {
1097 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1098 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1099 domain, path);
1100 WMReleasePropList(shared_dict);
1101 shared_dict = NULL;
1102 } else {
1103 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1104 WMIsPLDictionary(db->dictionary)) {
1105 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1106 WMReleasePropList(db->dictionary);
1107 db->dictionary = shared_dict;
1108 if (stbuf.st_mtime > db->timestamp)
1109 db->timestamp = stbuf.st_mtime;
1110 } else if (!db->dictionary) {
1111 db->dictionary = shared_dict;
1112 if (stbuf.st_mtime > db->timestamp)
1113 db->timestamp = stbuf.st_mtime;
1116 } else {
1117 wwarning(_("could not load domain %s from global defaults database (%s)"),
1118 domain, path);
1122 return db;
1126 void
1127 wReadStaticDefaults(WMPropList *dict)
1129 WMPropList *plvalue;
1130 WDefaultEntry *entry;
1131 int i;
1132 void *tdata;
1135 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1136 entry = &staticOptionList[i];
1138 if (dict)
1139 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1140 else
1141 plvalue = NULL;
1143 if (!plvalue) {
1144 /* no default in the DB. Use builtin default */
1145 plvalue = entry->plvalue;
1148 if (plvalue) {
1149 /* convert data */
1150 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1151 if (entry->update) {
1152 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1160 void
1161 wDefaultsCheckDomains(void *foo)
1163 WScreen *scr;
1164 struct stat stbuf;
1165 WMPropList *shared_dict = NULL;
1166 WMPropList *dict;
1167 int i;
1169 #ifdef HEARTBEAT
1170 puts("Checking domains...");
1171 #endif
1172 if (stat(WDWindowMaker->path, &stbuf)>=0
1173 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1174 #ifdef HEARTBEAT
1175 puts("Checking WindowMaker domain");
1176 #endif
1177 WDWindowMaker->timestamp = stbuf.st_mtime;
1179 /* global dictionary */
1180 shared_dict = readGlobalDomain("WindowMaker", True);
1181 /* user dictionary */
1182 dict = WMReadPropListFromFile(WDWindowMaker->path);
1183 if (dict) {
1184 if (!WMIsPLDictionary(dict)) {
1185 WMReleasePropList(dict);
1186 dict = NULL;
1187 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1188 "WindowMaker", WDWindowMaker->path);
1189 } else {
1190 if (shared_dict) {
1191 WMMergePLDictionaries(shared_dict, dict, True);
1192 WMReleasePropList(dict);
1193 dict = shared_dict;
1194 shared_dict = NULL;
1196 for (i=0; i<wScreenCount; i++) {
1197 scr = wScreenWithNumber(i);
1198 if (scr)
1199 wReadDefaults(scr, dict);
1201 if (WDWindowMaker->dictionary) {
1202 WMReleasePropList(WDWindowMaker->dictionary);
1204 WDWindowMaker->dictionary = dict;
1206 } else {
1207 wwarning(_("could not load domain %s from user defaults database"),
1208 "WindowMaker");
1210 if (shared_dict) {
1211 WMReleasePropList(shared_dict);
1215 if (stat(WDWindowAttributes->path, &stbuf)>=0
1216 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1217 #ifdef HEARTBEAT
1218 puts("Checking WMWindowAttributes domain");
1219 #endif
1220 /* global dictionary */
1221 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1222 /* user dictionary */
1223 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1224 if (dict) {
1225 if (!WMIsPLDictionary(dict)) {
1226 WMReleasePropList(dict);
1227 dict = NULL;
1228 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1229 "WMWindowAttributes", WDWindowAttributes->path);
1230 } else {
1231 if (shared_dict) {
1232 WMMergePLDictionaries(shared_dict, dict, True);
1233 WMReleasePropList(dict);
1234 dict = shared_dict;
1235 shared_dict = NULL;
1237 if (WDWindowAttributes->dictionary) {
1238 WMReleasePropList(WDWindowAttributes->dictionary);
1240 WDWindowAttributes->dictionary = dict;
1241 for (i=0; i<wScreenCount; i++) {
1242 scr = wScreenWithNumber(i);
1243 if (scr) {
1244 RImage *image;
1246 wDefaultUpdateIcons(scr);
1248 /* Update the panel image if changed */
1249 /* Don't worry. If the image is the same these
1250 * functions will have no performance impact. */
1251 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1253 if (!image) {
1254 wwarning(_("could not load logo image for panels: %s"),
1255 RMessageForError(RErrorCode));
1256 } else {
1257 WMSetApplicationIconImage(scr->wmscreen, image);
1258 RReleaseImage(image);
1263 } else {
1264 wwarning(_("could not load domain %s from user defaults database"),
1265 "WMWindowAttributes");
1267 WDWindowAttributes->timestamp = stbuf.st_mtime;
1268 if (shared_dict) {
1269 WMReleasePropList(shared_dict);
1273 #ifndef LITE
1274 if (stat(WDRootMenu->path, &stbuf)>=0
1275 && WDRootMenu->timestamp < stbuf.st_mtime) {
1276 dict = WMReadPropListFromFile(WDRootMenu->path);
1277 #ifdef HEARTBEAT
1278 puts("Checking WMRootMenu domain");
1279 #endif
1280 if (dict) {
1281 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1282 WMReleasePropList(dict);
1283 dict = NULL;
1284 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1285 "WMRootMenu", WDRootMenu->path);
1286 } else {
1287 if (WDRootMenu->dictionary) {
1288 WMReleasePropList(WDRootMenu->dictionary);
1290 WDRootMenu->dictionary = dict;
1291 wDefaultsMergeGlobalMenus(WDRootMenu);
1293 } else {
1294 wwarning(_("could not load domain %s from user defaults database"),
1295 "WMRootMenu");
1297 WDRootMenu->timestamp = stbuf.st_mtime;
1299 #endif /* !LITE */
1301 if (!foo)
1302 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1306 void
1307 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1309 WMPropList *plvalue, *old_value;
1310 WDefaultEntry *entry;
1311 int i, must_update;
1312 int update_workspace_back = 0; /* kluge :/ */
1313 int needs_refresh;
1314 void *tdata;
1315 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1316 ? WDWindowMaker->dictionary : NULL);
1318 must_update = 0;
1320 needs_refresh = 0;
1322 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1323 entry = &optionList[i];
1325 if (new_dict)
1326 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1327 else
1328 plvalue = NULL;
1330 if (!old_dict)
1331 old_value = NULL;
1332 else
1333 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1336 if (!plvalue && !old_value) {
1337 /* no default in the DB. Use builtin default */
1338 plvalue = entry->plvalue;
1339 if (plvalue && new_dict) {
1340 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1341 must_update = 1;
1343 } else if (!plvalue) {
1344 /* value was deleted from DB. Keep current value */
1345 continue;
1346 } else if (!old_value) {
1347 /* set value for the 1st time */
1348 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1349 /* value has changed */
1350 } else {
1352 if (strcmp(entry->key, "WorkspaceBack") == 0
1353 && update_workspace_back
1354 && scr->flags.backimage_helper_launched) {
1355 } else {
1356 /* value was not changed since last time */
1357 continue;
1361 if (plvalue) {
1362 #ifdef DEBUG
1363 printf("Updating %s to %s\n", entry->key,
1364 WMGetPropListDescription(plvalue, False));
1365 #endif
1366 /* convert data */
1367 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1369 * If the WorkspaceSpecificBack data has been changed
1370 * so that the helper will be launched now, we must be
1371 * sure to send the default background texture config
1372 * to the helper.
1374 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1375 && !scr->flags.backimage_helper_launched) {
1376 update_workspace_back = 1;
1378 if (entry->update) {
1379 needs_refresh |=
1380 (*entry->update)(scr, entry, tdata, entry->extra_data);
1386 if (needs_refresh!=0 && !scr->flags.startup) {
1387 int foo;
1389 foo = 0;
1390 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1391 foo |= WTextureSettings;
1392 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1393 foo |= WFontSettings;
1394 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1395 foo |= WColorSettings;
1396 if (foo)
1397 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1398 (void*)foo);
1400 foo = 0;
1401 if (needs_refresh & REFRESH_MENU_TEXTURE)
1402 foo |= WTextureSettings;
1403 if (needs_refresh & REFRESH_MENU_FONT)
1404 foo |= WFontSettings;
1405 if (needs_refresh & REFRESH_MENU_COLOR)
1406 foo |= WColorSettings;
1407 if (foo)
1408 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1409 (void*)foo);
1411 foo = 0;
1412 if (needs_refresh & REFRESH_WINDOW_FONT) {
1413 foo |= WFontSettings;
1415 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1416 foo |= WTextureSettings;
1418 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1419 foo |= WColorSettings;
1421 if (foo)
1422 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1423 (void*)foo);
1425 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1426 foo = 0;
1427 if (needs_refresh & REFRESH_ICON_FONT) {
1428 foo |= WFontSettings;
1430 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1431 foo |= WTextureSettings;
1433 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1434 foo |= WTextureSettings;
1436 if (foo)
1437 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1438 (void*)foo);
1440 if (needs_refresh & REFRESH_ICON_TILE)
1441 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1446 void
1447 wDefaultUpdateIcons(WScreen *scr)
1449 WAppIcon *aicon = scr->app_icon_list;
1450 WWindow *wwin = scr->focused_window;
1451 char *file;
1453 while(aicon) {
1454 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1455 False);
1456 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1457 || (file && !aicon->icon->file)) {
1458 RImage *new_image;
1460 if (aicon->icon->file)
1461 wfree(aicon->icon->file);
1462 aicon->icon->file = wstrdup(file);
1464 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1465 aicon->wm_class);
1466 if (new_image) {
1467 wIconChangeImage(aicon->icon, new_image);
1468 wAppIconPaint(aicon);
1471 aicon = aicon->next;
1474 if (!wPreferences.flags.noclip)
1475 wClipIconPaint(scr->clip_icon);
1477 while (wwin) {
1478 if (wwin->icon && wwin->flags.miniaturized) {
1479 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1480 False);
1481 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1482 || (file && !wwin->icon->file)) {
1483 RImage *new_image;
1485 if (wwin->icon->file)
1486 wfree(wwin->icon->file);
1487 wwin->icon->file = wstrdup(file);
1489 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1490 wwin->wm_class);
1491 if (new_image)
1492 wIconChangeImage(wwin->icon, new_image);
1495 wwin = wwin->prev;
1500 /* --------------------------- Local ----------------------- */
1502 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1503 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1504 entry->key, x); \
1505 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1506 var = entry->default_value;\
1507 } else var = WMGetFromPLString(value)\
1513 static int
1514 string2index(WMPropList *key, WMPropList *val, char *def,
1515 WOptionEnumeration *values)
1517 char *str;
1518 WOptionEnumeration *v;
1519 char buffer[TOTAL_VALUES_LENGTH];
1521 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1522 for (v=values; v->string!=NULL; v++) {
1523 if (strcasecmp(v->string, str)==0)
1524 return v->value;
1528 buffer[0] = 0;
1529 for (v=values; v->string!=NULL; v++) {
1530 if (!v->is_alias) {
1531 if (buffer[0]!=0)
1532 strcat(buffer, ", ");
1533 strcat(buffer, v->string);
1536 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1537 WMGetFromPLString(key), buffer);
1539 if (def) {
1540 return string2index(key, val, NULL, values);
1543 return -1;
1550 * value - is the value in the defaults DB
1551 * addr - is the address to store the data
1552 * ret - is the address to store a pointer to a temporary buffer. ret
1553 * must not be freed and is used by the set functions
1555 static int
1556 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1557 void **ret)
1559 static char data;
1560 char *val;
1561 int second_pass=0;
1563 GET_STRING_OR_DEFAULT("Boolean", val);
1565 again:
1566 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1567 || strcasecmp(val, "YES")==0) {
1569 data = 1;
1570 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1571 || strcasecmp(val, "NO")==0) {
1572 data = 0;
1573 } else {
1574 int i;
1575 if (sscanf(val, "%i", &i)==1) {
1576 if (i!=0)
1577 data = 1;
1578 else
1579 data = 0;
1580 } else {
1581 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1582 val, entry->key);
1583 if (second_pass==0) {
1584 val = WMGetFromPLString(entry->plvalue);
1585 second_pass = 1;
1586 wwarning(_("using default \"%s\" instead"), val);
1587 goto again;
1589 return False;
1593 if (ret)
1594 *ret = &data;
1595 if (addr)
1596 *(char*)addr = data;
1598 return True;
1602 static int
1603 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1604 void **ret)
1606 static int data;
1607 char *val;
1610 GET_STRING_OR_DEFAULT("Integer", val);
1612 if (sscanf(val, "%i", &data)!=1) {
1613 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1614 val, entry->key);
1615 val = WMGetFromPLString(entry->plvalue);
1616 wwarning(_("using default \"%s\" instead"), val);
1617 if (sscanf(val, "%i", &data)!=1) {
1618 return False;
1622 if (ret)
1623 *ret = &data;
1624 if (addr)
1625 *(int*)addr = data;
1627 return True;
1631 static int
1632 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1633 void **ret)
1635 static WCoord data;
1636 char *val_x, *val_y;
1637 int nelem, changed=0;
1638 WMPropList *elem_x, *elem_y;
1640 again:
1641 if (!WMIsPLArray(value)) {
1642 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1643 entry->key, "Coordinate");
1644 if (changed==0) {
1645 value = entry->plvalue;
1646 changed = 1;
1647 wwarning(_("using default \"%s\" instead"), entry->default_value);
1648 goto again;
1650 return False;
1653 nelem = WMGetPropListItemCount(value);
1654 if (nelem != 2) {
1655 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1656 entry->key);
1657 if (changed==0) {
1658 value = entry->plvalue;
1659 changed = 1;
1660 wwarning(_("using default \"%s\" instead"), entry->default_value);
1661 goto again;
1663 return False;
1666 elem_x = WMGetFromPLArray(value, 0);
1667 elem_y = WMGetFromPLArray(value, 1);
1669 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1670 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1671 entry->key);
1672 if (changed==0) {
1673 value = entry->plvalue;
1674 changed = 1;
1675 wwarning(_("using default \"%s\" instead"), entry->default_value);
1676 goto again;
1678 return False;
1681 val_x = WMGetFromPLString(elem_x);
1682 val_y = WMGetFromPLString(elem_y);
1684 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1685 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1686 if (changed==0) {
1687 value = entry->plvalue;
1688 changed = 1;
1689 wwarning(_("using default \"%s\" instead"), entry->default_value);
1690 goto again;
1692 return False;
1695 if (data.x < 0)
1696 data.x = 0;
1697 else if (data.x > scr->scr_width/3)
1698 data.x = scr->scr_width/3;
1699 if (data.y < 0)
1700 data.y = 0;
1701 else if (data.y > scr->scr_height/3)
1702 data.y = scr->scr_height/3;
1704 if (ret)
1705 *ret = &data;
1706 if (addr)
1707 *(WCoord*)addr = data;
1709 return True;
1713 #if 0
1714 /* This function is not used at the moment. */
1715 static int
1716 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1717 void **ret)
1719 static char *data;
1721 GET_STRING_OR_DEFAULT("String", data);
1723 if (!data) {
1724 data = WMGetFromPLString(entry->plvalue);
1725 if (!data)
1726 return False;
1729 if (ret)
1730 *ret = &data;
1731 if (addr)
1732 *(char**)addr = wstrdup(data);
1734 return True;
1736 #endif
1739 static int
1740 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1741 void **ret)
1743 static char *data;
1744 int i, count, len;
1745 char *ptr;
1746 WMPropList *d;
1747 int changed=0;
1749 again:
1750 if (!WMIsPLArray(value)) {
1751 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1752 entry->key, "an array of paths");
1753 if (changed==0) {
1754 value = entry->plvalue;
1755 changed = 1;
1756 wwarning(_("using default \"%s\" instead"), entry->default_value);
1757 goto again;
1759 return False;
1762 i = 0;
1763 count = WMGetPropListItemCount(value);
1764 if (count < 1) {
1765 if (changed==0) {
1766 value = entry->plvalue;
1767 changed = 1;
1768 wwarning(_("using default \"%s\" instead"), entry->default_value);
1769 goto again;
1771 return False;
1774 len = 0;
1775 for (i=0; i<count; i++) {
1776 d = WMGetFromPLArray(value, i);
1777 if (!d || !WMIsPLString(d)) {
1778 count = i;
1779 break;
1781 len += strlen(WMGetFromPLString(d))+1;
1784 ptr = data = wmalloc(len+1);
1786 for (i=0; i<count; i++) {
1787 d = WMGetFromPLArray(value, i);
1788 if (!d || !WMIsPLString(d)) {
1789 break;
1791 strcpy(ptr, WMGetFromPLString(d));
1792 ptr += strlen(WMGetFromPLString(d));
1793 *ptr = ':';
1794 ptr++;
1796 ptr--; *(ptr--) = 0;
1798 if (*(char**)addr!=NULL) {
1799 wfree(*(char**)addr);
1801 *(char**)addr = data;
1803 return True;
1807 static int
1808 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1809 void **ret)
1811 static signed char data;
1813 data = string2index(entry->plkey, value, entry->default_value,
1814 (WOptionEnumeration*)entry->extra_data);
1815 if (data < 0)
1816 return False;
1818 if (ret)
1819 *ret = &data;
1820 if (addr)
1821 *(signed char*)addr = data;
1823 return True;
1829 * (solid <color>)
1830 * (hgradient <color> <color>)
1831 * (vgradient <color> <color>)
1832 * (dgradient <color> <color>)
1833 * (mhgradient <color> <color> ...)
1834 * (mvgradient <color> <color> ...)
1835 * (mdgradient <color> <color> ...)
1836 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1837 * (tpixmap <file> <color>)
1838 * (spixmap <file> <color>)
1839 * (cpixmap <file> <color>)
1840 * (thgradient <file> <opaqueness> <color> <color>)
1841 * (tvgradient <file> <opaqueness> <color> <color>)
1842 * (tdgradient <file> <opaqueness> <color> <color>)
1843 * (function <lib> <function> ...)
1846 static WTexture*
1847 parse_texture(WScreen *scr, WMPropList *pl)
1849 WMPropList *elem;
1850 char *val;
1851 int nelem;
1852 WTexture *texture=NULL;
1854 nelem = WMGetPropListItemCount(pl);
1855 if (nelem < 1)
1856 return NULL;
1859 elem = WMGetFromPLArray(pl, 0);
1860 if (!elem || !WMIsPLString(elem))
1861 return NULL;
1862 val = WMGetFromPLString(elem);
1865 if (strcasecmp(val, "solid")==0) {
1866 XColor color;
1868 if (nelem != 2)
1869 return NULL;
1871 /* get color */
1873 elem = WMGetFromPLArray(pl, 1);
1874 if (!elem || !WMIsPLString(elem))
1875 return NULL;
1876 val = WMGetFromPLString(elem);
1878 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1879 wwarning(_("\"%s\" is not a valid color name"), val);
1880 return NULL;
1883 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1884 } else if (strcasecmp(val, "dgradient")==0
1885 || strcasecmp(val, "vgradient")==0
1886 || strcasecmp(val, "hgradient")==0) {
1887 RColor color1, color2;
1888 XColor xcolor;
1889 int type;
1891 if (nelem != 3) {
1892 wwarning(_("bad number of arguments in gradient specification"));
1893 return NULL;
1896 if (val[0]=='d' || val[0]=='D')
1897 type = WTEX_DGRADIENT;
1898 else if (val[0]=='h' || val[0]=='H')
1899 type = WTEX_HGRADIENT;
1900 else
1901 type = WTEX_VGRADIENT;
1904 /* get from color */
1905 elem = WMGetFromPLArray(pl, 1);
1906 if (!elem || !WMIsPLString(elem))
1907 return NULL;
1908 val = WMGetFromPLString(elem);
1910 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1911 wwarning(_("\"%s\" is not a valid color name"), val);
1912 return NULL;
1914 color1.alpha = 255;
1915 color1.red = xcolor.red >> 8;
1916 color1.green = xcolor.green >> 8;
1917 color1.blue = xcolor.blue >> 8;
1919 /* get to color */
1920 elem = WMGetFromPLArray(pl, 2);
1921 if (!elem || !WMIsPLString(elem)) {
1922 return NULL;
1924 val = WMGetFromPLString(elem);
1926 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1927 wwarning(_("\"%s\" is not a valid color name"), val);
1928 return NULL;
1930 color2.alpha = 255;
1931 color2.red = xcolor.red >> 8;
1932 color2.green = xcolor.green >> 8;
1933 color2.blue = xcolor.blue >> 8;
1935 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1937 } else if (strcasecmp(val, "igradient")==0) {
1938 RColor colors1[2], colors2[2];
1939 int th1, th2;
1940 XColor xcolor;
1941 int i;
1943 if (nelem != 7) {
1944 wwarning(_("bad number of arguments in gradient specification"));
1945 return NULL;
1948 /* get from color */
1949 for (i = 0; i < 2; i++) {
1950 elem = WMGetFromPLArray(pl, 1+i);
1951 if (!elem || !WMIsPLString(elem))
1952 return NULL;
1953 val = WMGetFromPLString(elem);
1955 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1956 wwarning(_("\"%s\" is not a valid color name"), val);
1957 return NULL;
1959 colors1[i].alpha = 255;
1960 colors1[i].red = xcolor.red >> 8;
1961 colors1[i].green = xcolor.green >> 8;
1962 colors1[i].blue = xcolor.blue >> 8;
1964 elem = WMGetFromPLArray(pl, 3);
1965 if (!elem || !WMIsPLString(elem))
1966 return NULL;
1967 val = WMGetFromPLString(elem);
1968 th1 = atoi(val);
1971 /* get from color */
1972 for (i = 0; i < 2; i++) {
1973 elem = WMGetFromPLArray(pl, 4+i);
1974 if (!elem || !WMIsPLString(elem))
1975 return NULL;
1976 val = WMGetFromPLString(elem);
1978 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1979 wwarning(_("\"%s\" is not a valid color name"), val);
1980 return NULL;
1982 colors2[i].alpha = 255;
1983 colors2[i].red = xcolor.red >> 8;
1984 colors2[i].green = xcolor.green >> 8;
1985 colors2[i].blue = xcolor.blue >> 8;
1987 elem = WMGetFromPLArray(pl, 6);
1988 if (!elem || !WMIsPLString(elem))
1989 return NULL;
1990 val = WMGetFromPLString(elem);
1991 th2 = atoi(val);
1993 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
1994 th2, colors2);
1996 } else if (strcasecmp(val, "mhgradient")==0
1997 || strcasecmp(val, "mvgradient")==0
1998 || strcasecmp(val, "mdgradient")==0) {
1999 XColor color;
2000 RColor **colors;
2001 int i, count;
2002 int type;
2004 if (nelem < 3) {
2005 wwarning(_("too few arguments in multicolor gradient specification"));
2006 return NULL;
2009 if (val[1]=='h' || val[1]=='H')
2010 type = WTEX_MHGRADIENT;
2011 else if (val[1]=='v' || val[1]=='V')
2012 type = WTEX_MVGRADIENT;
2013 else
2014 type = WTEX_MDGRADIENT;
2016 count = nelem-1;
2018 colors = wmalloc(sizeof(RColor*)*(count+1));
2020 for (i=0; i<count; i++) {
2021 elem = WMGetFromPLArray(pl, i+1);
2022 if (!elem || !WMIsPLString(elem)) {
2023 for (--i; i>=0; --i) {
2024 wfree(colors[i]);
2026 wfree(colors);
2027 return NULL;
2029 val = WMGetFromPLString(elem);
2031 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2032 wwarning(_("\"%s\" is not a valid color name"), val);
2033 for (--i; i>=0; --i) {
2034 wfree(colors[i]);
2036 wfree(colors);
2037 return NULL;
2038 } else {
2039 colors[i] = wmalloc(sizeof(RColor));
2040 colors[i]->red = color.red >> 8;
2041 colors[i]->green = color.green >> 8;
2042 colors[i]->blue = color.blue >> 8;
2045 colors[i] = NULL;
2047 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
2048 } else if (strcasecmp(val, "spixmap")==0 ||
2049 strcasecmp(val, "cpixmap")==0 ||
2050 strcasecmp(val, "tpixmap")==0) {
2051 XColor color;
2052 int type;
2054 if (nelem != 3)
2055 return NULL;
2057 if (val[0] == 's' || val[0] == 'S')
2058 type = WTP_SCALE;
2059 else if (val[0] == 'c' || val[0] == 'C')
2060 type = WTP_CENTER;
2061 else
2062 type = WTP_TILE;
2064 /* get color */
2065 elem = WMGetFromPLArray(pl, 2);
2066 if (!elem || !WMIsPLString(elem)) {
2067 return NULL;
2069 val = WMGetFromPLString(elem);
2071 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2072 wwarning(_("\"%s\" is not a valid color name"), val);
2073 return NULL;
2076 /* file name */
2077 elem = WMGetFromPLArray(pl, 1);
2078 if (!elem || !WMIsPLString(elem))
2079 return NULL;
2080 val = WMGetFromPLString(elem);
2082 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2083 } else if (strcasecmp(val, "thgradient")==0
2084 || strcasecmp(val, "tvgradient")==0
2085 || strcasecmp(val, "tdgradient")==0) {
2086 RColor color1, color2;
2087 XColor xcolor;
2088 int opacity;
2089 int style;
2091 if (val[1]=='h' || val[1]=='H')
2092 style = WTEX_THGRADIENT;
2093 else if (val[1]=='v' || val[1]=='V')
2094 style = WTEX_TVGRADIENT;
2095 else
2096 style = WTEX_TDGRADIENT;
2098 if (nelem != 5) {
2099 wwarning(_("bad number of arguments in textured gradient specification"));
2100 return NULL;
2103 /* get from color */
2104 elem = WMGetFromPLArray(pl, 3);
2105 if (!elem || !WMIsPLString(elem))
2106 return NULL;
2107 val = WMGetFromPLString(elem);
2109 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2110 wwarning(_("\"%s\" is not a valid color name"), val);
2111 return NULL;
2113 color1.alpha = 255;
2114 color1.red = xcolor.red >> 8;
2115 color1.green = xcolor.green >> 8;
2116 color1.blue = xcolor.blue >> 8;
2118 /* get to color */
2119 elem = WMGetFromPLArray(pl, 4);
2120 if (!elem || !WMIsPLString(elem)) {
2121 return NULL;
2123 val = WMGetFromPLString(elem);
2125 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2126 wwarning(_("\"%s\" is not a valid color name"), val);
2127 return NULL;
2129 color2.alpha = 255;
2130 color2.red = xcolor.red >> 8;
2131 color2.green = xcolor.green >> 8;
2132 color2.blue = xcolor.blue >> 8;
2134 /* get opacity */
2135 elem = WMGetFromPLArray(pl, 2);
2136 if (!elem || !WMIsPLString(elem))
2137 opacity = 128;
2138 else
2139 val = WMGetFromPLString(elem);
2141 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2142 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2143 opacity = 128;
2146 /* get file name */
2147 elem = WMGetFromPLArray(pl, 1);
2148 if (!elem || !WMIsPLString(elem))
2149 return NULL;
2150 val = WMGetFromPLString(elem);
2152 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2153 val, opacity);
2155 #ifdef TEXTURE_PLUGIN
2156 else if (strcasecmp(val, "function")==0) {
2157 WTexFunction *function;
2158 void (*initFunc) (Display *, Colormap);
2159 char *lib, *func, **argv;
2160 int i, argc;
2162 if (nelem < 3)
2163 return NULL;
2165 /* get the library name */
2166 elem = WMGetFromPLArray(pl, 1);
2167 if (!elem || !WMIsPLString(elem)) {
2168 return NULL;
2170 lib = WMGetFromPLString(elem);
2172 /* get the function name */
2173 elem = WMGetFromPLArray(pl, 2);
2174 if (!elem || !WMIsPLString(elem)) {
2175 return NULL;
2177 func = WMGetFromPLString(elem);
2179 argc = nelem - 2;
2180 argv = (char **)wmalloc(argc * sizeof(char *));
2182 /* get the parameters */
2183 argv[0] = wstrdup(func);
2184 for (i = 0; i < argc - 1; i++) {
2185 elem = WMGetFromPLArray(pl, 3 + i);
2186 if (!elem || !WMIsPLString(elem)) {
2187 wfree(argv);
2189 return NULL;
2191 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2194 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2196 #ifdef HAVE_DLFCN_H
2197 if (function) {
2198 initFunc = dlsym(function->handle, "initWindowMaker");
2199 if (initFunc) {
2200 initFunc(dpy, scr->w_colormap);
2201 } else {
2202 wwarning(_("could not initialize library %s"), lib);
2204 } else {
2205 wwarning(_("could not find function %s::%s"), lib, func);
2207 #endif /* HAVE_DLFCN_H */
2208 texture = (WTexture*)function;
2210 #endif /* TEXTURE_PLUGIN */
2211 else {
2212 wwarning(_("invalid texture type %s"), val);
2213 return NULL;
2215 return texture;
2220 static int
2221 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2222 void **ret)
2224 static WTexture *texture;
2225 int changed=0;
2227 again:
2228 if (!WMIsPLArray(value)) {
2229 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2230 entry->key, "Texture");
2231 if (changed==0) {
2232 value = entry->plvalue;
2233 changed = 1;
2234 wwarning(_("using default \"%s\" instead"), entry->default_value);
2235 goto again;
2237 return False;
2240 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2241 WMPropList *pl;
2243 pl = WMGetFromPLArray(value, 0);
2244 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2245 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2246 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2247 entry->key, "Solid Texture");
2249 value = entry->plvalue;
2250 changed = 1;
2251 wwarning(_("using default \"%s\" instead"), entry->default_value);
2252 goto again;
2256 texture = parse_texture(scr, value);
2258 if (!texture) {
2259 wwarning(_("Error in texture specification for key \"%s\""),
2260 entry->key);
2261 if (changed==0) {
2262 value = entry->plvalue;
2263 changed = 1;
2264 wwarning(_("using default \"%s\" instead"), entry->default_value);
2265 goto again;
2267 return False;
2270 if (ret)
2271 *ret = &texture;
2273 if (addr)
2274 *(WTexture**)addr = texture;
2276 return True;
2280 static int
2281 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2282 void *addr, void **ret)
2284 WMPropList *elem;
2285 int changed = 0;
2286 char *val;
2287 int nelem;
2289 again:
2290 if (!WMIsPLArray(value)) {
2291 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2292 "WorkspaceBack", "Texture or None");
2293 if (changed==0) {
2294 value = entry->plvalue;
2295 changed = 1;
2296 wwarning(_("using default \"%s\" instead"), entry->default_value);
2297 goto again;
2299 return False;
2302 /* only do basic error checking and verify for None texture */
2304 nelem = WMGetPropListItemCount(value);
2305 if (nelem > 0) {
2306 elem = WMGetFromPLArray(value, 0);
2307 if (!elem || !WMIsPLString(elem)) {
2308 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2309 if (changed==0) {
2310 value = entry->plvalue;
2311 changed = 1;
2312 wwarning(_("using default \"%s\" instead"), entry->default_value);
2313 goto again;
2315 return False;
2317 val = WMGetFromPLString(elem);
2319 if (strcasecmp(val, "None")==0)
2320 return True;
2322 *ret = WMRetainPropList(value);
2324 return True;
2328 static int
2329 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2330 void *addr, void **ret)
2332 WMPropList *elem;
2333 int nelem;
2334 int changed = 0;
2336 again:
2337 if (!WMIsPLArray(value)) {
2338 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2339 "WorkspaceSpecificBack", "an array of textures");
2340 if (changed==0) {
2341 value = entry->plvalue;
2342 changed = 1;
2343 wwarning(_("using default \"%s\" instead"), entry->default_value);
2344 goto again;
2346 return False;
2349 /* only do basic error checking and verify for None texture */
2351 nelem = WMGetPropListItemCount(value);
2352 if (nelem > 0) {
2353 while (nelem--) {
2354 elem = WMGetFromPLArray(value, nelem);
2355 if (!elem || !WMIsPLArray(elem)) {
2356 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2357 nelem);
2362 *ret = WMRetainPropList(value);
2364 #ifdef notworking
2366 * Kluge to force wmsetbg helper to set the default background.
2367 * If the WorkspaceSpecificBack is changed once wmaker has started,
2368 * the WorkspaceBack won't be sent to the helper, unless the user
2369 * changes it's value too. So, we must force this by removing the
2370 * value from the defaults DB.
2372 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2373 WMPropList *key = WMCreatePLString("WorkspaceBack");
2375 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2377 WMReleasePropList(key);
2379 #endif
2380 return True;
2384 static int
2385 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2386 void **ret)
2388 static WMFont *font;
2389 char *val;
2391 GET_STRING_OR_DEFAULT("Font", val);
2393 font = WMCreateFont(scr->wmscreen, val);
2394 if (!font)
2395 font = WMCreateFont(scr->wmscreen, "fixed");
2397 if (!font) {
2398 wfatal(_("could not load any usable font!!!"));
2399 exit(1);
2402 if (ret)
2403 *ret = font;
2405 /* can't assign font value outside update function */
2406 wassertrv(addr == NULL, True);
2408 return True;
2412 static int
2413 getColor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2414 void **ret)
2416 static XColor color;
2417 char *val;
2418 int second_pass=0;
2420 GET_STRING_OR_DEFAULT("Color", val);
2423 again:
2424 if (!wGetColor(scr, val, &color)) {
2425 wwarning(_("could not get color for key \"%s\""),
2426 entry->key);
2427 if (second_pass==0) {
2428 val = WMGetFromPLString(entry->plvalue);
2429 second_pass = 1;
2430 wwarning(_("using default \"%s\" instead"), val);
2431 goto again;
2433 return False;
2436 if (ret)
2437 *ret = &color;
2439 assert(addr==NULL);
2441 if (addr)
2442 *(unsigned long*)addr = pixel;
2445 return True;
2450 static int
2451 getKeybind(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2452 void **ret)
2454 static WShortKey shortcut;
2455 KeySym ksym;
2456 char *val;
2457 char *k;
2458 char buf[128], *b;
2461 GET_STRING_OR_DEFAULT("Key spec", val);
2463 if (!val || strcasecmp(val, "NONE")==0) {
2464 shortcut.keycode = 0;
2465 shortcut.modifier = 0;
2466 if (ret)
2467 *ret = &shortcut;
2468 return True;
2471 strcpy(buf, val);
2473 b = (char*)buf;
2475 /* get modifiers */
2476 shortcut.modifier = 0;
2477 while ((k = strchr(b, '+'))!=NULL) {
2478 int mod;
2480 *k = 0;
2481 mod = wXModifierFromKey(b);
2482 if (mod<0) {
2483 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2484 return False;
2486 shortcut.modifier |= mod;
2488 b = k+1;
2491 /* get key */
2492 ksym = XStringToKeysym(b);
2494 if (ksym==NoSymbol) {
2495 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2496 val);
2497 return False;
2500 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2501 if (shortcut.keycode==0) {
2502 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2503 return False;
2506 if (ret)
2507 *ret = &shortcut;
2509 return True;
2513 static int
2514 getModMask(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2515 void **ret)
2517 static unsigned int mask;
2518 char *str;
2520 GET_STRING_OR_DEFAULT("Modifier Key", str);
2522 if (!str)
2523 return False;
2525 mask = wXModifierFromKey(str);
2526 if (mask < 0) {
2527 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2528 mask = 0;
2529 return False;
2532 if (addr)
2533 *(unsigned int*)addr = mask;
2535 if (ret)
2536 *ret = &mask;
2538 return True;
2542 #ifdef NEWSTUFF
2543 static int
2544 getRImages(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2545 void *addr, void **ret)
2547 unsigned int mask;
2548 char *str;
2549 RImage *image;
2550 int i, n;
2551 int w, h;
2553 GET_STRING_OR_DEFAULT("Image File Path", str);
2554 if (!str)
2555 return False;
2557 image = RLoadImage(scr->rcontext, str, 0);
2558 if (!image) {
2559 wwarning(_("could not load image in option %s: %s"), entry->key,
2560 RMessageForError(RErrorCode));
2561 return False;
2564 if (*(RImage**)addr) {
2565 RReleaseImage(*(RImage**)addr);
2567 if (addr)
2568 *(RImage**)addr = image;
2570 assert(ret == NULL);
2572 if (ret)
2573 *(RImage**)ret = image;
2576 return True;
2578 #endif
2580 # include <X11/cursorfont.h>
2581 typedef struct
2583 char *name;
2584 int id;
2585 } WCursorLookup;
2587 #define CURSOR_ID_NONE (XC_num_glyphs)
2589 static WCursorLookup cursor_table[] =
2591 { "X_cursor", XC_X_cursor },
2592 { "arrow", XC_arrow },
2593 { "based_arrow_down", XC_based_arrow_down },
2594 { "based_arrow_up", XC_based_arrow_up },
2595 { "boat", XC_boat },
2596 { "bogosity", XC_bogosity },
2597 { "bottom_left_corner", XC_bottom_left_corner },
2598 { "bottom_right_corner", XC_bottom_right_corner },
2599 { "bottom_side", XC_bottom_side },
2600 { "bottom_tee", XC_bottom_tee },
2601 { "box_spiral", XC_box_spiral },
2602 { "center_ptr", XC_center_ptr },
2603 { "circle", XC_circle },
2604 { "clock", XC_clock },
2605 { "coffee_mug", XC_coffee_mug },
2606 { "cross", XC_cross },
2607 { "cross_reverse", XC_cross_reverse },
2608 { "crosshair", XC_crosshair },
2609 { "diamond_cross", XC_diamond_cross },
2610 { "dot", XC_dot },
2611 { "dotbox", XC_dotbox },
2612 { "double_arrow", XC_double_arrow },
2613 { "draft_large", XC_draft_large },
2614 { "draft_small", XC_draft_small },
2615 { "draped_box", XC_draped_box },
2616 { "exchange", XC_exchange },
2617 { "fleur", XC_fleur },
2618 { "gobbler", XC_gobbler },
2619 { "gumby", XC_gumby },
2620 { "hand1", XC_hand1 },
2621 { "hand2", XC_hand2 },
2622 { "heart", XC_heart },
2623 { "icon", XC_icon },
2624 { "iron_cross", XC_iron_cross },
2625 { "left_ptr", XC_left_ptr },
2626 { "left_side", XC_left_side },
2627 { "left_tee", XC_left_tee },
2628 { "leftbutton", XC_leftbutton },
2629 { "ll_angle", XC_ll_angle },
2630 { "lr_angle", XC_lr_angle },
2631 { "man", XC_man },
2632 { "middlebutton", XC_middlebutton },
2633 { "mouse", XC_mouse },
2634 { "pencil", XC_pencil },
2635 { "pirate", XC_pirate },
2636 { "plus", XC_plus },
2637 { "question_arrow", XC_question_arrow },
2638 { "right_ptr", XC_right_ptr },
2639 { "right_side", XC_right_side },
2640 { "right_tee", XC_right_tee },
2641 { "rightbutton", XC_rightbutton },
2642 { "rtl_logo", XC_rtl_logo },
2643 { "sailboat", XC_sailboat },
2644 { "sb_down_arrow", XC_sb_down_arrow },
2645 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2646 { "sb_left_arrow", XC_sb_left_arrow },
2647 { "sb_right_arrow", XC_sb_right_arrow },
2648 { "sb_up_arrow", XC_sb_up_arrow },
2649 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2650 { "shuttle", XC_shuttle },
2651 { "sizing", XC_sizing },
2652 { "spider", XC_spider },
2653 { "spraycan", XC_spraycan },
2654 { "star", XC_star },
2655 { "target", XC_target },
2656 { "tcross", XC_tcross },
2657 { "top_left_arrow", XC_top_left_arrow },
2658 { "top_left_corner", XC_top_left_corner },
2659 { "top_right_corner", XC_top_right_corner },
2660 { "top_side", XC_top_side },
2661 { "top_tee", XC_top_tee },
2662 { "trek", XC_trek },
2663 { "ul_angle", XC_ul_angle },
2664 { "umbrella", XC_umbrella },
2665 { "ur_angle", XC_ur_angle },
2666 { "watch", XC_watch },
2667 { "xterm", XC_xterm },
2668 { NULL, CURSOR_ID_NONE }
2671 static void
2672 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2674 switch(status) {
2675 case BitmapOpenFailed:
2676 wwarning(_("failed to open bitmap file \"%s\""), filename);
2677 break;
2678 case BitmapFileInvalid:
2679 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2680 break;
2681 case BitmapNoMemory:
2682 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2683 break;
2684 case BitmapSuccess:
2685 XFreePixmap(dpy, bitmap);
2686 break;
2691 * (none)
2692 * (builtin, <cursor_name>)
2693 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2695 static int
2696 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2698 WMPropList *elem;
2699 char *val;
2700 int nelem;
2701 int status = 0;
2703 nelem = WMGetPropListItemCount(pl);
2704 if (nelem < 1) {
2705 return(status);
2707 elem = WMGetFromPLArray(pl, 0);
2708 if (!elem || !WMIsPLString(elem)) {
2709 return(status);
2711 val = WMGetFromPLString(elem);
2713 if (0 == strcasecmp(val, "none")) {
2714 status = 1;
2715 *cursor = None;
2716 } else if (0 == strcasecmp(val, "builtin")) {
2717 int i;
2718 int cursor_id = CURSOR_ID_NONE;
2720 if (2 != nelem) {
2721 wwarning(_("bad number of arguments in cursor specification"));
2722 return(status);
2724 elem = WMGetFromPLArray(pl, 1);
2725 if (!elem || !WMIsPLString(elem)) {
2726 return(status);
2728 val = WMGetFromPLString(elem);
2730 for (i = 0; NULL != cursor_table[i].name; i++) {
2731 if (0 == strcasecmp(val, cursor_table[i].name)) {
2732 cursor_id = cursor_table[i].id;
2733 break;
2736 if (CURSOR_ID_NONE == cursor_id) {
2737 wwarning(_("unknown builtin cursor name \"%s\""), val);
2738 } else {
2739 *cursor = XCreateFontCursor(dpy, cursor_id);
2740 status = 1;
2742 } else if (0 == strcasecmp(val, "bitmap")) {
2743 char *bitmap_name;
2744 char *mask_name;
2745 int bitmap_status;
2746 int mask_status;
2747 Pixmap bitmap;
2748 Pixmap mask;
2749 unsigned int w, h;
2750 int x, y;
2751 XColor fg, bg;
2753 if (3 != nelem) {
2754 wwarning(_("bad number of arguments in cursor specification"));
2755 return(status);
2757 elem = WMGetFromPLArray(pl, 1);
2758 if (!elem || !WMIsPLString(elem)) {
2759 return(status);
2761 val = WMGetFromPLString(elem);
2762 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2763 if (!bitmap_name) {
2764 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2765 return(status);
2767 elem = WMGetFromPLArray(pl, 2);
2768 if (!elem || !WMIsPLString(elem)) {
2769 wfree(bitmap_name);
2770 return(status);
2772 val = WMGetFromPLString(elem);
2773 mask_name = FindImage(wPreferences.pixmap_path, val);
2774 if (!mask_name) {
2775 wfree(bitmap_name);
2776 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2777 return(status);
2779 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2780 &mask, &x, &y);
2781 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2782 &bitmap, &x, &y);
2783 if ((BitmapSuccess == bitmap_status) &&
2784 (BitmapSuccess == mask_status)) {
2785 fg.pixel = scr->black_pixel;
2786 bg.pixel = scr->white_pixel;
2787 XQueryColor(dpy, scr->w_colormap, &fg);
2788 XQueryColor(dpy, scr->w_colormap, &bg);
2789 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2790 status = 1;
2792 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2793 check_bitmap_status(mask_status, mask_name, mask);
2794 wfree(bitmap_name);
2795 wfree(mask_name);
2797 return(status);
2801 static int
2802 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2803 void **ret)
2805 static Cursor cursor;
2806 int status;
2807 int changed = 0;
2809 again:
2810 if (!WMIsPLArray(value)) {
2811 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2812 entry->key, "cursor specification");
2813 if (!changed) {
2814 value = entry->plvalue;
2815 changed = 1;
2816 wwarning(_("using default \"%s\" instead"), entry->default_value);
2817 goto again;
2819 return(False);
2821 status = parse_cursor(scr, value, &cursor);
2822 if (!status) {
2823 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2824 if (!changed) {
2825 value = entry->plvalue;
2826 changed = 1;
2827 wwarning(_("using default \"%s\" instead"), entry->default_value);
2828 goto again;
2830 return(False);
2832 if (ret) {
2833 *ret = &cursor;
2835 if (addr) {
2836 *(Cursor *)addr = cursor;
2838 return(True);
2840 #undef CURSOR_ID_NONE
2843 /* ---------------- value setting functions --------------- */
2844 static int
2845 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2847 return REFRESH_WINDOW_TITLE_COLOR;
2850 static int
2851 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2853 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2856 static int
2857 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2859 switch (which) {
2860 case WM_DOCK:
2861 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2862 break;
2863 case WM_CLIP:
2864 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2865 break;
2866 default:
2867 break;
2869 return 0;
2873 static int
2874 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2876 if (scr->workspaces) {
2877 wWorkspaceForceChange(scr, scr->current_workspace);
2878 wArrangeIcons(scr, False);
2880 return 0;
2883 #if not_used
2884 static int
2885 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2887 if (*value <= 0)
2888 *(int*)foo = 1;
2890 return 0;
2892 #endif
2896 static int
2897 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2899 Pixmap pixmap;
2900 RImage *img;
2901 int reset = 0;
2903 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2904 wPreferences.icon_size,
2905 ((*texture)->any.type & WREL_BORDER_MASK)
2906 ? WREL_ICON : WREL_FLAT);
2907 if (!img) {
2908 wwarning(_("could not render texture for icon background"));
2909 if (!entry->addr)
2910 wTextureDestroy(scr, *texture);
2911 return 0;
2913 RConvertImage(scr->rcontext, img, &pixmap);
2915 if (scr->icon_tile) {
2916 reset = 1;
2917 RReleaseImage(scr->icon_tile);
2918 XFreePixmap(dpy, scr->icon_tile_pixmap);
2921 scr->icon_tile = img;
2924 /* put the icon in the noticeboard hint */
2925 PropSetIconTileHint(scr, img);
2928 if (!wPreferences.flags.noclip) {
2929 if (scr->clip_tile) {
2930 RReleaseImage(scr->clip_tile);
2932 scr->clip_tile = wClipMakeTile(scr, img);
2935 scr->icon_tile_pixmap = pixmap;
2937 if (scr->def_icon_pixmap) {
2938 XFreePixmap(dpy, scr->def_icon_pixmap);
2939 scr->def_icon_pixmap = None;
2941 if (scr->def_ticon_pixmap) {
2942 XFreePixmap(dpy, scr->def_ticon_pixmap);
2943 scr->def_ticon_pixmap = None;
2946 if (scr->icon_back_texture) {
2947 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2949 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2951 if (scr->clip_balloon)
2952 XSetWindowBackground(dpy, scr->clip_balloon,
2953 (*texture)->any.color.pixel);
2956 * Free the texture as nobody else will use it, nor refer to it.
2958 if (!entry->addr)
2959 wTextureDestroy(scr, *texture);
2961 return (reset ? REFRESH_ICON_TILE : 0);
2966 static int
2967 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2969 if (scr->title_font) {
2970 WMReleaseFont(scr->title_font);
2972 scr->title_font = font;
2974 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2978 static int
2979 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2981 if (scr->menu_title_font) {
2982 WMReleaseFont(scr->menu_title_font);
2985 scr->menu_title_font = font;
2987 return REFRESH_MENU_TITLE_FONT;
2991 static int
2992 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2994 if (scr->menu_entry_font) {
2995 WMReleaseFont(scr->menu_entry_font);
2997 scr->menu_entry_font = font;
2999 return REFRESH_MENU_FONT;
3004 static int
3005 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3007 if (scr->icon_title_font) {
3008 WMReleaseFont(scr->icon_title_font);
3011 scr->icon_title_font = font;
3013 return REFRESH_ICON_FONT;
3017 static int
3018 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3020 if (scr->clip_title_font) {
3021 WMReleaseFont(scr->clip_title_font);
3024 scr->clip_title_font = font;
3026 return REFRESH_ICON_FONT;
3030 static int
3031 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3033 if (scr->workspace_name_font) {
3034 WMReleaseFont(scr->workspace_name_font);
3037 scr->workspace_name_font = font;
3039 return 0;
3043 static int
3044 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3046 if (scr->select_color)
3047 WMReleaseColor(scr->select_color);
3049 scr->select_color =
3050 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3051 color->blue, True);
3053 wFreeColor(scr, color->pixel);
3055 return REFRESH_MENU_COLOR;
3059 static int
3060 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3062 if (scr->select_text_color)
3063 WMReleaseColor(scr->select_text_color);
3065 scr->select_text_color =
3066 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3067 color->blue, True);
3069 wFreeColor(scr, color->pixel);
3071 return REFRESH_MENU_COLOR;
3075 static int
3076 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3078 if (scr->clip_title_color[index])
3079 WMReleaseColor(scr->clip_title_color[index]);
3080 scr->clip_title_color[index] = WMCreateRGBColor(scr->wmscreen, color->red,
3081 color->green, color->blue,
3082 True);
3083 #ifdef GRADIENT_CLIP_ARROW
3084 if (index == CLIP_NORMAL) {
3085 RImage *image;
3086 RColor color1, color2;
3087 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3088 int as = pt - 15; /* 15 = 5+5+5 */
3090 FREE_PIXMAP(scr->clip_arrow_gradient);
3092 color1.red = (color->red >> 8)*6/10;
3093 color1.green = (color->green >> 8)*6/10;
3094 color1.blue = (color->blue >> 8)*6/10;
3096 color2.red = WMIN((color->red >> 8)*20/10, 255);
3097 color2.green = WMIN((color->green >> 8)*20/10, 255);
3098 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3100 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3101 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3102 RReleaseImage(image);
3104 #endif /* GRADIENT_CLIP_ARROW */
3106 wFreeColor(scr, color->pixel);
3108 return REFRESH_ICON_TITLE_COLOR;
3112 static int
3113 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3115 if (scr->window_title_color[index])
3116 WMReleaseColor(scr->window_title_color[index]);
3118 scr->window_title_color[index] =
3119 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue,
3120 True);
3122 wFreeColor(scr, color->pixel);
3124 return REFRESH_WINDOW_TITLE_COLOR;
3128 static int
3129 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3131 if (scr->menu_title_color[0])
3132 WMReleaseColor(scr->menu_title_color[0]);
3134 scr->menu_title_color[0] =
3135 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3136 color->blue, True);
3138 wFreeColor(scr, color->pixel);
3140 return REFRESH_MENU_TITLE_COLOR;
3144 static int
3145 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3147 if (scr->mtext_color)
3148 WMReleaseColor(scr->mtext_color);
3150 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3151 color->green, color->blue, True);
3153 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3154 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3155 } else {
3156 WMSetColorAlpha(scr->dtext_color, 0xffff);
3159 wFreeColor(scr, color->pixel);
3161 return REFRESH_MENU_COLOR;
3165 static int
3166 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3168 if (scr->dtext_color)
3169 WMReleaseColor(scr->dtext_color);
3171 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3172 color->green, color->blue, True);
3174 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3175 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3176 } else {
3177 WMSetColorAlpha(scr->dtext_color, 0xffff);
3180 wFreeColor(scr, color->pixel);
3182 return REFRESH_MENU_COLOR;
3186 static int
3187 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3189 if (scr->icon_title_color)
3190 WMReleaseColor(scr->icon_title_color);
3191 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red,
3192 color->green, color->blue,
3193 True);
3195 wFreeColor(scr, color->pixel);
3197 return REFRESH_ICON_TITLE_COLOR;
3201 static int
3202 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3204 if (scr->icon_title_texture) {
3205 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3207 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3209 return REFRESH_ICON_TITLE_BACK;
3213 static void
3214 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3216 close(scr->helper_fd);
3217 scr->helper_fd = 0;
3218 scr->helper_pid = 0;
3219 scr->flags.backimage_helper_launched = 0;
3223 static int
3224 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3225 void *bar)
3227 WMPropList *val;
3228 char *str;
3229 int i;
3231 if (scr->flags.backimage_helper_launched) {
3232 if (WMGetPropListItemCount(value)==0) {
3233 SendHelperMessage(scr, 'C', 0, NULL);
3234 SendHelperMessage(scr, 'K', 0, NULL);
3236 WMReleasePropList(value);
3237 return 0;
3239 } else {
3240 pid_t pid;
3241 int filedes[2];
3243 if (WMGetPropListItemCount(value) == 0)
3244 return 0;
3246 if (pipe(filedes) < 0) {
3247 wsyserror("pipe() failed:can't set workspace specific background image");
3249 WMReleasePropList(value);
3250 return 0;
3253 pid = fork();
3254 if (pid < 0) {
3255 wsyserror("fork() failed:can't set workspace specific background image");
3256 if (close(filedes[0]) < 0)
3257 wsyserror("could not close pipe");
3258 if (close(filedes[1]) < 0)
3259 wsyserror("could not close pipe");
3261 } else if (pid == 0) {
3262 char *dither;
3264 SetupEnvironment(scr);
3266 if (close(0) < 0)
3267 wsyserror("could not close pipe");
3268 if (dup(filedes[0]) < 0) {
3269 wsyserror("dup() failed:can't set workspace specific background image");
3271 dither = wPreferences.no_dithering ? "-m" : "-d";
3272 if (wPreferences.smooth_workspace_back)
3273 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3274 else
3275 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3276 wsyserror("could not execute wmsetbg");
3277 exit(1);
3278 } else {
3280 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3281 wsyserror("error setting close-on-exec flag");
3283 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3284 wsyserror("error setting close-on-exec flag");
3287 scr->helper_fd = filedes[1];
3288 scr->helper_pid = pid;
3289 scr->flags.backimage_helper_launched = 1;
3291 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3293 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3298 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3299 val = WMGetFromPLArray(value, i);
3300 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3301 str = WMGetPropListDescription(val, False);
3303 SendHelperMessage(scr, 'S', i+1, str);
3305 wfree(str);
3306 } else {
3307 SendHelperMessage(scr, 'U', i+1, NULL);
3310 sleep(1);
3312 WMReleasePropList(value);
3313 return 0;
3317 static int
3318 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3319 void *bar)
3321 if (scr->flags.backimage_helper_launched) {
3322 char *str;
3324 if (WMGetPropListItemCount(value)==0) {
3325 SendHelperMessage(scr, 'U', 0, NULL);
3326 } else {
3327 /* set the default workspace background to this one */
3328 str = WMGetPropListDescription(value, False);
3329 if (str) {
3330 SendHelperMessage(scr, 'S', 0, str);
3331 wfree(str);
3332 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3333 } else {
3334 SendHelperMessage(scr, 'U', 0, NULL);
3337 } else if (WMGetPropListItemCount(value) > 0) {
3338 char *command;
3339 char *text;
3340 char *dither;
3341 int len;
3343 SetupEnvironment(scr);
3344 text = WMGetPropListDescription(value, False);
3345 len = strlen(text)+40;
3346 command = wmalloc(len);
3347 dither = wPreferences.no_dithering ? "-m" : "-d";
3348 if (wPreferences.smooth_workspace_back)
3349 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3350 else
3351 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3352 wfree(text);
3353 system(command);
3354 wfree(command);
3356 WMReleasePropList(value);
3358 return 0;
3362 #ifdef VIRTUAL_DESKTOP
3363 static int
3364 setVirtualEdgeThickness(WScreen *scr, WDefaultEntry *entry, int *value, void *dummy)
3366 wWorkspaceUpdateEdge(scr);
3367 return 0;
3369 #endif
3372 static int
3373 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3375 if (scr->widget_texture) {
3376 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3378 scr->widget_texture = *(WTexSolid**)texture;
3380 return 0;
3384 static int
3385 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3387 if (scr->window_title_texture[WS_FOCUSED]) {
3388 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3390 scr->window_title_texture[WS_FOCUSED] = *texture;
3392 return REFRESH_WINDOW_TEXTURES;
3396 static int
3397 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3399 if (scr->window_title_texture[WS_PFOCUSED]) {
3400 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3402 scr->window_title_texture[WS_PFOCUSED] = *texture;
3404 return REFRESH_WINDOW_TEXTURES;
3408 static int
3409 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3411 if (scr->window_title_texture[WS_UNFOCUSED]) {
3412 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3414 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3416 return REFRESH_WINDOW_TEXTURES;
3420 static int
3421 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3423 if (scr->resizebar_texture[0]) {
3424 wTextureDestroy(scr, scr->resizebar_texture[0]);
3426 scr->resizebar_texture[0] = *texture;
3428 return REFRESH_WINDOW_TEXTURES;
3432 static int
3433 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3435 if (scr->menu_title_texture[0]) {
3436 wTextureDestroy(scr, scr->menu_title_texture[0]);
3438 scr->menu_title_texture[0] = *texture;
3440 return REFRESH_MENU_TITLE_TEXTURE;
3444 static int
3445 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3447 if (scr->menu_item_texture) {
3448 wTextureDestroy(scr, scr->menu_item_texture);
3449 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3451 scr->menu_item_texture = *texture;
3453 scr->menu_item_auxtexture
3454 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3456 return REFRESH_MENU_TEXTURE;
3460 static int
3461 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3463 WWindow *wwin;
3464 wKeyBindings[index] = *shortcut;
3466 wwin = scr->focused_window;
3468 while (wwin!=NULL) {
3469 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3471 if (!WFLAGP(wwin, no_bind_keys)) {
3472 wWindowSetKeyGrabs(wwin);
3474 wwin = wwin->prev;
3477 return 0;
3481 static int
3482 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3484 wScreenUpdateUsableArea(scr);
3485 wArrangeIcons(scr, True);
3487 return 0;
3491 static int
3492 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3494 wScreenUpdateUsableArea(scr);
3496 return 0;
3500 static int
3501 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3503 return REFRESH_MENU_TEXTURE;
3508 static int
3509 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3511 return REFRESH_BUTTON_IMAGES;
3516 * Very ugly kluge.
3517 * Need access to the double click variables, so that all widgets in
3518 * wmaker panels will have the same dbl-click values.
3519 * TODO: figure a better way of dealing with it.
3521 #include <WINGs/WINGsP.h>
3523 static int
3524 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3526 extern _WINGsConfiguration WINGsConfiguration;
3528 if (*value <= 0)
3529 *(int*)foo = 1;
3531 WINGsConfiguration.doubleClickDelay = *value;
3533 return 0;
3537 #if 0
3538 static int
3539 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3541 extern _WINGsConfiguration WINGsConfiguration;
3543 WINGsConfiguration.useMultiByte = *value;
3545 return 0;
3547 #endif
3550 static int
3551 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3553 if (wCursor[index] != None) {
3554 XFreeCursor(dpy, wCursor[index]);
3557 wCursor[index] = *cursor;
3559 if (index==WCUR_ROOT && *cursor!=None) {
3560 XDefineCursor(dpy, scr->root_win, *cursor);
3563 return 0;