Improve dockapp recognition
[wmaker-crm.git] / src / defaults.c
blob6e002bdfdd9bfa67e830a7d8e962a5a08be787b2
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 #ifndef PATH_MAX
40 #define PATH_MAX DEFAULT_PATH_MAX
41 #endif
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/keysym.h>
47 #include <wraster.h>
49 #include "WindowMaker.h"
50 #include "framewin.h"
51 #include "window.h"
52 #include "texture.h"
53 #include "screen.h"
54 #include "resources.h"
55 #include "defaults.h"
56 #include "keybind.h"
57 #include "xmodifier.h"
58 #include "icon.h"
59 #include "funcs.h"
60 #include "actions.h"
61 #include "dock.h"
62 #include "workspace.h"
63 #include "properties.h"
65 #define MAX_SHORTCUT_LENGTH 32
67 #ifndef GLOBAL_DEFAULTS_SUBDIR
68 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
69 #endif
71 /***** Global *****/
72 extern WDDomain *WDWindowMaker;
73 extern WDDomain *WDWindowAttributes;
74 extern WDDomain *WDRootMenu;
75 extern int wScreenCount;
76 extern WPreferences wPreferences;
77 extern WShortKey wKeyBindings[WKBD_LAST];
79 typedef struct {
80 char *key;
81 char *default_value;
82 void *extra_data;
83 void *addr;
84 int (*convert) ();
85 int (*update) ();
86 WMPropList *plkey;
87 WMPropList *plvalue; /* default value */
88 } WDefaultEntry;
90 /* used to map strings to integers */
91 typedef struct {
92 char *string;
93 short value;
94 char is_alias;
95 } WOptionEnumeration;
97 /* type converters */
98 static int getBool();
99 static int getInt();
100 static int getCoord();
101 static int getPathList();
102 static int getEnum();
103 static int getTexture();
104 static int getWSBackground();
105 static int getWSSpecificBackground();
106 static int getFont();
107 static int getColor();
108 static int getKeybind();
109 static int getModMask();
110 static int getPropList();
112 /* value setting functions */
113 static int setJustify();
114 static int setClearance();
115 static int setIfDockPresent();
116 static int setStickyIcons();
117 static int setWidgetColor();
118 static int setIconTile();
119 static int setWinTitleFont();
120 static int setMenuTitleFont();
121 static int setMenuTextFont();
122 static int setIconTitleFont();
123 static int setIconTitleColor();
124 static int setIconTitleBack();
125 static int setLargeDisplayFont();
126 static int setWTitleColor();
127 static int setFTitleBack();
128 static int setPTitleBack();
129 static int setUTitleBack();
130 static int setResizebarBack();
131 static int setWorkspaceBack();
132 static int setWorkspaceSpecificBack();
133 static int setMenuTitleColor();
134 static int setMenuTextColor();
135 static int setMenuDisabledColor();
136 static int setMenuTitleBack();
137 static int setMenuTextBack();
138 static int setHightlight();
139 static int setHightlightText();
140 static int setKeyGrab();
141 static int setDoubleClick();
142 static int setIconPosition();
144 static int setClipTitleFont();
145 static int setClipTitleColor();
147 static int setMenuStyle();
148 static int setSwPOptions();
149 static int updateUsableArea();
151 extern Cursor wCursor[WCUR_LAST];
152 static int getCursor();
153 static int setCursor();
156 * Tables to convert strings to enumeration values.
157 * Values stored are char
160 /* WARNING: sum of length of all value strings must not exceed
161 * this value */
162 #define TOTAL_VALUES_LENGTH 80
164 #define REFRESH_WINDOW_TEXTURES (1<<0)
165 #define REFRESH_MENU_TEXTURE (1<<1)
166 #define REFRESH_MENU_FONT (1<<2)
167 #define REFRESH_MENU_COLOR (1<<3)
168 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
169 #define REFRESH_MENU_TITLE_FONT (1<<5)
170 #define REFRESH_MENU_TITLE_COLOR (1<<6)
171 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
172 #define REFRESH_WINDOW_FONT (1<<8)
173 #define REFRESH_ICON_TILE (1<<9)
174 #define REFRESH_ICON_FONT (1<<10)
175 #define REFRESH_WORKSPACE_BACK (1<<11)
177 #define REFRESH_BUTTON_IMAGES (1<<12)
179 #define REFRESH_ICON_TITLE_COLOR (1<<13)
180 #define REFRESH_ICON_TITLE_BACK (1<<14)
182 static WOptionEnumeration seFocusModes[] = {
183 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
184 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
185 {NULL, 0, 0}
188 static WOptionEnumeration seTitlebarModes[] = {
189 {"new", TS_NEW, 0}, {"old", TS_OLD, 0},
190 {"next", TS_NEXT, 0}, {NULL, 0, 0}
193 static WOptionEnumeration seColormapModes[] = {
194 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
195 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
196 {NULL, 0, 0}
199 static WOptionEnumeration sePlacements[] = {
200 {"Auto", WPM_AUTO, 0},
201 {"Smart", WPM_SMART, 0},
202 {"Cascade", WPM_CASCADE, 0},
203 {"Random", WPM_RANDOM, 0},
204 {"Manual", WPM_MANUAL, 0},
205 {NULL, 0, 0}
208 static WOptionEnumeration seGeomDisplays[] = {
209 {"None", WDIS_NONE, 0},
210 {"Center", WDIS_CENTER, 0},
211 {"Corner", WDIS_TOPLEFT, 0},
212 {"Floating", WDIS_FRAME_CENTER, 0},
213 {"Line", WDIS_NEW, 0},
214 {NULL, 0, 0}
217 static WOptionEnumeration seSpeeds[] = {
218 {"UltraFast", SPEED_ULTRAFAST, 0},
219 {"Fast", SPEED_FAST, 0},
220 {"Medium", SPEED_MEDIUM, 0},
221 {"Slow", SPEED_SLOW, 0},
222 {"UltraSlow", SPEED_ULTRASLOW, 0},
223 {NULL, 0, 0}
226 static WOptionEnumeration seMouseButtonActions[] = {
227 {"None", WA_NONE, 0},
228 {"SelectWindows", WA_SELECT_WINDOWS, 0},
229 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
230 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
231 {NULL, 0, 0}
234 static WOptionEnumeration seMouseWheelActions[] = {
235 {"None", WA_NONE, 0},
236 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
237 {NULL, 0, 0}
240 static WOptionEnumeration seIconificationStyles[] = {
241 {"Zoom", WIS_ZOOM, 0},
242 {"Twist", WIS_TWIST, 0},
243 {"Flip", WIS_FLIP, 0},
244 {"None", WIS_NONE, 0},
245 {"random", WIS_RANDOM, 0},
246 {NULL, 0, 0}
249 static WOptionEnumeration seJustifications[] = {
250 {"Left", WTJ_LEFT, 0},
251 {"Center", WTJ_CENTER, 0},
252 {"Right", WTJ_RIGHT, 0},
253 {NULL, 0, 0}
256 static WOptionEnumeration seIconPositions[] = {
257 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
258 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
259 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
260 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
261 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
262 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
263 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
264 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
265 {NULL, 0, 0}
268 static WOptionEnumeration seMenuStyles[] = {
269 {"normal", MS_NORMAL, 0},
270 {"singletexture", MS_SINGLE_TEXTURE, 0},
271 {"flat", MS_FLAT, 0},
272 {NULL, 0, 0}
275 static WOptionEnumeration seDisplayPositions[] = {
276 {"none", WD_NONE, 0},
277 {"center", WD_CENTER, 0},
278 {"top", WD_TOP, 0},
279 {"bottom", WD_BOTTOM, 0},
280 {"topleft", WD_TOPLEFT, 0},
281 {"topright", WD_TOPRIGHT, 0},
282 {"bottomleft", WD_BOTTOMLEFT, 0},
283 {"bottomright", WD_BOTTOMRIGHT, 0},
284 {NULL, 0, 0}
287 static WOptionEnumeration seWorkspaceBorder[] = {
288 {"None", WB_NONE, 0},
289 {"LeftRight", WB_LEFTRIGHT, 0},
290 {"TopBottom", WB_TOPBOTTOM, 0},
291 {"AllDirections", WB_ALLDIRS, 0},
292 {NULL, 0, 0}
296 * ALL entries in the tables bellow, NEED to have a default value
297 * defined, and this value needs to be correct.
300 /* these options will only affect the window manager on startup
302 * static defaults can't access the screen data, because it is
303 * created after these defaults are read
305 WDefaultEntry staticOptionList[] = {
307 {"ColormapSize", "4", NULL,
308 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
309 {"DisableDithering", "NO", NULL,
310 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
311 {"IconSize", "64", NULL,
312 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
313 {"ModifierKey", "Mod1", NULL,
314 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
315 {"DisableWSMouseActions", "NO", NULL,
316 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
317 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
318 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
319 {"NewStyle", "new", seTitlebarModes,
320 &wPreferences.new_style, getEnum, NULL, NULL, NULL},
321 {"DisableDock", "NO", (void *)WM_DOCK,
322 NULL, getBool, setIfDockPresent, NULL, NULL},
323 {"DisableClip", "NO", (void *)WM_CLIP,
324 NULL, getBool, setIfDockPresent, NULL, NULL},
325 {"DisableMiniwindows", "NO", NULL,
326 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
329 WDefaultEntry optionList[] = {
331 /* dynamic options */
333 {"IconPosition", "blh", seIconPositions,
334 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
335 {"IconificationStyle", "Zoom", seIconificationStyles,
336 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
337 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
338 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
339 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
340 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
341 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
342 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
343 {"MouseWheelAction", "None", seMouseWheelActions,
344 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
345 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
346 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
347 {"IconPath", DEF_ICON_PATHS, NULL,
348 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
349 {"ColormapMode", "auto", seColormapModes,
350 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
351 {"AutoFocus", "NO", NULL,
352 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
353 {"RaiseDelay", "0", NULL,
354 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
355 {"CirculateRaise", "NO", NULL,
356 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
357 {"Superfluous", "NO", NULL,
358 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
359 {"AdvanceToNewWorkspace", "NO", NULL,
360 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
361 {"CycleWorkspaces", "NO", NULL,
362 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
363 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
364 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
365 {"WorkspaceBorder", "None", seWorkspaceBorder,
366 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
367 {"WorkspaceBorderSize", "0", NULL,
368 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
369 {"StickyIcons", "NO", NULL,
370 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
371 {"SaveSessionOnExit", "NO", NULL,
372 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
373 {"WrapMenus", "NO", NULL,
374 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
375 {"ScrollableMenus", "NO", NULL,
376 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
377 {"MenuScrollSpeed", "medium", seSpeeds,
378 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
379 {"IconSlideSpeed", "medium", seSpeeds,
380 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
381 {"ShadeSpeed", "medium", seSpeeds,
382 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
383 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
384 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
385 {"AlignSubmenus", "NO", NULL,
386 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
387 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
388 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
389 {"WindowPlacement", "auto", sePlacements,
390 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
391 {"IgnoreFocusClick", "NO", NULL,
392 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
393 {"UseSaveUnders", "NO", NULL,
394 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
395 {"OpaqueMove", "NO", NULL,
396 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
397 {"DisableAnimations", "NO", NULL,
398 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
399 {"DontLinkWorkspaces", "NO", NULL,
400 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
401 {"AutoArrangeIcons", "NO", NULL,
402 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
403 {"NoWindowOverDock", "NO", NULL,
404 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
405 {"NoWindowOverIcons", "NO", NULL,
406 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
407 {"WindowPlaceOrigin", "(0, 0)", NULL,
408 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
409 {"ResizeDisplay", "corner", seGeomDisplays,
410 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
411 {"MoveDisplay", "corner", seGeomDisplays,
412 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
413 {"DontConfirmKill", "NO", NULL,
414 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
415 {"WindowTitleBalloons", "NO", NULL,
416 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
417 {"MiniwindowTitleBalloons", "NO", NULL,
418 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
419 {"AppIconBalloons", "NO", NULL,
420 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
421 {"HelpBalloons", "NO", NULL,
422 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
423 {"EdgeResistance", "30", NULL,
424 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
425 {"ResizeIncrement", "32", NULL,
426 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
427 {"Attraction", "NO", NULL,
428 &wPreferences.attract, getBool, NULL, NULL, NULL},
429 {"DisableBlinking", "NO", NULL,
430 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
431 {"SingleClickLaunch", "NO", NULL,
432 &wPreferences.single_click, getBool, NULL, NULL, NULL},
434 /* style options */
436 {"MenuStyle", "normal", seMenuStyles,
437 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
438 {"WidgetColor", "(solid, gray)", NULL,
439 NULL, getTexture, setWidgetColor, NULL, NULL},
440 {"WorkspaceSpecificBack", "()", NULL,
441 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
442 /* WorkspaceBack must come after WorkspaceSpecificBack or
443 * WorkspaceBack wont know WorkspaceSpecificBack was also
444 * specified and 2 copies of wmsetbg will be launched */
445 {"WorkspaceBack", "(solid, black)", NULL,
446 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
447 {"SmoothWorkspaceBack", "NO", NULL,
448 NULL, getBool, NULL, NULL, NULL},
449 {"IconBack", "(solid, gray)", NULL,
450 NULL, getTexture, setIconTile, NULL, NULL},
451 {"TitleJustify", "center", seJustifications,
452 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
453 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
454 NULL, getFont, setWinTitleFont, NULL, NULL},
455 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
456 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
457 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
458 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
459 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
460 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
461 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
462 NULL, getFont, setMenuTitleFont, NULL, NULL},
463 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
464 NULL, getFont, setMenuTextFont, NULL, NULL},
465 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
466 NULL, getFont, setIconTitleFont, NULL, NULL},
467 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
468 NULL, getFont, setClipTitleFont, NULL, NULL},
469 {"ShowClipTitle", "YES", NULL,
470 &wPreferences.show_clip_title, getBool, NULL, NULL, NULL},
471 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
472 NULL, getFont, setLargeDisplayFont, NULL, NULL},
473 {"HighlightColor", "white", NULL,
474 NULL, getColor, setHightlight, NULL, NULL},
475 {"HighlightTextColor", "black", NULL,
476 NULL, getColor, setHightlightText, NULL, NULL},
477 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
478 NULL, getColor, setClipTitleColor, NULL, NULL},
479 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
480 NULL, getColor, setClipTitleColor, NULL, NULL},
481 {"FTitleColor", "white", (void *)WS_FOCUSED,
482 NULL, getColor, setWTitleColor, NULL, NULL},
483 {"PTitleColor", "white", (void *)WS_PFOCUSED,
484 NULL, getColor, setWTitleColor, NULL, NULL},
485 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
486 NULL, getColor, setWTitleColor, NULL, NULL},
487 {"FTitleBack", "(solid, black)", NULL,
488 NULL, getTexture, setFTitleBack, NULL, NULL},
489 {"PTitleBack", "(solid, \"#616161\")", NULL,
490 NULL, getTexture, setPTitleBack, NULL, NULL},
491 {"UTitleBack", "(solid, gray)", NULL,
492 NULL, getTexture, setUTitleBack, NULL, NULL},
493 {"ResizebarBack", "(solid, gray)", NULL,
494 NULL, getTexture, setResizebarBack, NULL, NULL},
495 {"MenuTitleColor", "white", NULL,
496 NULL, getColor, setMenuTitleColor, NULL, NULL},
497 {"MenuTextColor", "black", NULL,
498 NULL, getColor, setMenuTextColor, NULL, NULL},
499 {"MenuDisabledColor", "\"#616161\"", NULL,
500 NULL, getColor, setMenuDisabledColor, NULL, NULL},
501 {"MenuTitleBack", "(solid, black)", NULL,
502 NULL, getTexture, setMenuTitleBack, NULL, NULL},
503 {"MenuTextBack", "(solid, gray)", NULL,
504 NULL, getTexture, setMenuTextBack, NULL, NULL},
505 {"IconTitleColor", "white", NULL,
506 NULL, getColor, setIconTitleColor, NULL, NULL},
507 {"IconTitleBack", "black", NULL,
508 NULL, getColor, setIconTitleBack, NULL, NULL},
509 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
510 NULL, getPropList, setSwPOptions, NULL, NULL},
512 /* keybindings */
514 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
515 NULL, getKeybind, setKeyGrab, NULL, NULL},
516 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
517 NULL, getKeybind, setKeyGrab, NULL, NULL},
518 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
519 NULL, getKeybind, setKeyGrab, NULL, NULL},
520 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
521 NULL, getKeybind, setKeyGrab, NULL, NULL},
522 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
523 NULL, getKeybind, setKeyGrab, NULL, NULL},
524 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
525 NULL, getKeybind, setKeyGrab, NULL, NULL},
526 {"MinimizeAllKey", "None", (void *)WKBD_MINIMIZEALL,
527 NULL, getKeybind, setKeyGrab, NULL, NULL },
528 {"HideKey", "None", (void *)WKBD_HIDE,
529 NULL, getKeybind, setKeyGrab, NULL, NULL},
530 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
531 NULL, getKeybind, setKeyGrab, NULL, NULL},
532 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
533 NULL, getKeybind, setKeyGrab, NULL, NULL},
534 {"CloseKey", "None", (void *)WKBD_CLOSE,
535 NULL, getKeybind, setKeyGrab, NULL, NULL},
536 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
537 NULL, getKeybind, setKeyGrab, NULL, NULL},
538 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
539 NULL, getKeybind, setKeyGrab, NULL, NULL},
540 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
541 NULL, getKeybind, setKeyGrab, NULL, NULL},
542 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
543 NULL, getKeybind, setKeyGrab, NULL, NULL},
544 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
545 NULL, getKeybind, setKeyGrab, NULL, NULL},
546 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
547 NULL, getKeybind, setKeyGrab, NULL, NULL},
548 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
549 NULL, getKeybind, setKeyGrab, NULL, NULL},
550 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
551 NULL, getKeybind, setKeyGrab, NULL, NULL},
552 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
553 NULL, getKeybind, setKeyGrab, NULL, NULL},
554 {"ShadeKey", "None", (void *)WKBD_SHADE,
555 NULL, getKeybind, setKeyGrab, NULL, NULL},
556 {"SelectKey", "None", (void *)WKBD_SELECT,
557 NULL, getKeybind, setKeyGrab, NULL, NULL},
558 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
559 NULL, getKeybind, setKeyGrab, NULL, NULL},
560 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
561 NULL, getKeybind, setKeyGrab, NULL, NULL},
562 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
563 NULL, getKeybind, setKeyGrab, NULL, NULL},
564 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
565 NULL, getKeybind, setKeyGrab, NULL, NULL},
566 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
567 NULL, getKeybind, setKeyGrab, NULL, NULL},
568 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
569 NULL, getKeybind, setKeyGrab, NULL, NULL},
570 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
571 NULL, getKeybind, setKeyGrab, NULL, NULL},
572 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
573 NULL, getKeybind, setKeyGrab, NULL, NULL},
574 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
575 NULL, getKeybind, setKeyGrab, NULL, NULL},
576 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
577 NULL, getKeybind, setKeyGrab, NULL, NULL},
578 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
579 NULL, getKeybind, setKeyGrab, NULL, NULL},
580 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
581 NULL, getKeybind, setKeyGrab, NULL, NULL},
582 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
583 NULL, getKeybind, setKeyGrab, NULL, NULL},
584 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
585 NULL, getKeybind, setKeyGrab, NULL, NULL},
586 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
587 NULL, getKeybind, setKeyGrab, NULL, NULL},
588 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
589 NULL, getKeybind, setKeyGrab, NULL, NULL},
590 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
591 NULL, getKeybind, setKeyGrab, NULL, NULL},
592 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
593 NULL, getKeybind, setKeyGrab, NULL, NULL},
594 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
595 NULL, getKeybind, setKeyGrab, NULL, NULL},
596 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
597 NULL, getKeybind, setKeyGrab, NULL, NULL},
598 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
599 NULL, getKeybind, setKeyGrab, NULL, NULL},
600 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
601 NULL, getKeybind, setKeyGrab, NULL, NULL},
602 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
603 NULL, getKeybind, setKeyGrab, NULL, NULL},
604 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
605 NULL, getKeybind, setKeyGrab, NULL, NULL},
606 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
607 NULL, getKeybind, setKeyGrab, NULL, NULL},
608 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
609 NULL, getKeybind, setKeyGrab, NULL, NULL},
610 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
611 NULL, getKeybind, setKeyGrab, NULL, NULL},
612 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
613 NULL, getKeybind, setKeyGrab, NULL, NULL},
614 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
615 NULL, getKeybind, setKeyGrab, NULL, NULL},
617 #ifdef KEEP_XKB_LOCK_STATUS
618 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
619 NULL, getKeybind, setKeyGrab, NULL, NULL},
620 {"KbdModeLock", "NO", NULL,
621 &wPreferences.modelock, getBool, NULL, NULL, NULL},
622 #endif /* KEEP_XKB_LOCK_STATUS */
624 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
625 NULL, getCursor, setCursor, NULL, NULL},
626 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
627 NULL, getCursor, setCursor, NULL, NULL},
628 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
629 NULL, getCursor, setCursor, NULL, NULL},
630 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
631 NULL, getCursor, setCursor, NULL, NULL},
632 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
633 NULL, getCursor, setCursor, NULL, NULL},
634 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
635 NULL, getCursor, setCursor, NULL, NULL},
636 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
637 NULL, getCursor, setCursor, NULL, NULL},
638 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
639 NULL, getCursor, setCursor, NULL, NULL},
640 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
641 NULL, getCursor, setCursor, NULL, NULL},
642 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
643 NULL, getCursor, setCursor, NULL, NULL},
644 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
645 NULL, getCursor, setCursor, NULL, NULL},
646 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
647 NULL, getCursor, setCursor, NULL, NULL},
648 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
649 NULL, getCursor, setCursor, NULL, NULL},
650 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
651 NULL, getCursor, setCursor, NULL, NULL},
652 {"DialogHistoryLines", "500", NULL,
653 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
654 {"CycleActiveHeadOnly", "NO", NULL,
655 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
658 static void initDefaults()
660 unsigned int i;
661 WDefaultEntry *entry;
663 WMPLSetCaseSensitive(False);
665 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
666 entry = &optionList[i];
668 entry->plkey = WMCreatePLString(entry->key);
669 if (entry->default_value)
670 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
671 else
672 entry->plvalue = NULL;
675 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
676 entry = &staticOptionList[i];
678 entry->plkey = WMCreatePLString(entry->key);
679 if (entry->default_value)
680 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
681 else
682 entry->plvalue = NULL;
686 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
688 WMPropList *globalDict = NULL;
689 char path[PATH_MAX];
690 struct stat stbuf;
692 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
693 if (stat(path, &stbuf) >= 0) {
694 globalDict = WMReadPropListFromFile(path);
695 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
696 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
697 WMReleasePropList(globalDict);
698 globalDict = NULL;
699 } else if (!globalDict) {
700 wwarning(_("could not load domain %s from global defaults database"), domainName);
704 return globalDict;
707 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
708 static void prependMenu(WMPropList * destarr, WMPropList * array)
710 WMPropList *item;
711 int i;
713 for (i = 0; i < WMGetPropListItemCount(array); i++) {
714 item = WMGetFromPLArray(array, i);
715 if (item)
716 WMInsertInPLArray(destarr, i + 1, item);
720 static void appendMenu(WMPropList * destarr, WMPropList * array)
722 WMPropList *item;
723 int i;
725 for (i = 0; i < WMGetPropListItemCount(array); i++) {
726 item = WMGetFromPLArray(array, i);
727 if (item)
728 WMAddToPLArray(destarr, item);
731 #endif
733 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
735 WMPropList *menu = menuDomain->dictionary;
736 WMPropList *submenu;
738 if (!menu || !WMIsPLArray(menu))
739 return;
741 #ifdef GLOBAL_PREAMBLE_MENU_FILE
742 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
744 if (submenu && !WMIsPLArray(submenu)) {
745 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
746 WMReleasePropList(submenu);
747 submenu = NULL;
749 if (submenu) {
750 prependMenu(menu, submenu);
751 WMReleasePropList(submenu);
753 #endif
755 #ifdef GLOBAL_EPILOGUE_MENU_FILE
756 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
758 if (submenu && !WMIsPLArray(submenu)) {
759 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
760 WMReleasePropList(submenu);
761 submenu = NULL;
763 if (submenu) {
764 appendMenu(menu, submenu);
765 WMReleasePropList(submenu);
767 #endif
769 menuDomain->dictionary = menu;
772 void wDefaultsDestroyDomain(WDDomain * domain)
774 if (domain->dictionary)
775 WMReleasePropList(domain->dictionary);
776 wfree(domain->path);
777 wfree(domain);
780 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
782 WDDomain *db;
783 struct stat stbuf;
784 static int inited = 0;
785 char path[PATH_MAX];
786 char *the_path;
787 WMPropList *shared_dict = NULL;
789 if (!inited) {
790 inited = 1;
791 initDefaults();
794 db = wmalloc(sizeof(WDDomain));
795 memset(db, 0, sizeof(WDDomain));
796 db->domain_name = domain;
797 db->path = wdefaultspathfordomain(domain);
798 the_path = db->path;
800 if (the_path && stat(the_path, &stbuf) >= 0) {
801 db->dictionary = WMReadPropListFromFile(the_path);
802 if (db->dictionary) {
803 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
804 WMReleasePropList(db->dictionary);
805 db->dictionary = NULL;
806 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
808 db->timestamp = stbuf.st_mtime;
809 } else {
810 wwarning(_("could not load domain %s from user defaults database"), domain);
814 /* global system dictionary */
815 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
816 if (stat(path, &stbuf) >= 0) {
817 shared_dict = WMReadPropListFromFile(path);
818 if (shared_dict) {
819 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
820 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
821 domain, path);
822 WMReleasePropList(shared_dict);
823 shared_dict = NULL;
824 } else {
825 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
826 WMIsPLDictionary(db->dictionary)) {
827 WMMergePLDictionaries(shared_dict, db->dictionary, True);
828 WMReleasePropList(db->dictionary);
829 db->dictionary = shared_dict;
830 if (stbuf.st_mtime > db->timestamp)
831 db->timestamp = stbuf.st_mtime;
832 } else if (!db->dictionary) {
833 db->dictionary = shared_dict;
834 if (stbuf.st_mtime > db->timestamp)
835 db->timestamp = stbuf.st_mtime;
838 } else {
839 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
843 return db;
846 void wReadStaticDefaults(WMPropList * dict)
848 WMPropList *plvalue;
849 WDefaultEntry *entry;
850 unsigned int i;
851 void *tdata;
853 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
854 entry = &staticOptionList[i];
856 if (dict)
857 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
858 else
859 plvalue = NULL;
861 if (!plvalue) {
862 /* no default in the DB. Use builtin default */
863 plvalue = entry->plvalue;
866 if (plvalue) {
867 /* convert data */
868 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
869 if (entry->update) {
870 (*entry->update) (NULL, entry, tdata, entry->extra_data);
876 void wDefaultsCheckDomains(void* arg)
878 WScreen *scr;
879 struct stat stbuf;
880 WMPropList *shared_dict = NULL;
881 WMPropList *dict;
882 int i;
884 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
885 WDWindowMaker->timestamp = stbuf.st_mtime;
887 /* global dictionary */
888 shared_dict = readGlobalDomain("WindowMaker", True);
889 /* user dictionary */
890 dict = WMReadPropListFromFile(WDWindowMaker->path);
891 if (dict) {
892 if (!WMIsPLDictionary(dict)) {
893 WMReleasePropList(dict);
894 dict = NULL;
895 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
896 "WindowMaker", WDWindowMaker->path);
897 } else {
898 if (shared_dict) {
899 WMMergePLDictionaries(shared_dict, dict, True);
900 WMReleasePropList(dict);
901 dict = shared_dict;
902 shared_dict = NULL;
904 for (i = 0; i < wScreenCount; i++) {
905 scr = wScreenWithNumber(i);
906 if (scr)
907 wReadDefaults(scr, dict);
909 if (WDWindowMaker->dictionary) {
910 WMReleasePropList(WDWindowMaker->dictionary);
912 WDWindowMaker->dictionary = dict;
914 } else {
915 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
917 if (shared_dict) {
918 WMReleasePropList(shared_dict);
922 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
923 /* global dictionary */
924 shared_dict = readGlobalDomain("WMWindowAttributes", True);
925 /* user dictionary */
926 dict = WMReadPropListFromFile(WDWindowAttributes->path);
927 if (dict) {
928 if (!WMIsPLDictionary(dict)) {
929 WMReleasePropList(dict);
930 dict = NULL;
931 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
932 "WMWindowAttributes", WDWindowAttributes->path);
933 } else {
934 if (shared_dict) {
935 WMMergePLDictionaries(shared_dict, dict, True);
936 WMReleasePropList(dict);
937 dict = shared_dict;
938 shared_dict = NULL;
940 if (WDWindowAttributes->dictionary) {
941 WMReleasePropList(WDWindowAttributes->dictionary);
943 WDWindowAttributes->dictionary = dict;
944 for (i = 0; i < wScreenCount; i++) {
945 scr = wScreenWithNumber(i);
946 if (scr) {
947 RImage *image;
949 wDefaultUpdateIcons(scr);
951 /* Update the panel image if changed */
952 /* Don't worry. If the image is the same these
953 * functions will have no performance impact. */
954 image = wDefaultGetImage(scr, "Logo", "WMPanel");
956 if (!image) {
957 wwarning(_("could not load logo image for panels: %s"),
958 RMessageForError(RErrorCode));
959 } else {
960 WMSetApplicationIconImage(scr->wmscreen, image);
961 RReleaseImage(image);
966 } else {
967 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
969 WDWindowAttributes->timestamp = stbuf.st_mtime;
970 if (shared_dict) {
971 WMReleasePropList(shared_dict);
975 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
976 dict = WMReadPropListFromFile(WDRootMenu->path);
977 if (dict) {
978 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
979 WMReleasePropList(dict);
980 dict = NULL;
981 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
982 "WMRootMenu", WDRootMenu->path);
983 } else {
984 if (WDRootMenu->dictionary) {
985 WMReleasePropList(WDRootMenu->dictionary);
987 WDRootMenu->dictionary = dict;
988 wDefaultsMergeGlobalMenus(WDRootMenu);
990 } else {
991 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
993 WDRootMenu->timestamp = stbuf.st_mtime;
995 #ifndef HAVE_INOTIFY
996 if (!arg)
997 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
998 #endif
1001 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1003 WMPropList *plvalue, *old_value;
1004 WDefaultEntry *entry;
1005 unsigned int i, must_update;
1006 int update_workspace_back = 0; /* kluge :/ */
1007 unsigned int needs_refresh;
1008 void *tdata;
1009 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1011 must_update = 0;
1013 needs_refresh = 0;
1015 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1016 entry = &optionList[i];
1018 if (new_dict)
1019 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1020 else
1021 plvalue = NULL;
1023 if (!old_dict)
1024 old_value = NULL;
1025 else
1026 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1028 if (!plvalue && !old_value) {
1029 /* no default in the DB. Use builtin default */
1030 plvalue = entry->plvalue;
1031 if (plvalue && new_dict) {
1032 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1033 must_update = 1;
1035 } else if (!plvalue) {
1036 /* value was deleted from DB. Keep current value */
1037 continue;
1038 } else if (!old_value) {
1039 /* set value for the 1st time */
1040 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1041 /* value has changed */
1042 } else {
1044 if (strcmp(entry->key, "WorkspaceBack") == 0
1045 && update_workspace_back && scr->flags.backimage_helper_launched) {
1046 } else {
1047 /* value was not changed since last time */
1048 continue;
1052 if (plvalue) {
1053 /* convert data */
1054 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1056 * If the WorkspaceSpecificBack data has been changed
1057 * so that the helper will be launched now, we must be
1058 * sure to send the default background texture config
1059 * to the helper.
1061 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1062 && !scr->flags.backimage_helper_launched) {
1063 update_workspace_back = 1;
1065 if (entry->update) {
1066 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1072 if (needs_refresh != 0 && !scr->flags.startup) {
1073 int foo;
1075 foo = 0;
1076 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1077 foo |= WTextureSettings;
1078 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1079 foo |= WFontSettings;
1080 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1081 foo |= WColorSettings;
1082 if (foo)
1083 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1084 (void *)(uintptr_t) foo);
1086 foo = 0;
1087 if (needs_refresh & REFRESH_MENU_TEXTURE)
1088 foo |= WTextureSettings;
1089 if (needs_refresh & REFRESH_MENU_FONT)
1090 foo |= WFontSettings;
1091 if (needs_refresh & REFRESH_MENU_COLOR)
1092 foo |= WColorSettings;
1093 if (foo)
1094 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1096 foo = 0;
1097 if (needs_refresh & REFRESH_WINDOW_FONT) {
1098 foo |= WFontSettings;
1100 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1101 foo |= WTextureSettings;
1103 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1104 foo |= WColorSettings;
1106 if (foo)
1107 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1109 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1110 foo = 0;
1111 if (needs_refresh & REFRESH_ICON_FONT) {
1112 foo |= WFontSettings;
1114 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1115 foo |= WTextureSettings;
1117 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1118 foo |= WTextureSettings;
1120 if (foo)
1121 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1122 (void *)(uintptr_t) foo);
1124 if (needs_refresh & REFRESH_ICON_TILE)
1125 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1129 void wDefaultUpdateIcons(WScreen * scr)
1131 WAppIcon *aicon = scr->app_icon_list;
1132 WWindow *wwin = scr->focused_window;
1133 char *file;
1135 while (aicon) {
1136 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1137 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1138 || (file && !aicon->icon->file)) {
1139 RImage *new_image;
1141 if (aicon->icon->file)
1142 wfree(aicon->icon->file);
1143 aicon->icon->file = wstrdup(file);
1145 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1146 if (new_image) {
1147 wIconChangeImage(aicon->icon, new_image);
1148 wAppIconPaint(aicon);
1151 aicon = aicon->next;
1154 if (!wPreferences.flags.noclip)
1155 wClipIconPaint(scr->clip_icon);
1157 while (wwin) {
1158 if (wwin->icon && wwin->flags.miniaturized) {
1159 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1160 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1161 || (file && !wwin->icon->file)) {
1162 RImage *new_image;
1164 if (wwin->icon->file)
1165 wfree(wwin->icon->file);
1166 wwin->icon->file = wstrdup(file);
1168 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1169 if (new_image)
1170 wIconChangeImage(wwin->icon, new_image);
1173 wwin = wwin->prev;
1177 /* --------------------------- Local ----------------------- */
1179 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1180 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1181 entry->key, x); \
1182 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1183 var = entry->default_value;\
1184 } else var = WMGetFromPLString(value)\
1187 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1189 char *str;
1190 WOptionEnumeration *v;
1191 char buffer[TOTAL_VALUES_LENGTH];
1193 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1194 for (v = values; v->string != NULL; v++) {
1195 if (strcasecmp(v->string, str) == 0)
1196 return v->value;
1200 buffer[0] = 0;
1201 for (v = values; v->string != NULL; v++) {
1202 if (!v->is_alias) {
1203 if (buffer[0] != 0)
1204 strcat(buffer, ", ");
1205 strcat(buffer, v->string);
1208 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1210 if (def) {
1211 return string2index(key, val, NULL, values);
1214 return -1;
1218 * value - is the value in the defaults DB
1219 * addr - is the address to store the data
1220 * ret - is the address to store a pointer to a temporary buffer. ret
1221 * must not be freed and is used by the set functions
1223 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1225 static char data;
1226 char *val;
1227 int second_pass = 0;
1229 GET_STRING_OR_DEFAULT("Boolean", val);
1231 again:
1232 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1233 || strcasecmp(val, "YES") == 0) {
1235 data = 1;
1236 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1237 || strcasecmp(val, "NO") == 0) {
1238 data = 0;
1239 } else {
1240 int i;
1241 if (sscanf(val, "%i", &i) == 1) {
1242 if (i != 0)
1243 data = 1;
1244 else
1245 data = 0;
1246 } else {
1247 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1248 if (second_pass == 0) {
1249 val = WMGetFromPLString(entry->plvalue);
1250 second_pass = 1;
1251 wwarning(_("using default \"%s\" instead"), val);
1252 goto again;
1254 return False;
1258 if (ret)
1259 *ret = &data;
1260 if (addr)
1261 *(char *)addr = data;
1263 return True;
1266 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1268 static int data;
1269 char *val;
1271 GET_STRING_OR_DEFAULT("Integer", val);
1273 if (sscanf(val, "%i", &data) != 1) {
1274 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1275 val = WMGetFromPLString(entry->plvalue);
1276 wwarning(_("using default \"%s\" instead"), val);
1277 if (sscanf(val, "%i", &data) != 1) {
1278 return False;
1282 if (ret)
1283 *ret = &data;
1284 if (addr)
1285 *(int *)addr = data;
1287 return True;
1290 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1292 static WCoord data;
1293 char *val_x, *val_y;
1294 int nelem, changed = 0;
1295 WMPropList *elem_x, *elem_y;
1297 again:
1298 if (!WMIsPLArray(value)) {
1299 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1300 if (changed == 0) {
1301 value = entry->plvalue;
1302 changed = 1;
1303 wwarning(_("using default \"%s\" instead"), entry->default_value);
1304 goto again;
1306 return False;
1309 nelem = WMGetPropListItemCount(value);
1310 if (nelem != 2) {
1311 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1312 if (changed == 0) {
1313 value = entry->plvalue;
1314 changed = 1;
1315 wwarning(_("using default \"%s\" instead"), entry->default_value);
1316 goto again;
1318 return False;
1321 elem_x = WMGetFromPLArray(value, 0);
1322 elem_y = WMGetFromPLArray(value, 1);
1324 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1325 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1326 if (changed == 0) {
1327 value = entry->plvalue;
1328 changed = 1;
1329 wwarning(_("using default \"%s\" instead"), entry->default_value);
1330 goto again;
1332 return False;
1335 val_x = WMGetFromPLString(elem_x);
1336 val_y = WMGetFromPLString(elem_y);
1338 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1339 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1340 if (changed == 0) {
1341 value = entry->plvalue;
1342 changed = 1;
1343 wwarning(_("using default \"%s\" instead"), entry->default_value);
1344 goto again;
1346 return False;
1349 if (data.x < 0)
1350 data.x = 0;
1351 else if (data.x > scr->scr_width / 3)
1352 data.x = scr->scr_width / 3;
1353 if (data.y < 0)
1354 data.y = 0;
1355 else if (data.y > scr->scr_height / 3)
1356 data.y = scr->scr_height / 3;
1358 if (ret)
1359 *ret = &data;
1360 if (addr)
1361 *(WCoord *) addr = data;
1363 return True;
1366 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1368 WMRetainPropList(value);
1370 *ret = value;
1372 return True;
1375 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1377 static char *data;
1378 int i, count, len;
1379 char *ptr;
1380 WMPropList *d;
1381 int changed = 0;
1383 again:
1384 if (!WMIsPLArray(value)) {
1385 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1386 if (changed == 0) {
1387 value = entry->plvalue;
1388 changed = 1;
1389 wwarning(_("using default \"%s\" instead"), entry->default_value);
1390 goto again;
1392 return False;
1395 i = 0;
1396 count = WMGetPropListItemCount(value);
1397 if (count < 1) {
1398 if (changed == 0) {
1399 value = entry->plvalue;
1400 changed = 1;
1401 wwarning(_("using default \"%s\" instead"), entry->default_value);
1402 goto again;
1404 return False;
1407 len = 0;
1408 for (i = 0; i < count; i++) {
1409 d = WMGetFromPLArray(value, i);
1410 if (!d || !WMIsPLString(d)) {
1411 count = i;
1412 break;
1414 len += strlen(WMGetFromPLString(d)) + 1;
1417 ptr = data = wmalloc(len + 1);
1419 for (i = 0; i < count; i++) {
1420 d = WMGetFromPLArray(value, i);
1421 if (!d || !WMIsPLString(d)) {
1422 break;
1424 strcpy(ptr, WMGetFromPLString(d));
1425 ptr += strlen(WMGetFromPLString(d));
1426 *ptr = ':';
1427 ptr++;
1429 ptr--;
1430 *(ptr--) = 0;
1432 if (*(char **)addr != NULL) {
1433 wfree(*(char **)addr);
1435 *(char **)addr = data;
1437 return True;
1440 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1442 static signed char data;
1444 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1445 if (data < 0)
1446 return False;
1448 if (ret)
1449 *ret = &data;
1450 if (addr)
1451 *(signed char *)addr = data;
1453 return True;
1457 * (solid <color>)
1458 * (hgradient <color> <color>)
1459 * (vgradient <color> <color>)
1460 * (dgradient <color> <color>)
1461 * (mhgradient <color> <color> ...)
1462 * (mvgradient <color> <color> ...)
1463 * (mdgradient <color> <color> ...)
1464 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1465 * (tpixmap <file> <color>)
1466 * (spixmap <file> <color>)
1467 * (cpixmap <file> <color>)
1468 * (thgradient <file> <opaqueness> <color> <color>)
1469 * (tvgradient <file> <opaqueness> <color> <color>)
1470 * (tdgradient <file> <opaqueness> <color> <color>)
1471 * (function <lib> <function> ...)
1474 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1476 WMPropList *elem;
1477 char *val;
1478 int nelem;
1479 WTexture *texture = NULL;
1481 nelem = WMGetPropListItemCount(pl);
1482 if (nelem < 1)
1483 return NULL;
1485 elem = WMGetFromPLArray(pl, 0);
1486 if (!elem || !WMIsPLString(elem))
1487 return NULL;
1488 val = WMGetFromPLString(elem);
1490 if (strcasecmp(val, "solid") == 0) {
1491 XColor color;
1493 if (nelem != 2)
1494 return NULL;
1496 /* get color */
1498 elem = WMGetFromPLArray(pl, 1);
1499 if (!elem || !WMIsPLString(elem))
1500 return NULL;
1501 val = WMGetFromPLString(elem);
1503 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1504 wwarning(_("\"%s\" is not a valid color name"), val);
1505 return NULL;
1508 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1509 } else if (strcasecmp(val, "dgradient") == 0
1510 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1511 RColor color1, color2;
1512 XColor xcolor;
1513 int type;
1515 if (nelem != 3) {
1516 wwarning(_("bad number of arguments in gradient specification"));
1517 return NULL;
1520 if (val[0] == 'd' || val[0] == 'D')
1521 type = WTEX_DGRADIENT;
1522 else if (val[0] == 'h' || val[0] == 'H')
1523 type = WTEX_HGRADIENT;
1524 else
1525 type = WTEX_VGRADIENT;
1527 /* get from color */
1528 elem = WMGetFromPLArray(pl, 1);
1529 if (!elem || !WMIsPLString(elem))
1530 return NULL;
1531 val = WMGetFromPLString(elem);
1533 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1534 wwarning(_("\"%s\" is not a valid color name"), val);
1535 return NULL;
1537 color1.alpha = 255;
1538 color1.red = xcolor.red >> 8;
1539 color1.green = xcolor.green >> 8;
1540 color1.blue = xcolor.blue >> 8;
1542 /* get to color */
1543 elem = WMGetFromPLArray(pl, 2);
1544 if (!elem || !WMIsPLString(elem)) {
1545 return NULL;
1547 val = WMGetFromPLString(elem);
1549 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1550 wwarning(_("\"%s\" is not a valid color name"), val);
1551 return NULL;
1553 color2.alpha = 255;
1554 color2.red = xcolor.red >> 8;
1555 color2.green = xcolor.green >> 8;
1556 color2.blue = xcolor.blue >> 8;
1558 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1560 } else if (strcasecmp(val, "igradient") == 0) {
1561 RColor colors1[2], colors2[2];
1562 int th1, th2;
1563 XColor xcolor;
1564 int i;
1566 if (nelem != 7) {
1567 wwarning(_("bad number of arguments in gradient specification"));
1568 return NULL;
1571 /* get from color */
1572 for (i = 0; i < 2; i++) {
1573 elem = WMGetFromPLArray(pl, 1 + i);
1574 if (!elem || !WMIsPLString(elem))
1575 return NULL;
1576 val = WMGetFromPLString(elem);
1578 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1579 wwarning(_("\"%s\" is not a valid color name"), val);
1580 return NULL;
1582 colors1[i].alpha = 255;
1583 colors1[i].red = xcolor.red >> 8;
1584 colors1[i].green = xcolor.green >> 8;
1585 colors1[i].blue = xcolor.blue >> 8;
1587 elem = WMGetFromPLArray(pl, 3);
1588 if (!elem || !WMIsPLString(elem))
1589 return NULL;
1590 val = WMGetFromPLString(elem);
1591 th1 = atoi(val);
1593 /* get from color */
1594 for (i = 0; i < 2; i++) {
1595 elem = WMGetFromPLArray(pl, 4 + i);
1596 if (!elem || !WMIsPLString(elem))
1597 return NULL;
1598 val = WMGetFromPLString(elem);
1600 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1601 wwarning(_("\"%s\" is not a valid color name"), val);
1602 return NULL;
1604 colors2[i].alpha = 255;
1605 colors2[i].red = xcolor.red >> 8;
1606 colors2[i].green = xcolor.green >> 8;
1607 colors2[i].blue = xcolor.blue >> 8;
1609 elem = WMGetFromPLArray(pl, 6);
1610 if (!elem || !WMIsPLString(elem))
1611 return NULL;
1612 val = WMGetFromPLString(elem);
1613 th2 = atoi(val);
1615 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1617 } else if (strcasecmp(val, "mhgradient") == 0
1618 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1619 XColor color;
1620 RColor **colors;
1621 int i, count;
1622 int type;
1624 if (nelem < 3) {
1625 wwarning(_("too few arguments in multicolor gradient specification"));
1626 return NULL;
1629 if (val[1] == 'h' || val[1] == 'H')
1630 type = WTEX_MHGRADIENT;
1631 else if (val[1] == 'v' || val[1] == 'V')
1632 type = WTEX_MVGRADIENT;
1633 else
1634 type = WTEX_MDGRADIENT;
1636 count = nelem - 1;
1638 colors = wmalloc(sizeof(RColor *) * (count + 1));
1640 for (i = 0; i < count; i++) {
1641 elem = WMGetFromPLArray(pl, i + 1);
1642 if (!elem || !WMIsPLString(elem)) {
1643 for (--i; i >= 0; --i) {
1644 wfree(colors[i]);
1646 wfree(colors);
1647 return NULL;
1649 val = WMGetFromPLString(elem);
1651 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1652 wwarning(_("\"%s\" is not a valid color name"), val);
1653 for (--i; i >= 0; --i) {
1654 wfree(colors[i]);
1656 wfree(colors);
1657 return NULL;
1658 } else {
1659 colors[i] = wmalloc(sizeof(RColor));
1660 colors[i]->red = color.red >> 8;
1661 colors[i]->green = color.green >> 8;
1662 colors[i]->blue = color.blue >> 8;
1665 colors[i] = NULL;
1667 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1668 } else if (strcasecmp(val, "spixmap") == 0 ||
1669 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1670 XColor color;
1671 int type;
1673 if (nelem != 3)
1674 return NULL;
1676 if (val[0] == 's' || val[0] == 'S')
1677 type = WTP_SCALE;
1678 else if (val[0] == 'c' || val[0] == 'C')
1679 type = WTP_CENTER;
1680 else
1681 type = WTP_TILE;
1683 /* get color */
1684 elem = WMGetFromPLArray(pl, 2);
1685 if (!elem || !WMIsPLString(elem)) {
1686 return NULL;
1688 val = WMGetFromPLString(elem);
1690 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1691 wwarning(_("\"%s\" is not a valid color name"), val);
1692 return NULL;
1695 /* file name */
1696 elem = WMGetFromPLArray(pl, 1);
1697 if (!elem || !WMIsPLString(elem))
1698 return NULL;
1699 val = WMGetFromPLString(elem);
1701 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1702 } else if (strcasecmp(val, "thgradient") == 0
1703 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1704 RColor color1, color2;
1705 XColor xcolor;
1706 int opacity;
1707 int style;
1709 if (val[1] == 'h' || val[1] == 'H')
1710 style = WTEX_THGRADIENT;
1711 else if (val[1] == 'v' || val[1] == 'V')
1712 style = WTEX_TVGRADIENT;
1713 else
1714 style = WTEX_TDGRADIENT;
1716 if (nelem != 5) {
1717 wwarning(_("bad number of arguments in textured gradient specification"));
1718 return NULL;
1721 /* get from color */
1722 elem = WMGetFromPLArray(pl, 3);
1723 if (!elem || !WMIsPLString(elem))
1724 return NULL;
1725 val = WMGetFromPLString(elem);
1727 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1728 wwarning(_("\"%s\" is not a valid color name"), val);
1729 return NULL;
1731 color1.alpha = 255;
1732 color1.red = xcolor.red >> 8;
1733 color1.green = xcolor.green >> 8;
1734 color1.blue = xcolor.blue >> 8;
1736 /* get to color */
1737 elem = WMGetFromPLArray(pl, 4);
1738 if (!elem || !WMIsPLString(elem)) {
1739 return NULL;
1741 val = WMGetFromPLString(elem);
1743 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1744 wwarning(_("\"%s\" is not a valid color name"), val);
1745 return NULL;
1747 color2.alpha = 255;
1748 color2.red = xcolor.red >> 8;
1749 color2.green = xcolor.green >> 8;
1750 color2.blue = xcolor.blue >> 8;
1752 /* get opacity */
1753 elem = WMGetFromPLArray(pl, 2);
1754 if (!elem || !WMIsPLString(elem))
1755 opacity = 128;
1756 else
1757 val = WMGetFromPLString(elem);
1759 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1760 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1761 opacity = 128;
1764 /* get file name */
1765 elem = WMGetFromPLArray(pl, 1);
1766 if (!elem || !WMIsPLString(elem))
1767 return NULL;
1768 val = WMGetFromPLString(elem);
1770 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1771 } else if (strcasecmp(val, "function") == 0) {
1772 /* Leave this in to handle the unlikely case of
1773 * someone actually having function textures configured */
1774 wwarning("function texture support has been removed");
1775 return NULL;
1776 } else {
1777 wwarning(_("invalid texture type %s"), val);
1778 return NULL;
1780 return texture;
1783 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1785 static WTexture *texture;
1786 int changed = 0;
1788 again:
1789 if (!WMIsPLArray(value)) {
1790 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1791 if (changed == 0) {
1792 value = entry->plvalue;
1793 changed = 1;
1794 wwarning(_("using default \"%s\" instead"), entry->default_value);
1795 goto again;
1797 return False;
1800 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1801 WMPropList *pl;
1803 pl = WMGetFromPLArray(value, 0);
1804 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1805 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1806 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1807 entry->key, "Solid Texture");
1809 value = entry->plvalue;
1810 changed = 1;
1811 wwarning(_("using default \"%s\" instead"), entry->default_value);
1812 goto again;
1816 texture = parse_texture(scr, value);
1818 if (!texture) {
1819 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1820 if (changed == 0) {
1821 value = entry->plvalue;
1822 changed = 1;
1823 wwarning(_("using default \"%s\" instead"), entry->default_value);
1824 goto again;
1826 return False;
1829 if (ret)
1830 *ret = &texture;
1832 if (addr)
1833 *(WTexture **) addr = texture;
1835 return True;
1838 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1840 WMPropList *elem;
1841 int changed = 0;
1842 char *val;
1843 int nelem;
1845 again:
1846 if (!WMIsPLArray(value)) {
1847 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1848 "WorkspaceBack", "Texture or None");
1849 if (changed == 0) {
1850 value = entry->plvalue;
1851 changed = 1;
1852 wwarning(_("using default \"%s\" instead"), entry->default_value);
1853 goto again;
1855 return False;
1858 /* only do basic error checking and verify for None texture */
1860 nelem = WMGetPropListItemCount(value);
1861 if (nelem > 0) {
1862 elem = WMGetFromPLArray(value, 0);
1863 if (!elem || !WMIsPLString(elem)) {
1864 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1865 if (changed == 0) {
1866 value = entry->plvalue;
1867 changed = 1;
1868 wwarning(_("using default \"%s\" instead"), entry->default_value);
1869 goto again;
1871 return False;
1873 val = WMGetFromPLString(elem);
1875 if (strcasecmp(val, "None") == 0)
1876 return True;
1878 *ret = WMRetainPropList(value);
1880 return True;
1883 static int
1884 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1886 WMPropList *elem;
1887 int nelem;
1888 int changed = 0;
1890 again:
1891 if (!WMIsPLArray(value)) {
1892 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1893 "WorkspaceSpecificBack", "an array of textures");
1894 if (changed == 0) {
1895 value = entry->plvalue;
1896 changed = 1;
1897 wwarning(_("using default \"%s\" instead"), entry->default_value);
1898 goto again;
1900 return False;
1903 /* only do basic error checking and verify for None texture */
1905 nelem = WMGetPropListItemCount(value);
1906 if (nelem > 0) {
1907 while (nelem--) {
1908 elem = WMGetFromPLArray(value, nelem);
1909 if (!elem || !WMIsPLArray(elem)) {
1910 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1911 nelem);
1916 *ret = WMRetainPropList(value);
1918 #ifdef notworking
1920 * Kluge to force wmsetbg helper to set the default background.
1921 * If the WorkspaceSpecificBack is changed once wmaker has started,
1922 * the WorkspaceBack won't be sent to the helper, unless the user
1923 * changes it's value too. So, we must force this by removing the
1924 * value from the defaults DB.
1926 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1927 WMPropList *key = WMCreatePLString("WorkspaceBack");
1929 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1931 WMReleasePropList(key);
1933 #endif
1934 return True;
1937 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1939 static WMFont *font;
1940 char *val;
1942 GET_STRING_OR_DEFAULT("Font", val);
1944 font = WMCreateFont(scr->wmscreen, val);
1945 if (!font)
1946 font = WMCreateFont(scr->wmscreen, "fixed");
1948 if (!font) {
1949 wfatal(_("could not load any usable font!!!"));
1950 exit(1);
1953 if (ret)
1954 *ret = font;
1956 /* can't assign font value outside update function */
1957 wassertrv(addr == NULL, True);
1959 return True;
1962 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1964 static XColor color;
1965 char *val;
1966 int second_pass = 0;
1968 GET_STRING_OR_DEFAULT("Color", val);
1970 again:
1971 if (!wGetColor(scr, val, &color)) {
1972 wwarning(_("could not get color for key \"%s\""), entry->key);
1973 if (second_pass == 0) {
1974 val = WMGetFromPLString(entry->plvalue);
1975 second_pass = 1;
1976 wwarning(_("using default \"%s\" instead"), val);
1977 goto again;
1979 return False;
1982 if (ret)
1983 *ret = &color;
1985 assert(addr == NULL);
1987 if (addr)
1988 *(unsigned long*)addr = pixel;
1991 return True;
1994 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1996 static WShortKey shortcut;
1997 KeySym ksym;
1998 char *val;
1999 char *k;
2000 char buf[MAX_SHORTCUT_LENGTH], *b;
2002 GET_STRING_OR_DEFAULT("Key spec", val);
2004 if (!val || strcasecmp(val, "NONE") == 0) {
2005 shortcut.keycode = 0;
2006 shortcut.modifier = 0;
2007 if (ret)
2008 *ret = &shortcut;
2009 return True;
2012 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2014 b = (char *)buf;
2016 /* get modifiers */
2017 shortcut.modifier = 0;
2018 while ((k = strchr(b, '+')) != NULL) {
2019 int mod;
2021 *k = 0;
2022 mod = wXModifierFromKey(b);
2023 if (mod < 0) {
2024 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2025 return False;
2027 shortcut.modifier |= mod;
2029 b = k + 1;
2032 /* get key */
2033 ksym = XStringToKeysym(b);
2035 if (ksym == NoSymbol) {
2036 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2037 return False;
2040 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2041 if (shortcut.keycode == 0) {
2042 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2043 return False;
2046 if (ret)
2047 *ret = &shortcut;
2049 return True;
2052 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2054 static int mask;
2055 char *str;
2057 GET_STRING_OR_DEFAULT("Modifier Key", str);
2059 if (!str)
2060 return False;
2062 mask = wXModifierFromKey(str);
2063 if (mask < 0) {
2064 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2065 mask = 0;
2066 return False;
2069 if (addr)
2070 *(int *)addr = mask;
2072 if (ret)
2073 *ret = &mask;
2075 return True;
2078 # include <X11/cursorfont.h>
2079 typedef struct {
2080 char *name;
2081 int id;
2082 } WCursorLookup;
2084 #define CURSOR_ID_NONE (XC_num_glyphs)
2086 static WCursorLookup cursor_table[] = {
2087 {"X_cursor", XC_X_cursor},
2088 {"arrow", XC_arrow},
2089 {"based_arrow_down", XC_based_arrow_down},
2090 {"based_arrow_up", XC_based_arrow_up},
2091 {"boat", XC_boat},
2092 {"bogosity", XC_bogosity},
2093 {"bottom_left_corner", XC_bottom_left_corner},
2094 {"bottom_right_corner", XC_bottom_right_corner},
2095 {"bottom_side", XC_bottom_side},
2096 {"bottom_tee", XC_bottom_tee},
2097 {"box_spiral", XC_box_spiral},
2098 {"center_ptr", XC_center_ptr},
2099 {"circle", XC_circle},
2100 {"clock", XC_clock},
2101 {"coffee_mug", XC_coffee_mug},
2102 {"cross", XC_cross},
2103 {"cross_reverse", XC_cross_reverse},
2104 {"crosshair", XC_crosshair},
2105 {"diamond_cross", XC_diamond_cross},
2106 {"dot", XC_dot},
2107 {"dotbox", XC_dotbox},
2108 {"double_arrow", XC_double_arrow},
2109 {"draft_large", XC_draft_large},
2110 {"draft_small", XC_draft_small},
2111 {"draped_box", XC_draped_box},
2112 {"exchange", XC_exchange},
2113 {"fleur", XC_fleur},
2114 {"gobbler", XC_gobbler},
2115 {"gumby", XC_gumby},
2116 {"hand1", XC_hand1},
2117 {"hand2", XC_hand2},
2118 {"heart", XC_heart},
2119 {"icon", XC_icon},
2120 {"iron_cross", XC_iron_cross},
2121 {"left_ptr", XC_left_ptr},
2122 {"left_side", XC_left_side},
2123 {"left_tee", XC_left_tee},
2124 {"leftbutton", XC_leftbutton},
2125 {"ll_angle", XC_ll_angle},
2126 {"lr_angle", XC_lr_angle},
2127 {"man", XC_man},
2128 {"middlebutton", XC_middlebutton},
2129 {"mouse", XC_mouse},
2130 {"pencil", XC_pencil},
2131 {"pirate", XC_pirate},
2132 {"plus", XC_plus},
2133 {"question_arrow", XC_question_arrow},
2134 {"right_ptr", XC_right_ptr},
2135 {"right_side", XC_right_side},
2136 {"right_tee", XC_right_tee},
2137 {"rightbutton", XC_rightbutton},
2138 {"rtl_logo", XC_rtl_logo},
2139 {"sailboat", XC_sailboat},
2140 {"sb_down_arrow", XC_sb_down_arrow},
2141 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2142 {"sb_left_arrow", XC_sb_left_arrow},
2143 {"sb_right_arrow", XC_sb_right_arrow},
2144 {"sb_up_arrow", XC_sb_up_arrow},
2145 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2146 {"shuttle", XC_shuttle},
2147 {"sizing", XC_sizing},
2148 {"spider", XC_spider},
2149 {"spraycan", XC_spraycan},
2150 {"star", XC_star},
2151 {"target", XC_target},
2152 {"tcross", XC_tcross},
2153 {"top_left_arrow", XC_top_left_arrow},
2154 {"top_left_corner", XC_top_left_corner},
2155 {"top_right_corner", XC_top_right_corner},
2156 {"top_side", XC_top_side},
2157 {"top_tee", XC_top_tee},
2158 {"trek", XC_trek},
2159 {"ul_angle", XC_ul_angle},
2160 {"umbrella", XC_umbrella},
2161 {"ur_angle", XC_ur_angle},
2162 {"watch", XC_watch},
2163 {"xterm", XC_xterm},
2164 {NULL, CURSOR_ID_NONE}
2167 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2169 switch (status) {
2170 case BitmapOpenFailed:
2171 wwarning(_("failed to open bitmap file \"%s\""), filename);
2172 break;
2173 case BitmapFileInvalid:
2174 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2175 break;
2176 case BitmapNoMemory:
2177 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2178 break;
2179 case BitmapSuccess:
2180 XFreePixmap(dpy, bitmap);
2181 break;
2186 * (none)
2187 * (builtin, <cursor_name>)
2188 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2190 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2192 WMPropList *elem;
2193 char *val;
2194 int nelem;
2195 int status = 0;
2197 nelem = WMGetPropListItemCount(pl);
2198 if (nelem < 1) {
2199 return (status);
2201 elem = WMGetFromPLArray(pl, 0);
2202 if (!elem || !WMIsPLString(elem)) {
2203 return (status);
2205 val = WMGetFromPLString(elem);
2207 if (strcasecmp(val, "none") == 0) {
2208 status = 1;
2209 *cursor = None;
2210 } else if (strcasecmp(val, "builtin") == 0) {
2211 int i;
2212 int cursor_id = CURSOR_ID_NONE;
2214 if (nelem != 2) {
2215 wwarning(_("bad number of arguments in cursor specification"));
2216 return (status);
2218 elem = WMGetFromPLArray(pl, 1);
2219 if (!elem || !WMIsPLString(elem)) {
2220 return (status);
2222 val = WMGetFromPLString(elem);
2224 for (i = 0; cursor_table[i].name != NULL; i++) {
2225 if (strcasecmp(val, cursor_table[i].name) == 0) {
2226 cursor_id = cursor_table[i].id;
2227 break;
2230 if (CURSOR_ID_NONE == cursor_id) {
2231 wwarning(_("unknown builtin cursor name \"%s\""), val);
2232 } else {
2233 *cursor = XCreateFontCursor(dpy, cursor_id);
2234 status = 1;
2236 } else if (strcasecmp(val, "bitmap") == 0) {
2237 char *bitmap_name;
2238 char *mask_name;
2239 int bitmap_status;
2240 int mask_status;
2241 Pixmap bitmap;
2242 Pixmap mask;
2243 unsigned int w, h;
2244 int x, y;
2245 XColor fg, bg;
2247 if (nelem != 3) {
2248 wwarning(_("bad number of arguments in cursor specification"));
2249 return (status);
2251 elem = WMGetFromPLArray(pl, 1);
2252 if (!elem || !WMIsPLString(elem)) {
2253 return (status);
2255 val = WMGetFromPLString(elem);
2256 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2257 if (!bitmap_name) {
2258 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2259 return (status);
2261 elem = WMGetFromPLArray(pl, 2);
2262 if (!elem || !WMIsPLString(elem)) {
2263 wfree(bitmap_name);
2264 return (status);
2266 val = WMGetFromPLString(elem);
2267 mask_name = FindImage(wPreferences.pixmap_path, val);
2268 if (!mask_name) {
2269 wfree(bitmap_name);
2270 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2271 return (status);
2273 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2274 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2275 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2276 fg.pixel = scr->black_pixel;
2277 bg.pixel = scr->white_pixel;
2278 XQueryColor(dpy, scr->w_colormap, &fg);
2279 XQueryColor(dpy, scr->w_colormap, &bg);
2280 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2281 status = 1;
2283 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2284 check_bitmap_status(mask_status, mask_name, mask);
2285 wfree(bitmap_name);
2286 wfree(mask_name);
2288 return (status);
2291 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2293 static Cursor cursor;
2294 int status;
2295 int changed = 0;
2297 again:
2298 if (!WMIsPLArray(value)) {
2299 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2300 entry->key, "cursor specification");
2301 if (!changed) {
2302 value = entry->plvalue;
2303 changed = 1;
2304 wwarning(_("using default \"%s\" instead"), entry->default_value);
2305 goto again;
2307 return (False);
2309 status = parse_cursor(scr, value, &cursor);
2310 if (!status) {
2311 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2312 if (!changed) {
2313 value = entry->plvalue;
2314 changed = 1;
2315 wwarning(_("using default \"%s\" instead"), entry->default_value);
2316 goto again;
2318 return (False);
2320 if (ret) {
2321 *ret = &cursor;
2323 if (addr) {
2324 *(Cursor *) addr = cursor;
2326 return (True);
2329 #undef CURSOR_ID_NONE
2331 /* ---------------- value setting functions --------------- */
2332 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2334 return REFRESH_WINDOW_TITLE_COLOR;
2337 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2339 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2342 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2344 switch (which) {
2345 case WM_DOCK:
2346 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2347 break;
2348 case WM_CLIP:
2349 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2350 break;
2351 default:
2352 break;
2354 return 0;
2357 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2359 if (scr->workspaces) {
2360 wWorkspaceForceChange(scr, scr->current_workspace);
2361 wArrangeIcons(scr, False);
2363 return 0;
2366 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2368 Pixmap pixmap;
2369 RImage *img;
2370 int reset = 0;
2372 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2373 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2374 ? WREL_ICON : WREL_FLAT);
2375 if (!img) {
2376 wwarning(_("could not render texture for icon background"));
2377 if (!entry->addr)
2378 wTextureDestroy(scr, *texture);
2379 return 0;
2381 RConvertImage(scr->rcontext, img, &pixmap);
2383 if (scr->icon_tile) {
2384 reset = 1;
2385 RReleaseImage(scr->icon_tile);
2386 XFreePixmap(dpy, scr->icon_tile_pixmap);
2389 scr->icon_tile = img;
2391 /* put the icon in the noticeboard hint */
2392 PropSetIconTileHint(scr, img);
2394 if (!wPreferences.flags.noclip) {
2395 if (scr->clip_tile) {
2396 RReleaseImage(scr->clip_tile);
2398 scr->clip_tile = wClipMakeTile(scr, img);
2401 scr->icon_tile_pixmap = pixmap;
2403 if (scr->def_icon_pixmap) {
2404 XFreePixmap(dpy, scr->def_icon_pixmap);
2405 scr->def_icon_pixmap = None;
2407 if (scr->def_ticon_pixmap) {
2408 XFreePixmap(dpy, scr->def_ticon_pixmap);
2409 scr->def_ticon_pixmap = None;
2412 if (scr->icon_back_texture) {
2413 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2415 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2417 if (scr->clip_balloon)
2418 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2421 * Free the texture as nobody else will use it, nor refer to it.
2423 if (!entry->addr)
2424 wTextureDestroy(scr, *texture);
2426 return (reset ? REFRESH_ICON_TILE : 0);
2429 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2431 if (scr->title_font) {
2432 WMReleaseFont(scr->title_font);
2434 scr->title_font = font;
2436 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2439 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2441 if (scr->menu_title_font) {
2442 WMReleaseFont(scr->menu_title_font);
2445 scr->menu_title_font = font;
2447 return REFRESH_MENU_TITLE_FONT;
2450 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2452 if (scr->menu_entry_font) {
2453 WMReleaseFont(scr->menu_entry_font);
2455 scr->menu_entry_font = font;
2457 return REFRESH_MENU_FONT;
2460 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2462 if (scr->icon_title_font) {
2463 WMReleaseFont(scr->icon_title_font);
2466 scr->icon_title_font = font;
2468 return REFRESH_ICON_FONT;
2471 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2473 if (scr->clip_title_font) {
2474 WMReleaseFont(scr->clip_title_font);
2477 scr->clip_title_font = font;
2479 return REFRESH_ICON_FONT;
2482 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2484 if (scr->workspace_name_font) {
2485 WMReleaseFont(scr->workspace_name_font);
2488 scr->workspace_name_font = font;
2490 return 0;
2493 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2495 if (scr->select_color)
2496 WMReleaseColor(scr->select_color);
2498 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2500 wFreeColor(scr, color->pixel);
2502 return REFRESH_MENU_COLOR;
2505 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2507 if (scr->select_text_color)
2508 WMReleaseColor(scr->select_text_color);
2510 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2512 wFreeColor(scr, color->pixel);
2514 return REFRESH_MENU_COLOR;
2517 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2519 if (scr->clip_title_color[widx])
2520 WMReleaseColor(scr->clip_title_color[widx]);
2521 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2522 #ifdef GRADIENT_CLIP_ARROW
2523 if (widx == CLIP_NORMAL) {
2524 RImage *image;
2525 RColor color1, color2;
2526 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2527 int as = pt - 15; /* 15 = 5+5+5 */
2529 FREE_PIXMAP(scr->clip_arrow_gradient);
2531 color1.red = (color->red >> 8) * 6 / 10;
2532 color1.green = (color->green >> 8) * 6 / 10;
2533 color1.blue = (color->blue >> 8) * 6 / 10;
2535 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2536 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2537 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2539 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2540 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2541 RReleaseImage(image);
2543 #endif /* GRADIENT_CLIP_ARROW */
2545 wFreeColor(scr, color->pixel);
2547 return REFRESH_ICON_TITLE_COLOR;
2550 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2552 if (scr->window_title_color[widx])
2553 WMReleaseColor(scr->window_title_color[widx]);
2555 scr->window_title_color[widx] =
2556 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2558 wFreeColor(scr, color->pixel);
2560 return REFRESH_WINDOW_TITLE_COLOR;
2563 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2565 if (scr->menu_title_color[0])
2566 WMReleaseColor(scr->menu_title_color[0]);
2568 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2570 wFreeColor(scr, color->pixel);
2572 return REFRESH_MENU_TITLE_COLOR;
2575 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2577 if (scr->mtext_color)
2578 WMReleaseColor(scr->mtext_color);
2580 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2582 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2583 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2584 } else {
2585 WMSetColorAlpha(scr->dtext_color, 0xffff);
2588 wFreeColor(scr, color->pixel);
2590 return REFRESH_MENU_COLOR;
2593 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2595 if (scr->dtext_color)
2596 WMReleaseColor(scr->dtext_color);
2598 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2600 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2601 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2602 } else {
2603 WMSetColorAlpha(scr->dtext_color, 0xffff);
2606 wFreeColor(scr, color->pixel);
2608 return REFRESH_MENU_COLOR;
2611 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2613 if (scr->icon_title_color)
2614 WMReleaseColor(scr->icon_title_color);
2615 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2617 wFreeColor(scr, color->pixel);
2619 return REFRESH_ICON_TITLE_COLOR;
2622 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2624 if (scr->icon_title_texture) {
2625 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2627 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2629 return REFRESH_ICON_TITLE_BACK;
2632 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2634 close(scr->helper_fd);
2635 scr->helper_fd = 0;
2636 scr->helper_pid = 0;
2637 scr->flags.backimage_helper_launched = 0;
2640 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2642 WMPropList *val;
2643 char *str;
2644 int i;
2646 if (scr->flags.backimage_helper_launched) {
2647 if (WMGetPropListItemCount(value) == 0) {
2648 SendHelperMessage(scr, 'C', 0, NULL);
2649 SendHelperMessage(scr, 'K', 0, NULL);
2651 WMReleasePropList(value);
2652 return 0;
2654 } else {
2655 pid_t pid;
2656 int filedes[2];
2658 if (WMGetPropListItemCount(value) == 0)
2659 return 0;
2661 if (pipe(filedes) < 0) {
2662 wsyserror("pipe() failed:can't set workspace specific background image");
2664 WMReleasePropList(value);
2665 return 0;
2668 pid = fork();
2669 if (pid < 0) {
2670 wsyserror("fork() failed:can't set workspace specific background image");
2671 if (close(filedes[0]) < 0)
2672 wsyserror("could not close pipe");
2673 if (close(filedes[1]) < 0)
2674 wsyserror("could not close pipe");
2676 } else if (pid == 0) {
2677 char *dither;
2679 SetupEnvironment(scr);
2681 if (close(0) < 0)
2682 wsyserror("could not close pipe");
2683 if (dup(filedes[0]) < 0) {
2684 wsyserror("dup() failed:can't set workspace specific background image");
2686 dither = wPreferences.no_dithering ? "-m" : "-d";
2687 if (wPreferences.smooth_workspace_back)
2688 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2689 else
2690 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2691 wsyserror("could not execute wmsetbg");
2692 exit(1);
2693 } else {
2695 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2696 wsyserror("error setting close-on-exec flag");
2698 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2699 wsyserror("error setting close-on-exec flag");
2702 scr->helper_fd = filedes[1];
2703 scr->helper_pid = pid;
2704 scr->flags.backimage_helper_launched = 1;
2706 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2708 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2713 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2714 val = WMGetFromPLArray(value, i);
2715 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2716 str = WMGetPropListDescription(val, False);
2718 SendHelperMessage(scr, 'S', i + 1, str);
2720 wfree(str);
2721 } else {
2722 SendHelperMessage(scr, 'U', i + 1, NULL);
2725 sleep(1);
2727 WMReleasePropList(value);
2728 return 0;
2731 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2733 if (scr->flags.backimage_helper_launched) {
2734 char *str;
2736 if (WMGetPropListItemCount(value) == 0) {
2737 SendHelperMessage(scr, 'U', 0, NULL);
2738 } else {
2739 /* set the default workspace background to this one */
2740 str = WMGetPropListDescription(value, False);
2741 if (str) {
2742 SendHelperMessage(scr, 'S', 0, str);
2743 wfree(str);
2744 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2745 } else {
2746 SendHelperMessage(scr, 'U', 0, NULL);
2749 } else if (WMGetPropListItemCount(value) > 0) {
2750 char *command;
2751 char *text;
2752 char *dither;
2753 int len;
2755 text = WMGetPropListDescription(value, False);
2756 len = strlen(text) + 40;
2757 command = wmalloc(len);
2758 dither = wPreferences.no_dithering ? "-m" : "-d";
2759 if (wPreferences.smooth_workspace_back)
2760 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2761 else
2762 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2763 wfree(text);
2764 ExecuteShellCommand(scr, command);
2765 wfree(command);
2767 WMReleasePropList(value);
2769 return 0;
2772 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2774 if (scr->widget_texture) {
2775 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2777 scr->widget_texture = *(WTexSolid **) texture;
2779 return 0;
2782 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2784 if (scr->window_title_texture[WS_FOCUSED]) {
2785 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2787 scr->window_title_texture[WS_FOCUSED] = *texture;
2789 return REFRESH_WINDOW_TEXTURES;
2792 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2794 if (scr->window_title_texture[WS_PFOCUSED]) {
2795 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2797 scr->window_title_texture[WS_PFOCUSED] = *texture;
2799 return REFRESH_WINDOW_TEXTURES;
2802 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2804 if (scr->window_title_texture[WS_UNFOCUSED]) {
2805 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2807 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2809 return REFRESH_WINDOW_TEXTURES;
2812 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2814 if (scr->resizebar_texture[0]) {
2815 wTextureDestroy(scr, scr->resizebar_texture[0]);
2817 scr->resizebar_texture[0] = *texture;
2819 return REFRESH_WINDOW_TEXTURES;
2822 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2824 if (scr->menu_title_texture[0]) {
2825 wTextureDestroy(scr, scr->menu_title_texture[0]);
2827 scr->menu_title_texture[0] = *texture;
2829 return REFRESH_MENU_TITLE_TEXTURE;
2832 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2834 if (scr->menu_item_texture) {
2835 wTextureDestroy(scr, scr->menu_item_texture);
2836 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2838 scr->menu_item_texture = *texture;
2840 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2842 return REFRESH_MENU_TEXTURE;
2845 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2847 WWindow *wwin;
2848 wKeyBindings[widx] = *shortcut;
2850 wwin = scr->focused_window;
2852 while (wwin != NULL) {
2853 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2855 if (!WFLAGP(wwin, no_bind_keys)) {
2856 wWindowSetKeyGrabs(wwin);
2858 wwin = wwin->prev;
2861 return 0;
2864 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2866 wScreenUpdateUsableArea(scr);
2867 wArrangeIcons(scr, True);
2869 return 0;
2872 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2874 wScreenUpdateUsableArea(scr);
2876 return 0;
2879 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2881 return REFRESH_MENU_TEXTURE;
2884 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2886 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2888 RCopyArea(img, image, x, y, w, h, 0, 0);
2890 return img;
2893 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2895 char *path;
2896 RImage *bgimage;
2897 int cwidth, cheight;
2898 WPreferences *prefs = (WPreferences *) foo;
2900 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2901 if (prefs->swtileImage)
2902 RReleaseImage(prefs->swtileImage);
2903 prefs->swtileImage = NULL;
2905 WMReleasePropList(array);
2906 return 0;
2909 switch (WMGetPropListItemCount(array)) {
2910 case 4:
2911 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2912 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2913 break;
2914 } else
2915 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2917 if (!path) {
2918 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2919 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2920 } else {
2921 bgimage = RLoadImage(scr->rcontext, path, 0);
2922 if (!bgimage) {
2923 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2924 wfree(path);
2925 } else {
2926 wfree(path);
2928 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2929 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2931 if (cwidth <= 0 || cheight <= 0 ||
2932 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2933 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2934 else {
2935 int i;
2936 int swidth, theight;
2937 for (i = 0; i < 9; i++) {
2938 if (prefs->swbackImage[i])
2939 RReleaseImage(prefs->swbackImage[i]);
2940 prefs->swbackImage[i] = NULL;
2942 swidth = (bgimage->width - cwidth) / 2;
2943 theight = (bgimage->height - cheight) / 2;
2945 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2946 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2947 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2948 swidth, theight);
2950 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2951 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2952 cwidth, cheight);
2953 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2954 swidth, cheight);
2956 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2957 swidth, theight);
2958 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2959 cwidth, theight);
2960 prefs->swbackImage[8] =
2961 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2962 theight);
2964 // check if anything failed
2965 for (i = 0; i < 9; i++) {
2966 if (!prefs->swbackImage[i]) {
2967 for (; i >= 0; --i) {
2968 RReleaseImage(prefs->swbackImage[i]);
2969 prefs->swbackImage[i] = NULL;
2971 break;
2975 RReleaseImage(bgimage);
2979 case 1:
2980 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2981 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2982 break;
2983 } else
2984 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2986 if (!path) {
2987 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2988 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2989 } else {
2990 if (prefs->swtileImage)
2991 RReleaseImage(prefs->swtileImage);
2993 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2994 if (!prefs->swtileImage) {
2995 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2997 wfree(path);
2999 break;
3001 default:
3002 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3003 break;
3006 WMReleasePropList(array);
3008 return 0;
3012 * Very ugly kluge.
3013 * Need access to the double click variables, so that all widgets in
3014 * wmaker panels will have the same dbl-click values.
3015 * TODO: figure a better way of dealing with it.
3017 #include <WINGs/WINGsP.h>
3019 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3021 extern _WINGsConfiguration WINGsConfiguration;
3023 if (*value <= 0)
3024 *(int *)foo = 1;
3026 WINGsConfiguration.doubleClickDelay = *value;
3028 return 0;
3031 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3033 if (wCursor[widx] != None) {
3034 XFreeCursor(dpy, wCursor[widx]);
3037 wCursor[widx] = *cursor;
3039 if (widx == WCUR_ROOT && *cursor != None) {
3040 XDefineCursor(dpy, scr->root_win, *cursor);
3043 return 0;