Remove LITE config option
[wmaker-crm.git] / src / defaults.c
blobcd2ae25c5d648da83efdd565e4691a673fe1f027
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
51 #include <wraster.h>
53 #include "WindowMaker.h"
54 #include "wcore.h"
55 #include "framewin.h"
56 #include "window.h"
57 #include "texture.h"
58 #include "screen.h"
59 #include "resources.h"
60 #include "defaults.h"
61 #include "keybind.h"
62 #include "xmodifier.h"
63 #include "icon.h"
64 #include "funcs.h"
65 #include "actions.h"
66 #include "dock.h"
67 #include "workspace.h"
68 #include "properties.h"
70 #define MAX_SHORTCUT_LENGTH 32
72 /***** Global *****/
74 extern WDDomain *WDWindowMaker;
75 extern WDDomain *WDWindowAttributes;
76 extern WDDomain *WDRootMenu;
78 extern int wScreenCount;
80 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
81 extern Atom _XA_WINDOWMAKER_ICON_TILE;
84 extern WMPropList *wDomainName;
85 extern WMPropList *wAttributeDomainName;
87 extern WPreferences wPreferences;
89 extern WShortKey wKeyBindings[WKBD_LAST];
91 typedef struct {
92 char *key;
93 char *default_value;
94 void *extra_data;
95 void *addr;
96 int (*convert) ();
97 int (*update) ();
98 WMPropList *plkey;
99 WMPropList *plvalue; /* default value */
100 } WDefaultEntry;
102 /* used to map strings to integers */
103 typedef struct {
104 char *string;
105 short value;
106 char is_alias;
107 } WOptionEnumeration;
109 /* type converters */
110 static int getBool();
111 static int getInt();
112 static int getCoord();
113 #if 0
114 /* this is not used yet */
115 static int getString();
116 #endif
117 static int getPathList();
118 static int getEnum();
119 static int getTexture();
120 static int getWSBackground();
121 static int getWSSpecificBackground();
122 static int getFont();
123 static int getColor();
124 static int getKeybind();
125 static int getModMask();
126 #ifdef NEWSTUFF
127 static int getRImage();
128 #endif
129 static int getPropList();
131 /* value setting functions */
132 static int setJustify();
133 static int setClearance();
134 static int setIfDockPresent();
135 static int setStickyIcons();
137 static int setPositive();
139 static int setWidgetColor();
140 static int setIconTile();
141 static int setWinTitleFont();
142 static int setMenuTitleFont();
143 static int setMenuTextFont();
144 static int setIconTitleFont();
145 static int setIconTitleColor();
146 static int setIconTitleBack();
147 static int setLargeDisplayFont();
148 static int setWTitleColor();
149 static int setFTitleBack();
150 static int setPTitleBack();
151 static int setUTitleBack();
152 static int setResizebarBack();
153 static int setWorkspaceBack();
154 static int setWorkspaceSpecificBack();
155 #ifdef VIRTUAL_DESKTOP
156 static int setVirtualDeskEnable();
157 #endif
158 static int setMenuTitleColor();
159 static int setMenuTextColor();
160 static int setMenuDisabledColor();
161 static int setMenuTitleBack();
162 static int setMenuTextBack();
163 static int setHightlight();
164 static int setHightlightText();
165 static int setKeyGrab();
166 static int setDoubleClick();
167 static int setIconPosition();
169 static int setClipTitleFont();
170 static int setClipTitleColor();
172 static int setMenuStyle();
173 static int setSwPOptions();
174 static int updateUsableArea();
176 extern Cursor wCursor[WCUR_LAST];
177 static int getCursor();
178 static int setCursor();
181 * Tables to convert strings to enumeration values.
182 * Values stored are char
185 /* WARNING: sum of length of all value strings must not exceed
186 * this value */
187 #define TOTAL_VALUES_LENGTH 80
189 #define REFRESH_WINDOW_TEXTURES (1<<0)
190 #define REFRESH_MENU_TEXTURE (1<<1)
191 #define REFRESH_MENU_FONT (1<<2)
192 #define REFRESH_MENU_COLOR (1<<3)
193 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
194 #define REFRESH_MENU_TITLE_FONT (1<<5)
195 #define REFRESH_MENU_TITLE_COLOR (1<<6)
196 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
197 #define REFRESH_WINDOW_FONT (1<<8)
198 #define REFRESH_ICON_TILE (1<<9)
199 #define REFRESH_ICON_FONT (1<<10)
200 #define REFRESH_WORKSPACE_BACK (1<<11)
202 #define REFRESH_BUTTON_IMAGES (1<<12)
204 #define REFRESH_ICON_TITLE_COLOR (1<<13)
205 #define REFRESH_ICON_TITLE_BACK (1<<14)
207 static WOptionEnumeration seFocusModes[] = {
208 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
209 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
210 {NULL, 0, 0}
213 static WOptionEnumeration seColormapModes[] = {
214 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
215 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
216 {NULL, 0, 0}
219 static WOptionEnumeration sePlacements[] = {
220 {"Auto", WPM_AUTO, 0},
221 {"Smart", WPM_SMART, 0},
222 {"Cascade", WPM_CASCADE, 0},
223 {"Random", WPM_RANDOM, 0},
224 {"Manual", WPM_MANUAL, 0},
225 {NULL, 0, 0}
228 static WOptionEnumeration seGeomDisplays[] = {
229 {"None", WDIS_NONE, 0},
230 {"Center", WDIS_CENTER, 0},
231 {"Corner", WDIS_TOPLEFT, 0},
232 {"Floating", WDIS_FRAME_CENTER, 0},
233 {"Line", WDIS_NEW, 0},
234 {NULL, 0, 0}
237 static WOptionEnumeration seSpeeds[] = {
238 {"UltraFast", SPEED_ULTRAFAST, 0},
239 {"Fast", SPEED_FAST, 0},
240 {"Medium", SPEED_MEDIUM, 0},
241 {"Slow", SPEED_SLOW, 0},
242 {"UltraSlow", SPEED_ULTRASLOW, 0},
243 {NULL, 0, 0}
246 static WOptionEnumeration seMouseButtonActions[] = {
247 {"None", WA_NONE, 0},
248 {"SelectWindows", WA_SELECT_WINDOWS, 0},
249 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
250 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
251 {NULL, 0, 0}
254 static WOptionEnumeration seMouseWheelActions[] = {
255 {"None", WA_NONE, 0},
256 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
257 {NULL, 0, 0}
260 static WOptionEnumeration seIconificationStyles[] = {
261 {"Zoom", WIS_ZOOM, 0},
262 {"Twist", WIS_TWIST, 0},
263 {"Flip", WIS_FLIP, 0},
264 {"None", WIS_NONE, 0},
265 {"random", WIS_RANDOM, 0},
266 {NULL, 0, 0}
269 static WOptionEnumeration seJustifications[] = {
270 {"Left", WTJ_LEFT, 0},
271 {"Center", WTJ_CENTER, 0},
272 {"Right", WTJ_RIGHT, 0},
273 {NULL, 0, 0}
276 static WOptionEnumeration seIconPositions[] = {
277 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
278 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
279 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
280 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
281 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
282 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
283 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
284 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
285 {NULL, 0, 0}
288 static WOptionEnumeration seMenuStyles[] = {
289 {"normal", MS_NORMAL, 0},
290 {"singletexture", MS_SINGLE_TEXTURE, 0},
291 {"flat", MS_FLAT, 0},
292 {NULL, 0, 0}
295 static WOptionEnumeration seDisplayPositions[] = {
296 {"none", WD_NONE, 0},
297 {"center", WD_CENTER, 0},
298 {"top", WD_TOP, 0},
299 {"bottom", WD_BOTTOM, 0},
300 {"topleft", WD_TOPLEFT, 0},
301 {"topright", WD_TOPRIGHT, 0},
302 {"bottomleft", WD_BOTTOMLEFT, 0},
303 {"bottomright", WD_BOTTOMRIGHT, 0},
304 {NULL, 0, 0}
307 static WOptionEnumeration seWorkspaceBorder[] = {
308 {"None", WB_NONE, 0},
309 {"LeftRight", WB_LEFTRIGHT, 0},
310 {"TopBottom", WB_TOPBOTTOM, 0},
311 {"AllDirections", WB_ALLDIRS, 0},
312 {NULL, 0, 0}
316 * ALL entries in the tables bellow, NEED to have a default value
317 * defined, and this value needs to be correct.
320 /* these options will only affect the window manager on startup
322 * static defaults can't access the screen data, because it is
323 * created after these defaults are read
325 WDefaultEntry staticOptionList[] = {
327 {"ColormapSize", "4", NULL,
328 &wPreferences.cmap_size, getInt, NULL},
329 {"DisableDithering", "NO", NULL,
330 &wPreferences.no_dithering, getBool, NULL},
331 /* static by laziness */
332 {"IconSize", "64", NULL,
333 &wPreferences.icon_size, getInt, NULL},
334 {"ModifierKey", "Mod1", NULL,
335 &wPreferences.modifier_mask, getModMask, NULL},
336 {"DisableWSMouseActions", "NO", NULL,
337 &wPreferences.disable_root_mouse, getBool, NULL},
338 {"FocusMode", "manual", seFocusModes,
339 &wPreferences.focus_mode, getEnum, NULL}, /* have a problem when switching from manual to sloppy without restart */
340 {"NewStyle", "NO", NULL,
341 &wPreferences.new_style, getBool, NULL},
342 {"DisableDock", "NO", (void *)WM_DOCK,
343 NULL, getBool, setIfDockPresent},
344 {"DisableClip", "NO", (void *)WM_CLIP,
345 NULL, getBool, setIfDockPresent},
346 {"DisableMiniwindows", "NO", NULL,
347 &wPreferences.disable_miniwindows, getBool, NULL}
350 WDefaultEntry optionList[] = {
351 /* dynamic options */
352 {"IconPosition", "blh", seIconPositions,
353 &wPreferences.icon_yard, getEnum, setIconPosition},
354 {"IconificationStyle", "Zoom", seIconificationStyles,
355 &wPreferences.iconification_style, getEnum, NULL},
356 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
357 &wPreferences.mouse_button1, getEnum, NULL},
358 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
359 &wPreferences.mouse_button2, getEnum, NULL},
360 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
361 &wPreferences.mouse_button3, getEnum, NULL},
362 {"MouseWheelAction", "None", seMouseWheelActions,
363 &wPreferences.mouse_wheel, getEnum, NULL},
364 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
365 &wPreferences.pixmap_path, getPathList, NULL},
366 {"IconPath", DEF_ICON_PATHS, NULL,
367 &wPreferences.icon_path, getPathList, NULL},
368 {"ColormapMode", "auto", seColormapModes,
369 &wPreferences.colormap_mode, getEnum, NULL},
370 {"AutoFocus", "NO", NULL,
371 &wPreferences.auto_focus, getBool, NULL},
372 {"RaiseDelay", "0", NULL,
373 &wPreferences.raise_delay, getInt, NULL},
374 {"CirculateRaise", "NO", NULL,
375 &wPreferences.circ_raise, getBool, NULL},
376 {"Superfluous", "NO", NULL,
377 &wPreferences.superfluous, getBool, NULL},
378 {"AdvanceToNewWorkspace", "NO", NULL,
379 &wPreferences.ws_advance, getBool, NULL},
380 {"CycleWorkspaces", "NO", NULL,
381 &wPreferences.ws_cycle, getBool, NULL},
382 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
383 &wPreferences.workspace_name_display_position, getEnum, NULL},
384 {"WorkspaceBorder", "None", seWorkspaceBorder,
385 &wPreferences.workspace_border_position, getEnum, updateUsableArea},
386 {"WorkspaceBorderSize", "0", NULL,
387 &wPreferences.workspace_border_size, getInt, updateUsableArea},
388 #ifdef VIRTUAL_DESKTOP
389 {"EnableVirtualDesktop", "NO", NULL,
390 &wPreferences.vdesk_enable, getBool, setVirtualDeskEnable},
391 {"VirtualEdgeExtendSpace", "0", NULL,
392 &wPreferences.vedge_bordersize, getInt, NULL},
393 {"VirtualEdgeHorizonScrollSpeed", "30", NULL,
394 &wPreferences.vedge_hscrollspeed, getInt, NULL},
395 {"VirtualEdgeVerticalScrollSpeed", "30", NULL,
396 &wPreferences.vedge_vscrollspeed, getInt, NULL},
397 {"VirtualEdgeResistance", "30", NULL,
398 &wPreferences.vedge_resistance, getInt, NULL},
399 {"VirtualEdgeAttraction", "30", NULL,
400 &wPreferences.vedge_attraction, getInt, NULL},
401 {"VirtualEdgeLeftKey", "None", (void *)WKBD_VDESK_LEFT,
402 NULL, getKeybind, setKeyGrab},
403 {"VirtualEdgeRightKey", "None", (void *)WKBD_VDESK_RIGHT,
404 NULL, getKeybind, setKeyGrab},
405 {"VirtualEdgeUpKey", "None", (void *)WKBD_VDESK_UP,
406 NULL, getKeybind, setKeyGrab},
407 {"VirtualEdgeDownKey", "None", (void *)WKBD_VDESK_DOWN,
408 NULL, getKeybind, setKeyGrab},
409 #endif
410 {"StickyIcons", "NO", NULL,
411 &wPreferences.sticky_icons, getBool, setStickyIcons},
412 {"SaveSessionOnExit", "NO", NULL,
413 &wPreferences.save_session_on_exit, getBool, NULL},
414 {"WrapMenus", "NO", NULL,
415 &wPreferences.wrap_menus, getBool, NULL},
416 {"ScrollableMenus", "NO", NULL,
417 &wPreferences.scrollable_menus, getBool, NULL},
418 {"MenuScrollSpeed", "medium", seSpeeds,
419 &wPreferences.menu_scroll_speed, getEnum, NULL},
420 {"IconSlideSpeed", "medium", seSpeeds,
421 &wPreferences.icon_slide_speed, getEnum, NULL},
422 {"ShadeSpeed", "medium", seSpeeds,
423 &wPreferences.shade_speed, getEnum, NULL},
424 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
425 &wPreferences.dblclick_time, getInt, setDoubleClick,
427 {"AlignSubmenus", "NO", NULL,
428 &wPreferences.align_menus, getBool, NULL},
429 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
430 &wPreferences.open_transients_with_parent, getBool, NULL},
431 {"WindowPlacement", "auto", sePlacements,
432 &wPreferences.window_placement, getEnum, NULL},
433 {"IgnoreFocusClick", "NO", NULL,
434 &wPreferences.ignore_focus_click, getBool, NULL},
435 {"UseSaveUnders", "NO", NULL,
436 &wPreferences.use_saveunders, getBool, NULL},
437 {"OpaqueMove", "NO", NULL,
438 &wPreferences.opaque_move, getBool, NULL},
439 {"DisableSound", "NO", NULL,
440 &wPreferences.no_sound, getBool, NULL},
441 {"DisableAnimations", "NO", NULL,
442 &wPreferences.no_animations, getBool, NULL},
443 {"DontLinkWorkspaces", "NO", NULL,
444 &wPreferences.no_autowrap, getBool, NULL},
445 {"AutoArrangeIcons", "NO", NULL,
446 &wPreferences.auto_arrange_icons, getBool, NULL},
447 {"NoWindowOverDock", "NO", NULL,
448 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
449 {"NoWindowOverIcons", "NO", NULL,
450 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
451 {"WindowPlaceOrigin", "(0, 0)", NULL,
452 &wPreferences.window_place_origin, getCoord, NULL},
453 {"ResizeDisplay", "corner", seGeomDisplays,
454 &wPreferences.size_display, getEnum, NULL},
455 {"MoveDisplay", "corner", seGeomDisplays,
456 &wPreferences.move_display, getEnum, NULL},
457 {"DontConfirmKill", "NO", NULL,
458 &wPreferences.dont_confirm_kill, getBool, NULL},
459 {"WindowTitleBalloons", "NO", NULL,
460 &wPreferences.window_balloon, getBool, NULL},
461 {"MiniwindowTitleBalloons", "NO", NULL,
462 &wPreferences.miniwin_balloon, getBool, NULL},
463 {"AppIconBalloons", "NO", NULL,
464 &wPreferences.appicon_balloon, getBool, NULL},
465 {"HelpBalloons", "NO", NULL,
466 &wPreferences.help_balloon, getBool, NULL},
467 {"EdgeResistance", "30", NULL,
468 &wPreferences.edge_resistance, getInt, NULL},
469 {"Attraction", "NO", NULL,
470 &wPreferences.attract, getBool, NULL},
471 {"DisableBlinking", "NO", NULL,
472 &wPreferences.dont_blink, getBool, NULL},
473 /* style options */
474 {"MenuStyle", "normal", seMenuStyles,
475 &wPreferences.menu_style, getEnum, setMenuStyle},
476 {"WidgetColor", "(solid, gray)", NULL,
477 NULL, getTexture, setWidgetColor,
479 {"WorkspaceSpecificBack", "()", NULL,
480 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
481 /* WorkspaceBack must come after WorkspaceSpecificBack or
482 * WorkspaceBack wont know WorkspaceSpecificBack was also
483 * specified and 2 copies of wmsetbg will be launched */
484 {"WorkspaceBack", "(solid, black)", NULL,
485 NULL, getWSBackground, setWorkspaceBack},
486 {"SmoothWorkspaceBack", "NO", NULL,
487 NULL, getBool, NULL},
488 {"IconBack", "(solid, gray)", NULL,
489 NULL, getTexture, setIconTile},
490 {"TitleJustify", "center", seJustifications,
491 &wPreferences.title_justification, getEnum, setJustify},
492 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
493 NULL, getFont, setWinTitleFont,
495 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
496 &wPreferences.window_title_clearance, getInt, setClearance},
497 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
498 &wPreferences.menu_title_clearance, getInt, setClearance},
499 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
500 &wPreferences.menu_text_clearance, getInt, setClearance},
501 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
502 NULL, getFont, setMenuTitleFont},
503 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
504 NULL, getFont, setMenuTextFont},
505 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
506 NULL, getFont, setIconTitleFont},
507 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
508 NULL, getFont, setClipTitleFont},
509 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
510 NULL, getFont, setLargeDisplayFont},
511 {"HighlightColor", "white", NULL,
512 NULL, getColor, setHightlight},
513 {"HighlightTextColor", "black", NULL,
514 NULL, getColor, setHightlightText},
515 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
516 NULL, getColor, setClipTitleColor},
517 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
518 NULL, getColor, setClipTitleColor},
519 {"FTitleColor", "white", (void *)WS_FOCUSED,
520 NULL, getColor, setWTitleColor},
521 {"PTitleColor", "white", (void *)WS_PFOCUSED,
522 NULL, getColor, setWTitleColor},
523 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
524 NULL, getColor, setWTitleColor},
525 {"FTitleBack", "(solid, black)", NULL,
526 NULL, getTexture, setFTitleBack},
527 {"PTitleBack", "(solid, \"#616161\")", NULL,
528 NULL, getTexture, setPTitleBack},
529 {"UTitleBack", "(solid, gray)", NULL,
530 NULL, getTexture, setUTitleBack},
531 {"ResizebarBack", "(solid, gray)", NULL,
532 NULL, getTexture, setResizebarBack},
533 {"MenuTitleColor", "white", NULL,
534 NULL, getColor, setMenuTitleColor},
535 {"MenuTextColor", "black", NULL,
536 NULL, getColor, setMenuTextColor},
537 {"MenuDisabledColor", "\"#616161\"", NULL,
538 NULL, getColor, setMenuDisabledColor},
539 {"MenuTitleBack", "(solid, black)", NULL,
540 NULL, getTexture, setMenuTitleBack},
541 {"MenuTextBack", "(solid, gray)", NULL,
542 NULL, getTexture, setMenuTextBack},
543 {"IconTitleColor", "white", NULL,
544 NULL, getColor, setIconTitleColor},
545 {"IconTitleBack", "black", NULL,
546 NULL, getColor, setIconTitleBack},
547 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
548 NULL, getPropList, setSwPOptions},
549 /* keybindings */
550 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
551 NULL, getKeybind, setKeyGrab},
552 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
553 NULL, getKeybind, setKeyGrab},
554 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
555 NULL, getKeybind, setKeyGrab},
556 {"ClipLowerKey", "None", (void *)WKBD_CLIPLOWER,
557 NULL, getKeybind, setKeyGrab},
558 {"ClipRaiseKey", "None", (void *)WKBD_CLIPRAISE,
559 NULL, getKeybind, setKeyGrab},
560 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
561 NULL, getKeybind, setKeyGrab},
562 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
563 NULL, getKeybind, setKeyGrab},
564 {"HideKey", "None", (void *)WKBD_HIDE,
565 NULL, getKeybind, setKeyGrab},
566 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
567 NULL, getKeybind, setKeyGrab},
568 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
569 NULL, getKeybind, setKeyGrab},
570 {"CloseKey", "None", (void *)WKBD_CLOSE,
571 NULL, getKeybind, setKeyGrab},
572 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
573 NULL, getKeybind, setKeyGrab},
574 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
575 NULL, getKeybind, setKeyGrab},
576 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
577 NULL, getKeybind, setKeyGrab},
578 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
579 NULL, getKeybind, setKeyGrab},
580 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
581 NULL, getKeybind, setKeyGrab},
582 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
583 NULL, getKeybind, setKeyGrab},
584 {"ShadeKey", "None", (void *)WKBD_SHADE,
585 NULL, getKeybind, setKeyGrab},
586 {"SelectKey", "None", (void *)WKBD_SELECT,
587 NULL, getKeybind, setKeyGrab},
588 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
589 NULL, getKeybind, setKeyGrab},
590 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
591 NULL, getKeybind, setKeyGrab},
592 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
593 NULL, getKeybind, setKeyGrab},
594 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
595 NULL, getKeybind, setKeyGrab},
596 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
597 NULL, getKeybind, setKeyGrab},
598 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
599 NULL, getKeybind, setKeyGrab},
600 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
601 NULL, getKeybind, setKeyGrab},
602 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
603 NULL, getKeybind, setKeyGrab},
604 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
605 NULL, getKeybind, setKeyGrab},
606 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
607 NULL, getKeybind, setKeyGrab},
608 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
609 NULL, getKeybind, setKeyGrab},
610 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
611 NULL, getKeybind, setKeyGrab},
612 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
613 NULL, getKeybind, setKeyGrab},
614 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
615 NULL, getKeybind, setKeyGrab},
616 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
617 NULL, getKeybind, setKeyGrab},
618 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
619 NULL, getKeybind, setKeyGrab},
620 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
621 NULL, getKeybind, setKeyGrab},
622 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
623 NULL, getKeybind, setKeyGrab},
624 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
625 NULL, getKeybind, setKeyGrab},
626 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
627 NULL, getKeybind, setKeyGrab}
628 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
629 NULL, getKeybind, setKeyGrab},
630 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
631 NULL, getKeybind, setKeyGrab},
632 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
633 NULL, getKeybind, setKeyGrab},
634 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
635 NULL, getKeybind, setKeyGrab},
636 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
637 NULL, getKeybind, setKeyGrab},
638 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
639 NULL, getKeybind, setKeyGrab},
640 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
641 NULL, getKeybind, setKeyGrab},
643 #ifdef KEEP_XKB_LOCK_STATUS
644 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
645 NULL, getKeybind, setKeyGrab},
646 {"KbdModeLock", "NO", NULL,
647 &wPreferences.modelock, getBool, NULL},
648 #endif /* KEEP_XKB_LOCK_STATUS */
650 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
651 NULL, getCursor, setCursor},
652 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
653 NULL, getCursor, setCursor},
654 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
655 NULL, getCursor, setCursor},
656 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
657 NULL, getCursor, setCursor},
658 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
659 (void *)WCUR_TOPLEFTRESIZE,
660 NULL, getCursor, setCursor},
661 {"TopRightResizeCursor", "(builtin, top_right_corner)",
662 (void *)WCUR_TOPRIGHTRESIZE,
663 NULL, getCursor, setCursor},
664 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
665 (void *)WCUR_BOTTOMLEFTRESIZE,
666 NULL, getCursor, setCursor},
667 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
668 (void *)WCUR_BOTTOMRIGHTRESIZE,
669 NULL, getCursor, setCursor},
670 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
671 (void *)WCUR_VERTICALRESIZE,
672 NULL, getCursor, setCursor},
673 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
674 (void *)WCUR_HORIZONRESIZE,
675 NULL, getCursor, setCursor},
676 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
677 NULL, getCursor, setCursor},
678 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
679 NULL, getCursor, setCursor},
680 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
681 NULL, getCursor, setCursor},
682 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
683 NULL, getCursor, setCursor}
686 #if 0
687 static void rereadDefaults(void);
688 #endif
690 #if 0
691 static void rereadDefaults(void)
693 /* must defer the update because accessing X data from a
694 * signal handler can mess up Xlib */
697 #endif
699 static void initDefaults()
701 unsigned int i;
702 WDefaultEntry *entry;
704 WMPLSetCaseSensitive(False);
706 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
707 entry = &optionList[i];
709 entry->plkey = WMCreatePLString(entry->key);
710 if (entry->default_value)
711 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
712 else
713 entry->plvalue = NULL;
716 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
717 entry = &staticOptionList[i];
719 entry->plkey = WMCreatePLString(entry->key);
720 if (entry->default_value)
721 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
722 else
723 entry->plvalue = NULL;
727 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
728 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
730 PLRegister(wDomainName, rereadDefaults);
731 PLRegister(wAttributeDomainName, rereadDefaults);
735 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
737 WMPropList *globalDict = NULL;
738 char path[PATH_MAX];
739 struct stat stbuf;
741 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domainName);
742 if (stat(path, &stbuf) >= 0) {
743 globalDict = WMReadPropListFromFile(path);
744 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
745 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
746 WMReleasePropList(globalDict);
747 globalDict = NULL;
748 } else if (!globalDict) {
749 wwarning(_("could not load domain %s from global defaults database"), domainName);
753 return globalDict;
756 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
757 static void prependMenu(WMPropList * destarr, WMPropList * array)
759 WMPropList *item;
760 int i;
762 for (i = 0; i < WMGetPropListItemCount(array); i++) {
763 item = WMGetFromPLArray(array, i);
764 if (item)
765 WMInsertInPLArray(destarr, i + 1, item);
769 static void appendMenu(WMPropList * destarr, WMPropList * array)
771 WMPropList *item;
772 int i;
774 for (i = 0; i < WMGetPropListItemCount(array); i++) {
775 item = WMGetFromPLArray(array, i);
776 if (item)
777 WMAddToPLArray(destarr, item);
780 #endif
782 /* Fixup paths for cached pixmaps from .AppInfo to Library/WindowMaker/... */
783 static Bool fixupCachedPixmapsPaths(WMPropList * dict)
785 WMPropList *allApps, *app, *props, *iconkey, *icon, *newicon;
786 char *path, *fixedpath, *ptr, *search;
787 int i, len, slen;
788 Bool changed = False;
790 search = "/.AppInfo/WindowMaker/";
791 slen = strlen(search);
793 iconkey = WMCreatePLString("Icon");
794 allApps = WMGetPLDictionaryKeys(dict);
796 for (i = 0; i < WMGetPropListItemCount(allApps); i++) {
797 app = WMGetFromPLArray(allApps, i);
798 props = WMGetFromPLDictionary(dict, app);
799 if (!props)
800 continue;
801 icon = WMGetFromPLDictionary(props, iconkey);
802 if (icon && WMIsPLString(icon)) {
803 path = WMGetFromPLString(icon);
804 ptr = strstr(path, search);
805 if (ptr) {
806 changed = True;
807 len = (ptr - path);
808 fixedpath = wmalloc(strlen(path) + 32);
809 strncpy(fixedpath, path, len);
810 fixedpath[len] = 0;
811 strcat(fixedpath, "/Library/WindowMaker/CachedPixmaps/");
812 strcat(fixedpath, ptr + slen);
813 newicon = WMCreatePLString(fixedpath);
814 WMPutInPLDictionary(props, iconkey, newicon);
815 WMReleasePropList(newicon);
816 wfree(fixedpath);
821 WMReleasePropList(allApps);
822 WMReleasePropList(iconkey);
824 return changed;
827 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
829 WMPropList *menu = menuDomain->dictionary;
830 WMPropList *submenu;
832 if (!menu || !WMIsPLArray(menu))
833 return;
835 #ifdef GLOBAL_PREAMBLE_MENU_FILE
836 submenu = WMReadPropListFromFile(SYSCONFDIR "/WindowMaker/" GLOBAL_PREAMBLE_MENU_FILE);
838 if (submenu && !WMIsPLArray(submenu)) {
839 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
840 WMReleasePropList(submenu);
841 submenu = NULL;
843 if (submenu) {
844 prependMenu(menu, submenu);
845 WMReleasePropList(submenu);
847 #endif
849 #ifdef GLOBAL_EPILOGUE_MENU_FILE
850 submenu = WMReadPropListFromFile(SYSCONFDIR "/WindowMaker/" GLOBAL_EPILOGUE_MENU_FILE);
852 if (submenu && !WMIsPLArray(submenu)) {
853 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
854 WMReleasePropList(submenu);
855 submenu = NULL;
857 if (submenu) {
858 appendMenu(menu, submenu);
859 WMReleasePropList(submenu);
861 #endif
863 menuDomain->dictionary = menu;
866 #if 0
867 WMPropList *wDefaultsInit(int screen_number)
869 static int defaults_inited = 0;
870 WMPropList *dict;
872 if (!defaults_inited) {
873 initDefaults();
876 dict = PLGetDomain(wDomainName);
877 if (!dict) {
878 wwarning(_("could not read domain \"%s\" from defaults database"), WMGetFromPLString(wDomainName));
881 return dict;
883 #endif
885 void wDefaultsDestroyDomain(WDDomain * domain)
887 if (domain->dictionary)
888 WMReleasePropList(domain->dictionary);
889 wfree(domain->path);
890 wfree(domain);
893 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
895 WDDomain *db;
896 struct stat stbuf;
897 static int inited = 0;
898 char path[PATH_MAX];
899 char *the_path;
900 WMPropList *shared_dict = NULL;
902 if (!inited) {
903 inited = 1;
904 initDefaults();
907 db = wmalloc(sizeof(WDDomain));
908 memset(db, 0, sizeof(WDDomain));
909 db->domain_name = domain;
910 db->path = wdefaultspathfordomain(domain);
911 the_path = db->path;
913 if (the_path && stat(the_path, &stbuf) >= 0) {
914 db->dictionary = WMReadPropListFromFile(the_path);
915 if (db->dictionary) {
916 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
917 WMReleasePropList(db->dictionary);
918 db->dictionary = NULL;
919 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
921 if (strcmp(domain, "WMWindowAttributes") == 0 && db->dictionary) {
922 if (fixupCachedPixmapsPaths(db->dictionary)) {
923 WMWritePropListToFile(db->dictionary, db->path, True);
924 /* re-read the timestamp. if this fails take current time */
925 if (stat(db->path, &stbuf) < 0) {
926 stbuf.st_mtime = time(NULL);
930 db->timestamp = stbuf.st_mtime;
931 } else {
932 wwarning(_("could not load domain %s from user defaults database"), domain);
936 /* global system dictionary */
937 snprintf(path, sizeof(path), "%s/WindowMaker/%s", SYSCONFDIR, domain);
938 if (stat(path, &stbuf) >= 0) {
939 shared_dict = WMReadPropListFromFile(path);
940 if (shared_dict) {
941 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
942 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
943 domain, path);
944 WMReleasePropList(shared_dict);
945 shared_dict = NULL;
946 } else {
947 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
948 WMIsPLDictionary(db->dictionary)) {
949 WMMergePLDictionaries(shared_dict, db->dictionary, True);
950 WMReleasePropList(db->dictionary);
951 db->dictionary = shared_dict;
952 if (stbuf.st_mtime > db->timestamp)
953 db->timestamp = stbuf.st_mtime;
954 } else if (!db->dictionary) {
955 db->dictionary = shared_dict;
956 if (stbuf.st_mtime > db->timestamp)
957 db->timestamp = stbuf.st_mtime;
960 } else {
961 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
965 return db;
968 void wReadStaticDefaults(WMPropList * dict)
970 WMPropList *plvalue;
971 WDefaultEntry *entry;
972 unsigned int i;
973 void *tdata;
975 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
976 entry = &staticOptionList[i];
978 if (dict)
979 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
980 else
981 plvalue = NULL;
983 if (!plvalue) {
984 /* no default in the DB. Use builtin default */
985 plvalue = entry->plvalue;
988 if (plvalue) {
989 /* convert data */
990 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
991 if (entry->update) {
992 (*entry->update) (NULL, entry, tdata, entry->extra_data);
998 void wDefaultsCheckDomains(void)
1000 WScreen *scr;
1001 struct stat stbuf;
1002 WMPropList *shared_dict = NULL;
1003 WMPropList *dict;
1004 int i;
1006 #ifdef HEARTBEAT
1007 puts("Checking domains...");
1008 #endif
1009 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
1010 #ifdef HEARTBEAT
1011 puts("Checking WindowMaker domain");
1012 #endif
1013 WDWindowMaker->timestamp = stbuf.st_mtime;
1015 /* global dictionary */
1016 shared_dict = readGlobalDomain("WindowMaker", True);
1017 /* user dictionary */
1018 dict = WMReadPropListFromFile(WDWindowMaker->path);
1019 if (dict) {
1020 if (!WMIsPLDictionary(dict)) {
1021 WMReleasePropList(dict);
1022 dict = NULL;
1023 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1024 "WindowMaker", WDWindowMaker->path);
1025 } else {
1026 if (shared_dict) {
1027 WMMergePLDictionaries(shared_dict, dict, True);
1028 WMReleasePropList(dict);
1029 dict = shared_dict;
1030 shared_dict = NULL;
1032 for (i = 0; i < wScreenCount; i++) {
1033 scr = wScreenWithNumber(i);
1034 if (scr)
1035 wReadDefaults(scr, dict);
1037 if (WDWindowMaker->dictionary) {
1038 WMReleasePropList(WDWindowMaker->dictionary);
1040 WDWindowMaker->dictionary = dict;
1042 } else {
1043 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
1045 if (shared_dict) {
1046 WMReleasePropList(shared_dict);
1050 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
1051 #ifdef HEARTBEAT
1052 puts("Checking WMWindowAttributes domain");
1053 #endif
1054 /* global dictionary */
1055 shared_dict = readGlobalDomain("WMWindowAttributes", True);
1056 /* user dictionary */
1057 dict = WMReadPropListFromFile(WDWindowAttributes->path);
1058 if (dict) {
1059 if (!WMIsPLDictionary(dict)) {
1060 WMReleasePropList(dict);
1061 dict = NULL;
1062 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1063 "WMWindowAttributes", WDWindowAttributes->path);
1064 } else {
1065 if (shared_dict) {
1066 WMMergePLDictionaries(shared_dict, dict, True);
1067 WMReleasePropList(dict);
1068 dict = shared_dict;
1069 shared_dict = NULL;
1071 if (WDWindowAttributes->dictionary) {
1072 WMReleasePropList(WDWindowAttributes->dictionary);
1074 WDWindowAttributes->dictionary = dict;
1075 for (i = 0; i < wScreenCount; i++) {
1076 scr = wScreenWithNumber(i);
1077 if (scr) {
1078 RImage *image;
1080 wDefaultUpdateIcons(scr);
1082 /* Update the panel image if changed */
1083 /* Don't worry. If the image is the same these
1084 * functions will have no performance impact. */
1085 image = wDefaultGetImage(scr, "Logo", "WMPanel");
1087 if (!image) {
1088 wwarning(_("could not load logo image for panels: %s"),
1089 RMessageForError(RErrorCode));
1090 } else {
1091 WMSetApplicationIconImage(scr->wmscreen, image);
1092 RReleaseImage(image);
1097 } else {
1098 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1100 WDWindowAttributes->timestamp = stbuf.st_mtime;
1101 if (shared_dict) {
1102 WMReleasePropList(shared_dict);
1106 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1107 dict = WMReadPropListFromFile(WDRootMenu->path);
1108 #ifdef HEARTBEAT
1109 puts("Checking WMRootMenu domain");
1110 #endif
1111 if (dict) {
1112 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1113 WMReleasePropList(dict);
1114 dict = NULL;
1115 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1116 "WMRootMenu", WDRootMenu->path);
1117 } else {
1118 if (WDRootMenu->dictionary) {
1119 WMReleasePropList(WDRootMenu->dictionary);
1121 WDRootMenu->dictionary = dict;
1122 wDefaultsMergeGlobalMenus(WDRootMenu);
1124 } else {
1125 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1127 WDRootMenu->timestamp = stbuf.st_mtime;
1131 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1133 WMPropList *plvalue, *old_value;
1134 WDefaultEntry *entry;
1135 unsigned int i, must_update;
1136 int update_workspace_back = 0; /* kluge :/ */
1137 unsigned int needs_refresh;
1138 void *tdata;
1139 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1141 must_update = 0;
1143 needs_refresh = 0;
1145 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1146 entry = &optionList[i];
1148 if (new_dict)
1149 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1150 else
1151 plvalue = NULL;
1153 if (!old_dict)
1154 old_value = NULL;
1155 else
1156 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1158 if (!plvalue && !old_value) {
1159 /* no default in the DB. Use builtin default */
1160 plvalue = entry->plvalue;
1161 if (plvalue && new_dict) {
1162 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1163 must_update = 1;
1165 } else if (!plvalue) {
1166 /* value was deleted from DB. Keep current value */
1167 continue;
1168 } else if (!old_value) {
1169 /* set value for the 1st time */
1170 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1171 /* value has changed */
1172 } else {
1174 if (strcmp(entry->key, "WorkspaceBack") == 0
1175 && update_workspace_back && scr->flags.backimage_helper_launched) {
1176 } else {
1177 /* value was not changed since last time */
1178 continue;
1182 if (plvalue) {
1183 #ifdef DEBUG
1184 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1185 #endif
1186 /* convert data */
1187 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1189 * If the WorkspaceSpecificBack data has been changed
1190 * so that the helper will be launched now, we must be
1191 * sure to send the default background texture config
1192 * to the helper.
1194 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1195 && !scr->flags.backimage_helper_launched) {
1196 update_workspace_back = 1;
1198 if (entry->update) {
1199 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1205 if (needs_refresh != 0 && !scr->flags.startup) {
1206 int foo;
1208 foo = 0;
1209 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1210 foo |= WTextureSettings;
1211 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1212 foo |= WFontSettings;
1213 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1214 foo |= WColorSettings;
1215 if (foo)
1216 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1217 (void *)(uintptr_t) foo);
1219 foo = 0;
1220 if (needs_refresh & REFRESH_MENU_TEXTURE)
1221 foo |= WTextureSettings;
1222 if (needs_refresh & REFRESH_MENU_FONT)
1223 foo |= WFontSettings;
1224 if (needs_refresh & REFRESH_MENU_COLOR)
1225 foo |= WColorSettings;
1226 if (foo)
1227 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1229 foo = 0;
1230 if (needs_refresh & REFRESH_WINDOW_FONT) {
1231 foo |= WFontSettings;
1233 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1234 foo |= WTextureSettings;
1236 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1237 foo |= WColorSettings;
1239 if (foo)
1240 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1242 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1243 foo = 0;
1244 if (needs_refresh & REFRESH_ICON_FONT) {
1245 foo |= WFontSettings;
1247 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1248 foo |= WTextureSettings;
1250 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1251 foo |= WTextureSettings;
1253 if (foo)
1254 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1255 (void *)(uintptr_t) foo);
1257 if (needs_refresh & REFRESH_ICON_TILE)
1258 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1262 void wDefaultUpdateIcons(WScreen * scr)
1264 WAppIcon *aicon = scr->app_icon_list;
1265 WWindow *wwin = scr->focused_window;
1266 char *file;
1268 while (aicon) {
1269 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1270 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1271 || (file && !aicon->icon->file)) {
1272 RImage *new_image;
1274 if (aicon->icon->file)
1275 wfree(aicon->icon->file);
1276 aicon->icon->file = wstrdup(file);
1278 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1279 if (new_image) {
1280 wIconChangeImage(aicon->icon, new_image);
1281 wAppIconPaint(aicon);
1284 aicon = aicon->next;
1287 if (!wPreferences.flags.noclip)
1288 wClipIconPaint(scr->clip_icon);
1290 while (wwin) {
1291 if (wwin->icon && wwin->flags.miniaturized) {
1292 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1293 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1294 || (file && !wwin->icon->file)) {
1295 RImage *new_image;
1297 if (wwin->icon->file)
1298 wfree(wwin->icon->file);
1299 wwin->icon->file = wstrdup(file);
1301 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1302 if (new_image)
1303 wIconChangeImage(wwin->icon, new_image);
1306 wwin = wwin->prev;
1310 /* --------------------------- Local ----------------------- */
1312 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1313 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1314 entry->key, x); \
1315 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1316 var = entry->default_value;\
1317 } else var = WMGetFromPLString(value)\
1320 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1322 char *str;
1323 WOptionEnumeration *v;
1324 char buffer[TOTAL_VALUES_LENGTH];
1326 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1327 for (v = values; v->string != NULL; v++) {
1328 if (strcasecmp(v->string, str) == 0)
1329 return v->value;
1333 buffer[0] = 0;
1334 for (v = values; v->string != NULL; v++) {
1335 if (!v->is_alias) {
1336 if (buffer[0] != 0)
1337 strcat(buffer, ", ");
1338 strcat(buffer, v->string);
1341 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1343 if (def) {
1344 return string2index(key, val, NULL, values);
1347 return -1;
1351 * value - is the value in the defaults DB
1352 * addr - is the address to store the data
1353 * ret - is the address to store a pointer to a temporary buffer. ret
1354 * must not be freed and is used by the set functions
1356 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1358 static char data;
1359 char *val;
1360 int second_pass = 0;
1362 GET_STRING_OR_DEFAULT("Boolean", val);
1364 again:
1365 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1366 || strcasecmp(val, "YES") == 0) {
1368 data = 1;
1369 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1370 || strcasecmp(val, "NO") == 0) {
1371 data = 0;
1372 } else {
1373 int i;
1374 if (sscanf(val, "%i", &i) == 1) {
1375 if (i != 0)
1376 data = 1;
1377 else
1378 data = 0;
1379 } else {
1380 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1381 if (second_pass == 0) {
1382 val = WMGetFromPLString(entry->plvalue);
1383 second_pass = 1;
1384 wwarning(_("using default \"%s\" instead"), val);
1385 goto again;
1387 return False;
1391 if (ret)
1392 *ret = &data;
1393 if (addr)
1394 *(char *)addr = data;
1396 return True;
1399 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1401 static int data;
1402 char *val;
1404 GET_STRING_OR_DEFAULT("Integer", val);
1406 if (sscanf(val, "%i", &data) != 1) {
1407 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1408 val = WMGetFromPLString(entry->plvalue);
1409 wwarning(_("using default \"%s\" instead"), val);
1410 if (sscanf(val, "%i", &data) != 1) {
1411 return False;
1415 if (ret)
1416 *ret = &data;
1417 if (addr)
1418 *(int *)addr = data;
1420 return True;
1423 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1425 static WCoord data;
1426 char *val_x, *val_y;
1427 int nelem, changed = 0;
1428 WMPropList *elem_x, *elem_y;
1430 again:
1431 if (!WMIsPLArray(value)) {
1432 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1433 if (changed == 0) {
1434 value = entry->plvalue;
1435 changed = 1;
1436 wwarning(_("using default \"%s\" instead"), entry->default_value);
1437 goto again;
1439 return False;
1442 nelem = WMGetPropListItemCount(value);
1443 if (nelem != 2) {
1444 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1445 if (changed == 0) {
1446 value = entry->plvalue;
1447 changed = 1;
1448 wwarning(_("using default \"%s\" instead"), entry->default_value);
1449 goto again;
1451 return False;
1454 elem_x = WMGetFromPLArray(value, 0);
1455 elem_y = WMGetFromPLArray(value, 1);
1457 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1458 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1459 if (changed == 0) {
1460 value = entry->plvalue;
1461 changed = 1;
1462 wwarning(_("using default \"%s\" instead"), entry->default_value);
1463 goto again;
1465 return False;
1468 val_x = WMGetFromPLString(elem_x);
1469 val_y = WMGetFromPLString(elem_y);
1471 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1472 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1473 if (changed == 0) {
1474 value = entry->plvalue;
1475 changed = 1;
1476 wwarning(_("using default \"%s\" instead"), entry->default_value);
1477 goto again;
1479 return False;
1482 if (data.x < 0)
1483 data.x = 0;
1484 else if (data.x > scr->scr_width / 3)
1485 data.x = scr->scr_width / 3;
1486 if (data.y < 0)
1487 data.y = 0;
1488 else if (data.y > scr->scr_height / 3)
1489 data.y = scr->scr_height / 3;
1491 if (ret)
1492 *ret = &data;
1493 if (addr)
1494 *(WCoord *) addr = data;
1496 return True;
1499 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1501 WMRetainPropList(value);
1503 *ret = value;
1505 return True;
1508 #if 0
1509 /* This function is not used at the moment. */
1510 static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1512 static char *data;
1514 GET_STRING_OR_DEFAULT("String", data);
1516 if (!data) {
1517 data = WMGetFromPLString(entry->plvalue);
1518 if (!data)
1519 return False;
1522 if (ret)
1523 *ret = &data;
1524 if (addr)
1525 *(char **)addr = wstrdup(data);
1527 return True;
1529 #endif
1531 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1533 static char *data;
1534 int i, count, len;
1535 char *ptr;
1536 WMPropList *d;
1537 int changed = 0;
1539 again:
1540 if (!WMIsPLArray(value)) {
1541 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1542 if (changed == 0) {
1543 value = entry->plvalue;
1544 changed = 1;
1545 wwarning(_("using default \"%s\" instead"), entry->default_value);
1546 goto again;
1548 return False;
1551 i = 0;
1552 count = WMGetPropListItemCount(value);
1553 if (count < 1) {
1554 if (changed == 0) {
1555 value = entry->plvalue;
1556 changed = 1;
1557 wwarning(_("using default \"%s\" instead"), entry->default_value);
1558 goto again;
1560 return False;
1563 len = 0;
1564 for (i = 0; i < count; i++) {
1565 d = WMGetFromPLArray(value, i);
1566 if (!d || !WMIsPLString(d)) {
1567 count = i;
1568 break;
1570 len += strlen(WMGetFromPLString(d)) + 1;
1573 ptr = data = wmalloc(len + 1);
1575 for (i = 0; i < count; i++) {
1576 d = WMGetFromPLArray(value, i);
1577 if (!d || !WMIsPLString(d)) {
1578 break;
1580 strcpy(ptr, WMGetFromPLString(d));
1581 ptr += strlen(WMGetFromPLString(d));
1582 *ptr = ':';
1583 ptr++;
1585 ptr--;
1586 *(ptr--) = 0;
1588 if (*(char **)addr != NULL) {
1589 wfree(*(char **)addr);
1591 *(char **)addr = data;
1593 return True;
1596 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1598 static signed char data;
1600 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1601 if (data < 0)
1602 return False;
1604 if (ret)
1605 *ret = &data;
1606 if (addr)
1607 *(signed char *)addr = data;
1609 return True;
1613 * (solid <color>)
1614 * (hgradient <color> <color>)
1615 * (vgradient <color> <color>)
1616 * (dgradient <color> <color>)
1617 * (mhgradient <color> <color> ...)
1618 * (mvgradient <color> <color> ...)
1619 * (mdgradient <color> <color> ...)
1620 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1621 * (tpixmap <file> <color>)
1622 * (spixmap <file> <color>)
1623 * (cpixmap <file> <color>)
1624 * (thgradient <file> <opaqueness> <color> <color>)
1625 * (tvgradient <file> <opaqueness> <color> <color>)
1626 * (tdgradient <file> <opaqueness> <color> <color>)
1627 * (function <lib> <function> ...)
1630 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1632 WMPropList *elem;
1633 char *val;
1634 int nelem;
1635 WTexture *texture = NULL;
1637 nelem = WMGetPropListItemCount(pl);
1638 if (nelem < 1)
1639 return NULL;
1641 elem = WMGetFromPLArray(pl, 0);
1642 if (!elem || !WMIsPLString(elem))
1643 return NULL;
1644 val = WMGetFromPLString(elem);
1646 if (strcasecmp(val, "solid") == 0) {
1647 XColor color;
1649 if (nelem != 2)
1650 return NULL;
1652 /* get color */
1654 elem = WMGetFromPLArray(pl, 1);
1655 if (!elem || !WMIsPLString(elem))
1656 return NULL;
1657 val = WMGetFromPLString(elem);
1659 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1660 wwarning(_("\"%s\" is not a valid color name"), val);
1661 return NULL;
1664 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1665 } else if (strcasecmp(val, "dgradient") == 0
1666 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1667 RColor color1, color2;
1668 XColor xcolor;
1669 int type;
1671 if (nelem != 3) {
1672 wwarning(_("bad number of arguments in gradient specification"));
1673 return NULL;
1676 if (val[0] == 'd' || val[0] == 'D')
1677 type = WTEX_DGRADIENT;
1678 else if (val[0] == 'h' || val[0] == 'H')
1679 type = WTEX_HGRADIENT;
1680 else
1681 type = WTEX_VGRADIENT;
1683 /* get from color */
1684 elem = WMGetFromPLArray(pl, 1);
1685 if (!elem || !WMIsPLString(elem))
1686 return NULL;
1687 val = WMGetFromPLString(elem);
1689 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1690 wwarning(_("\"%s\" is not a valid color name"), val);
1691 return NULL;
1693 color1.alpha = 255;
1694 color1.red = xcolor.red >> 8;
1695 color1.green = xcolor.green >> 8;
1696 color1.blue = xcolor.blue >> 8;
1698 /* get to color */
1699 elem = WMGetFromPLArray(pl, 2);
1700 if (!elem || !WMIsPLString(elem)) {
1701 return NULL;
1703 val = WMGetFromPLString(elem);
1705 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1706 wwarning(_("\"%s\" is not a valid color name"), val);
1707 return NULL;
1709 color2.alpha = 255;
1710 color2.red = xcolor.red >> 8;
1711 color2.green = xcolor.green >> 8;
1712 color2.blue = xcolor.blue >> 8;
1714 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1716 } else if (strcasecmp(val, "igradient") == 0) {
1717 RColor colors1[2], colors2[2];
1718 int th1, th2;
1719 XColor xcolor;
1720 int i;
1722 if (nelem != 7) {
1723 wwarning(_("bad number of arguments in gradient specification"));
1724 return NULL;
1727 /* get from color */
1728 for (i = 0; i < 2; i++) {
1729 elem = WMGetFromPLArray(pl, 1 + i);
1730 if (!elem || !WMIsPLString(elem))
1731 return NULL;
1732 val = WMGetFromPLString(elem);
1734 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1735 wwarning(_("\"%s\" is not a valid color name"), val);
1736 return NULL;
1738 colors1[i].alpha = 255;
1739 colors1[i].red = xcolor.red >> 8;
1740 colors1[i].green = xcolor.green >> 8;
1741 colors1[i].blue = xcolor.blue >> 8;
1743 elem = WMGetFromPLArray(pl, 3);
1744 if (!elem || !WMIsPLString(elem))
1745 return NULL;
1746 val = WMGetFromPLString(elem);
1747 th1 = atoi(val);
1749 /* get from color */
1750 for (i = 0; i < 2; i++) {
1751 elem = WMGetFromPLArray(pl, 4 + i);
1752 if (!elem || !WMIsPLString(elem))
1753 return NULL;
1754 val = WMGetFromPLString(elem);
1756 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1757 wwarning(_("\"%s\" is not a valid color name"), val);
1758 return NULL;
1760 colors2[i].alpha = 255;
1761 colors2[i].red = xcolor.red >> 8;
1762 colors2[i].green = xcolor.green >> 8;
1763 colors2[i].blue = xcolor.blue >> 8;
1765 elem = WMGetFromPLArray(pl, 6);
1766 if (!elem || !WMIsPLString(elem))
1767 return NULL;
1768 val = WMGetFromPLString(elem);
1769 th2 = atoi(val);
1771 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1773 } else if (strcasecmp(val, "mhgradient") == 0
1774 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1775 XColor color;
1776 RColor **colors;
1777 int i, count;
1778 int type;
1780 if (nelem < 3) {
1781 wwarning(_("too few arguments in multicolor gradient specification"));
1782 return NULL;
1785 if (val[1] == 'h' || val[1] == 'H')
1786 type = WTEX_MHGRADIENT;
1787 else if (val[1] == 'v' || val[1] == 'V')
1788 type = WTEX_MVGRADIENT;
1789 else
1790 type = WTEX_MDGRADIENT;
1792 count = nelem - 1;
1794 colors = wmalloc(sizeof(RColor *) * (count + 1));
1796 for (i = 0; i < count; i++) {
1797 elem = WMGetFromPLArray(pl, i + 1);
1798 if (!elem || !WMIsPLString(elem)) {
1799 for (--i; i >= 0; --i) {
1800 wfree(colors[i]);
1802 wfree(colors);
1803 return NULL;
1805 val = WMGetFromPLString(elem);
1807 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1808 wwarning(_("\"%s\" is not a valid color name"), val);
1809 for (--i; i >= 0; --i) {
1810 wfree(colors[i]);
1812 wfree(colors);
1813 return NULL;
1814 } else {
1815 colors[i] = wmalloc(sizeof(RColor));
1816 colors[i]->red = color.red >> 8;
1817 colors[i]->green = color.green >> 8;
1818 colors[i]->blue = color.blue >> 8;
1821 colors[i] = NULL;
1823 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1824 } else if (strcasecmp(val, "spixmap") == 0 ||
1825 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1826 XColor color;
1827 int type;
1829 if (nelem != 3)
1830 return NULL;
1832 if (val[0] == 's' || val[0] == 'S')
1833 type = WTP_SCALE;
1834 else if (val[0] == 'c' || val[0] == 'C')
1835 type = WTP_CENTER;
1836 else
1837 type = WTP_TILE;
1839 /* get color */
1840 elem = WMGetFromPLArray(pl, 2);
1841 if (!elem || !WMIsPLString(elem)) {
1842 return NULL;
1844 val = WMGetFromPLString(elem);
1846 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1847 wwarning(_("\"%s\" is not a valid color name"), val);
1848 return NULL;
1851 /* file name */
1852 elem = WMGetFromPLArray(pl, 1);
1853 if (!elem || !WMIsPLString(elem))
1854 return NULL;
1855 val = WMGetFromPLString(elem);
1857 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1858 } else if (strcasecmp(val, "thgradient") == 0
1859 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1860 RColor color1, color2;
1861 XColor xcolor;
1862 int opacity;
1863 int style;
1865 if (val[1] == 'h' || val[1] == 'H')
1866 style = WTEX_THGRADIENT;
1867 else if (val[1] == 'v' || val[1] == 'V')
1868 style = WTEX_TVGRADIENT;
1869 else
1870 style = WTEX_TDGRADIENT;
1872 if (nelem != 5) {
1873 wwarning(_("bad number of arguments in textured gradient specification"));
1874 return NULL;
1877 /* get from color */
1878 elem = WMGetFromPLArray(pl, 3);
1879 if (!elem || !WMIsPLString(elem))
1880 return NULL;
1881 val = WMGetFromPLString(elem);
1883 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1884 wwarning(_("\"%s\" is not a valid color name"), val);
1885 return NULL;
1887 color1.alpha = 255;
1888 color1.red = xcolor.red >> 8;
1889 color1.green = xcolor.green >> 8;
1890 color1.blue = xcolor.blue >> 8;
1892 /* get to color */
1893 elem = WMGetFromPLArray(pl, 4);
1894 if (!elem || !WMIsPLString(elem)) {
1895 return NULL;
1897 val = WMGetFromPLString(elem);
1899 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1900 wwarning(_("\"%s\" is not a valid color name"), val);
1901 return NULL;
1903 color2.alpha = 255;
1904 color2.red = xcolor.red >> 8;
1905 color2.green = xcolor.green >> 8;
1906 color2.blue = xcolor.blue >> 8;
1908 /* get opacity */
1909 elem = WMGetFromPLArray(pl, 2);
1910 if (!elem || !WMIsPLString(elem))
1911 opacity = 128;
1912 else
1913 val = WMGetFromPLString(elem);
1915 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1916 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1917 opacity = 128;
1920 /* get file name */
1921 elem = WMGetFromPLArray(pl, 1);
1922 if (!elem || !WMIsPLString(elem))
1923 return NULL;
1924 val = WMGetFromPLString(elem);
1926 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1928 #ifdef TEXTURE_PLUGIN
1929 else if (strcasecmp(val, "function") == 0) {
1930 WTexFunction *function;
1931 void (*initFunc) (Display *, Colormap);
1932 char *lib, *func, **argv;
1933 int i, argc;
1935 if (nelem < 3)
1936 return NULL;
1938 /* get the library name */
1939 elem = WMGetFromPLArray(pl, 1);
1940 if (!elem || !WMIsPLString(elem)) {
1941 return NULL;
1943 lib = WMGetFromPLString(elem);
1945 /* get the function name */
1946 elem = WMGetFromPLArray(pl, 2);
1947 if (!elem || !WMIsPLString(elem)) {
1948 return NULL;
1950 func = WMGetFromPLString(elem);
1952 argc = nelem - 2;
1953 argv = (char **)wmalloc(argc * sizeof(char *));
1955 /* get the parameters */
1956 argv[0] = wstrdup(func);
1957 for (i = 0; i < argc - 1; i++) {
1958 elem = WMGetFromPLArray(pl, 3 + i);
1959 if (!elem || !WMIsPLString(elem)) {
1960 wfree(argv);
1962 return NULL;
1964 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1967 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1969 #ifdef HAVE_DLFCN_H
1970 if (function) {
1971 initFunc = dlsym(function->handle, "initWindowMaker");
1972 if (initFunc) {
1973 initFunc(dpy, scr->w_colormap);
1974 } else {
1975 wwarning(_("could not initialize library %s"), lib);
1977 } else {
1978 wwarning(_("could not find function %s::%s"), lib, func);
1980 #endif /* HAVE_DLFCN_H */
1981 texture = (WTexture *) function;
1983 #endif /* TEXTURE_PLUGIN */
1984 else {
1985 wwarning(_("invalid texture type %s"), val);
1986 return NULL;
1988 return texture;
1991 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1993 static WTexture *texture;
1994 int changed = 0;
1996 again:
1997 if (!WMIsPLArray(value)) {
1998 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1999 if (changed == 0) {
2000 value = entry->plvalue;
2001 changed = 1;
2002 wwarning(_("using default \"%s\" instead"), entry->default_value);
2003 goto again;
2005 return False;
2008 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
2009 WMPropList *pl;
2011 pl = WMGetFromPLArray(value, 0);
2012 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
2013 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
2014 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2015 entry->key, "Solid Texture");
2017 value = entry->plvalue;
2018 changed = 1;
2019 wwarning(_("using default \"%s\" instead"), entry->default_value);
2020 goto again;
2024 texture = parse_texture(scr, value);
2026 if (!texture) {
2027 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
2028 if (changed == 0) {
2029 value = entry->plvalue;
2030 changed = 1;
2031 wwarning(_("using default \"%s\" instead"), entry->default_value);
2032 goto again;
2034 return False;
2037 if (ret)
2038 *ret = &texture;
2040 if (addr)
2041 *(WTexture **) addr = texture;
2043 return True;
2046 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2048 WMPropList *elem;
2049 int changed = 0;
2050 char *val;
2051 int nelem;
2053 again:
2054 if (!WMIsPLArray(value)) {
2055 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2056 "WorkspaceBack", "Texture or None");
2057 if (changed == 0) {
2058 value = entry->plvalue;
2059 changed = 1;
2060 wwarning(_("using default \"%s\" instead"), entry->default_value);
2061 goto again;
2063 return False;
2066 /* only do basic error checking and verify for None texture */
2068 nelem = WMGetPropListItemCount(value);
2069 if (nelem > 0) {
2070 elem = WMGetFromPLArray(value, 0);
2071 if (!elem || !WMIsPLString(elem)) {
2072 wwarning(_("Wrong type for workspace background. Should be a texture type."));
2073 if (changed == 0) {
2074 value = entry->plvalue;
2075 changed = 1;
2076 wwarning(_("using default \"%s\" instead"), entry->default_value);
2077 goto again;
2079 return False;
2081 val = WMGetFromPLString(elem);
2083 if (strcasecmp(val, "None") == 0)
2084 return True;
2086 *ret = WMRetainPropList(value);
2088 return True;
2091 static int
2092 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2094 WMPropList *elem;
2095 int nelem;
2096 int changed = 0;
2098 again:
2099 if (!WMIsPLArray(value)) {
2100 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2101 "WorkspaceSpecificBack", "an array of textures");
2102 if (changed == 0) {
2103 value = entry->plvalue;
2104 changed = 1;
2105 wwarning(_("using default \"%s\" instead"), entry->default_value);
2106 goto again;
2108 return False;
2111 /* only do basic error checking and verify for None texture */
2113 nelem = WMGetPropListItemCount(value);
2114 if (nelem > 0) {
2115 while (nelem--) {
2116 elem = WMGetFromPLArray(value, nelem);
2117 if (!elem || !WMIsPLArray(elem)) {
2118 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
2119 nelem);
2124 *ret = WMRetainPropList(value);
2126 #ifdef notworking
2128 * Kluge to force wmsetbg helper to set the default background.
2129 * If the WorkspaceSpecificBack is changed once wmaker has started,
2130 * the WorkspaceBack won't be sent to the helper, unless the user
2131 * changes it's value too. So, we must force this by removing the
2132 * value from the defaults DB.
2134 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2135 WMPropList *key = WMCreatePLString("WorkspaceBack");
2137 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2139 WMReleasePropList(key);
2141 #endif
2142 return True;
2145 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2147 static WMFont *font;
2148 char *val;
2150 GET_STRING_OR_DEFAULT("Font", val);
2152 font = WMCreateFont(scr->wmscreen, val);
2153 if (!font)
2154 font = WMCreateFont(scr->wmscreen, "fixed");
2156 if (!font) {
2157 wfatal(_("could not load any usable font!!!"));
2158 exit(1);
2161 if (ret)
2162 *ret = font;
2164 /* can't assign font value outside update function */
2165 wassertrv(addr == NULL, True);
2167 return True;
2170 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2172 static XColor color;
2173 char *val;
2174 int second_pass = 0;
2176 GET_STRING_OR_DEFAULT("Color", val);
2178 again:
2179 if (!wGetColor(scr, val, &color)) {
2180 wwarning(_("could not get color for key \"%s\""), entry->key);
2181 if (second_pass == 0) {
2182 val = WMGetFromPLString(entry->plvalue);
2183 second_pass = 1;
2184 wwarning(_("using default \"%s\" instead"), val);
2185 goto again;
2187 return False;
2190 if (ret)
2191 *ret = &color;
2193 assert(addr == NULL);
2195 if (addr)
2196 *(unsigned long*)addr = pixel;
2199 return True;
2202 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2204 static WShortKey shortcut;
2205 KeySym ksym;
2206 char *val;
2207 char *k;
2208 char buf[MAX_SHORTCUT_LENGTH], *b;
2210 GET_STRING_OR_DEFAULT("Key spec", val);
2212 if (!val || strcasecmp(val, "NONE") == 0) {
2213 shortcut.keycode = 0;
2214 shortcut.modifier = 0;
2215 if (ret)
2216 *ret = &shortcut;
2217 return True;
2220 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2222 b = (char *)buf;
2224 /* get modifiers */
2225 shortcut.modifier = 0;
2226 while ((k = strchr(b, '+')) != NULL) {
2227 int mod;
2229 *k = 0;
2230 mod = wXModifierFromKey(b);
2231 if (mod < 0) {
2232 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2233 return False;
2235 shortcut.modifier |= mod;
2237 b = k + 1;
2240 /* get key */
2241 ksym = XStringToKeysym(b);
2243 if (ksym == NoSymbol) {
2244 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2245 return False;
2248 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2249 if (shortcut.keycode == 0) {
2250 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2251 return False;
2254 if (ret)
2255 *ret = &shortcut;
2257 return True;
2260 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2262 static int mask;
2263 char *str;
2265 GET_STRING_OR_DEFAULT("Modifier Key", str);
2267 if (!str)
2268 return False;
2270 mask = wXModifierFromKey(str);
2271 if (mask < 0) {
2272 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2273 mask = 0;
2274 return False;
2277 if (addr)
2278 *(int *)addr = mask;
2280 if (ret)
2281 *ret = &mask;
2283 return True;
2286 #ifdef NEWSTUFF
2287 static int getRImages(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2289 unsigned int mask;
2290 char *str;
2291 RImage *image;
2292 int i, n;
2293 int w, h;
2295 GET_STRING_OR_DEFAULT("Image File Path", str);
2296 if (!str)
2297 return False;
2299 image = RLoadImage(scr->rcontext, str, 0);
2300 if (!image) {
2301 wwarning(_("could not load image in option %s: %s"), entry->key, RMessageForError(RErrorCode));
2302 return False;
2305 if (*(RImage **) addr) {
2306 RReleaseImage(*(RImage **) addr);
2308 if (addr)
2309 *(RImage **) addr = image;
2311 assert(ret == NULL);
2313 if (ret)
2314 *(RImage**)ret = image;
2317 return True;
2319 #endif
2321 # include <X11/cursorfont.h>
2322 typedef struct {
2323 char *name;
2324 int id;
2325 } WCursorLookup;
2327 #define CURSOR_ID_NONE (XC_num_glyphs)
2329 static WCursorLookup cursor_table[] = {
2330 {"X_cursor", XC_X_cursor},
2331 {"arrow", XC_arrow},
2332 {"based_arrow_down", XC_based_arrow_down},
2333 {"based_arrow_up", XC_based_arrow_up},
2334 {"boat", XC_boat},
2335 {"bogosity", XC_bogosity},
2336 {"bottom_left_corner", XC_bottom_left_corner},
2337 {"bottom_right_corner", XC_bottom_right_corner},
2338 {"bottom_side", XC_bottom_side},
2339 {"bottom_tee", XC_bottom_tee},
2340 {"box_spiral", XC_box_spiral},
2341 {"center_ptr", XC_center_ptr},
2342 {"circle", XC_circle},
2343 {"clock", XC_clock},
2344 {"coffee_mug", XC_coffee_mug},
2345 {"cross", XC_cross},
2346 {"cross_reverse", XC_cross_reverse},
2347 {"crosshair", XC_crosshair},
2348 {"diamond_cross", XC_diamond_cross},
2349 {"dot", XC_dot},
2350 {"dotbox", XC_dotbox},
2351 {"double_arrow", XC_double_arrow},
2352 {"draft_large", XC_draft_large},
2353 {"draft_small", XC_draft_small},
2354 {"draped_box", XC_draped_box},
2355 {"exchange", XC_exchange},
2356 {"fleur", XC_fleur},
2357 {"gobbler", XC_gobbler},
2358 {"gumby", XC_gumby},
2359 {"hand1", XC_hand1},
2360 {"hand2", XC_hand2},
2361 {"heart", XC_heart},
2362 {"icon", XC_icon},
2363 {"iron_cross", XC_iron_cross},
2364 {"left_ptr", XC_left_ptr},
2365 {"left_side", XC_left_side},
2366 {"left_tee", XC_left_tee},
2367 {"leftbutton", XC_leftbutton},
2368 {"ll_angle", XC_ll_angle},
2369 {"lr_angle", XC_lr_angle},
2370 {"man", XC_man},
2371 {"middlebutton", XC_middlebutton},
2372 {"mouse", XC_mouse},
2373 {"pencil", XC_pencil},
2374 {"pirate", XC_pirate},
2375 {"plus", XC_plus},
2376 {"question_arrow", XC_question_arrow},
2377 {"right_ptr", XC_right_ptr},
2378 {"right_side", XC_right_side},
2379 {"right_tee", XC_right_tee},
2380 {"rightbutton", XC_rightbutton},
2381 {"rtl_logo", XC_rtl_logo},
2382 {"sailboat", XC_sailboat},
2383 {"sb_down_arrow", XC_sb_down_arrow},
2384 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2385 {"sb_left_arrow", XC_sb_left_arrow},
2386 {"sb_right_arrow", XC_sb_right_arrow},
2387 {"sb_up_arrow", XC_sb_up_arrow},
2388 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2389 {"shuttle", XC_shuttle},
2390 {"sizing", XC_sizing},
2391 {"spider", XC_spider},
2392 {"spraycan", XC_spraycan},
2393 {"star", XC_star},
2394 {"target", XC_target},
2395 {"tcross", XC_tcross},
2396 {"top_left_arrow", XC_top_left_arrow},
2397 {"top_left_corner", XC_top_left_corner},
2398 {"top_right_corner", XC_top_right_corner},
2399 {"top_side", XC_top_side},
2400 {"top_tee", XC_top_tee},
2401 {"trek", XC_trek},
2402 {"ul_angle", XC_ul_angle},
2403 {"umbrella", XC_umbrella},
2404 {"ur_angle", XC_ur_angle},
2405 {"watch", XC_watch},
2406 {"xterm", XC_xterm},
2407 {NULL, CURSOR_ID_NONE}
2410 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2412 switch (status) {
2413 case BitmapOpenFailed:
2414 wwarning(_("failed to open bitmap file \"%s\""), filename);
2415 break;
2416 case BitmapFileInvalid:
2417 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2418 break;
2419 case BitmapNoMemory:
2420 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2421 break;
2422 case BitmapSuccess:
2423 XFreePixmap(dpy, bitmap);
2424 break;
2429 * (none)
2430 * (builtin, <cursor_name>)
2431 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2433 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2435 WMPropList *elem;
2436 char *val;
2437 int nelem;
2438 int status = 0;
2440 nelem = WMGetPropListItemCount(pl);
2441 if (nelem < 1) {
2442 return (status);
2444 elem = WMGetFromPLArray(pl, 0);
2445 if (!elem || !WMIsPLString(elem)) {
2446 return (status);
2448 val = WMGetFromPLString(elem);
2450 if (0 == strcasecmp(val, "none")) {
2451 status = 1;
2452 *cursor = None;
2453 } else if (0 == strcasecmp(val, "builtin")) {
2454 int i;
2455 int cursor_id = CURSOR_ID_NONE;
2457 if (2 != nelem) {
2458 wwarning(_("bad number of arguments in cursor specification"));
2459 return (status);
2461 elem = WMGetFromPLArray(pl, 1);
2462 if (!elem || !WMIsPLString(elem)) {
2463 return (status);
2465 val = WMGetFromPLString(elem);
2467 for (i = 0; NULL != cursor_table[i].name; i++) {
2468 if (0 == strcasecmp(val, cursor_table[i].name)) {
2469 cursor_id = cursor_table[i].id;
2470 break;
2473 if (CURSOR_ID_NONE == cursor_id) {
2474 wwarning(_("unknown builtin cursor name \"%s\""), val);
2475 } else {
2476 *cursor = XCreateFontCursor(dpy, cursor_id);
2477 status = 1;
2479 } else if (0 == strcasecmp(val, "bitmap")) {
2480 char *bitmap_name;
2481 char *mask_name;
2482 int bitmap_status;
2483 int mask_status;
2484 Pixmap bitmap;
2485 Pixmap mask;
2486 unsigned int w, h;
2487 int x, y;
2488 XColor fg, bg;
2490 if (3 != nelem) {
2491 wwarning(_("bad number of arguments in cursor specification"));
2492 return (status);
2494 elem = WMGetFromPLArray(pl, 1);
2495 if (!elem || !WMIsPLString(elem)) {
2496 return (status);
2498 val = WMGetFromPLString(elem);
2499 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2500 if (!bitmap_name) {
2501 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2502 return (status);
2504 elem = WMGetFromPLArray(pl, 2);
2505 if (!elem || !WMIsPLString(elem)) {
2506 wfree(bitmap_name);
2507 return (status);
2509 val = WMGetFromPLString(elem);
2510 mask_name = FindImage(wPreferences.pixmap_path, val);
2511 if (!mask_name) {
2512 wfree(bitmap_name);
2513 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2514 return (status);
2516 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2517 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2518 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2519 fg.pixel = scr->black_pixel;
2520 bg.pixel = scr->white_pixel;
2521 XQueryColor(dpy, scr->w_colormap, &fg);
2522 XQueryColor(dpy, scr->w_colormap, &bg);
2523 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2524 status = 1;
2526 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2527 check_bitmap_status(mask_status, mask_name, mask);
2528 wfree(bitmap_name);
2529 wfree(mask_name);
2531 return (status);
2534 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2536 static Cursor cursor;
2537 int status;
2538 int changed = 0;
2540 again:
2541 if (!WMIsPLArray(value)) {
2542 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2543 entry->key, "cursor specification");
2544 if (!changed) {
2545 value = entry->plvalue;
2546 changed = 1;
2547 wwarning(_("using default \"%s\" instead"), entry->default_value);
2548 goto again;
2550 return (False);
2552 status = parse_cursor(scr, value, &cursor);
2553 if (!status) {
2554 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2555 if (!changed) {
2556 value = entry->plvalue;
2557 changed = 1;
2558 wwarning(_("using default \"%s\" instead"), entry->default_value);
2559 goto again;
2561 return (False);
2563 if (ret) {
2564 *ret = &cursor;
2566 if (addr) {
2567 *(Cursor *) addr = cursor;
2569 return (True);
2572 #undef CURSOR_ID_NONE
2574 /* ---------------- value setting functions --------------- */
2575 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2577 return REFRESH_WINDOW_TITLE_COLOR;
2580 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2582 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2585 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2587 switch (which) {
2588 case WM_DOCK:
2589 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2590 break;
2591 case WM_CLIP:
2592 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2593 break;
2594 default:
2595 break;
2597 return 0;
2600 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2602 if (scr->workspaces) {
2603 wWorkspaceForceChange(scr, scr->current_workspace);
2604 wArrangeIcons(scr, False);
2606 return 0;
2609 #if not_used
2610 static int setPositive(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2612 if (*value <= 0)
2613 *(int *)foo = 1;
2615 return 0;
2617 #endif
2619 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2621 Pixmap pixmap;
2622 RImage *img;
2623 int reset = 0;
2625 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2626 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2627 ? WREL_ICON : WREL_FLAT);
2628 if (!img) {
2629 wwarning(_("could not render texture for icon background"));
2630 if (!entry->addr)
2631 wTextureDestroy(scr, *texture);
2632 return 0;
2634 RConvertImage(scr->rcontext, img, &pixmap);
2636 if (scr->icon_tile) {
2637 reset = 1;
2638 RReleaseImage(scr->icon_tile);
2639 XFreePixmap(dpy, scr->icon_tile_pixmap);
2642 scr->icon_tile = img;
2644 /* put the icon in the noticeboard hint */
2645 PropSetIconTileHint(scr, img);
2647 if (!wPreferences.flags.noclip) {
2648 if (scr->clip_tile) {
2649 RReleaseImage(scr->clip_tile);
2651 scr->clip_tile = wClipMakeTile(scr, img);
2654 scr->icon_tile_pixmap = pixmap;
2656 if (scr->def_icon_pixmap) {
2657 XFreePixmap(dpy, scr->def_icon_pixmap);
2658 scr->def_icon_pixmap = None;
2660 if (scr->def_ticon_pixmap) {
2661 XFreePixmap(dpy, scr->def_ticon_pixmap);
2662 scr->def_ticon_pixmap = None;
2665 if (scr->icon_back_texture) {
2666 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2668 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2670 if (scr->clip_balloon)
2671 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2674 * Free the texture as nobody else will use it, nor refer to it.
2676 if (!entry->addr)
2677 wTextureDestroy(scr, *texture);
2679 return (reset ? REFRESH_ICON_TILE : 0);
2682 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2684 if (scr->title_font) {
2685 WMReleaseFont(scr->title_font);
2687 scr->title_font = font;
2689 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2692 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2694 if (scr->menu_title_font) {
2695 WMReleaseFont(scr->menu_title_font);
2698 scr->menu_title_font = font;
2700 return REFRESH_MENU_TITLE_FONT;
2703 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2705 if (scr->menu_entry_font) {
2706 WMReleaseFont(scr->menu_entry_font);
2708 scr->menu_entry_font = font;
2710 return REFRESH_MENU_FONT;
2713 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2715 if (scr->icon_title_font) {
2716 WMReleaseFont(scr->icon_title_font);
2719 scr->icon_title_font = font;
2721 return REFRESH_ICON_FONT;
2724 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2726 if (scr->clip_title_font) {
2727 WMReleaseFont(scr->clip_title_font);
2730 scr->clip_title_font = font;
2732 return REFRESH_ICON_FONT;
2735 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2737 if (scr->workspace_name_font) {
2738 WMReleaseFont(scr->workspace_name_font);
2741 scr->workspace_name_font = font;
2743 return 0;
2746 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2748 if (scr->select_color)
2749 WMReleaseColor(scr->select_color);
2751 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2753 wFreeColor(scr, color->pixel);
2755 return REFRESH_MENU_COLOR;
2758 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2760 if (scr->select_text_color)
2761 WMReleaseColor(scr->select_text_color);
2763 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2765 wFreeColor(scr, color->pixel);
2767 return REFRESH_MENU_COLOR;
2770 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2772 if (scr->clip_title_color[widx])
2773 WMReleaseColor(scr->clip_title_color[widx]);
2774 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2775 #ifdef GRADIENT_CLIP_ARROW
2776 if (widx == CLIP_NORMAL) {
2777 RImage *image;
2778 RColor color1, color2;
2779 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2780 int as = pt - 15; /* 15 = 5+5+5 */
2782 FREE_PIXMAP(scr->clip_arrow_gradient);
2784 color1.red = (color->red >> 8) * 6 / 10;
2785 color1.green = (color->green >> 8) * 6 / 10;
2786 color1.blue = (color->blue >> 8) * 6 / 10;
2788 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2789 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2790 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2792 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2793 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2794 RReleaseImage(image);
2796 #endif /* GRADIENT_CLIP_ARROW */
2798 wFreeColor(scr, color->pixel);
2800 return REFRESH_ICON_TITLE_COLOR;
2803 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2805 if (scr->window_title_color[widx])
2806 WMReleaseColor(scr->window_title_color[widx]);
2808 scr->window_title_color[widx] =
2809 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2811 wFreeColor(scr, color->pixel);
2813 return REFRESH_WINDOW_TITLE_COLOR;
2816 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2818 if (scr->menu_title_color[0])
2819 WMReleaseColor(scr->menu_title_color[0]);
2821 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2823 wFreeColor(scr, color->pixel);
2825 return REFRESH_MENU_TITLE_COLOR;
2828 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2830 if (scr->mtext_color)
2831 WMReleaseColor(scr->mtext_color);
2833 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2835 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2836 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2837 } else {
2838 WMSetColorAlpha(scr->dtext_color, 0xffff);
2841 wFreeColor(scr, color->pixel);
2843 return REFRESH_MENU_COLOR;
2846 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2848 if (scr->dtext_color)
2849 WMReleaseColor(scr->dtext_color);
2851 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2853 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2854 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2855 } else {
2856 WMSetColorAlpha(scr->dtext_color, 0xffff);
2859 wFreeColor(scr, color->pixel);
2861 return REFRESH_MENU_COLOR;
2864 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2866 if (scr->icon_title_color)
2867 WMReleaseColor(scr->icon_title_color);
2868 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2870 wFreeColor(scr, color->pixel);
2872 return REFRESH_ICON_TITLE_COLOR;
2875 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2877 if (scr->icon_title_texture) {
2878 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2880 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2882 return REFRESH_ICON_TITLE_BACK;
2885 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2887 close(scr->helper_fd);
2888 scr->helper_fd = 0;
2889 scr->helper_pid = 0;
2890 scr->flags.backimage_helper_launched = 0;
2893 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2895 WMPropList *val;
2896 char *str;
2897 int i;
2899 if (scr->flags.backimage_helper_launched) {
2900 if (WMGetPropListItemCount(value) == 0) {
2901 SendHelperMessage(scr, 'C', 0, NULL);
2902 SendHelperMessage(scr, 'K', 0, NULL);
2904 WMReleasePropList(value);
2905 return 0;
2907 } else {
2908 pid_t pid;
2909 int filedes[2];
2911 if (WMGetPropListItemCount(value) == 0)
2912 return 0;
2914 if (pipe(filedes) < 0) {
2915 wsyserror("pipe() failed:can't set workspace specific background image");
2917 WMReleasePropList(value);
2918 return 0;
2921 pid = fork();
2922 if (pid < 0) {
2923 wsyserror("fork() failed:can't set workspace specific background image");
2924 if (close(filedes[0]) < 0)
2925 wsyserror("could not close pipe");
2926 if (close(filedes[1]) < 0)
2927 wsyserror("could not close pipe");
2929 } else if (pid == 0) {
2930 char *dither;
2932 SetupEnvironment(scr);
2934 if (close(0) < 0)
2935 wsyserror("could not close pipe");
2936 if (dup(filedes[0]) < 0) {
2937 wsyserror("dup() failed:can't set workspace specific background image");
2939 dither = wPreferences.no_dithering ? "-m" : "-d";
2940 if (wPreferences.smooth_workspace_back)
2941 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2942 else
2943 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2944 wsyserror("could not execute wmsetbg");
2945 exit(1);
2946 } else {
2948 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2949 wsyserror("error setting close-on-exec flag");
2951 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2952 wsyserror("error setting close-on-exec flag");
2955 scr->helper_fd = filedes[1];
2956 scr->helper_pid = pid;
2957 scr->flags.backimage_helper_launched = 1;
2959 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2961 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2966 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2967 val = WMGetFromPLArray(value, i);
2968 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2969 str = WMGetPropListDescription(val, False);
2971 SendHelperMessage(scr, 'S', i + 1, str);
2973 wfree(str);
2974 } else {
2975 SendHelperMessage(scr, 'U', i + 1, NULL);
2978 sleep(1);
2980 WMReleasePropList(value);
2981 return 0;
2984 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2986 if (scr->flags.backimage_helper_launched) {
2987 char *str;
2989 if (WMGetPropListItemCount(value) == 0) {
2990 SendHelperMessage(scr, 'U', 0, NULL);
2991 } else {
2992 /* set the default workspace background to this one */
2993 str = WMGetPropListDescription(value, False);
2994 if (str) {
2995 SendHelperMessage(scr, 'S', 0, str);
2996 wfree(str);
2997 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2998 } else {
2999 SendHelperMessage(scr, 'U', 0, NULL);
3002 } else if (WMGetPropListItemCount(value) > 0) {
3003 char *command;
3004 char *text;
3005 char *dither;
3006 int len;
3008 SetupEnvironment(scr);
3009 text = WMGetPropListDescription(value, False);
3010 len = strlen(text) + 40;
3011 command = wmalloc(len);
3012 dither = wPreferences.no_dithering ? "-m" : "-d";
3013 if (wPreferences.smooth_workspace_back)
3014 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
3015 else
3016 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
3017 wfree(text);
3018 system(command);
3019 wfree(command);
3021 WMReleasePropList(value);
3023 return 0;
3026 #ifdef VIRTUAL_DESKTOP
3027 static int setVirtualDeskEnable(WScreen * scr, WDefaultEntry * entry, void *foo, void *bar)
3029 wWorkspaceUpdateEdge(scr);
3030 return 0;
3032 #endif
3034 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3036 if (scr->widget_texture) {
3037 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
3039 scr->widget_texture = *(WTexSolid **) texture;
3041 return 0;
3044 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3046 if (scr->window_title_texture[WS_FOCUSED]) {
3047 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
3049 scr->window_title_texture[WS_FOCUSED] = *texture;
3051 return REFRESH_WINDOW_TEXTURES;
3054 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3056 if (scr->window_title_texture[WS_PFOCUSED]) {
3057 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
3059 scr->window_title_texture[WS_PFOCUSED] = *texture;
3061 return REFRESH_WINDOW_TEXTURES;
3064 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3066 if (scr->window_title_texture[WS_UNFOCUSED]) {
3067 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
3069 scr->window_title_texture[WS_UNFOCUSED] = *texture;
3071 return REFRESH_WINDOW_TEXTURES;
3074 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3076 if (scr->resizebar_texture[0]) {
3077 wTextureDestroy(scr, scr->resizebar_texture[0]);
3079 scr->resizebar_texture[0] = *texture;
3081 return REFRESH_WINDOW_TEXTURES;
3084 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3086 if (scr->menu_title_texture[0]) {
3087 wTextureDestroy(scr, scr->menu_title_texture[0]);
3089 scr->menu_title_texture[0] = *texture;
3091 return REFRESH_MENU_TITLE_TEXTURE;
3094 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
3096 if (scr->menu_item_texture) {
3097 wTextureDestroy(scr, scr->menu_item_texture);
3098 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
3100 scr->menu_item_texture = *texture;
3102 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
3104 return REFRESH_MENU_TEXTURE;
3107 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
3109 WWindow *wwin;
3110 wKeyBindings[widx] = *shortcut;
3112 wwin = scr->focused_window;
3114 while (wwin != NULL) {
3115 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
3117 if (!WFLAGP(wwin, no_bind_keys)) {
3118 wWindowSetKeyGrabs(wwin);
3120 wwin = wwin->prev;
3123 return 0;
3126 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3128 wScreenUpdateUsableArea(scr);
3129 wArrangeIcons(scr, True);
3131 return 0;
3134 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
3136 wScreenUpdateUsableArea(scr);
3138 return 0;
3141 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3143 return REFRESH_MENU_TEXTURE;
3146 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
3148 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
3150 RCopyArea(img, image, x, y, w, h, 0, 0);
3152 return img;
3155 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
3157 char *path;
3158 RImage *bgimage;
3159 int cwidth, cheight;
3160 WPreferences *prefs = (WPreferences *) foo;
3162 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
3163 if (prefs->swtileImage)
3164 RReleaseImage(prefs->swtileImage);
3165 prefs->swtileImage = NULL;
3167 WMReleasePropList(array);
3168 return 0;
3171 switch (WMGetPropListItemCount(array)) {
3172 case 4:
3173 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3174 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3175 break;
3176 } else
3177 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3179 if (!path) {
3180 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3181 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3182 } else {
3183 bgimage = RLoadImage(scr->rcontext, path, 0);
3184 if (!bgimage) {
3185 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3186 wfree(path);
3187 } else {
3188 wfree(path);
3190 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3191 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3193 if (cwidth <= 0 || cheight <= 0 ||
3194 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3195 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3196 else {
3197 int i;
3198 int swidth, theight;
3199 for (i = 0; i < 9; i++) {
3200 if (prefs->swbackImage[i])
3201 RReleaseImage(prefs->swbackImage[i]);
3202 prefs->swbackImage[i] = NULL;
3204 swidth = (bgimage->width - cwidth) / 2;
3205 theight = (bgimage->height - cheight) / 2;
3207 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3208 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3209 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3210 swidth, theight);
3212 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3213 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3214 cwidth, cheight);
3215 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3216 swidth, cheight);
3218 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3219 swidth, theight);
3220 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3221 cwidth, theight);
3222 prefs->swbackImage[8] =
3223 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3224 theight);
3226 // check if anything failed
3227 for (i = 0; i < 9; i++) {
3228 if (!prefs->swbackImage[i]) {
3229 for (; i >= 0; --i) {
3230 RReleaseImage(prefs->swbackImage[i]);
3231 prefs->swbackImage[i] = NULL;
3233 break;
3237 RReleaseImage(bgimage);
3241 case 1:
3242 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3243 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3244 break;
3245 } else
3246 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3248 if (!path) {
3249 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3250 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3251 } else {
3252 if (prefs->swtileImage)
3253 RReleaseImage(prefs->swtileImage);
3255 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3256 if (!prefs->swtileImage) {
3257 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3259 wfree(path);
3261 break;
3263 default:
3264 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3265 break;
3268 WMReleasePropList(array);
3270 return 0;
3274 static int
3275 setButtonImages(WScreen *scr, WDefaultEntry *entry, int *value, void *foo)
3277 return REFRESH_BUTTON_IMAGES;
3282 * Very ugly kluge.
3283 * Need access to the double click variables, so that all widgets in
3284 * wmaker panels will have the same dbl-click values.
3285 * TODO: figure a better way of dealing with it.
3287 #include <WINGs/WINGsP.h>
3289 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3291 extern _WINGsConfiguration WINGsConfiguration;
3293 if (*value <= 0)
3294 *(int *)foo = 1;
3296 WINGsConfiguration.doubleClickDelay = *value;
3298 return 0;
3301 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3303 if (wCursor[widx] != None) {
3304 XFreeCursor(dpy, wCursor[widx]);
3307 wCursor[widx] = *cursor;
3309 if (widx == WCUR_ROOT && *cursor != None) {
3310 XDefineCursor(dpy, scr->root_win, *cursor);
3313 return 0;