code review
[wmaker-crm.git] / src / defaults.c
blobf3334911ed01a90acea087c7d2df64b4907faebe
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;
953 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
954 static void prependMenu(WMPropList *destarr, WMPropList *array)
956 WMPropList *item;
957 int i;
959 for (i=0; i<WMGetPropListItemCount(array); i++) {
960 item = WMGetFromPLArray(array, i);
961 if (item)
962 WMInsertInPLArray(destarr, i+1, item);
966 static void 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 wDefaultsMergeGlobalMenus(WDDomain *menuDomain)
982 WMPropList *menu = menuDomain->dictionary;
983 WMPropList *submenu;
985 if (!menu || !WMIsPLArray(menu))
986 return;
988 #ifdef GLOBAL_PREAMBLE_MENU_FILE
989 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_PREAMBLE_MENU_FILE);
991 if (submenu && !WMIsPLArray(submenu)) {
992 wwarning(_("invalid global menu file %s"),
993 GLOBAL_PREAMBLE_MENU_FILE);
994 WMReleasePropList(submenu);
995 submenu = NULL;
997 if (submenu) {
998 prependMenu(menu, submenu);
999 WMReleasePropList(submenu);
1001 #endif
1003 #ifdef GLOBAL_EPILOGUE_MENU_FILE
1004 submenu = WMReadPropListFromFile(SYSCONFDIR"/WindowMaker/"GLOBAL_EPILOGUE_MENU_FILE);
1006 if (submenu && !WMIsPLArray(submenu)) {
1007 wwarning(_("invalid global menu file %s"),
1008 GLOBAL_EPILOGUE_MENU_FILE);
1009 WMReleasePropList(submenu);
1010 submenu = NULL;
1012 if (submenu) {
1013 appendMenu(menu, submenu);
1014 WMReleasePropList(submenu);
1016 #endif
1018 menuDomain->dictionary = menu;
1022 #if 0
1023 WMPropList*
1024 wDefaultsInit(int screen_number)
1026 static int defaults_inited = 0;
1027 WMPropList *dict;
1029 if (!defaults_inited) {
1030 initDefaults();
1033 dict = PLGetDomain(wDomainName);
1034 if (!dict) {
1035 wwarning(_("could not read domain \"%s\" from defaults database"),
1036 WMGetFromPLString(wDomainName));
1039 return dict;
1041 #endif
1044 void
1045 wDefaultsDestroyDomain(WDDomain *domain)
1047 if (domain->dictionary)
1048 WMReleasePropList(domain->dictionary);
1049 wfree(domain->path);
1050 wfree(domain);
1054 WDDomain*
1055 wDefaultsInitDomain(char *domain, Bool requireDictionary)
1057 WDDomain *db;
1058 struct stat stbuf;
1059 static int inited = 0;
1060 char path[PATH_MAX];
1061 char *the_path;
1062 WMPropList *shared_dict=NULL;
1064 if (!inited) {
1065 inited = 1;
1066 initDefaults();
1069 db = wmalloc(sizeof(WDDomain));
1070 memset(db, 0, sizeof(WDDomain));
1071 db->domain_name = domain;
1072 db->path = wdefaultspathfordomain(domain);
1073 the_path = db->path;
1075 if (the_path && stat(the_path, &stbuf)>=0) {
1076 db->dictionary = WMReadPropListFromFile(the_path);
1077 if (db->dictionary) {
1078 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
1079 WMReleasePropList(db->dictionary);
1080 db->dictionary = NULL;
1081 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1082 domain, the_path);
1084 db->timestamp = stbuf.st_mtime;
1085 } else {
1086 wwarning(_("could not load domain %s from user defaults database"),
1087 domain);
1091 /* global system dictionary */
1092 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
1093 if (stat(path, &stbuf)>=0) {
1094 shared_dict = WMReadPropListFromFile(path);
1095 if (shared_dict) {
1096 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
1097 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
1098 domain, path);
1099 WMReleasePropList(shared_dict);
1100 shared_dict = NULL;
1101 } else {
1102 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
1103 WMIsPLDictionary(db->dictionary)) {
1104 WMMergePLDictionaries(shared_dict, db->dictionary, True);
1105 WMReleasePropList(db->dictionary);
1106 db->dictionary = shared_dict;
1107 if (stbuf.st_mtime > db->timestamp)
1108 db->timestamp = stbuf.st_mtime;
1109 } else if (!db->dictionary) {
1110 db->dictionary = shared_dict;
1111 if (stbuf.st_mtime > db->timestamp)
1112 db->timestamp = stbuf.st_mtime;
1115 } else {
1116 wwarning(_("could not load domain %s from global defaults database (%s)"),
1117 domain, path);
1121 return db;
1125 void
1126 wReadStaticDefaults(WMPropList *dict)
1128 WMPropList *plvalue;
1129 WDefaultEntry *entry;
1130 int i;
1131 void *tdata;
1134 for (i=0; i<sizeof(staticOptionList)/sizeof(WDefaultEntry); i++) {
1135 entry = &staticOptionList[i];
1137 if (dict)
1138 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
1139 else
1140 plvalue = NULL;
1142 if (!plvalue) {
1143 /* no default in the DB. Use builtin default */
1144 plvalue = entry->plvalue;
1147 if (plvalue) {
1148 /* convert data */
1149 (*entry->convert)(NULL, entry, plvalue, entry->addr, &tdata);
1150 if (entry->update) {
1151 (*entry->update)(NULL, entry, tdata, entry->extra_data);
1159 void
1160 wDefaultsCheckDomains(void *foo)
1162 WScreen *scr;
1163 struct stat stbuf;
1164 WMPropList *shared_dict = NULL;
1165 WMPropList *dict;
1166 int i;
1168 #ifdef HEARTBEAT
1169 puts("Checking domains...");
1170 #endif
1171 if (stat(WDWindowMaker->path, &stbuf)>=0
1172 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1173 #ifdef HEARTBEAT
1174 puts("Checking WindowMaker domain");
1175 #endif
1176 WDWindowMaker->timestamp = stbuf.st_mtime;
1178 /* global dictionary */
1179 shared_dict = readGlobalDomain("WindowMaker", True);
1180 /* user dictionary */
1181 dict = WMReadPropListFromFile(WDWindowMaker->path);
1182 if (dict) {
1183 if (!WMIsPLDictionary(dict)) {
1184 WMReleasePropList(dict);
1185 dict = NULL;
1186 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1187 "WindowMaker", WDWindowMaker->path);
1188 } else {
1189 if (shared_dict) {
1190 WMMergePLDictionaries(shared_dict, dict, True);
1191 WMReleasePropList(dict);
1192 dict = shared_dict;
1193 shared_dict = NULL;
1195 for (i=0; i<wScreenCount; i++) {
1196 scr = wScreenWithNumber(i);
1197 if (scr)
1198 wReadDefaults(scr, dict);
1200 if (WDWindowMaker->dictionary) {
1201 WMReleasePropList(WDWindowMaker->dictionary);
1203 WDWindowMaker->dictionary = dict;
1205 } else {
1206 wwarning(_("could not load domain %s from user defaults database"),
1207 "WindowMaker");
1209 if (shared_dict) {
1210 WMReleasePropList(shared_dict);
1214 if (stat(WDWindowAttributes->path, &stbuf)>=0
1215 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1216 #ifdef HEARTBEAT
1217 puts("Checking WMWindowAttributes domain");
1218 #endif
1219 /* global dictionary */
1220 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1221 /* user dictionary */
1222 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1223 if (dict) {
1224 if (!WMIsPLDictionary(dict)) {
1225 WMReleasePropList(dict);
1226 dict = NULL;
1227 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1228 "WMWindowAttributes", WDWindowAttributes->path);
1229 } else {
1230 if (shared_dict) {
1231 WMMergePLDictionaries(shared_dict, dict, True);
1232 WMReleasePropList(dict);
1233 dict = shared_dict;
1234 shared_dict = NULL;
1236 if (WDWindowAttributes->dictionary) {
1237 WMReleasePropList(WDWindowAttributes->dictionary);
1239 WDWindowAttributes->dictionary = dict;
1240 for (i=0; i<wScreenCount; i++) {
1241 scr = wScreenWithNumber(i);
1242 if (scr) {
1243 RImage *image;
1245 wDefaultUpdateIcons(scr);
1247 /* Update the panel image if changed */
1248 /* Don't worry. If the image is the same these
1249 * functions will have no performance impact. */
1250 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1252 if (!image) {
1253 wwarning(_("could not load logo image for panels: %s"),
1254 RMessageForError(RErrorCode));
1255 } else {
1256 WMSetApplicationIconImage(scr->wmscreen, image);
1257 RReleaseImage(image);
1262 } else {
1263 wwarning(_("could not load domain %s from user defaults database"),
1264 "WMWindowAttributes");
1266 WDWindowAttributes->timestamp = stbuf.st_mtime;
1267 if (shared_dict) {
1268 WMReleasePropList(shared_dict);
1272 #ifndef LITE
1273 if (stat(WDRootMenu->path, &stbuf)>=0
1274 && WDRootMenu->timestamp < stbuf.st_mtime) {
1275 dict = WMReadPropListFromFile(WDRootMenu->path);
1276 #ifdef HEARTBEAT
1277 puts("Checking WMRootMenu domain");
1278 #endif
1279 if (dict) {
1280 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1281 WMReleasePropList(dict);
1282 dict = NULL;
1283 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1284 "WMRootMenu", WDRootMenu->path);
1285 } else {
1286 if (WDRootMenu->dictionary) {
1287 WMReleasePropList(WDRootMenu->dictionary);
1289 WDRootMenu->dictionary = dict;
1290 wDefaultsMergeGlobalMenus(WDRootMenu);
1292 } else {
1293 wwarning(_("could not load domain %s from user defaults database"),
1294 "WMRootMenu");
1296 WDRootMenu->timestamp = stbuf.st_mtime;
1298 #endif /* !LITE */
1300 if (!foo)
1301 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, foo);
1305 void
1306 wReadDefaults(WScreen *scr, WMPropList *new_dict)
1308 WMPropList *plvalue, *old_value;
1309 WDefaultEntry *entry;
1310 int i, must_update;
1311 int update_workspace_back = 0; /* kluge :/ */
1312 int needs_refresh;
1313 void *tdata;
1314 WMPropList *old_dict = (WDWindowMaker->dictionary!=new_dict
1315 ? WDWindowMaker->dictionary : NULL);
1317 must_update = 0;
1319 needs_refresh = 0;
1321 for (i=0; i<sizeof(optionList)/sizeof(WDefaultEntry); i++) {
1322 entry = &optionList[i];
1324 if (new_dict)
1325 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1326 else
1327 plvalue = NULL;
1329 if (!old_dict)
1330 old_value = NULL;
1331 else
1332 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1335 if (!plvalue && !old_value) {
1336 /* no default in the DB. Use builtin default */
1337 plvalue = entry->plvalue;
1338 if (plvalue && new_dict) {
1339 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1340 must_update = 1;
1342 } else if (!plvalue) {
1343 /* value was deleted from DB. Keep current value */
1344 continue;
1345 } else if (!old_value) {
1346 /* set value for the 1st time */
1347 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1348 /* value has changed */
1349 } else {
1351 if (strcmp(entry->key, "WorkspaceBack") == 0
1352 && update_workspace_back
1353 && scr->flags.backimage_helper_launched) {
1354 } else {
1355 /* value was not changed since last time */
1356 continue;
1360 if (plvalue) {
1361 #ifdef DEBUG
1362 printf("Updating %s to %s\n", entry->key,
1363 WMGetPropListDescription(plvalue, False));
1364 #endif
1365 /* convert data */
1366 if ((*entry->convert)(scr, entry, plvalue, entry->addr, &tdata)) {
1368 * If the WorkspaceSpecificBack data has been changed
1369 * so that the helper will be launched now, we must be
1370 * sure to send the default background texture config
1371 * to the helper.
1373 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1374 && !scr->flags.backimage_helper_launched) {
1375 update_workspace_back = 1;
1377 if (entry->update) {
1378 needs_refresh |=
1379 (*entry->update)(scr, entry, tdata, entry->extra_data);
1385 if (needs_refresh!=0 && !scr->flags.startup) {
1386 int foo;
1388 foo = 0;
1389 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1390 foo |= WTextureSettings;
1391 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1392 foo |= WFontSettings;
1393 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1394 foo |= WColorSettings;
1395 if (foo)
1396 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1397 (void*)foo);
1399 foo = 0;
1400 if (needs_refresh & REFRESH_MENU_TEXTURE)
1401 foo |= WTextureSettings;
1402 if (needs_refresh & REFRESH_MENU_FONT)
1403 foo |= WFontSettings;
1404 if (needs_refresh & REFRESH_MENU_COLOR)
1405 foo |= WColorSettings;
1406 if (foo)
1407 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
1408 (void*)foo);
1410 foo = 0;
1411 if (needs_refresh & REFRESH_WINDOW_FONT) {
1412 foo |= WFontSettings;
1414 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1415 foo |= WTextureSettings;
1417 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1418 foo |= WColorSettings;
1420 if (foo)
1421 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
1422 (void*)foo);
1424 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1425 foo = 0;
1426 if (needs_refresh & REFRESH_ICON_FONT) {
1427 foo |= WFontSettings;
1429 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1430 foo |= WTextureSettings;
1432 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1433 foo |= WTextureSettings;
1435 if (foo)
1436 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1437 (void*)foo);
1439 if (needs_refresh & REFRESH_ICON_TILE)
1440 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1445 void
1446 wDefaultUpdateIcons(WScreen *scr)
1448 WAppIcon *aicon = scr->app_icon_list;
1449 WWindow *wwin = scr->focused_window;
1450 char *file;
1452 while(aicon) {
1453 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class,
1454 False);
1455 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file)!=0)
1456 || (file && !aicon->icon->file)) {
1457 RImage *new_image;
1459 if (aicon->icon->file)
1460 wfree(aicon->icon->file);
1461 aicon->icon->file = wstrdup(file);
1463 new_image = wDefaultGetImage(scr, aicon->wm_instance,
1464 aicon->wm_class);
1465 if (new_image) {
1466 wIconChangeImage(aicon->icon, new_image);
1467 wAppIconPaint(aicon);
1470 aicon = aicon->next;
1473 if (!wPreferences.flags.noclip)
1474 wClipIconPaint(scr->clip_icon);
1476 while (wwin) {
1477 if (wwin->icon && wwin->flags.miniaturized) {
1478 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class,
1479 False);
1480 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file)!=0)
1481 || (file && !wwin->icon->file)) {
1482 RImage *new_image;
1484 if (wwin->icon->file)
1485 wfree(wwin->icon->file);
1486 wwin->icon->file = wstrdup(file);
1488 new_image = wDefaultGetImage(scr, wwin->wm_instance,
1489 wwin->wm_class);
1490 if (new_image)
1491 wIconChangeImage(wwin->icon, new_image);
1494 wwin = wwin->prev;
1499 /* --------------------------- Local ----------------------- */
1501 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1502 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1503 entry->key, x); \
1504 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1505 var = entry->default_value;\
1506 } else var = WMGetFromPLString(value)\
1512 static int
1513 string2index(WMPropList *key, WMPropList *val, char *def,
1514 WOptionEnumeration *values)
1516 char *str;
1517 WOptionEnumeration *v;
1518 char buffer[TOTAL_VALUES_LENGTH];
1520 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1521 for (v=values; v->string!=NULL; v++) {
1522 if (strcasecmp(v->string, str)==0)
1523 return v->value;
1527 buffer[0] = 0;
1528 for (v=values; v->string!=NULL; v++) {
1529 if (!v->is_alias) {
1530 if (buffer[0]!=0)
1531 strcat(buffer, ", ");
1532 strcat(buffer, v->string);
1535 wwarning(_("wrong option value for key \"%s\". Should be one of %s"),
1536 WMGetFromPLString(key), buffer);
1538 if (def) {
1539 return string2index(key, val, NULL, values);
1542 return -1;
1549 * value - is the value in the defaults DB
1550 * addr - is the address to store the data
1551 * ret - is the address to store a pointer to a temporary buffer. ret
1552 * must not be freed and is used by the set functions
1554 static int
1555 getBool(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1556 void **ret)
1558 static char data;
1559 char *val;
1560 int second_pass=0;
1562 GET_STRING_OR_DEFAULT("Boolean", val);
1564 again:
1565 if ((val[1]=='\0' && (val[0]=='y' || val[0]=='Y'))
1566 || strcasecmp(val, "YES")==0) {
1568 data = 1;
1569 } else if ((val[1]=='\0' && (val[0]=='n' || val[0]=='N'))
1570 || strcasecmp(val, "NO")==0) {
1571 data = 0;
1572 } else {
1573 int i;
1574 if (sscanf(val, "%i", &i)==1) {
1575 if (i!=0)
1576 data = 1;
1577 else
1578 data = 0;
1579 } else {
1580 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""),
1581 val, entry->key);
1582 if (second_pass==0) {
1583 val = WMGetFromPLString(entry->plvalue);
1584 second_pass = 1;
1585 wwarning(_("using default \"%s\" instead"), val);
1586 goto again;
1588 return False;
1592 if (ret)
1593 *ret = &data;
1595 if (addr) {
1596 *(char*)addr = data;
1599 return True;
1603 static int
1604 getInt(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1605 void **ret)
1607 static int data;
1608 char *val;
1611 GET_STRING_OR_DEFAULT("Integer", val);
1613 if (sscanf(val, "%i", &data)!=1) {
1614 wwarning(_("can't convert \"%s\" to integer for key \"%s\""),
1615 val, entry->key);
1616 val = WMGetFromPLString(entry->plvalue);
1617 wwarning(_("using default \"%s\" instead"), val);
1618 if (sscanf(val, "%i", &data)!=1) {
1619 return False;
1623 if (ret)
1624 *ret = &data;
1626 if (addr) {
1627 *(int*)addr = data;
1629 return True;
1633 static int
1634 getCoord(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1635 void **ret)
1637 static WCoord data;
1638 char *val_x, *val_y;
1639 int nelem, changed=0;
1640 WMPropList *elem_x, *elem_y;
1642 again:
1643 if (!WMIsPLArray(value)) {
1644 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1645 entry->key, "Coordinate");
1646 if (changed==0) {
1647 value = entry->plvalue;
1648 changed = 1;
1649 wwarning(_("using default \"%s\" instead"), entry->default_value);
1650 goto again;
1652 return False;
1655 nelem = WMGetPropListItemCount(value);
1656 if (nelem != 2) {
1657 wwarning(_("Incorrect number of elements in array for key \"%s\"."),
1658 entry->key);
1659 if (changed==0) {
1660 value = entry->plvalue;
1661 changed = 1;
1662 wwarning(_("using default \"%s\" instead"), entry->default_value);
1663 goto again;
1665 return False;
1668 elem_x = WMGetFromPLArray(value, 0);
1669 elem_y = WMGetFromPLArray(value, 1);
1671 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1672 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."),
1673 entry->key);
1674 if (changed==0) {
1675 value = entry->plvalue;
1676 changed = 1;
1677 wwarning(_("using default \"%s\" instead"), entry->default_value);
1678 goto again;
1680 return False;
1683 val_x = WMGetFromPLString(elem_x);
1684 val_y = WMGetFromPLString(elem_y);
1686 if (sscanf(val_x, "%i", &data.x)!=1 || sscanf(val_y, "%i", &data.y)!=1) {
1687 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1688 if (changed==0) {
1689 value = entry->plvalue;
1690 changed = 1;
1691 wwarning(_("using default \"%s\" instead"), entry->default_value);
1692 goto again;
1694 return False;
1697 if (data.x < 0)
1698 data.x = 0;
1699 else if (data.x > scr->scr_width/3)
1700 data.x = scr->scr_width/3;
1701 if (data.y < 0)
1702 data.y = 0;
1703 else if (data.y > scr->scr_height/3)
1704 data.y = scr->scr_height/3;
1706 if (ret)
1707 *ret = &data;
1709 if (addr) {
1710 *(WCoord*)addr = data;
1713 return True;
1717 #if 0
1718 /* This function is not used at the moment. */
1719 static int
1720 getString(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1721 void **ret)
1723 static char *data;
1725 GET_STRING_OR_DEFAULT("String", data);
1727 if (!data) {
1728 data = WMGetFromPLString(entry->plvalue);
1729 if (!data)
1730 return False;
1733 if (ret)
1734 *ret = &data;
1736 if (addr)
1737 *(char**)addr = wstrdup(data);
1739 return True;
1741 #endif
1744 static int
1745 getPathList(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1746 void **ret)
1748 static char *data;
1749 int i, count, len;
1750 char *ptr;
1751 WMPropList *d;
1752 int changed=0;
1754 again:
1755 if (!WMIsPLArray(value)) {
1756 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1757 entry->key, "an array of paths");
1758 if (changed==0) {
1759 value = entry->plvalue;
1760 changed = 1;
1761 wwarning(_("using default \"%s\" instead"), entry->default_value);
1762 goto again;
1764 return False;
1767 i = 0;
1768 count = WMGetPropListItemCount(value);
1769 if (count < 1) {
1770 if (changed==0) {
1771 value = entry->plvalue;
1772 changed = 1;
1773 wwarning(_("using default \"%s\" instead"), entry->default_value);
1774 goto again;
1776 return False;
1779 len = 0;
1780 for (i=0; i<count; i++) {
1781 d = WMGetFromPLArray(value, i);
1782 if (!d || !WMIsPLString(d)) {
1783 count = i;
1784 break;
1786 len += strlen(WMGetFromPLString(d))+1;
1789 ptr = data = wmalloc(len+1);
1791 for (i=0; i<count; i++) {
1792 d = WMGetFromPLArray(value, i);
1793 if (!d || !WMIsPLString(d)) {
1794 break;
1796 strcpy(ptr, WMGetFromPLString(d));
1797 ptr += strlen(WMGetFromPLString(d));
1798 *ptr = ':';
1799 ptr++;
1801 ptr--; *(ptr--) = 0;
1803 if (*(char**)addr!=NULL) {
1804 wfree(*(char**)addr);
1806 *(char**)addr = data;
1808 return True;
1812 static int
1813 getEnum(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
1814 void **ret)
1816 static signed char data;
1818 data = string2index(entry->plkey, value, entry->default_value,
1819 (WOptionEnumeration*)entry->extra_data);
1820 if (data < 0)
1821 return False;
1823 if (ret)
1824 *ret = &data;
1826 if (addr)
1827 *(signed char*)addr = data;
1829 return True;
1835 * (solid <color>)
1836 * (hgradient <color> <color>)
1837 * (vgradient <color> <color>)
1838 * (dgradient <color> <color>)
1839 * (mhgradient <color> <color> ...)
1840 * (mvgradient <color> <color> ...)
1841 * (mdgradient <color> <color> ...)
1842 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1843 * (tpixmap <file> <color>)
1844 * (spixmap <file> <color>)
1845 * (cpixmap <file> <color>)
1846 * (thgradient <file> <opaqueness> <color> <color>)
1847 * (tvgradient <file> <opaqueness> <color> <color>)
1848 * (tdgradient <file> <opaqueness> <color> <color>)
1849 * (function <lib> <function> ...)
1852 static WTexture*
1853 parse_texture(WScreen *scr, WMPropList *pl)
1855 WMPropList *elem;
1856 char *val;
1857 int nelem;
1858 WTexture *texture=NULL;
1860 nelem = WMGetPropListItemCount(pl);
1861 if (nelem < 1)
1862 return NULL;
1865 elem = WMGetFromPLArray(pl, 0);
1866 if (!elem || !WMIsPLString(elem))
1867 return NULL;
1868 val = WMGetFromPLString(elem);
1871 if (strcasecmp(val, "solid")==0) {
1872 XColor color;
1874 if (nelem != 2)
1875 return NULL;
1877 /* get color */
1879 elem = WMGetFromPLArray(pl, 1);
1880 if (!elem || !WMIsPLString(elem))
1881 return NULL;
1882 val = WMGetFromPLString(elem);
1884 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1885 wwarning(_("\"%s\" is not a valid color name"), val);
1886 return NULL;
1889 texture = (WTexture*)wTextureMakeSolid(scr, &color);
1890 } else if (strcasecmp(val, "dgradient")==0
1891 || strcasecmp(val, "vgradient")==0
1892 || strcasecmp(val, "hgradient")==0) {
1893 RColor color1, color2;
1894 XColor xcolor;
1895 int type;
1897 if (nelem != 3) {
1898 wwarning(_("bad number of arguments in gradient specification"));
1899 return NULL;
1902 if (val[0]=='d' || val[0]=='D')
1903 type = WTEX_DGRADIENT;
1904 else if (val[0]=='h' || val[0]=='H')
1905 type = WTEX_HGRADIENT;
1906 else
1907 type = WTEX_VGRADIENT;
1910 /* get from color */
1911 elem = WMGetFromPLArray(pl, 1);
1912 if (!elem || !WMIsPLString(elem))
1913 return NULL;
1914 val = WMGetFromPLString(elem);
1916 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1917 wwarning(_("\"%s\" is not a valid color name"), val);
1918 return NULL;
1920 color1.alpha = 255;
1921 color1.red = xcolor.red >> 8;
1922 color1.green = xcolor.green >> 8;
1923 color1.blue = xcolor.blue >> 8;
1925 /* get to color */
1926 elem = WMGetFromPLArray(pl, 2);
1927 if (!elem || !WMIsPLString(elem)) {
1928 return NULL;
1930 val = WMGetFromPLString(elem);
1932 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1933 wwarning(_("\"%s\" is not a valid color name"), val);
1934 return NULL;
1936 color2.alpha = 255;
1937 color2.red = xcolor.red >> 8;
1938 color2.green = xcolor.green >> 8;
1939 color2.blue = xcolor.blue >> 8;
1941 texture = (WTexture*)wTextureMakeGradient(scr, type, &color1, &color2);
1943 } else if (strcasecmp(val, "igradient")==0) {
1944 RColor colors1[2], colors2[2];
1945 int th1, th2;
1946 XColor xcolor;
1947 int i;
1949 if (nelem != 7) {
1950 wwarning(_("bad number of arguments in gradient specification"));
1951 return NULL;
1954 /* get from color */
1955 for (i = 0; i < 2; i++) {
1956 elem = WMGetFromPLArray(pl, 1+i);
1957 if (!elem || !WMIsPLString(elem))
1958 return NULL;
1959 val = WMGetFromPLString(elem);
1961 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1962 wwarning(_("\"%s\" is not a valid color name"), val);
1963 return NULL;
1965 colors1[i].alpha = 255;
1966 colors1[i].red = xcolor.red >> 8;
1967 colors1[i].green = xcolor.green >> 8;
1968 colors1[i].blue = xcolor.blue >> 8;
1970 elem = WMGetFromPLArray(pl, 3);
1971 if (!elem || !WMIsPLString(elem))
1972 return NULL;
1973 val = WMGetFromPLString(elem);
1974 th1 = atoi(val);
1977 /* get from color */
1978 for (i = 0; i < 2; i++) {
1979 elem = WMGetFromPLArray(pl, 4+i);
1980 if (!elem || !WMIsPLString(elem))
1981 return NULL;
1982 val = WMGetFromPLString(elem);
1984 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1985 wwarning(_("\"%s\" is not a valid color name"), val);
1986 return NULL;
1988 colors2[i].alpha = 255;
1989 colors2[i].red = xcolor.red >> 8;
1990 colors2[i].green = xcolor.green >> 8;
1991 colors2[i].blue = xcolor.blue >> 8;
1993 elem = WMGetFromPLArray(pl, 6);
1994 if (!elem || !WMIsPLString(elem))
1995 return NULL;
1996 val = WMGetFromPLString(elem);
1997 th2 = atoi(val);
1999 texture = (WTexture*)wTextureMakeIGradient(scr, th1, colors1,
2000 th2, colors2);
2002 } else if (strcasecmp(val, "mhgradient")==0
2003 || strcasecmp(val, "mvgradient")==0
2004 || strcasecmp(val, "mdgradient")==0) {
2005 XColor color;
2006 RColor **colors;
2007 int i, count;
2008 int type;
2010 if (nelem < 3) {
2011 wwarning(_("too few arguments in multicolor gradient specification"));
2012 return NULL;
2015 if (val[1]=='h' || val[1]=='H')
2016 type = WTEX_MHGRADIENT;
2017 else if (val[1]=='v' || val[1]=='V')
2018 type = WTEX_MVGRADIENT;
2019 else
2020 type = WTEX_MDGRADIENT;
2022 count = nelem-1;
2024 colors = wmalloc(sizeof(RColor*)*(count+1));
2026 for (i=0; i<count; i++) {
2027 elem = WMGetFromPLArray(pl, i+1);
2028 if (!elem || !WMIsPLString(elem)) {
2029 for (--i; i>=0; --i) {
2030 wfree(colors[i]);
2032 wfree(colors);
2033 return NULL;
2035 val = WMGetFromPLString(elem);
2037 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2038 wwarning(_("\"%s\" is not a valid color name"), val);
2039 for (--i; i>=0; --i) {
2040 wfree(colors[i]);
2042 wfree(colors);
2043 return NULL;
2044 } else {
2045 colors[i] = wmalloc(sizeof(RColor));
2046 colors[i]->red = color.red >> 8;
2047 colors[i]->green = color.green >> 8;
2048 colors[i]->blue = color.blue >> 8;
2051 colors[i] = NULL;
2053 texture = (WTexture*)wTextureMakeMGradient(scr, type, colors);
2054 } else if (strcasecmp(val, "spixmap")==0 ||
2055 strcasecmp(val, "cpixmap")==0 ||
2056 strcasecmp(val, "tpixmap")==0) {
2057 XColor color;
2058 int type;
2060 if (nelem != 3)
2061 return NULL;
2063 if (val[0] == 's' || val[0] == 'S')
2064 type = WTP_SCALE;
2065 else if (val[0] == 'c' || val[0] == 'C')
2066 type = WTP_CENTER;
2067 else
2068 type = WTP_TILE;
2070 /* get color */
2071 elem = WMGetFromPLArray(pl, 2);
2072 if (!elem || !WMIsPLString(elem)) {
2073 return NULL;
2075 val = WMGetFromPLString(elem);
2077 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
2078 wwarning(_("\"%s\" is not a valid color name"), val);
2079 return NULL;
2082 /* file name */
2083 elem = WMGetFromPLArray(pl, 1);
2084 if (!elem || !WMIsPLString(elem))
2085 return NULL;
2086 val = WMGetFromPLString(elem);
2088 texture = (WTexture*)wTextureMakePixmap(scr, type, val, &color);
2089 } else if (strcasecmp(val, "thgradient")==0
2090 || strcasecmp(val, "tvgradient")==0
2091 || strcasecmp(val, "tdgradient")==0) {
2092 RColor color1, color2;
2093 XColor xcolor;
2094 int opacity;
2095 int style;
2097 if (val[1]=='h' || val[1]=='H')
2098 style = WTEX_THGRADIENT;
2099 else if (val[1]=='v' || val[1]=='V')
2100 style = WTEX_TVGRADIENT;
2101 else
2102 style = WTEX_TDGRADIENT;
2104 if (nelem != 5) {
2105 wwarning(_("bad number of arguments in textured gradient specification"));
2106 return NULL;
2109 /* get from color */
2110 elem = WMGetFromPLArray(pl, 3);
2111 if (!elem || !WMIsPLString(elem))
2112 return NULL;
2113 val = WMGetFromPLString(elem);
2115 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2116 wwarning(_("\"%s\" is not a valid color name"), val);
2117 return NULL;
2119 color1.alpha = 255;
2120 color1.red = xcolor.red >> 8;
2121 color1.green = xcolor.green >> 8;
2122 color1.blue = xcolor.blue >> 8;
2124 /* get to color */
2125 elem = WMGetFromPLArray(pl, 4);
2126 if (!elem || !WMIsPLString(elem)) {
2127 return NULL;
2129 val = WMGetFromPLString(elem);
2131 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
2132 wwarning(_("\"%s\" is not a valid color name"), val);
2133 return NULL;
2135 color2.alpha = 255;
2136 color2.red = xcolor.red >> 8;
2137 color2.green = xcolor.green >> 8;
2138 color2.blue = xcolor.blue >> 8;
2140 /* get opacity */
2141 elem = WMGetFromPLArray(pl, 2);
2142 if (!elem || !WMIsPLString(elem))
2143 opacity = 128;
2144 else
2145 val = WMGetFromPLString(elem);
2147 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
2148 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
2149 opacity = 128;
2152 /* get file name */
2153 elem = WMGetFromPLArray(pl, 1);
2154 if (!elem || !WMIsPLString(elem))
2155 return NULL;
2156 val = WMGetFromPLString(elem);
2158 texture = (WTexture*)wTextureMakeTGradient(scr, style, &color1, &color2,
2159 val, opacity);
2161 #ifdef TEXTURE_PLUGIN
2162 else if (strcasecmp(val, "function")==0) {
2163 WTexFunction *function;
2164 void (*initFunc) (Display *, Colormap);
2165 char *lib, *func, **argv;
2166 int i, argc;
2168 if (nelem < 3)
2169 return NULL;
2171 /* get the library name */
2172 elem = WMGetFromPLArray(pl, 1);
2173 if (!elem || !WMIsPLString(elem)) {
2174 return NULL;
2176 lib = WMGetFromPLString(elem);
2178 /* get the function name */
2179 elem = WMGetFromPLArray(pl, 2);
2180 if (!elem || !WMIsPLString(elem)) {
2181 return NULL;
2183 func = WMGetFromPLString(elem);
2185 argc = nelem - 2;
2186 argv = (char **)wmalloc(argc * sizeof(char *));
2188 /* get the parameters */
2189 argv[0] = wstrdup(func);
2190 for (i = 0; i < argc - 1; i++) {
2191 elem = WMGetFromPLArray(pl, 3 + i);
2192 if (!elem || !WMIsPLString(elem)) {
2193 wfree(argv);
2195 return NULL;
2197 argv[i+1] = wstrdup(WMGetFromPLString(elem));
2200 function = wTextureMakeFunction(scr, lib, func, argc, argv);
2202 #ifdef HAVE_DLFCN_H
2203 if (function) {
2204 initFunc = dlsym(function->handle, "initWindowMaker");
2205 if (initFunc) {
2206 initFunc(dpy, scr->w_colormap);
2207 } else {
2208 wwarning(_("could not initialize library %s"), lib);
2210 } else {
2211 wwarning(_("could not find function %s::%s"), lib, func);
2213 #endif /* HAVE_DLFCN_H */
2214 texture = (WTexture*)function;
2216 #endif /* TEXTURE_PLUGIN */
2217 else {
2218 wwarning(_("invalid texture type %s"), val);
2219 return NULL;
2221 return texture;
2226 static int
2227 getTexture(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2228 void **ret)
2230 static WTexture *texture;
2231 int changed=0;
2233 again:
2234 if (!WMIsPLArray(value)) {
2235 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2236 entry->key, "Texture");
2237 if (changed==0) {
2238 value = entry->plvalue;
2239 changed = 1;
2240 wwarning(_("using default \"%s\" instead"), entry->default_value);
2241 goto again;
2243 return False;
2246 if (strcmp(entry->key, "WidgetColor")==0 && !changed) {
2247 WMPropList *pl;
2249 pl = WMGetFromPLArray(value, 0);
2250 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2251 || strcasecmp(WMGetFromPLString(pl), "solid")!=0) {
2252 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2253 entry->key, "Solid Texture");
2255 value = entry->plvalue;
2256 changed = 1;
2257 wwarning(_("using default \"%s\" instead"), entry->default_value);
2258 goto again;
2262 texture = parse_texture(scr, value);
2264 if (!texture) {
2265 wwarning(_("Error in texture specification for key \"%s\""),
2266 entry->key);
2267 if (changed==0) {
2268 value = entry->plvalue;
2269 changed = 1;
2270 wwarning(_("using default \"%s\" instead"), entry->default_value);
2271 goto again;
2273 return False;
2276 if (ret)
2277 *ret = &texture;
2279 if (addr)
2280 *(WTexture**)addr = texture;
2282 return True;
2286 static int
2287 getWSBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2288 void *addr, void **ret)
2290 WMPropList *elem;
2291 int changed = 0;
2292 char *val;
2293 int nelem;
2295 again:
2296 if (!WMIsPLArray(value)) {
2297 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2298 "WorkspaceBack", "Texture or None");
2299 if (changed==0) {
2300 value = entry->plvalue;
2301 changed = 1;
2302 wwarning(_("using default \"%s\" instead"), entry->default_value);
2303 goto again;
2305 return False;
2308 /* only do basic error checking and verify for None texture */
2310 nelem = WMGetPropListItemCount(value);
2311 if (nelem > 0) {
2312 elem = WMGetFromPLArray(value, 0);
2313 if (!elem || !WMIsPLString(elem)) {
2314 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2315 if (changed==0) {
2316 value = entry->plvalue;
2317 changed = 1;
2318 wwarning(_("using default \"%s\" instead"), entry->default_value);
2319 goto again;
2321 return False;
2323 val = WMGetFromPLString(elem);
2325 if (strcasecmp(val, "None")==0)
2326 return True;
2328 *ret = WMRetainPropList(value);
2330 return True;
2334 static int
2335 getWSSpecificBackground(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2336 void *addr, void **ret)
2338 WMPropList *elem;
2339 int nelem;
2340 int changed = 0;
2342 again:
2343 if (!WMIsPLArray(value)) {
2344 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2345 "WorkspaceSpecificBack", "an array of textures");
2346 if (changed==0) {
2347 value = entry->plvalue;
2348 changed = 1;
2349 wwarning(_("using default \"%s\" instead"), entry->default_value);
2350 goto again;
2352 return False;
2355 /* only do basic error checking and verify for None texture */
2357 nelem = WMGetPropListItemCount(value);
2358 if (nelem > 0) {
2359 while (nelem--) {
2360 elem = WMGetFromPLArray(value, nelem);
2361 if (!elem || !WMIsPLArray(elem)) {
2362 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2363 nelem);
2368 *ret = WMRetainPropList(value);
2370 #ifdef notworking
2372 * Kluge to force wmsetbg helper to set the default background.
2373 * If the WorkspaceSpecificBack is changed once wmaker has started,
2374 * the WorkspaceBack won't be sent to the helper, unless the user
2375 * changes it's value too. So, we must force this by removing the
2376 * value from the defaults DB.
2378 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2379 WMPropList *key = WMCreatePLString("WorkspaceBack");
2381 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2383 WMReleasePropList(key);
2385 #endif
2386 return True;
2390 static int
2391 getFont(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2392 void **ret)
2394 static WMFont *font;
2395 char *val;
2397 GET_STRING_OR_DEFAULT("Font", val);
2399 font = WMCreateFont(scr->wmscreen, val);
2400 if (!font)
2401 font = WMCreateFont(scr->wmscreen, "fixed");
2403 if (!font) {
2404 wfatal(_("could not load any usable font!!!"));
2405 exit(1);
2408 if (ret)
2409 *ret = font;
2411 /* can't assign font value outside update function */
2412 wassertrv(addr == NULL, True);
2414 return True;
2418 static int
2419 getColor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2420 void **ret)
2422 static XColor color;
2423 char *val;
2424 int second_pass=0;
2426 GET_STRING_OR_DEFAULT("Color", val);
2429 again:
2430 if (!wGetColor(scr, val, &color)) {
2431 wwarning(_("could not get color for key \"%s\""),
2432 entry->key);
2433 if (second_pass==0) {
2434 val = WMGetFromPLString(entry->plvalue);
2435 second_pass = 1;
2436 wwarning(_("using default \"%s\" instead"), val);
2437 goto again;
2439 return False;
2442 if (ret)
2443 *ret = &color;
2445 assert(addr==NULL);
2447 if (addr)
2448 *(unsigned long*)addr = pixel;
2451 return True;
2456 static int
2457 getKeybind(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2458 void **ret)
2460 static WShortKey shortcut;
2461 KeySym ksym;
2462 char *val;
2463 char *k;
2464 char buf[128], *b;
2467 GET_STRING_OR_DEFAULT("Key spec", val);
2469 if (!val || strcasecmp(val, "NONE")==0) {
2470 shortcut.keycode = 0;
2471 shortcut.modifier = 0;
2472 if (ret)
2473 *ret = &shortcut;
2474 return True;
2477 strcpy(buf, val);
2479 b = (char*)buf;
2481 /* get modifiers */
2482 shortcut.modifier = 0;
2483 while ((k = strchr(b, '+'))!=NULL) {
2484 int mod;
2486 *k = 0;
2487 mod = wXModifierFromKey(b);
2488 if (mod<0) {
2489 wwarning(_("%s:invalid key modifier \"%s\""), entry->key, b);
2490 return False;
2492 shortcut.modifier |= mod;
2494 b = k+1;
2497 /* get key */
2498 ksym = XStringToKeysym(b);
2500 if (ksym==NoSymbol) {
2501 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key,
2502 val);
2503 return False;
2506 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2507 if (shortcut.keycode==0) {
2508 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2509 return False;
2512 if (ret)
2513 *ret = &shortcut;
2515 return True;
2519 static int
2520 getModMask(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2521 void **ret)
2523 static unsigned int mask;
2524 char *str;
2526 GET_STRING_OR_DEFAULT("Modifier Key", str);
2528 if (!str)
2529 return False;
2531 mask = wXModifierFromKey(str);
2532 if (mask < 0) {
2533 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2534 mask = 0;
2535 return False;
2538 if (addr)
2539 *(unsigned int*)addr = mask;
2541 if (ret)
2542 *ret = &mask;
2544 return True;
2548 #ifdef NEWSTUFF
2549 static int
2550 getRImages(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
2551 void *addr, void **ret)
2553 unsigned int mask;
2554 char *str;
2555 RImage *image;
2556 int i, n;
2557 int w, h;
2559 GET_STRING_OR_DEFAULT("Image File Path", str);
2560 if (!str)
2561 return False;
2563 image = RLoadImage(scr->rcontext, str, 0);
2564 if (!image) {
2565 wwarning(_("could not load image in option %s: %s"), entry->key,
2566 RMessageForError(RErrorCode));
2567 return False;
2570 if (*(RImage**)addr) {
2571 RReleaseImage(*(RImage**)addr);
2573 if (addr)
2574 *(RImage**)addr = image;
2576 assert(ret == NULL);
2578 if (ret)
2579 *(RImage**)ret = image;
2582 return True;
2584 #endif
2586 # include <X11/cursorfont.h>
2587 typedef struct
2589 char *name;
2590 int id;
2591 } WCursorLookup;
2593 #define CURSOR_ID_NONE (XC_num_glyphs)
2595 static WCursorLookup cursor_table[] =
2597 { "X_cursor", XC_X_cursor },
2598 { "arrow", XC_arrow },
2599 { "based_arrow_down", XC_based_arrow_down },
2600 { "based_arrow_up", XC_based_arrow_up },
2601 { "boat", XC_boat },
2602 { "bogosity", XC_bogosity },
2603 { "bottom_left_corner", XC_bottom_left_corner },
2604 { "bottom_right_corner", XC_bottom_right_corner },
2605 { "bottom_side", XC_bottom_side },
2606 { "bottom_tee", XC_bottom_tee },
2607 { "box_spiral", XC_box_spiral },
2608 { "center_ptr", XC_center_ptr },
2609 { "circle", XC_circle },
2610 { "clock", XC_clock },
2611 { "coffee_mug", XC_coffee_mug },
2612 { "cross", XC_cross },
2613 { "cross_reverse", XC_cross_reverse },
2614 { "crosshair", XC_crosshair },
2615 { "diamond_cross", XC_diamond_cross },
2616 { "dot", XC_dot },
2617 { "dotbox", XC_dotbox },
2618 { "double_arrow", XC_double_arrow },
2619 { "draft_large", XC_draft_large },
2620 { "draft_small", XC_draft_small },
2621 { "draped_box", XC_draped_box },
2622 { "exchange", XC_exchange },
2623 { "fleur", XC_fleur },
2624 { "gobbler", XC_gobbler },
2625 { "gumby", XC_gumby },
2626 { "hand1", XC_hand1 },
2627 { "hand2", XC_hand2 },
2628 { "heart", XC_heart },
2629 { "icon", XC_icon },
2630 { "iron_cross", XC_iron_cross },
2631 { "left_ptr", XC_left_ptr },
2632 { "left_side", XC_left_side },
2633 { "left_tee", XC_left_tee },
2634 { "leftbutton", XC_leftbutton },
2635 { "ll_angle", XC_ll_angle },
2636 { "lr_angle", XC_lr_angle },
2637 { "man", XC_man },
2638 { "middlebutton", XC_middlebutton },
2639 { "mouse", XC_mouse },
2640 { "pencil", XC_pencil },
2641 { "pirate", XC_pirate },
2642 { "plus", XC_plus },
2643 { "question_arrow", XC_question_arrow },
2644 { "right_ptr", XC_right_ptr },
2645 { "right_side", XC_right_side },
2646 { "right_tee", XC_right_tee },
2647 { "rightbutton", XC_rightbutton },
2648 { "rtl_logo", XC_rtl_logo },
2649 { "sailboat", XC_sailboat },
2650 { "sb_down_arrow", XC_sb_down_arrow },
2651 { "sb_h_double_arrow", XC_sb_h_double_arrow },
2652 { "sb_left_arrow", XC_sb_left_arrow },
2653 { "sb_right_arrow", XC_sb_right_arrow },
2654 { "sb_up_arrow", XC_sb_up_arrow },
2655 { "sb_v_double_arrow", XC_sb_v_double_arrow },
2656 { "shuttle", XC_shuttle },
2657 { "sizing", XC_sizing },
2658 { "spider", XC_spider },
2659 { "spraycan", XC_spraycan },
2660 { "star", XC_star },
2661 { "target", XC_target },
2662 { "tcross", XC_tcross },
2663 { "top_left_arrow", XC_top_left_arrow },
2664 { "top_left_corner", XC_top_left_corner },
2665 { "top_right_corner", XC_top_right_corner },
2666 { "top_side", XC_top_side },
2667 { "top_tee", XC_top_tee },
2668 { "trek", XC_trek },
2669 { "ul_angle", XC_ul_angle },
2670 { "umbrella", XC_umbrella },
2671 { "ur_angle", XC_ur_angle },
2672 { "watch", XC_watch },
2673 { "xterm", XC_xterm },
2674 { NULL, CURSOR_ID_NONE }
2677 static void
2678 check_bitmap_status(int status, char *filename, Pixmap bitmap)
2680 switch(status) {
2681 case BitmapOpenFailed:
2682 wwarning(_("failed to open bitmap file \"%s\""), filename);
2683 break;
2684 case BitmapFileInvalid:
2685 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2686 break;
2687 case BitmapNoMemory:
2688 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2689 break;
2690 case BitmapSuccess:
2691 XFreePixmap(dpy, bitmap);
2692 break;
2697 * (none)
2698 * (builtin, <cursor_name>)
2699 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2701 static int
2702 parse_cursor(WScreen *scr, WMPropList *pl, Cursor *cursor)
2704 WMPropList *elem;
2705 char *val;
2706 int nelem;
2707 int status = 0;
2709 nelem = WMGetPropListItemCount(pl);
2710 if (nelem < 1) {
2711 return(status);
2713 elem = WMGetFromPLArray(pl, 0);
2714 if (!elem || !WMIsPLString(elem)) {
2715 return(status);
2717 val = WMGetFromPLString(elem);
2719 if (0 == strcasecmp(val, "none")) {
2720 status = 1;
2721 *cursor = None;
2722 } else if (0 == strcasecmp(val, "builtin")) {
2723 int i;
2724 int cursor_id = CURSOR_ID_NONE;
2726 if (2 != nelem) {
2727 wwarning(_("bad number of arguments in cursor specification"));
2728 return(status);
2730 elem = WMGetFromPLArray(pl, 1);
2731 if (!elem || !WMIsPLString(elem)) {
2732 return(status);
2734 val = WMGetFromPLString(elem);
2736 for (i = 0; NULL != cursor_table[i].name; i++) {
2737 if (0 == strcasecmp(val, cursor_table[i].name)) {
2738 cursor_id = cursor_table[i].id;
2739 break;
2742 if (CURSOR_ID_NONE == cursor_id) {
2743 wwarning(_("unknown builtin cursor name \"%s\""), val);
2744 } else {
2745 *cursor = XCreateFontCursor(dpy, cursor_id);
2746 status = 1;
2748 } else if (0 == strcasecmp(val, "bitmap")) {
2749 char *bitmap_name;
2750 char *mask_name;
2751 int bitmap_status;
2752 int mask_status;
2753 Pixmap bitmap;
2754 Pixmap mask;
2755 unsigned int w, h;
2756 int x, y;
2757 XColor fg, bg;
2759 if (3 != nelem) {
2760 wwarning(_("bad number of arguments in cursor specification"));
2761 return(status);
2763 elem = WMGetFromPLArray(pl, 1);
2764 if (!elem || !WMIsPLString(elem)) {
2765 return(status);
2767 val = WMGetFromPLString(elem);
2768 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2769 if (!bitmap_name) {
2770 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2771 return(status);
2773 elem = WMGetFromPLArray(pl, 2);
2774 if (!elem || !WMIsPLString(elem)) {
2775 wfree(bitmap_name);
2776 return(status);
2778 val = WMGetFromPLString(elem);
2779 mask_name = FindImage(wPreferences.pixmap_path, val);
2780 if (!mask_name) {
2781 wfree(bitmap_name);
2782 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2783 return(status);
2785 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h,
2786 &mask, &x, &y);
2787 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h,
2788 &bitmap, &x, &y);
2789 if ((BitmapSuccess == bitmap_status) &&
2790 (BitmapSuccess == mask_status)) {
2791 fg.pixel = scr->black_pixel;
2792 bg.pixel = scr->white_pixel;
2793 XQueryColor(dpy, scr->w_colormap, &fg);
2794 XQueryColor(dpy, scr->w_colormap, &bg);
2795 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2796 status = 1;
2798 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2799 check_bitmap_status(mask_status, mask_name, mask);
2800 wfree(bitmap_name);
2801 wfree(mask_name);
2803 return(status);
2807 static int
2808 getCursor(WScreen *scr, WDefaultEntry *entry, WMPropList *value, void *addr,
2809 void **ret)
2811 static Cursor cursor;
2812 int status;
2813 int changed = 0;
2815 again:
2816 if (!WMIsPLArray(value)) {
2817 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2818 entry->key, "cursor specification");
2819 if (!changed) {
2820 value = entry->plvalue;
2821 changed = 1;
2822 wwarning(_("using default \"%s\" instead"), entry->default_value);
2823 goto again;
2825 return(False);
2827 status = parse_cursor(scr, value, &cursor);
2828 if (!status) {
2829 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2830 if (!changed) {
2831 value = entry->plvalue;
2832 changed = 1;
2833 wwarning(_("using default \"%s\" instead"), entry->default_value);
2834 goto again;
2836 return(False);
2838 if (ret) {
2839 *ret = &cursor;
2841 if (addr) {
2842 *(Cursor *)addr = cursor;
2844 return(True);
2846 #undef CURSOR_ID_NONE
2849 /* ---------------- value setting functions --------------- */
2850 static int
2851 setJustify(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2853 return REFRESH_WINDOW_TITLE_COLOR;
2856 static int
2857 setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2859 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES|REFRESH_MENU_TITLE_FONT|REFRESH_MENU_FONT;
2862 static int
2863 setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which)
2865 switch (which) {
2866 case WM_DOCK:
2867 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2868 break;
2869 case WM_CLIP:
2870 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2871 break;
2872 default:
2873 break;
2875 return 0;
2879 static int
2880 setStickyIcons(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
2882 if (scr->workspaces) {
2883 wWorkspaceForceChange(scr, scr->current_workspace);
2884 wArrangeIcons(scr, False);
2886 return 0;
2889 #if not_used
2890 static int
2891 setPositive(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
2893 if (*value <= 0)
2894 *(int*)foo = 1;
2896 return 0;
2898 #endif
2902 static int
2903 setIconTile(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
2905 Pixmap pixmap;
2906 RImage *img;
2907 int reset = 0;
2909 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2910 wPreferences.icon_size,
2911 ((*texture)->any.type & WREL_BORDER_MASK)
2912 ? WREL_ICON : WREL_FLAT);
2913 if (!img) {
2914 wwarning(_("could not render texture for icon background"));
2915 if (!entry->addr)
2916 wTextureDestroy(scr, *texture);
2917 return 0;
2919 RConvertImage(scr->rcontext, img, &pixmap);
2921 if (scr->icon_tile) {
2922 reset = 1;
2923 RReleaseImage(scr->icon_tile);
2924 XFreePixmap(dpy, scr->icon_tile_pixmap);
2927 scr->icon_tile = img;
2930 /* put the icon in the noticeboard hint */
2931 PropSetIconTileHint(scr, img);
2934 if (!wPreferences.flags.noclip) {
2935 if (scr->clip_tile) {
2936 RReleaseImage(scr->clip_tile);
2938 scr->clip_tile = wClipMakeTile(scr, img);
2941 scr->icon_tile_pixmap = pixmap;
2943 if (scr->def_icon_pixmap) {
2944 XFreePixmap(dpy, scr->def_icon_pixmap);
2945 scr->def_icon_pixmap = None;
2947 if (scr->def_ticon_pixmap) {
2948 XFreePixmap(dpy, scr->def_ticon_pixmap);
2949 scr->def_ticon_pixmap = None;
2952 if (scr->icon_back_texture) {
2953 wTextureDestroy(scr, (WTexture*)scr->icon_back_texture);
2955 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2957 if (scr->clip_balloon)
2958 XSetWindowBackground(dpy, scr->clip_balloon,
2959 (*texture)->any.color.pixel);
2962 * Free the texture as nobody else will use it, nor refer to it.
2964 if (!entry->addr)
2965 wTextureDestroy(scr, *texture);
2967 return (reset ? REFRESH_ICON_TILE : 0);
2972 static int
2973 setWinTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2975 if (scr->title_font) {
2976 WMReleaseFont(scr->title_font);
2978 scr->title_font = font;
2980 return REFRESH_WINDOW_FONT|REFRESH_BUTTON_IMAGES;
2984 static int
2985 setMenuTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
2987 if (scr->menu_title_font) {
2988 WMReleaseFont(scr->menu_title_font);
2991 scr->menu_title_font = font;
2993 return REFRESH_MENU_TITLE_FONT;
2997 static int
2998 setMenuTextFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3000 if (scr->menu_entry_font) {
3001 WMReleaseFont(scr->menu_entry_font);
3003 scr->menu_entry_font = font;
3005 return REFRESH_MENU_FONT;
3010 static int
3011 setIconTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3013 if (scr->icon_title_font) {
3014 WMReleaseFont(scr->icon_title_font);
3017 scr->icon_title_font = font;
3019 return REFRESH_ICON_FONT;
3023 static int
3024 setClipTitleFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3026 if (scr->clip_title_font) {
3027 WMReleaseFont(scr->clip_title_font);
3030 scr->clip_title_font = font;
3032 return REFRESH_ICON_FONT;
3036 static int
3037 setLargeDisplayFont(WScreen *scr, WDefaultEntry *entry, WMFont *font, void *foo)
3039 if (scr->workspace_name_font) {
3040 WMReleaseFont(scr->workspace_name_font);
3043 scr->workspace_name_font = font;
3045 return 0;
3049 static int
3050 setHightlight(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3052 if (scr->select_color)
3053 WMReleaseColor(scr->select_color);
3055 scr->select_color =
3056 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3057 color->blue, True);
3059 wFreeColor(scr, color->pixel);
3061 return REFRESH_MENU_COLOR;
3065 static int
3066 setHightlightText(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3068 if (scr->select_text_color)
3069 WMReleaseColor(scr->select_text_color);
3071 scr->select_text_color =
3072 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3073 color->blue, True);
3075 wFreeColor(scr, color->pixel);
3077 return REFRESH_MENU_COLOR;
3081 static int
3082 setClipTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3084 if (scr->clip_title_color[index])
3085 WMReleaseColor(scr->clip_title_color[index]);
3086 scr->clip_title_color[index] = WMCreateRGBColor(scr->wmscreen, color->red,
3087 color->green, color->blue,
3088 True);
3089 #ifdef GRADIENT_CLIP_ARROW
3090 if (index == CLIP_NORMAL) {
3091 RImage *image;
3092 RColor color1, color2;
3093 int pt = CLIP_BUTTON_SIZE*wPreferences.icon_size/64;
3094 int as = pt - 15; /* 15 = 5+5+5 */
3096 FREE_PIXMAP(scr->clip_arrow_gradient);
3098 color1.red = (color->red >> 8)*6/10;
3099 color1.green = (color->green >> 8)*6/10;
3100 color1.blue = (color->blue >> 8)*6/10;
3102 color2.red = WMIN((color->red >> 8)*20/10, 255);
3103 color2.green = WMIN((color->green >> 8)*20/10, 255);
3104 color2.blue = WMIN((color->blue >> 8)*20/10, 255);
3106 image = RRenderGradient(as+1, as+1, &color1, &color2, RDiagonalGradient);
3107 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
3108 RReleaseImage(image);
3110 #endif /* GRADIENT_CLIP_ARROW */
3112 wFreeColor(scr, color->pixel);
3114 return REFRESH_ICON_TITLE_COLOR;
3118 static int
3119 setWTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3121 if (scr->window_title_color[index])
3122 WMReleaseColor(scr->window_title_color[index]);
3124 scr->window_title_color[index] =
3125 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue,
3126 True);
3128 wFreeColor(scr, color->pixel);
3130 return REFRESH_WINDOW_TITLE_COLOR;
3134 static int
3135 setMenuTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3137 if (scr->menu_title_color[0])
3138 WMReleaseColor(scr->menu_title_color[0]);
3140 scr->menu_title_color[0] =
3141 WMCreateRGBColor(scr->wmscreen, color->red, color->green,
3142 color->blue, True);
3144 wFreeColor(scr, color->pixel);
3146 return REFRESH_MENU_TITLE_COLOR;
3150 static int
3151 setMenuTextColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3153 if (scr->mtext_color)
3154 WMReleaseColor(scr->mtext_color);
3156 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3157 color->green, color->blue, True);
3159 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3160 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3161 } else {
3162 WMSetColorAlpha(scr->dtext_color, 0xffff);
3165 wFreeColor(scr, color->pixel);
3167 return REFRESH_MENU_COLOR;
3171 static int
3172 setMenuDisabledColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3174 if (scr->dtext_color)
3175 WMReleaseColor(scr->dtext_color);
3177 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red,
3178 color->green, color->blue, True);
3180 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
3181 WMSetColorAlpha(scr->dtext_color, 0x7fff);
3182 } else {
3183 WMSetColorAlpha(scr->dtext_color, 0xffff);
3186 wFreeColor(scr, color->pixel);
3188 return REFRESH_MENU_COLOR;
3192 static int
3193 setIconTitleColor(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3195 if (scr->icon_title_color)
3196 WMReleaseColor(scr->icon_title_color);
3197 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red,
3198 color->green, color->blue,
3199 True);
3201 wFreeColor(scr, color->pixel);
3203 return REFRESH_ICON_TITLE_COLOR;
3207 static int
3208 setIconTitleBack(WScreen *scr, WDefaultEntry *entry, XColor *color, void *foo)
3210 if (scr->icon_title_texture) {
3211 wTextureDestroy(scr, (WTexture*)scr->icon_title_texture);
3213 scr->icon_title_texture = wTextureMakeSolid(scr, color);
3215 return REFRESH_ICON_TITLE_BACK;
3219 static void
3220 trackDeadProcess(pid_t pid, unsigned char status, WScreen *scr)
3222 close(scr->helper_fd);
3223 scr->helper_fd = 0;
3224 scr->helper_pid = 0;
3225 scr->flags.backimage_helper_launched = 0;
3229 static int
3230 setWorkspaceSpecificBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3231 void *bar)
3233 WMPropList *val;
3234 char *str;
3235 int i;
3237 if (scr->flags.backimage_helper_launched) {
3238 if (WMGetPropListItemCount(value)==0) {
3239 SendHelperMessage(scr, 'C', 0, NULL);
3240 SendHelperMessage(scr, 'K', 0, NULL);
3242 WMReleasePropList(value);
3243 return 0;
3245 } else {
3246 pid_t pid;
3247 int filedes[2];
3249 if (WMGetPropListItemCount(value) == 0)
3250 return 0;
3252 if (pipe(filedes) < 0) {
3253 wsyserror("pipe() failed:can't set workspace specific background image");
3255 WMReleasePropList(value);
3256 return 0;
3259 pid = fork();
3260 if (pid < 0) {
3261 wsyserror("fork() failed:can't set workspace specific background image");
3262 if (close(filedes[0]) < 0)
3263 wsyserror("could not close pipe");
3264 if (close(filedes[1]) < 0)
3265 wsyserror("could not close pipe");
3267 } else if (pid == 0) {
3268 char *dither;
3270 SetupEnvironment(scr);
3272 if (close(0) < 0)
3273 wsyserror("could not close pipe");
3274 if (dup(filedes[0]) < 0) {
3275 wsyserror("dup() failed:can't set workspace specific background image");
3277 dither = wPreferences.no_dithering ? "-m" : "-d";
3278 if (wPreferences.smooth_workspace_back)
3279 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
3280 else
3281 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
3282 wsyserror("could not execute wmsetbg");
3283 exit(1);
3284 } else {
3286 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
3287 wsyserror("error setting close-on-exec flag");
3289 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
3290 wsyserror("error setting close-on-exec flag");
3293 scr->helper_fd = filedes[1];
3294 scr->helper_pid = pid;
3295 scr->flags.backimage_helper_launched = 1;
3297 wAddDeathHandler(pid, (WDeathHandler*)trackDeadProcess, scr);
3299 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
3304 for (i = 0; i < WMGetPropListItemCount(value); i++) {
3305 val = WMGetFromPLArray(value, i);
3306 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val)>0) {
3307 str = WMGetPropListDescription(val, False);
3309 SendHelperMessage(scr, 'S', i+1, str);
3311 wfree(str);
3312 } else {
3313 SendHelperMessage(scr, 'U', i+1, NULL);
3316 sleep(1);
3318 WMReleasePropList(value);
3319 return 0;
3323 static int
3324 setWorkspaceBack(WScreen *scr, WDefaultEntry *entry, WMPropList *value,
3325 void *bar)
3327 if (scr->flags.backimage_helper_launched) {
3328 char *str;
3330 if (WMGetPropListItemCount(value)==0) {
3331 SendHelperMessage(scr, 'U', 0, NULL);
3332 } else {
3333 /* set the default workspace background to this one */
3334 str = WMGetPropListDescription(value, False);
3335 if (str) {
3336 SendHelperMessage(scr, 'S', 0, str);
3337 wfree(str);
3338 SendHelperMessage(scr, 'C', scr->current_workspace+1, NULL);
3339 } else {
3340 SendHelperMessage(scr, 'U', 0, NULL);
3343 } else if (WMGetPropListItemCount(value) > 0) {
3344 char *command;
3345 char *text;
3346 char *dither;
3347 int len;
3349 SetupEnvironment(scr);
3350 text = WMGetPropListDescription(value, False);
3351 len = strlen(text)+40;
3352 command = wmalloc(len);
3353 dither = wPreferences.no_dithering ? "-m" : "-d";
3354 if (wPreferences.smooth_workspace_back)
3355 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3356 else
3357 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3358 wfree(text);
3359 system(command);
3360 wfree(command);
3362 WMReleasePropList(value);
3364 return 0;
3368 #ifdef VIRTUAL_DESKTOP
3369 static int
3370 setVirtualEdgeThickness(WScreen *scr, WDefaultEntry *entry, XColor *color, long index)
3372 wWorkspaceUpdateEdge(scr);
3373 return 0;
3375 #endif
3378 static int
3379 setWidgetColor(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3381 if (scr->widget_texture) {
3382 wTextureDestroy(scr, (WTexture*)scr->widget_texture);
3384 scr->widget_texture = *(WTexSolid**)texture;
3386 return 0;
3390 static int
3391 setFTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3393 if (scr->window_title_texture[WS_FOCUSED]) {
3394 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3396 scr->window_title_texture[WS_FOCUSED] = *texture;
3398 return REFRESH_WINDOW_TEXTURES;
3402 static int
3403 setPTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3405 if (scr->window_title_texture[WS_PFOCUSED]) {
3406 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3408 scr->window_title_texture[WS_PFOCUSED] = *texture;
3410 return REFRESH_WINDOW_TEXTURES;
3414 static int
3415 setUTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3417 if (scr->window_title_texture[WS_UNFOCUSED]) {
3418 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3420 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3422 return REFRESH_WINDOW_TEXTURES;
3426 static int
3427 setResizebarBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3429 if (scr->resizebar_texture[0]) {
3430 wTextureDestroy(scr, scr->resizebar_texture[0]);
3432 scr->resizebar_texture[0] = *texture;
3434 return REFRESH_WINDOW_TEXTURES;
3438 static int
3439 setMenuTitleBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3441 if (scr->menu_title_texture[0]) {
3442 wTextureDestroy(scr, scr->menu_title_texture[0]);
3444 scr->menu_title_texture[0] = *texture;
3446 return REFRESH_MENU_TITLE_TEXTURE;
3450 static int
3451 setMenuTextBack(WScreen *scr, WDefaultEntry *entry, WTexture **texture, void *foo)
3453 if (scr->menu_item_texture) {
3454 wTextureDestroy(scr, scr->menu_item_texture);
3455 wTextureDestroy(scr, (WTexture*)scr->menu_item_auxtexture);
3457 scr->menu_item_texture = *texture;
3459 scr->menu_item_auxtexture
3460 = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3462 return REFRESH_MENU_TEXTURE;
3466 static int
3467 setKeyGrab(WScreen *scr, WDefaultEntry *entry, WShortKey *shortcut, long index)
3469 WWindow *wwin;
3470 wKeyBindings[index] = *shortcut;
3472 wwin = scr->focused_window;
3474 while (wwin!=NULL) {
3475 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3477 if (!WFLAGP(wwin, no_bind_keys)) {
3478 wWindowSetKeyGrabs(wwin);
3480 wwin = wwin->prev;
3483 return 0;
3487 static int
3488 setIconPosition(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3490 wScreenUpdateUsableArea(scr);
3491 wArrangeIcons(scr, True);
3493 return 0;
3497 static int
3498 updateUsableArea(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo)
3500 wScreenUpdateUsableArea(scr);
3502 return 0;
3506 static int
3507 setMenuStyle(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3509 return REFRESH_MENU_TEXTURE;
3514 static int
3515 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3517 return REFRESH_BUTTON_IMAGES;
3522 * Very ugly kluge.
3523 * Need access to the double click variables, so that all widgets in
3524 * wmaker panels will have the same dbl-click values.
3525 * TODO: figure a better way of dealing with it.
3527 #include <WINGs/WINGsP.h>
3529 static int
3530 setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3532 extern _WINGsConfiguration WINGsConfiguration;
3534 if (*value <= 0)
3535 *(int*)foo = 1;
3537 WINGsConfiguration.doubleClickDelay = *value;
3539 return 0;
3543 #if 0
3544 static int
3545 setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo)
3547 extern _WINGsConfiguration WINGsConfiguration;
3549 WINGsConfiguration.useMultiByte = *value;
3551 return 0;
3553 #endif
3556 static int
3557 setCursor(WScreen *scr, WDefaultEntry *entry, Cursor *cursor, long index)
3559 if (wCursor[index] != None) {
3560 XFreeCursor(dpy, wCursor[index]);
3563 wCursor[index] = *cursor;
3565 if (index==WCUR_ROOT && *cursor!=None) {
3566 XDefineCursor(dpy, scr->root_win, *cursor);
3569 return 0;