Fix internationalized format string warnings
[wmaker-crm.git] / src / defaults.c
blobed7ad1af3ef326ba71720bf06bf83505232d8ecf
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 *****/
73 extern WDDomain *WDWindowMaker;
74 extern WDDomain *WDWindowAttributes;
75 extern WDDomain *WDRootMenu;
77 extern int wScreenCount;
79 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
80 extern Atom _XA_WINDOWMAKER_ICON_TILE;
82 extern WPreferences wPreferences;
84 extern WShortKey wKeyBindings[WKBD_LAST];
86 typedef struct {
87 char *key;
88 char *default_value;
89 void *extra_data;
90 void *addr;
91 int (*convert) ();
92 int (*update) ();
93 WMPropList *plkey;
94 WMPropList *plvalue; /* default value */
95 } WDefaultEntry;
97 /* used to map strings to integers */
98 typedef struct {
99 char *string;
100 short value;
101 char is_alias;
102 } WOptionEnumeration;
104 /* type converters */
105 static int getBool();
106 static int getInt();
107 static int getCoord();
108 static int getPathList();
109 static int getEnum();
110 static int getTexture();
111 static int getWSBackground();
112 static int getWSSpecificBackground();
113 static int getFont();
114 static int getColor();
115 static int getKeybind();
116 static int getModMask();
117 #ifdef NEWSTUFF
118 static int getRImage();
119 #endif
120 static int getPropList();
122 /* value setting functions */
123 static int setJustify();
124 static int setClearance();
125 static int setIfDockPresent();
126 static int setStickyIcons();
127 static int setWidgetColor();
128 static int setIconTile();
129 static int setWinTitleFont();
130 static int setMenuTitleFont();
131 static int setMenuTextFont();
132 static int setIconTitleFont();
133 static int setIconTitleColor();
134 static int setIconTitleBack();
135 static int setLargeDisplayFont();
136 static int setWTitleColor();
137 static int setFTitleBack();
138 static int setPTitleBack();
139 static int setUTitleBack();
140 static int setResizebarBack();
141 static int setWorkspaceBack();
142 static int setWorkspaceSpecificBack();
143 static int setMenuTitleColor();
144 static int setMenuTextColor();
145 static int setMenuDisabledColor();
146 static int setMenuTitleBack();
147 static int setMenuTextBack();
148 static int setHightlight();
149 static int setHightlightText();
150 static int setKeyGrab();
151 static int setDoubleClick();
152 static int setIconPosition();
154 static int setClipTitleFont();
155 static int setClipTitleColor();
157 static int setMenuStyle();
158 static int setSwPOptions();
159 static int updateUsableArea();
161 extern Cursor wCursor[WCUR_LAST];
162 static int getCursor();
163 static int setCursor();
166 * Tables to convert strings to enumeration values.
167 * Values stored are char
170 /* WARNING: sum of length of all value strings must not exceed
171 * this value */
172 #define TOTAL_VALUES_LENGTH 80
174 #define REFRESH_WINDOW_TEXTURES (1<<0)
175 #define REFRESH_MENU_TEXTURE (1<<1)
176 #define REFRESH_MENU_FONT (1<<2)
177 #define REFRESH_MENU_COLOR (1<<3)
178 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
179 #define REFRESH_MENU_TITLE_FONT (1<<5)
180 #define REFRESH_MENU_TITLE_COLOR (1<<6)
181 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
182 #define REFRESH_WINDOW_FONT (1<<8)
183 #define REFRESH_ICON_TILE (1<<9)
184 #define REFRESH_ICON_FONT (1<<10)
185 #define REFRESH_WORKSPACE_BACK (1<<11)
187 #define REFRESH_BUTTON_IMAGES (1<<12)
189 #define REFRESH_ICON_TITLE_COLOR (1<<13)
190 #define REFRESH_ICON_TITLE_BACK (1<<14)
192 static WOptionEnumeration seFocusModes[] = {
193 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
194 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
195 {NULL, 0, 0}
198 static WOptionEnumeration seColormapModes[] = {
199 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
200 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
201 {NULL, 0, 0}
204 static WOptionEnumeration sePlacements[] = {
205 {"Auto", WPM_AUTO, 0},
206 {"Smart", WPM_SMART, 0},
207 {"Cascade", WPM_CASCADE, 0},
208 {"Random", WPM_RANDOM, 0},
209 {"Manual", WPM_MANUAL, 0},
210 {NULL, 0, 0}
213 static WOptionEnumeration seGeomDisplays[] = {
214 {"None", WDIS_NONE, 0},
215 {"Center", WDIS_CENTER, 0},
216 {"Corner", WDIS_TOPLEFT, 0},
217 {"Floating", WDIS_FRAME_CENTER, 0},
218 {"Line", WDIS_NEW, 0},
219 {NULL, 0, 0}
222 static WOptionEnumeration seSpeeds[] = {
223 {"UltraFast", SPEED_ULTRAFAST, 0},
224 {"Fast", SPEED_FAST, 0},
225 {"Medium", SPEED_MEDIUM, 0},
226 {"Slow", SPEED_SLOW, 0},
227 {"UltraSlow", SPEED_ULTRASLOW, 0},
228 {NULL, 0, 0}
231 static WOptionEnumeration seMouseButtonActions[] = {
232 {"None", WA_NONE, 0},
233 {"SelectWindows", WA_SELECT_WINDOWS, 0},
234 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
235 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
236 {NULL, 0, 0}
239 static WOptionEnumeration seMouseWheelActions[] = {
240 {"None", WA_NONE, 0},
241 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
242 {NULL, 0, 0}
245 static WOptionEnumeration seIconificationStyles[] = {
246 {"Zoom", WIS_ZOOM, 0},
247 {"Twist", WIS_TWIST, 0},
248 {"Flip", WIS_FLIP, 0},
249 {"None", WIS_NONE, 0},
250 {"random", WIS_RANDOM, 0},
251 {NULL, 0, 0}
254 static WOptionEnumeration seJustifications[] = {
255 {"Left", WTJ_LEFT, 0},
256 {"Center", WTJ_CENTER, 0},
257 {"Right", WTJ_RIGHT, 0},
258 {NULL, 0, 0}
261 static WOptionEnumeration seIconPositions[] = {
262 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
263 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
264 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
265 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
266 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
267 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
268 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
269 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
270 {NULL, 0, 0}
273 static WOptionEnumeration seMenuStyles[] = {
274 {"normal", MS_NORMAL, 0},
275 {"singletexture", MS_SINGLE_TEXTURE, 0},
276 {"flat", MS_FLAT, 0},
277 {NULL, 0, 0}
280 static WOptionEnumeration seDisplayPositions[] = {
281 {"none", WD_NONE, 0},
282 {"center", WD_CENTER, 0},
283 {"top", WD_TOP, 0},
284 {"bottom", WD_BOTTOM, 0},
285 {"topleft", WD_TOPLEFT, 0},
286 {"topright", WD_TOPRIGHT, 0},
287 {"bottomleft", WD_BOTTOMLEFT, 0},
288 {"bottomright", WD_BOTTOMRIGHT, 0},
289 {NULL, 0, 0}
292 static WOptionEnumeration seWorkspaceBorder[] = {
293 {"None", WB_NONE, 0},
294 {"LeftRight", WB_LEFTRIGHT, 0},
295 {"TopBottom", WB_TOPBOTTOM, 0},
296 {"AllDirections", WB_ALLDIRS, 0},
297 {NULL, 0, 0}
301 * ALL entries in the tables bellow, NEED to have a default value
302 * defined, and this value needs to be correct.
305 /* these options will only affect the window manager on startup
307 * static defaults can't access the screen data, because it is
308 * created after these defaults are read
310 WDefaultEntry staticOptionList[] = {
312 {"ColormapSize", "4", NULL,
313 &wPreferences.cmap_size, getInt, NULL, NULL, NULL},
314 {"DisableDithering", "NO", NULL,
315 &wPreferences.no_dithering, getBool, NULL, NULL, NULL},
316 {"IconSize", "64", NULL,
317 &wPreferences.icon_size, getInt, NULL, NULL, NULL},
318 {"ModifierKey", "Mod1", NULL,
319 &wPreferences.modifier_mask, getModMask, NULL, NULL, NULL},
320 {"DisableWSMouseActions", "NO", NULL,
321 &wPreferences.disable_root_mouse, getBool, NULL, NULL, NULL},
322 {"FocusMode", "manual", seFocusModes, /* have a problem when switching from */
323 &wPreferences.focus_mode, getEnum, NULL, NULL, NULL}, /* manual to sloppy without restart */
324 {"NewStyle", "NO", NULL,
325 &wPreferences.new_style, getBool, NULL, NULL, NULL},
326 {"DisableDock", "NO", (void *)WM_DOCK,
327 NULL, getBool, setIfDockPresent, NULL, NULL},
328 {"DisableClip", "NO", (void *)WM_CLIP,
329 NULL, getBool, setIfDockPresent, NULL, NULL},
330 {"DisableMiniwindows", "NO", NULL,
331 &wPreferences.disable_miniwindows, getBool, NULL, NULL, NULL}
334 WDefaultEntry optionList[] = {
336 /* dynamic options */
338 {"IconPosition", "blh", seIconPositions,
339 &wPreferences.icon_yard, getEnum, setIconPosition, NULL, NULL},
340 {"IconificationStyle", "Zoom", seIconificationStyles,
341 &wPreferences.iconification_style, getEnum, NULL, NULL, NULL},
342 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
343 &wPreferences.mouse_button1, getEnum, NULL, NULL, NULL},
344 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
345 &wPreferences.mouse_button2, getEnum, NULL, NULL, NULL},
346 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
347 &wPreferences.mouse_button3, getEnum, NULL, NULL, NULL},
348 {"MouseWheelAction", "None", seMouseWheelActions,
349 &wPreferences.mouse_wheel, getEnum, NULL, NULL, NULL},
350 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
351 &wPreferences.pixmap_path, getPathList, NULL, NULL, NULL},
352 {"IconPath", DEF_ICON_PATHS, NULL,
353 &wPreferences.icon_path, getPathList, NULL, NULL, NULL},
354 {"ColormapMode", "auto", seColormapModes,
355 &wPreferences.colormap_mode, getEnum, NULL, NULL, NULL},
356 {"AutoFocus", "NO", NULL,
357 &wPreferences.auto_focus, getBool, NULL, NULL, NULL},
358 {"RaiseDelay", "0", NULL,
359 &wPreferences.raise_delay, getInt, NULL, NULL, NULL},
360 {"CirculateRaise", "NO", NULL,
361 &wPreferences.circ_raise, getBool, NULL, NULL, NULL},
362 {"Superfluous", "NO", NULL,
363 &wPreferences.superfluous, getBool, NULL, NULL, NULL},
364 {"AdvanceToNewWorkspace", "NO", NULL,
365 &wPreferences.ws_advance, getBool, NULL, NULL, NULL},
366 {"CycleWorkspaces", "NO", NULL,
367 &wPreferences.ws_cycle, getBool, NULL, NULL, NULL},
368 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
369 &wPreferences.workspace_name_display_position, getEnum, NULL, NULL, NULL},
370 {"WorkspaceBorder", "None", seWorkspaceBorder,
371 &wPreferences.workspace_border_position, getEnum, updateUsableArea, NULL, NULL},
372 {"WorkspaceBorderSize", "0", NULL,
373 &wPreferences.workspace_border_size, getInt, updateUsableArea, NULL, NULL},
374 {"StickyIcons", "NO", NULL,
375 &wPreferences.sticky_icons, getBool, setStickyIcons, NULL, NULL},
376 {"SaveSessionOnExit", "NO", NULL,
377 &wPreferences.save_session_on_exit, getBool, NULL, NULL, NULL},
378 {"WrapMenus", "NO", NULL,
379 &wPreferences.wrap_menus, getBool, NULL, NULL, NULL},
380 {"ScrollableMenus", "NO", NULL,
381 &wPreferences.scrollable_menus, getBool, NULL, NULL, NULL},
382 {"MenuScrollSpeed", "medium", seSpeeds,
383 &wPreferences.menu_scroll_speed, getEnum, NULL, NULL, NULL},
384 {"IconSlideSpeed", "medium", seSpeeds,
385 &wPreferences.icon_slide_speed, getEnum, NULL, NULL, NULL},
386 {"ShadeSpeed", "medium", seSpeeds,
387 &wPreferences.shade_speed, getEnum, NULL, NULL, NULL},
388 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
389 &wPreferences.dblclick_time, getInt, setDoubleClick, NULL, NULL},
390 {"AlignSubmenus", "NO", NULL,
391 &wPreferences.align_menus, getBool, NULL, NULL, NULL},
392 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
393 &wPreferences.open_transients_with_parent, getBool, NULL, NULL, NULL},
394 {"WindowPlacement", "auto", sePlacements,
395 &wPreferences.window_placement, getEnum, NULL, NULL, NULL},
396 {"IgnoreFocusClick", "NO", NULL,
397 &wPreferences.ignore_focus_click, getBool, NULL, NULL, NULL},
398 {"UseSaveUnders", "NO", NULL,
399 &wPreferences.use_saveunders, getBool, NULL, NULL, NULL},
400 {"OpaqueMove", "NO", NULL,
401 &wPreferences.opaque_move, getBool, NULL, NULL, NULL},
402 {"DisableAnimations", "NO", NULL,
403 &wPreferences.no_animations, getBool, NULL, NULL, NULL},
404 {"DontLinkWorkspaces", "NO", NULL,
405 &wPreferences.no_autowrap, getBool, NULL, NULL, NULL},
406 {"AutoArrangeIcons", "NO", NULL,
407 &wPreferences.auto_arrange_icons, getBool, NULL, NULL, NULL},
408 {"NoWindowOverDock", "NO", NULL,
409 &wPreferences.no_window_over_dock, getBool, updateUsableArea, NULL, NULL},
410 {"NoWindowOverIcons", "NO", NULL,
411 &wPreferences.no_window_over_icons, getBool, updateUsableArea, NULL, NULL},
412 {"WindowPlaceOrigin", "(0, 0)", NULL,
413 &wPreferences.window_place_origin, getCoord, NULL, NULL, NULL},
414 {"ResizeDisplay", "corner", seGeomDisplays,
415 &wPreferences.size_display, getEnum, NULL, NULL, NULL},
416 {"MoveDisplay", "corner", seGeomDisplays,
417 &wPreferences.move_display, getEnum, NULL, NULL, NULL},
418 {"DontConfirmKill", "NO", NULL,
419 &wPreferences.dont_confirm_kill, getBool, NULL, NULL, NULL},
420 {"WindowTitleBalloons", "NO", NULL,
421 &wPreferences.window_balloon, getBool, NULL, NULL, NULL},
422 {"MiniwindowTitleBalloons", "NO", NULL,
423 &wPreferences.miniwin_balloon, getBool, NULL, NULL, NULL},
424 {"AppIconBalloons", "NO", NULL,
425 &wPreferences.appicon_balloon, getBool, NULL, NULL, NULL},
426 {"HelpBalloons", "NO", NULL,
427 &wPreferences.help_balloon, getBool, NULL, NULL, NULL},
428 {"EdgeResistance", "30", NULL,
429 &wPreferences.edge_resistance, getInt, NULL, NULL, NULL},
430 {"ResizeIncrement", "32", NULL,
431 &wPreferences.resize_increment, getInt, NULL, NULL, NULL},
432 {"Attraction", "NO", NULL,
433 &wPreferences.attract, getBool, NULL, NULL, NULL},
434 {"DisableBlinking", "NO", NULL,
435 &wPreferences.dont_blink, getBool, NULL, NULL, NULL},
436 {"SingleClickLaunch", "NO", NULL,
437 &wPreferences.single_click, getBool, NULL, NULL, NULL},
439 /* style options */
441 {"MenuStyle", "normal", seMenuStyles,
442 &wPreferences.menu_style, getEnum, setMenuStyle, NULL, NULL},
443 {"WidgetColor", "(solid, gray)", NULL,
444 NULL, getTexture, setWidgetColor, NULL, NULL},
445 {"WorkspaceSpecificBack", "()", NULL,
446 NULL, getWSSpecificBackground, setWorkspaceSpecificBack, NULL, NULL},
447 /* WorkspaceBack must come after WorkspaceSpecificBack or
448 * WorkspaceBack wont know WorkspaceSpecificBack was also
449 * specified and 2 copies of wmsetbg will be launched */
450 {"WorkspaceBack", "(solid, black)", NULL,
451 NULL, getWSBackground, setWorkspaceBack, NULL, NULL},
452 {"SmoothWorkspaceBack", "NO", NULL,
453 NULL, getBool, NULL, NULL, NULL},
454 {"IconBack", "(solid, gray)", NULL,
455 NULL, getTexture, setIconTile, NULL, NULL},
456 {"TitleJustify", "center", seJustifications,
457 &wPreferences.title_justification, getEnum, setJustify, NULL, NULL},
458 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
459 NULL, getFont, setWinTitleFont, NULL, NULL},
460 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
461 &wPreferences.window_title_clearance, getInt, setClearance, NULL, NULL},
462 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
463 &wPreferences.menu_title_clearance, getInt, setClearance, NULL, NULL},
464 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
465 &wPreferences.menu_text_clearance, getInt, setClearance, NULL, NULL},
466 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
467 NULL, getFont, setMenuTitleFont, NULL, NULL},
468 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
469 NULL, getFont, setMenuTextFont, NULL, NULL},
470 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
471 NULL, getFont, setIconTitleFont, NULL, NULL},
472 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
473 NULL, getFont, setClipTitleFont, NULL, NULL},
474 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
475 NULL, getFont, setLargeDisplayFont, NULL, NULL},
476 {"HighlightColor", "white", NULL,
477 NULL, getColor, setHightlight, NULL, NULL},
478 {"HighlightTextColor", "black", NULL,
479 NULL, getColor, setHightlightText, NULL, NULL},
480 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
481 NULL, getColor, setClipTitleColor, NULL, NULL},
482 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
483 NULL, getColor, setClipTitleColor, NULL, NULL},
484 {"FTitleColor", "white", (void *)WS_FOCUSED,
485 NULL, getColor, setWTitleColor, NULL, NULL},
486 {"PTitleColor", "white", (void *)WS_PFOCUSED,
487 NULL, getColor, setWTitleColor, NULL, NULL},
488 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
489 NULL, getColor, setWTitleColor, NULL, NULL},
490 {"FTitleBack", "(solid, black)", NULL,
491 NULL, getTexture, setFTitleBack, NULL, NULL},
492 {"PTitleBack", "(solid, \"#616161\")", NULL,
493 NULL, getTexture, setPTitleBack, NULL, NULL},
494 {"UTitleBack", "(solid, gray)", NULL,
495 NULL, getTexture, setUTitleBack, NULL, NULL},
496 {"ResizebarBack", "(solid, gray)", NULL,
497 NULL, getTexture, setResizebarBack, NULL, NULL},
498 {"MenuTitleColor", "white", NULL,
499 NULL, getColor, setMenuTitleColor, NULL, NULL},
500 {"MenuTextColor", "black", NULL,
501 NULL, getColor, setMenuTextColor, NULL, NULL},
502 {"MenuDisabledColor", "\"#616161\"", NULL,
503 NULL, getColor, setMenuDisabledColor, NULL, NULL},
504 {"MenuTitleBack", "(solid, black)", NULL,
505 NULL, getTexture, setMenuTitleBack, NULL, NULL},
506 {"MenuTextBack", "(solid, gray)", NULL,
507 NULL, getTexture, setMenuTextBack, NULL, NULL},
508 {"IconTitleColor", "white", NULL,
509 NULL, getColor, setIconTitleColor, NULL, NULL},
510 {"IconTitleBack", "black", NULL,
511 NULL, getColor, setIconTitleBack, NULL, NULL},
512 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
513 NULL, getPropList, setSwPOptions, NULL, NULL},
515 /* keybindings */
517 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
518 NULL, getKeybind, setKeyGrab, NULL, NULL},
519 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
520 NULL, getKeybind, setKeyGrab, NULL, NULL},
521 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
522 NULL, getKeybind, setKeyGrab, NULL, NULL},
523 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
524 NULL, getKeybind, setKeyGrab, NULL, NULL},
525 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
526 NULL, getKeybind, setKeyGrab, NULL, NULL},
527 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
528 NULL, getKeybind, setKeyGrab, NULL, NULL},
529 {"HideKey", "None", (void *)WKBD_HIDE,
530 NULL, getKeybind, setKeyGrab, NULL, NULL},
531 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
532 NULL, getKeybind, setKeyGrab, NULL, NULL},
533 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
534 NULL, getKeybind, setKeyGrab, NULL, NULL},
535 {"CloseKey", "None", (void *)WKBD_CLOSE,
536 NULL, getKeybind, setKeyGrab, NULL, NULL},
537 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
538 NULL, getKeybind, setKeyGrab, NULL, NULL},
539 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
540 NULL, getKeybind, setKeyGrab, NULL, NULL},
541 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
542 NULL, getKeybind, setKeyGrab, NULL, NULL},
543 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
544 NULL, getKeybind, setKeyGrab, NULL, NULL},
545 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
546 NULL, getKeybind, setKeyGrab, NULL, NULL},
547 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
548 NULL, getKeybind, setKeyGrab, NULL, NULL},
549 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
550 NULL, getKeybind, setKeyGrab, NULL, NULL},
551 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
552 NULL, getKeybind, setKeyGrab, NULL, NULL},
553 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
554 NULL, getKeybind, setKeyGrab, NULL, NULL},
555 {"ShadeKey", "None", (void *)WKBD_SHADE,
556 NULL, getKeybind, setKeyGrab, NULL, NULL},
557 {"SelectKey", "None", (void *)WKBD_SELECT,
558 NULL, getKeybind, setKeyGrab, NULL, NULL},
559 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
560 NULL, getKeybind, setKeyGrab, NULL, NULL},
561 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
562 NULL, getKeybind, setKeyGrab, NULL, NULL},
563 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
564 NULL, getKeybind, setKeyGrab, NULL, NULL},
565 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
566 NULL, getKeybind, setKeyGrab, NULL, NULL},
567 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
568 NULL, getKeybind, setKeyGrab, NULL, NULL},
569 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
570 NULL, getKeybind, setKeyGrab, NULL, NULL},
571 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
572 NULL, getKeybind, setKeyGrab, NULL, NULL},
573 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
574 NULL, getKeybind, setKeyGrab, NULL, NULL},
575 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
576 NULL, getKeybind, setKeyGrab, NULL, NULL},
577 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
578 NULL, getKeybind, setKeyGrab, NULL, NULL},
579 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
580 NULL, getKeybind, setKeyGrab, NULL, NULL},
581 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
582 NULL, getKeybind, setKeyGrab, NULL, NULL},
583 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
584 NULL, getKeybind, setKeyGrab, NULL, NULL},
585 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
586 NULL, getKeybind, setKeyGrab, NULL, NULL},
587 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
588 NULL, getKeybind, setKeyGrab, NULL, NULL},
589 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
590 NULL, getKeybind, setKeyGrab, NULL, NULL},
591 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
592 NULL, getKeybind, setKeyGrab, NULL, NULL},
593 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
594 NULL, getKeybind, setKeyGrab, NULL, NULL},
595 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
596 NULL, getKeybind, setKeyGrab, NULL, NULL},
597 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
598 NULL, getKeybind, setKeyGrab, NULL, NULL},
599 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
600 NULL, getKeybind, setKeyGrab, NULL, NULL},
601 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
602 NULL, getKeybind, setKeyGrab, NULL, NULL},
603 {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
604 NULL, getKeybind, setKeyGrab, NULL, NULL},
605 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
606 NULL, getKeybind, setKeyGrab, NULL, NULL},
607 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
608 NULL, getKeybind, setKeyGrab, NULL, NULL},
609 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
610 NULL, getKeybind, setKeyGrab, NULL, NULL},
611 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
612 NULL, getKeybind, setKeyGrab, NULL, NULL},
613 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
614 NULL, getKeybind, setKeyGrab, NULL, NULL},
615 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
616 NULL, getKeybind, setKeyGrab, NULL, NULL},
618 #ifdef KEEP_XKB_LOCK_STATUS
619 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
620 NULL, getKeybind, setKeyGrab, NULL, NULL},
621 {"KbdModeLock", "NO", NULL,
622 &wPreferences.modelock, getBool, NULL, NULL, NULL},
623 #endif /* KEEP_XKB_LOCK_STATUS */
625 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
626 NULL, getCursor, setCursor, NULL, NULL},
627 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
628 NULL, getCursor, setCursor, NULL, NULL},
629 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
630 NULL, getCursor, setCursor, NULL, NULL},
631 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
632 NULL, getCursor, setCursor, NULL, NULL},
633 {"TopLeftResizeCursor", "(builtin, top_left_corner)", (void *)WCUR_TOPLEFTRESIZE,
634 NULL, getCursor, setCursor, NULL, NULL},
635 {"TopRightResizeCursor", "(builtin, top_right_corner)", (void *)WCUR_TOPRIGHTRESIZE,
636 NULL, getCursor, setCursor, NULL, NULL},
637 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)", (void *)WCUR_BOTTOMLEFTRESIZE,
638 NULL, getCursor, setCursor, NULL, NULL},
639 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)", (void *)WCUR_BOTTOMRIGHTRESIZE,
640 NULL, getCursor, setCursor, NULL, NULL},
641 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)", (void *)WCUR_VERTICALRESIZE,
642 NULL, getCursor, setCursor, NULL, NULL},
643 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)", (void *)WCUR_HORIZONRESIZE,
644 NULL, getCursor, setCursor, NULL, NULL},
645 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
646 NULL, getCursor, setCursor, NULL, NULL},
647 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
648 NULL, getCursor, setCursor, NULL, NULL},
649 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
650 NULL, getCursor, setCursor, NULL, NULL},
651 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
652 NULL, getCursor, setCursor, NULL, NULL},
653 {"DialogHistoryLines", "500", NULL,
654 &wPreferences.history_lines, getInt, NULL, NULL, NULL},
655 {"CycleActiveHeadOnly", "NO", NULL,
656 &wPreferences.cycle_active_head_only, getBool, NULL, NULL, NULL}
659 static void initDefaults()
661 unsigned int i;
662 WDefaultEntry *entry;
664 WMPLSetCaseSensitive(False);
666 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
667 entry = &optionList[i];
669 entry->plkey = WMCreatePLString(entry->key);
670 if (entry->default_value)
671 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
672 else
673 entry->plvalue = NULL;
676 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
677 entry = &staticOptionList[i];
679 entry->plkey = WMCreatePLString(entry->key);
680 if (entry->default_value)
681 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
682 else
683 entry->plvalue = NULL;
687 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
689 WMPropList *globalDict = NULL;
690 char path[PATH_MAX];
691 struct stat stbuf;
693 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
694 if (stat(path, &stbuf) >= 0) {
695 globalDict = WMReadPropListFromFile(path);
696 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
697 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
698 WMReleasePropList(globalDict);
699 globalDict = NULL;
700 } else if (!globalDict) {
701 wwarning(_("could not load domain %s from global defaults database"), domainName);
705 return globalDict;
708 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
709 static void prependMenu(WMPropList * destarr, WMPropList * array)
711 WMPropList *item;
712 int i;
714 for (i = 0; i < WMGetPropListItemCount(array); i++) {
715 item = WMGetFromPLArray(array, i);
716 if (item)
717 WMInsertInPLArray(destarr, i + 1, item);
721 static void appendMenu(WMPropList * destarr, WMPropList * array)
723 WMPropList *item;
724 int i;
726 for (i = 0; i < WMGetPropListItemCount(array); i++) {
727 item = WMGetFromPLArray(array, i);
728 if (item)
729 WMAddToPLArray(destarr, item);
732 #endif
734 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
736 WMPropList *menu = menuDomain->dictionary;
737 WMPropList *submenu;
739 if (!menu || !WMIsPLArray(menu))
740 return;
742 #ifdef GLOBAL_PREAMBLE_MENU_FILE
743 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
745 if (submenu && !WMIsPLArray(submenu)) {
746 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
747 WMReleasePropList(submenu);
748 submenu = NULL;
750 if (submenu) {
751 prependMenu(menu, submenu);
752 WMReleasePropList(submenu);
754 #endif
756 #ifdef GLOBAL_EPILOGUE_MENU_FILE
757 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
759 if (submenu && !WMIsPLArray(submenu)) {
760 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
761 WMReleasePropList(submenu);
762 submenu = NULL;
764 if (submenu) {
765 appendMenu(menu, submenu);
766 WMReleasePropList(submenu);
768 #endif
770 menuDomain->dictionary = menu;
773 void wDefaultsDestroyDomain(WDDomain * domain)
775 if (domain->dictionary)
776 WMReleasePropList(domain->dictionary);
777 wfree(domain->path);
778 wfree(domain);
781 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
783 WDDomain *db;
784 struct stat stbuf;
785 static int inited = 0;
786 char path[PATH_MAX];
787 char *the_path;
788 WMPropList *shared_dict = NULL;
790 if (!inited) {
791 inited = 1;
792 initDefaults();
795 db = wmalloc(sizeof(WDDomain));
796 memset(db, 0, sizeof(WDDomain));
797 db->domain_name = domain;
798 db->path = wdefaultspathfordomain(domain);
799 the_path = db->path;
801 if (the_path && stat(the_path, &stbuf) >= 0) {
802 db->dictionary = WMReadPropListFromFile(the_path);
803 if (db->dictionary) {
804 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
805 WMReleasePropList(db->dictionary);
806 db->dictionary = NULL;
807 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
809 db->timestamp = stbuf.st_mtime;
810 } else {
811 wwarning(_("could not load domain %s from user defaults database"), domain);
815 /* global system dictionary */
816 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
817 if (stat(path, &stbuf) >= 0) {
818 shared_dict = WMReadPropListFromFile(path);
819 if (shared_dict) {
820 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
821 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
822 domain, path);
823 WMReleasePropList(shared_dict);
824 shared_dict = NULL;
825 } else {
826 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
827 WMIsPLDictionary(db->dictionary)) {
828 WMMergePLDictionaries(shared_dict, db->dictionary, True);
829 WMReleasePropList(db->dictionary);
830 db->dictionary = shared_dict;
831 if (stbuf.st_mtime > db->timestamp)
832 db->timestamp = stbuf.st_mtime;
833 } else if (!db->dictionary) {
834 db->dictionary = shared_dict;
835 if (stbuf.st_mtime > db->timestamp)
836 db->timestamp = stbuf.st_mtime;
839 } else {
840 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
844 return db;
847 void wReadStaticDefaults(WMPropList * dict)
849 WMPropList *plvalue;
850 WDefaultEntry *entry;
851 unsigned int i;
852 void *tdata;
854 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
855 entry = &staticOptionList[i];
857 if (dict)
858 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
859 else
860 plvalue = NULL;
862 if (!plvalue) {
863 /* no default in the DB. Use builtin default */
864 plvalue = entry->plvalue;
867 if (plvalue) {
868 /* convert data */
869 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
870 if (entry->update) {
871 (*entry->update) (NULL, entry, tdata, entry->extra_data);
877 void wDefaultsCheckDomains(void* arg)
879 WScreen *scr;
880 struct stat stbuf;
881 WMPropList *shared_dict = NULL;
882 WMPropList *dict;
883 int i;
885 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
886 WDWindowMaker->timestamp = stbuf.st_mtime;
888 /* global dictionary */
889 shared_dict = readGlobalDomain("WindowMaker", True);
890 /* user dictionary */
891 dict = WMReadPropListFromFile(WDWindowMaker->path);
892 if (dict) {
893 if (!WMIsPLDictionary(dict)) {
894 WMReleasePropList(dict);
895 dict = NULL;
896 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
897 "WindowMaker", WDWindowMaker->path);
898 } else {
899 if (shared_dict) {
900 WMMergePLDictionaries(shared_dict, dict, True);
901 WMReleasePropList(dict);
902 dict = shared_dict;
903 shared_dict = NULL;
905 for (i = 0; i < wScreenCount; i++) {
906 scr = wScreenWithNumber(i);
907 if (scr)
908 wReadDefaults(scr, dict);
910 if (WDWindowMaker->dictionary) {
911 WMReleasePropList(WDWindowMaker->dictionary);
913 WDWindowMaker->dictionary = dict;
915 } else {
916 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
918 if (shared_dict) {
919 WMReleasePropList(shared_dict);
923 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
924 /* global dictionary */
925 shared_dict = readGlobalDomain("WMWindowAttributes", True);
926 /* user dictionary */
927 dict = WMReadPropListFromFile(WDWindowAttributes->path);
928 if (dict) {
929 if (!WMIsPLDictionary(dict)) {
930 WMReleasePropList(dict);
931 dict = NULL;
932 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
933 "WMWindowAttributes", WDWindowAttributes->path);
934 } else {
935 if (shared_dict) {
936 WMMergePLDictionaries(shared_dict, dict, True);
937 WMReleasePropList(dict);
938 dict = shared_dict;
939 shared_dict = NULL;
941 if (WDWindowAttributes->dictionary) {
942 WMReleasePropList(WDWindowAttributes->dictionary);
944 WDWindowAttributes->dictionary = dict;
945 for (i = 0; i < wScreenCount; i++) {
946 scr = wScreenWithNumber(i);
947 if (scr) {
948 RImage *image;
950 wDefaultUpdateIcons(scr);
952 /* Update the panel image if changed */
953 /* Don't worry. If the image is the same these
954 * functions will have no performance impact. */
955 image = wDefaultGetImage(scr, "Logo", "WMPanel");
957 if (!image) {
958 wwarning(_("could not load logo image for panels: %s"),
959 RMessageForError(RErrorCode));
960 } else {
961 WMSetApplicationIconImage(scr->wmscreen, image);
962 RReleaseImage(image);
967 } else {
968 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
970 WDWindowAttributes->timestamp = stbuf.st_mtime;
971 if (shared_dict) {
972 WMReleasePropList(shared_dict);
976 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
977 dict = WMReadPropListFromFile(WDRootMenu->path);
978 if (dict) {
979 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
980 WMReleasePropList(dict);
981 dict = NULL;
982 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
983 "WMRootMenu", WDRootMenu->path);
984 } else {
985 if (WDRootMenu->dictionary) {
986 WMReleasePropList(WDRootMenu->dictionary);
988 WDRootMenu->dictionary = dict;
989 wDefaultsMergeGlobalMenus(WDRootMenu);
991 } else {
992 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
994 WDRootMenu->timestamp = stbuf.st_mtime;
996 #ifndef HAVE_INOTIFY
997 if (!arg)
998 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
999 #endif
1002 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1004 WMPropList *plvalue, *old_value;
1005 WDefaultEntry *entry;
1006 unsigned int i, must_update;
1007 int update_workspace_back = 0; /* kluge :/ */
1008 unsigned int needs_refresh;
1009 void *tdata;
1010 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1012 must_update = 0;
1014 needs_refresh = 0;
1016 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1017 entry = &optionList[i];
1019 if (new_dict)
1020 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1021 else
1022 plvalue = NULL;
1024 if (!old_dict)
1025 old_value = NULL;
1026 else
1027 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1029 if (!plvalue && !old_value) {
1030 /* no default in the DB. Use builtin default */
1031 plvalue = entry->plvalue;
1032 if (plvalue && new_dict) {
1033 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1034 must_update = 1;
1036 } else if (!plvalue) {
1037 /* value was deleted from DB. Keep current value */
1038 continue;
1039 } else if (!old_value) {
1040 /* set value for the 1st time */
1041 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1042 /* value has changed */
1043 } else {
1045 if (strcmp(entry->key, "WorkspaceBack") == 0
1046 && update_workspace_back && scr->flags.backimage_helper_launched) {
1047 } else {
1048 /* value was not changed since last time */
1049 continue;
1053 if (plvalue) {
1054 /* convert data */
1055 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1057 * If the WorkspaceSpecificBack data has been changed
1058 * so that the helper will be launched now, we must be
1059 * sure to send the default background texture config
1060 * to the helper.
1062 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1063 && !scr->flags.backimage_helper_launched) {
1064 update_workspace_back = 1;
1066 if (entry->update) {
1067 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1073 if (needs_refresh != 0 && !scr->flags.startup) {
1074 int foo;
1076 foo = 0;
1077 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1078 foo |= WTextureSettings;
1079 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1080 foo |= WFontSettings;
1081 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1082 foo |= WColorSettings;
1083 if (foo)
1084 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1085 (void *)(uintptr_t) foo);
1087 foo = 0;
1088 if (needs_refresh & REFRESH_MENU_TEXTURE)
1089 foo |= WTextureSettings;
1090 if (needs_refresh & REFRESH_MENU_FONT)
1091 foo |= WFontSettings;
1092 if (needs_refresh & REFRESH_MENU_COLOR)
1093 foo |= WColorSettings;
1094 if (foo)
1095 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1097 foo = 0;
1098 if (needs_refresh & REFRESH_WINDOW_FONT) {
1099 foo |= WFontSettings;
1101 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1102 foo |= WTextureSettings;
1104 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1105 foo |= WColorSettings;
1107 if (foo)
1108 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1110 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1111 foo = 0;
1112 if (needs_refresh & REFRESH_ICON_FONT) {
1113 foo |= WFontSettings;
1115 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1116 foo |= WTextureSettings;
1118 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1119 foo |= WTextureSettings;
1121 if (foo)
1122 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1123 (void *)(uintptr_t) foo);
1125 if (needs_refresh & REFRESH_ICON_TILE)
1126 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1130 void wDefaultUpdateIcons(WScreen * scr)
1132 WAppIcon *aicon = scr->app_icon_list;
1133 WWindow *wwin = scr->focused_window;
1134 char *file;
1136 while (aicon) {
1137 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1138 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1139 || (file && !aicon->icon->file)) {
1140 RImage *new_image;
1142 if (aicon->icon->file)
1143 wfree(aicon->icon->file);
1144 aicon->icon->file = wstrdup(file);
1146 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1147 if (new_image) {
1148 wIconChangeImage(aicon->icon, new_image);
1149 wAppIconPaint(aicon);
1152 aicon = aicon->next;
1155 if (!wPreferences.flags.noclip)
1156 wClipIconPaint(scr->clip_icon);
1158 while (wwin) {
1159 if (wwin->icon && wwin->flags.miniaturized) {
1160 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1161 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1162 || (file && !wwin->icon->file)) {
1163 RImage *new_image;
1165 if (wwin->icon->file)
1166 wfree(wwin->icon->file);
1167 wwin->icon->file = wstrdup(file);
1169 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1170 if (new_image)
1171 wIconChangeImage(wwin->icon, new_image);
1174 wwin = wwin->prev;
1178 /* --------------------------- Local ----------------------- */
1180 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1181 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1182 entry->key, x); \
1183 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1184 var = entry->default_value;\
1185 } else var = WMGetFromPLString(value)\
1188 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1190 char *str;
1191 WOptionEnumeration *v;
1192 char buffer[TOTAL_VALUES_LENGTH];
1194 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1195 for (v = values; v->string != NULL; v++) {
1196 if (strcasecmp(v->string, str) == 0)
1197 return v->value;
1201 buffer[0] = 0;
1202 for (v = values; v->string != NULL; v++) {
1203 if (!v->is_alias) {
1204 if (buffer[0] != 0)
1205 strcat(buffer, ", ");
1206 strcat(buffer, v->string);
1209 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1211 if (def) {
1212 return string2index(key, val, NULL, values);
1215 return -1;
1219 * value - is the value in the defaults DB
1220 * addr - is the address to store the data
1221 * ret - is the address to store a pointer to a temporary buffer. ret
1222 * must not be freed and is used by the set functions
1224 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1226 static char data;
1227 char *val;
1228 int second_pass = 0;
1230 GET_STRING_OR_DEFAULT("Boolean", val);
1232 again:
1233 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1234 || strcasecmp(val, "YES") == 0) {
1236 data = 1;
1237 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1238 || strcasecmp(val, "NO") == 0) {
1239 data = 0;
1240 } else {
1241 int i;
1242 if (sscanf(val, "%i", &i) == 1) {
1243 if (i != 0)
1244 data = 1;
1245 else
1246 data = 0;
1247 } else {
1248 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1249 if (second_pass == 0) {
1250 val = WMGetFromPLString(entry->plvalue);
1251 second_pass = 1;
1252 wwarning(_("using default \"%s\" instead"), val);
1253 goto again;
1255 return False;
1259 if (ret)
1260 *ret = &data;
1261 if (addr)
1262 *(char *)addr = data;
1264 return True;
1267 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1269 static int data;
1270 char *val;
1272 GET_STRING_OR_DEFAULT("Integer", val);
1274 if (sscanf(val, "%i", &data) != 1) {
1275 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1276 val = WMGetFromPLString(entry->plvalue);
1277 wwarning(_("using default \"%s\" instead"), val);
1278 if (sscanf(val, "%i", &data) != 1) {
1279 return False;
1283 if (ret)
1284 *ret = &data;
1285 if (addr)
1286 *(int *)addr = data;
1288 return True;
1291 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1293 static WCoord data;
1294 char *val_x, *val_y;
1295 int nelem, changed = 0;
1296 WMPropList *elem_x, *elem_y;
1298 again:
1299 if (!WMIsPLArray(value)) {
1300 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1301 if (changed == 0) {
1302 value = entry->plvalue;
1303 changed = 1;
1304 wwarning(_("using default \"%s\" instead"), entry->default_value);
1305 goto again;
1307 return False;
1310 nelem = WMGetPropListItemCount(value);
1311 if (nelem != 2) {
1312 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1313 if (changed == 0) {
1314 value = entry->plvalue;
1315 changed = 1;
1316 wwarning(_("using default \"%s\" instead"), entry->default_value);
1317 goto again;
1319 return False;
1322 elem_x = WMGetFromPLArray(value, 0);
1323 elem_y = WMGetFromPLArray(value, 1);
1325 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1326 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1327 if (changed == 0) {
1328 value = entry->plvalue;
1329 changed = 1;
1330 wwarning(_("using default \"%s\" instead"), entry->default_value);
1331 goto again;
1333 return False;
1336 val_x = WMGetFromPLString(elem_x);
1337 val_y = WMGetFromPLString(elem_y);
1339 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1340 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1341 if (changed == 0) {
1342 value = entry->plvalue;
1343 changed = 1;
1344 wwarning(_("using default \"%s\" instead"), entry->default_value);
1345 goto again;
1347 return False;
1350 if (data.x < 0)
1351 data.x = 0;
1352 else if (data.x > scr->scr_width / 3)
1353 data.x = scr->scr_width / 3;
1354 if (data.y < 0)
1355 data.y = 0;
1356 else if (data.y > scr->scr_height / 3)
1357 data.y = scr->scr_height / 3;
1359 if (ret)
1360 *ret = &data;
1361 if (addr)
1362 *(WCoord *) addr = data;
1364 return True;
1367 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1369 WMRetainPropList(value);
1371 *ret = value;
1373 return True;
1376 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1378 static char *data;
1379 int i, count, len;
1380 char *ptr;
1381 WMPropList *d;
1382 int changed = 0;
1384 again:
1385 if (!WMIsPLArray(value)) {
1386 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1387 if (changed == 0) {
1388 value = entry->plvalue;
1389 changed = 1;
1390 wwarning(_("using default \"%s\" instead"), entry->default_value);
1391 goto again;
1393 return False;
1396 i = 0;
1397 count = WMGetPropListItemCount(value);
1398 if (count < 1) {
1399 if (changed == 0) {
1400 value = entry->plvalue;
1401 changed = 1;
1402 wwarning(_("using default \"%s\" instead"), entry->default_value);
1403 goto again;
1405 return False;
1408 len = 0;
1409 for (i = 0; i < count; i++) {
1410 d = WMGetFromPLArray(value, i);
1411 if (!d || !WMIsPLString(d)) {
1412 count = i;
1413 break;
1415 len += strlen(WMGetFromPLString(d)) + 1;
1418 ptr = data = wmalloc(len + 1);
1420 for (i = 0; i < count; i++) {
1421 d = WMGetFromPLArray(value, i);
1422 if (!d || !WMIsPLString(d)) {
1423 break;
1425 strcpy(ptr, WMGetFromPLString(d));
1426 ptr += strlen(WMGetFromPLString(d));
1427 *ptr = ':';
1428 ptr++;
1430 ptr--;
1431 *(ptr--) = 0;
1433 if (*(char **)addr != NULL) {
1434 wfree(*(char **)addr);
1436 *(char **)addr = data;
1438 return True;
1441 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1443 static signed char data;
1445 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1446 if (data < 0)
1447 return False;
1449 if (ret)
1450 *ret = &data;
1451 if (addr)
1452 *(signed char *)addr = data;
1454 return True;
1458 * (solid <color>)
1459 * (hgradient <color> <color>)
1460 * (vgradient <color> <color>)
1461 * (dgradient <color> <color>)
1462 * (mhgradient <color> <color> ...)
1463 * (mvgradient <color> <color> ...)
1464 * (mdgradient <color> <color> ...)
1465 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1466 * (tpixmap <file> <color>)
1467 * (spixmap <file> <color>)
1468 * (cpixmap <file> <color>)
1469 * (thgradient <file> <opaqueness> <color> <color>)
1470 * (tvgradient <file> <opaqueness> <color> <color>)
1471 * (tdgradient <file> <opaqueness> <color> <color>)
1472 * (function <lib> <function> ...)
1475 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1477 WMPropList *elem;
1478 char *val;
1479 int nelem;
1480 WTexture *texture = NULL;
1482 nelem = WMGetPropListItemCount(pl);
1483 if (nelem < 1)
1484 return NULL;
1486 elem = WMGetFromPLArray(pl, 0);
1487 if (!elem || !WMIsPLString(elem))
1488 return NULL;
1489 val = WMGetFromPLString(elem);
1491 if (strcasecmp(val, "solid") == 0) {
1492 XColor color;
1494 if (nelem != 2)
1495 return NULL;
1497 /* get color */
1499 elem = WMGetFromPLArray(pl, 1);
1500 if (!elem || !WMIsPLString(elem))
1501 return NULL;
1502 val = WMGetFromPLString(elem);
1504 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1505 wwarning(_("\"%s\" is not a valid color name"), val);
1506 return NULL;
1509 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1510 } else if (strcasecmp(val, "dgradient") == 0
1511 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1512 RColor color1, color2;
1513 XColor xcolor;
1514 int type;
1516 if (nelem != 3) {
1517 wwarning(_("bad number of arguments in gradient specification"));
1518 return NULL;
1521 if (val[0] == 'd' || val[0] == 'D')
1522 type = WTEX_DGRADIENT;
1523 else if (val[0] == 'h' || val[0] == 'H')
1524 type = WTEX_HGRADIENT;
1525 else
1526 type = WTEX_VGRADIENT;
1528 /* get from color */
1529 elem = WMGetFromPLArray(pl, 1);
1530 if (!elem || !WMIsPLString(elem))
1531 return NULL;
1532 val = WMGetFromPLString(elem);
1534 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1535 wwarning(_("\"%s\" is not a valid color name"), val);
1536 return NULL;
1538 color1.alpha = 255;
1539 color1.red = xcolor.red >> 8;
1540 color1.green = xcolor.green >> 8;
1541 color1.blue = xcolor.blue >> 8;
1543 /* get to color */
1544 elem = WMGetFromPLArray(pl, 2);
1545 if (!elem || !WMIsPLString(elem)) {
1546 return NULL;
1548 val = WMGetFromPLString(elem);
1550 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1551 wwarning(_("\"%s\" is not a valid color name"), val);
1552 return NULL;
1554 color2.alpha = 255;
1555 color2.red = xcolor.red >> 8;
1556 color2.green = xcolor.green >> 8;
1557 color2.blue = xcolor.blue >> 8;
1559 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1561 } else if (strcasecmp(val, "igradient") == 0) {
1562 RColor colors1[2], colors2[2];
1563 int th1, th2;
1564 XColor xcolor;
1565 int i;
1567 if (nelem != 7) {
1568 wwarning(_("bad number of arguments in gradient specification"));
1569 return NULL;
1572 /* get from color */
1573 for (i = 0; i < 2; i++) {
1574 elem = WMGetFromPLArray(pl, 1 + i);
1575 if (!elem || !WMIsPLString(elem))
1576 return NULL;
1577 val = WMGetFromPLString(elem);
1579 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1580 wwarning(_("\"%s\" is not a valid color name"), val);
1581 return NULL;
1583 colors1[i].alpha = 255;
1584 colors1[i].red = xcolor.red >> 8;
1585 colors1[i].green = xcolor.green >> 8;
1586 colors1[i].blue = xcolor.blue >> 8;
1588 elem = WMGetFromPLArray(pl, 3);
1589 if (!elem || !WMIsPLString(elem))
1590 return NULL;
1591 val = WMGetFromPLString(elem);
1592 th1 = atoi(val);
1594 /* get from color */
1595 for (i = 0; i < 2; i++) {
1596 elem = WMGetFromPLArray(pl, 4 + i);
1597 if (!elem || !WMIsPLString(elem))
1598 return NULL;
1599 val = WMGetFromPLString(elem);
1601 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1602 wwarning(_("\"%s\" is not a valid color name"), val);
1603 return NULL;
1605 colors2[i].alpha = 255;
1606 colors2[i].red = xcolor.red >> 8;
1607 colors2[i].green = xcolor.green >> 8;
1608 colors2[i].blue = xcolor.blue >> 8;
1610 elem = WMGetFromPLArray(pl, 6);
1611 if (!elem || !WMIsPLString(elem))
1612 return NULL;
1613 val = WMGetFromPLString(elem);
1614 th2 = atoi(val);
1616 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1618 } else if (strcasecmp(val, "mhgradient") == 0
1619 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1620 XColor color;
1621 RColor **colors;
1622 int i, count;
1623 int type;
1625 if (nelem < 3) {
1626 wwarning(_("too few arguments in multicolor gradient specification"));
1627 return NULL;
1630 if (val[1] == 'h' || val[1] == 'H')
1631 type = WTEX_MHGRADIENT;
1632 else if (val[1] == 'v' || val[1] == 'V')
1633 type = WTEX_MVGRADIENT;
1634 else
1635 type = WTEX_MDGRADIENT;
1637 count = nelem - 1;
1639 colors = wmalloc(sizeof(RColor *) * (count + 1));
1641 for (i = 0; i < count; i++) {
1642 elem = WMGetFromPLArray(pl, i + 1);
1643 if (!elem || !WMIsPLString(elem)) {
1644 for (--i; i >= 0; --i) {
1645 wfree(colors[i]);
1647 wfree(colors);
1648 return NULL;
1650 val = WMGetFromPLString(elem);
1652 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1653 wwarning(_("\"%s\" is not a valid color name"), val);
1654 for (--i; i >= 0; --i) {
1655 wfree(colors[i]);
1657 wfree(colors);
1658 return NULL;
1659 } else {
1660 colors[i] = wmalloc(sizeof(RColor));
1661 colors[i]->red = color.red >> 8;
1662 colors[i]->green = color.green >> 8;
1663 colors[i]->blue = color.blue >> 8;
1666 colors[i] = NULL;
1668 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1669 } else if (strcasecmp(val, "spixmap") == 0 ||
1670 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1671 XColor color;
1672 int type;
1674 if (nelem != 3)
1675 return NULL;
1677 if (val[0] == 's' || val[0] == 'S')
1678 type = WTP_SCALE;
1679 else if (val[0] == 'c' || val[0] == 'C')
1680 type = WTP_CENTER;
1681 else
1682 type = WTP_TILE;
1684 /* get color */
1685 elem = WMGetFromPLArray(pl, 2);
1686 if (!elem || !WMIsPLString(elem)) {
1687 return NULL;
1689 val = WMGetFromPLString(elem);
1691 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1692 wwarning(_("\"%s\" is not a valid color name"), val);
1693 return NULL;
1696 /* file name */
1697 elem = WMGetFromPLArray(pl, 1);
1698 if (!elem || !WMIsPLString(elem))
1699 return NULL;
1700 val = WMGetFromPLString(elem);
1702 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1703 } else if (strcasecmp(val, "thgradient") == 0
1704 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1705 RColor color1, color2;
1706 XColor xcolor;
1707 int opacity;
1708 int style;
1710 if (val[1] == 'h' || val[1] == 'H')
1711 style = WTEX_THGRADIENT;
1712 else if (val[1] == 'v' || val[1] == 'V')
1713 style = WTEX_TVGRADIENT;
1714 else
1715 style = WTEX_TDGRADIENT;
1717 if (nelem != 5) {
1718 wwarning(_("bad number of arguments in textured gradient specification"));
1719 return NULL;
1722 /* get from color */
1723 elem = WMGetFromPLArray(pl, 3);
1724 if (!elem || !WMIsPLString(elem))
1725 return NULL;
1726 val = WMGetFromPLString(elem);
1728 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1729 wwarning(_("\"%s\" is not a valid color name"), val);
1730 return NULL;
1732 color1.alpha = 255;
1733 color1.red = xcolor.red >> 8;
1734 color1.green = xcolor.green >> 8;
1735 color1.blue = xcolor.blue >> 8;
1737 /* get to color */
1738 elem = WMGetFromPLArray(pl, 4);
1739 if (!elem || !WMIsPLString(elem)) {
1740 return NULL;
1742 val = WMGetFromPLString(elem);
1744 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1745 wwarning(_("\"%s\" is not a valid color name"), val);
1746 return NULL;
1748 color2.alpha = 255;
1749 color2.red = xcolor.red >> 8;
1750 color2.green = xcolor.green >> 8;
1751 color2.blue = xcolor.blue >> 8;
1753 /* get opacity */
1754 elem = WMGetFromPLArray(pl, 2);
1755 if (!elem || !WMIsPLString(elem))
1756 opacity = 128;
1757 else
1758 val = WMGetFromPLString(elem);
1760 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1761 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1762 opacity = 128;
1765 /* get file name */
1766 elem = WMGetFromPLArray(pl, 1);
1767 if (!elem || !WMIsPLString(elem))
1768 return NULL;
1769 val = WMGetFromPLString(elem);
1771 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1772 } else if (strcasecmp(val, "function") == 0) {
1773 /* Leave this in to handle the unlikely case of
1774 * someone actually having function textures configured */
1775 wwarning("function texture support has been removed");
1776 return NULL;
1777 } else {
1778 wwarning(_("invalid texture type %s"), val);
1779 return NULL;
1781 return texture;
1784 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1786 static WTexture *texture;
1787 int changed = 0;
1789 again:
1790 if (!WMIsPLArray(value)) {
1791 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1792 if (changed == 0) {
1793 value = entry->plvalue;
1794 changed = 1;
1795 wwarning(_("using default \"%s\" instead"), entry->default_value);
1796 goto again;
1798 return False;
1801 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1802 WMPropList *pl;
1804 pl = WMGetFromPLArray(value, 0);
1805 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1806 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1807 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1808 entry->key, "Solid Texture");
1810 value = entry->plvalue;
1811 changed = 1;
1812 wwarning(_("using default \"%s\" instead"), entry->default_value);
1813 goto again;
1817 texture = parse_texture(scr, value);
1819 if (!texture) {
1820 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1821 if (changed == 0) {
1822 value = entry->plvalue;
1823 changed = 1;
1824 wwarning(_("using default \"%s\" instead"), entry->default_value);
1825 goto again;
1827 return False;
1830 if (ret)
1831 *ret = &texture;
1833 if (addr)
1834 *(WTexture **) addr = texture;
1836 return True;
1839 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1841 WMPropList *elem;
1842 int changed = 0;
1843 char *val;
1844 int nelem;
1846 again:
1847 if (!WMIsPLArray(value)) {
1848 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1849 "WorkspaceBack", "Texture or None");
1850 if (changed == 0) {
1851 value = entry->plvalue;
1852 changed = 1;
1853 wwarning(_("using default \"%s\" instead"), entry->default_value);
1854 goto again;
1856 return False;
1859 /* only do basic error checking and verify for None texture */
1861 nelem = WMGetPropListItemCount(value);
1862 if (nelem > 0) {
1863 elem = WMGetFromPLArray(value, 0);
1864 if (!elem || !WMIsPLString(elem)) {
1865 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1866 if (changed == 0) {
1867 value = entry->plvalue;
1868 changed = 1;
1869 wwarning(_("using default \"%s\" instead"), entry->default_value);
1870 goto again;
1872 return False;
1874 val = WMGetFromPLString(elem);
1876 if (strcasecmp(val, "None") == 0)
1877 return True;
1879 *ret = WMRetainPropList(value);
1881 return True;
1884 static int
1885 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1887 WMPropList *elem;
1888 int nelem;
1889 int changed = 0;
1891 again:
1892 if (!WMIsPLArray(value)) {
1893 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1894 "WorkspaceSpecificBack", "an array of textures");
1895 if (changed == 0) {
1896 value = entry->plvalue;
1897 changed = 1;
1898 wwarning(_("using default \"%s\" instead"), entry->default_value);
1899 goto again;
1901 return False;
1904 /* only do basic error checking and verify for None texture */
1906 nelem = WMGetPropListItemCount(value);
1907 if (nelem > 0) {
1908 while (nelem--) {
1909 elem = WMGetFromPLArray(value, nelem);
1910 if (!elem || !WMIsPLArray(elem)) {
1911 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1912 nelem);
1917 *ret = WMRetainPropList(value);
1919 #ifdef notworking
1921 * Kluge to force wmsetbg helper to set the default background.
1922 * If the WorkspaceSpecificBack is changed once wmaker has started,
1923 * the WorkspaceBack won't be sent to the helper, unless the user
1924 * changes it's value too. So, we must force this by removing the
1925 * value from the defaults DB.
1927 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1928 WMPropList *key = WMCreatePLString("WorkspaceBack");
1930 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1932 WMReleasePropList(key);
1934 #endif
1935 return True;
1938 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1940 static WMFont *font;
1941 char *val;
1943 GET_STRING_OR_DEFAULT("Font", val);
1945 font = WMCreateFont(scr->wmscreen, val);
1946 if (!font)
1947 font = WMCreateFont(scr->wmscreen, "fixed");
1949 if (!font) {
1950 wfatal(_("could not load any usable font!!!"));
1951 exit(1);
1954 if (ret)
1955 *ret = font;
1957 /* can't assign font value outside update function */
1958 wassertrv(addr == NULL, True);
1960 return True;
1963 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1965 static XColor color;
1966 char *val;
1967 int second_pass = 0;
1969 GET_STRING_OR_DEFAULT("Color", val);
1971 again:
1972 if (!wGetColor(scr, val, &color)) {
1973 wwarning(_("could not get color for key \"%s\""), entry->key);
1974 if (second_pass == 0) {
1975 val = WMGetFromPLString(entry->plvalue);
1976 second_pass = 1;
1977 wwarning(_("using default \"%s\" instead"), val);
1978 goto again;
1980 return False;
1983 if (ret)
1984 *ret = &color;
1986 assert(addr == NULL);
1988 if (addr)
1989 *(unsigned long*)addr = pixel;
1992 return True;
1995 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1997 static WShortKey shortcut;
1998 KeySym ksym;
1999 char *val;
2000 char *k;
2001 char buf[MAX_SHORTCUT_LENGTH], *b;
2003 GET_STRING_OR_DEFAULT("Key spec", val);
2005 if (!val || strcasecmp(val, "NONE") == 0) {
2006 shortcut.keycode = 0;
2007 shortcut.modifier = 0;
2008 if (ret)
2009 *ret = &shortcut;
2010 return True;
2013 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2015 b = (char *)buf;
2017 /* get modifiers */
2018 shortcut.modifier = 0;
2019 while ((k = strchr(b, '+')) != NULL) {
2020 int mod;
2022 *k = 0;
2023 mod = wXModifierFromKey(b);
2024 if (mod < 0) {
2025 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2026 return False;
2028 shortcut.modifier |= mod;
2030 b = k + 1;
2033 /* get key */
2034 ksym = XStringToKeysym(b);
2036 if (ksym == NoSymbol) {
2037 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2038 return False;
2041 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2042 if (shortcut.keycode == 0) {
2043 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2044 return False;
2047 if (ret)
2048 *ret = &shortcut;
2050 return True;
2053 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2055 static int mask;
2056 char *str;
2058 GET_STRING_OR_DEFAULT("Modifier Key", str);
2060 if (!str)
2061 return False;
2063 mask = wXModifierFromKey(str);
2064 if (mask < 0) {
2065 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2066 mask = 0;
2067 return False;
2070 if (addr)
2071 *(int *)addr = mask;
2073 if (ret)
2074 *ret = &mask;
2076 return True;
2079 # include <X11/cursorfont.h>
2080 typedef struct {
2081 char *name;
2082 int id;
2083 } WCursorLookup;
2085 #define CURSOR_ID_NONE (XC_num_glyphs)
2087 static WCursorLookup cursor_table[] = {
2088 {"X_cursor", XC_X_cursor},
2089 {"arrow", XC_arrow},
2090 {"based_arrow_down", XC_based_arrow_down},
2091 {"based_arrow_up", XC_based_arrow_up},
2092 {"boat", XC_boat},
2093 {"bogosity", XC_bogosity},
2094 {"bottom_left_corner", XC_bottom_left_corner},
2095 {"bottom_right_corner", XC_bottom_right_corner},
2096 {"bottom_side", XC_bottom_side},
2097 {"bottom_tee", XC_bottom_tee},
2098 {"box_spiral", XC_box_spiral},
2099 {"center_ptr", XC_center_ptr},
2100 {"circle", XC_circle},
2101 {"clock", XC_clock},
2102 {"coffee_mug", XC_coffee_mug},
2103 {"cross", XC_cross},
2104 {"cross_reverse", XC_cross_reverse},
2105 {"crosshair", XC_crosshair},
2106 {"diamond_cross", XC_diamond_cross},
2107 {"dot", XC_dot},
2108 {"dotbox", XC_dotbox},
2109 {"double_arrow", XC_double_arrow},
2110 {"draft_large", XC_draft_large},
2111 {"draft_small", XC_draft_small},
2112 {"draped_box", XC_draped_box},
2113 {"exchange", XC_exchange},
2114 {"fleur", XC_fleur},
2115 {"gobbler", XC_gobbler},
2116 {"gumby", XC_gumby},
2117 {"hand1", XC_hand1},
2118 {"hand2", XC_hand2},
2119 {"heart", XC_heart},
2120 {"icon", XC_icon},
2121 {"iron_cross", XC_iron_cross},
2122 {"left_ptr", XC_left_ptr},
2123 {"left_side", XC_left_side},
2124 {"left_tee", XC_left_tee},
2125 {"leftbutton", XC_leftbutton},
2126 {"ll_angle", XC_ll_angle},
2127 {"lr_angle", XC_lr_angle},
2128 {"man", XC_man},
2129 {"middlebutton", XC_middlebutton},
2130 {"mouse", XC_mouse},
2131 {"pencil", XC_pencil},
2132 {"pirate", XC_pirate},
2133 {"plus", XC_plus},
2134 {"question_arrow", XC_question_arrow},
2135 {"right_ptr", XC_right_ptr},
2136 {"right_side", XC_right_side},
2137 {"right_tee", XC_right_tee},
2138 {"rightbutton", XC_rightbutton},
2139 {"rtl_logo", XC_rtl_logo},
2140 {"sailboat", XC_sailboat},
2141 {"sb_down_arrow", XC_sb_down_arrow},
2142 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2143 {"sb_left_arrow", XC_sb_left_arrow},
2144 {"sb_right_arrow", XC_sb_right_arrow},
2145 {"sb_up_arrow", XC_sb_up_arrow},
2146 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2147 {"shuttle", XC_shuttle},
2148 {"sizing", XC_sizing},
2149 {"spider", XC_spider},
2150 {"spraycan", XC_spraycan},
2151 {"star", XC_star},
2152 {"target", XC_target},
2153 {"tcross", XC_tcross},
2154 {"top_left_arrow", XC_top_left_arrow},
2155 {"top_left_corner", XC_top_left_corner},
2156 {"top_right_corner", XC_top_right_corner},
2157 {"top_side", XC_top_side},
2158 {"top_tee", XC_top_tee},
2159 {"trek", XC_trek},
2160 {"ul_angle", XC_ul_angle},
2161 {"umbrella", XC_umbrella},
2162 {"ur_angle", XC_ur_angle},
2163 {"watch", XC_watch},
2164 {"xterm", XC_xterm},
2165 {NULL, CURSOR_ID_NONE}
2168 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2170 switch (status) {
2171 case BitmapOpenFailed:
2172 wwarning(_("failed to open bitmap file \"%s\""), filename);
2173 break;
2174 case BitmapFileInvalid:
2175 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2176 break;
2177 case BitmapNoMemory:
2178 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2179 break;
2180 case BitmapSuccess:
2181 XFreePixmap(dpy, bitmap);
2182 break;
2187 * (none)
2188 * (builtin, <cursor_name>)
2189 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2191 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2193 WMPropList *elem;
2194 char *val;
2195 int nelem;
2196 int status = 0;
2198 nelem = WMGetPropListItemCount(pl);
2199 if (nelem < 1) {
2200 return (status);
2202 elem = WMGetFromPLArray(pl, 0);
2203 if (!elem || !WMIsPLString(elem)) {
2204 return (status);
2206 val = WMGetFromPLString(elem);
2208 if (strcasecmp(val, "none") == 0) {
2209 status = 1;
2210 *cursor = None;
2211 } else if (strcasecmp(val, "builtin") == 0) {
2212 int i;
2213 int cursor_id = CURSOR_ID_NONE;
2215 if (nelem != 2) {
2216 wwarning(_("bad number of arguments in cursor specification"));
2217 return (status);
2219 elem = WMGetFromPLArray(pl, 1);
2220 if (!elem || !WMIsPLString(elem)) {
2221 return (status);
2223 val = WMGetFromPLString(elem);
2225 for (i = 0; cursor_table[i].name != NULL; i++) {
2226 if (strcasecmp(val, cursor_table[i].name) == 0) {
2227 cursor_id = cursor_table[i].id;
2228 break;
2231 if (CURSOR_ID_NONE == cursor_id) {
2232 wwarning(_("unknown builtin cursor name \"%s\""), val);
2233 } else {
2234 *cursor = XCreateFontCursor(dpy, cursor_id);
2235 status = 1;
2237 } else if (strcasecmp(val, "bitmap") == 0) {
2238 char *bitmap_name;
2239 char *mask_name;
2240 int bitmap_status;
2241 int mask_status;
2242 Pixmap bitmap;
2243 Pixmap mask;
2244 unsigned int w, h;
2245 int x, y;
2246 XColor fg, bg;
2248 if (nelem != 3) {
2249 wwarning(_("bad number of arguments in cursor specification"));
2250 return (status);
2252 elem = WMGetFromPLArray(pl, 1);
2253 if (!elem || !WMIsPLString(elem)) {
2254 return (status);
2256 val = WMGetFromPLString(elem);
2257 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2258 if (!bitmap_name) {
2259 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2260 return (status);
2262 elem = WMGetFromPLArray(pl, 2);
2263 if (!elem || !WMIsPLString(elem)) {
2264 wfree(bitmap_name);
2265 return (status);
2267 val = WMGetFromPLString(elem);
2268 mask_name = FindImage(wPreferences.pixmap_path, val);
2269 if (!mask_name) {
2270 wfree(bitmap_name);
2271 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2272 return (status);
2274 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2275 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2276 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2277 fg.pixel = scr->black_pixel;
2278 bg.pixel = scr->white_pixel;
2279 XQueryColor(dpy, scr->w_colormap, &fg);
2280 XQueryColor(dpy, scr->w_colormap, &bg);
2281 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2282 status = 1;
2284 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2285 check_bitmap_status(mask_status, mask_name, mask);
2286 wfree(bitmap_name);
2287 wfree(mask_name);
2289 return (status);
2292 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2294 static Cursor cursor;
2295 int status;
2296 int changed = 0;
2298 again:
2299 if (!WMIsPLArray(value)) {
2300 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2301 entry->key, "cursor specification");
2302 if (!changed) {
2303 value = entry->plvalue;
2304 changed = 1;
2305 wwarning(_("using default \"%s\" instead"), entry->default_value);
2306 goto again;
2308 return (False);
2310 status = parse_cursor(scr, value, &cursor);
2311 if (!status) {
2312 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2313 if (!changed) {
2314 value = entry->plvalue;
2315 changed = 1;
2316 wwarning(_("using default \"%s\" instead"), entry->default_value);
2317 goto again;
2319 return (False);
2321 if (ret) {
2322 *ret = &cursor;
2324 if (addr) {
2325 *(Cursor *) addr = cursor;
2327 return (True);
2330 #undef CURSOR_ID_NONE
2332 /* ---------------- value setting functions --------------- */
2333 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2335 return REFRESH_WINDOW_TITLE_COLOR;
2338 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2340 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2343 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2345 switch (which) {
2346 case WM_DOCK:
2347 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2348 break;
2349 case WM_CLIP:
2350 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2351 break;
2352 default:
2353 break;
2355 return 0;
2358 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2360 if (scr->workspaces) {
2361 wWorkspaceForceChange(scr, scr->current_workspace);
2362 wArrangeIcons(scr, False);
2364 return 0;
2367 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2369 Pixmap pixmap;
2370 RImage *img;
2371 int reset = 0;
2373 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2374 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2375 ? WREL_ICON : WREL_FLAT);
2376 if (!img) {
2377 wwarning(_("could not render texture for icon background"));
2378 if (!entry->addr)
2379 wTextureDestroy(scr, *texture);
2380 return 0;
2382 RConvertImage(scr->rcontext, img, &pixmap);
2384 if (scr->icon_tile) {
2385 reset = 1;
2386 RReleaseImage(scr->icon_tile);
2387 XFreePixmap(dpy, scr->icon_tile_pixmap);
2390 scr->icon_tile = img;
2392 /* put the icon in the noticeboard hint */
2393 PropSetIconTileHint(scr, img);
2395 if (!wPreferences.flags.noclip) {
2396 if (scr->clip_tile) {
2397 RReleaseImage(scr->clip_tile);
2399 scr->clip_tile = wClipMakeTile(scr, img);
2402 scr->icon_tile_pixmap = pixmap;
2404 if (scr->def_icon_pixmap) {
2405 XFreePixmap(dpy, scr->def_icon_pixmap);
2406 scr->def_icon_pixmap = None;
2408 if (scr->def_ticon_pixmap) {
2409 XFreePixmap(dpy, scr->def_ticon_pixmap);
2410 scr->def_ticon_pixmap = None;
2413 if (scr->icon_back_texture) {
2414 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2416 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2418 if (scr->clip_balloon)
2419 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2422 * Free the texture as nobody else will use it, nor refer to it.
2424 if (!entry->addr)
2425 wTextureDestroy(scr, *texture);
2427 return (reset ? REFRESH_ICON_TILE : 0);
2430 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2432 if (scr->title_font) {
2433 WMReleaseFont(scr->title_font);
2435 scr->title_font = font;
2437 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2440 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2442 if (scr->menu_title_font) {
2443 WMReleaseFont(scr->menu_title_font);
2446 scr->menu_title_font = font;
2448 return REFRESH_MENU_TITLE_FONT;
2451 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2453 if (scr->menu_entry_font) {
2454 WMReleaseFont(scr->menu_entry_font);
2456 scr->menu_entry_font = font;
2458 return REFRESH_MENU_FONT;
2461 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2463 if (scr->icon_title_font) {
2464 WMReleaseFont(scr->icon_title_font);
2467 scr->icon_title_font = font;
2469 return REFRESH_ICON_FONT;
2472 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2474 if (scr->clip_title_font) {
2475 WMReleaseFont(scr->clip_title_font);
2478 scr->clip_title_font = font;
2480 return REFRESH_ICON_FONT;
2483 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2485 if (scr->workspace_name_font) {
2486 WMReleaseFont(scr->workspace_name_font);
2489 scr->workspace_name_font = font;
2491 return 0;
2494 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2496 if (scr->select_color)
2497 WMReleaseColor(scr->select_color);
2499 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2501 wFreeColor(scr, color->pixel);
2503 return REFRESH_MENU_COLOR;
2506 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2508 if (scr->select_text_color)
2509 WMReleaseColor(scr->select_text_color);
2511 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2513 wFreeColor(scr, color->pixel);
2515 return REFRESH_MENU_COLOR;
2518 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2520 if (scr->clip_title_color[widx])
2521 WMReleaseColor(scr->clip_title_color[widx]);
2522 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2523 #ifdef GRADIENT_CLIP_ARROW
2524 if (widx == CLIP_NORMAL) {
2525 RImage *image;
2526 RColor color1, color2;
2527 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2528 int as = pt - 15; /* 15 = 5+5+5 */
2530 FREE_PIXMAP(scr->clip_arrow_gradient);
2532 color1.red = (color->red >> 8) * 6 / 10;
2533 color1.green = (color->green >> 8) * 6 / 10;
2534 color1.blue = (color->blue >> 8) * 6 / 10;
2536 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2537 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2538 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2540 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2541 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2542 RReleaseImage(image);
2544 #endif /* GRADIENT_CLIP_ARROW */
2546 wFreeColor(scr, color->pixel);
2548 return REFRESH_ICON_TITLE_COLOR;
2551 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2553 if (scr->window_title_color[widx])
2554 WMReleaseColor(scr->window_title_color[widx]);
2556 scr->window_title_color[widx] =
2557 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2559 wFreeColor(scr, color->pixel);
2561 return REFRESH_WINDOW_TITLE_COLOR;
2564 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2566 if (scr->menu_title_color[0])
2567 WMReleaseColor(scr->menu_title_color[0]);
2569 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2571 wFreeColor(scr, color->pixel);
2573 return REFRESH_MENU_TITLE_COLOR;
2576 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2578 if (scr->mtext_color)
2579 WMReleaseColor(scr->mtext_color);
2581 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2583 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2584 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2585 } else {
2586 WMSetColorAlpha(scr->dtext_color, 0xffff);
2589 wFreeColor(scr, color->pixel);
2591 return REFRESH_MENU_COLOR;
2594 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2596 if (scr->dtext_color)
2597 WMReleaseColor(scr->dtext_color);
2599 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2601 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2602 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2603 } else {
2604 WMSetColorAlpha(scr->dtext_color, 0xffff);
2607 wFreeColor(scr, color->pixel);
2609 return REFRESH_MENU_COLOR;
2612 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2614 if (scr->icon_title_color)
2615 WMReleaseColor(scr->icon_title_color);
2616 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2618 wFreeColor(scr, color->pixel);
2620 return REFRESH_ICON_TITLE_COLOR;
2623 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2625 if (scr->icon_title_texture) {
2626 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2628 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2630 return REFRESH_ICON_TITLE_BACK;
2633 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2635 close(scr->helper_fd);
2636 scr->helper_fd = 0;
2637 scr->helper_pid = 0;
2638 scr->flags.backimage_helper_launched = 0;
2641 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2643 WMPropList *val;
2644 char *str;
2645 int i;
2647 if (scr->flags.backimage_helper_launched) {
2648 if (WMGetPropListItemCount(value) == 0) {
2649 SendHelperMessage(scr, 'C', 0, NULL);
2650 SendHelperMessage(scr, 'K', 0, NULL);
2652 WMReleasePropList(value);
2653 return 0;
2655 } else {
2656 pid_t pid;
2657 int filedes[2];
2659 if (WMGetPropListItemCount(value) == 0)
2660 return 0;
2662 if (pipe(filedes) < 0) {
2663 wsyserror("pipe() failed:can't set workspace specific background image");
2665 WMReleasePropList(value);
2666 return 0;
2669 pid = fork();
2670 if (pid < 0) {
2671 wsyserror("fork() failed:can't set workspace specific background image");
2672 if (close(filedes[0]) < 0)
2673 wsyserror("could not close pipe");
2674 if (close(filedes[1]) < 0)
2675 wsyserror("could not close pipe");
2677 } else if (pid == 0) {
2678 char *dither;
2680 SetupEnvironment(scr);
2682 if (close(0) < 0)
2683 wsyserror("could not close pipe");
2684 if (dup(filedes[0]) < 0) {
2685 wsyserror("dup() failed:can't set workspace specific background image");
2687 dither = wPreferences.no_dithering ? "-m" : "-d";
2688 if (wPreferences.smooth_workspace_back)
2689 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2690 else
2691 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2692 wsyserror("could not execute wmsetbg");
2693 exit(1);
2694 } else {
2696 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2697 wsyserror("error setting close-on-exec flag");
2699 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2700 wsyserror("error setting close-on-exec flag");
2703 scr->helper_fd = filedes[1];
2704 scr->helper_pid = pid;
2705 scr->flags.backimage_helper_launched = 1;
2707 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2709 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2714 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2715 val = WMGetFromPLArray(value, i);
2716 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2717 str = WMGetPropListDescription(val, False);
2719 SendHelperMessage(scr, 'S', i + 1, str);
2721 wfree(str);
2722 } else {
2723 SendHelperMessage(scr, 'U', i + 1, NULL);
2726 sleep(1);
2728 WMReleasePropList(value);
2729 return 0;
2732 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2734 if (scr->flags.backimage_helper_launched) {
2735 char *str;
2737 if (WMGetPropListItemCount(value) == 0) {
2738 SendHelperMessage(scr, 'U', 0, NULL);
2739 } else {
2740 /* set the default workspace background to this one */
2741 str = WMGetPropListDescription(value, False);
2742 if (str) {
2743 SendHelperMessage(scr, 'S', 0, str);
2744 wfree(str);
2745 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2746 } else {
2747 SendHelperMessage(scr, 'U', 0, NULL);
2750 } else if (WMGetPropListItemCount(value) > 0) {
2751 char *command;
2752 char *text;
2753 char *dither;
2754 int len;
2756 text = WMGetPropListDescription(value, False);
2757 len = strlen(text) + 40;
2758 command = wmalloc(len);
2759 dither = wPreferences.no_dithering ? "-m" : "-d";
2760 if (wPreferences.smooth_workspace_back)
2761 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2762 else
2763 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2764 wfree(text);
2765 ExecuteShellCommand(scr, command);
2766 wfree(command);
2768 WMReleasePropList(value);
2770 return 0;
2773 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2775 if (scr->widget_texture) {
2776 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2778 scr->widget_texture = *(WTexSolid **) texture;
2780 return 0;
2783 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2785 if (scr->window_title_texture[WS_FOCUSED]) {
2786 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2788 scr->window_title_texture[WS_FOCUSED] = *texture;
2790 return REFRESH_WINDOW_TEXTURES;
2793 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2795 if (scr->window_title_texture[WS_PFOCUSED]) {
2796 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2798 scr->window_title_texture[WS_PFOCUSED] = *texture;
2800 return REFRESH_WINDOW_TEXTURES;
2803 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2805 if (scr->window_title_texture[WS_UNFOCUSED]) {
2806 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2808 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2810 return REFRESH_WINDOW_TEXTURES;
2813 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2815 if (scr->resizebar_texture[0]) {
2816 wTextureDestroy(scr, scr->resizebar_texture[0]);
2818 scr->resizebar_texture[0] = *texture;
2820 return REFRESH_WINDOW_TEXTURES;
2823 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2825 if (scr->menu_title_texture[0]) {
2826 wTextureDestroy(scr, scr->menu_title_texture[0]);
2828 scr->menu_title_texture[0] = *texture;
2830 return REFRESH_MENU_TITLE_TEXTURE;
2833 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2835 if (scr->menu_item_texture) {
2836 wTextureDestroy(scr, scr->menu_item_texture);
2837 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2839 scr->menu_item_texture = *texture;
2841 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2843 return REFRESH_MENU_TEXTURE;
2846 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2848 WWindow *wwin;
2849 wKeyBindings[widx] = *shortcut;
2851 wwin = scr->focused_window;
2853 while (wwin != NULL) {
2854 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2856 if (!WFLAGP(wwin, no_bind_keys)) {
2857 wWindowSetKeyGrabs(wwin);
2859 wwin = wwin->prev;
2862 return 0;
2865 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2867 wScreenUpdateUsableArea(scr);
2868 wArrangeIcons(scr, True);
2870 return 0;
2873 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2875 wScreenUpdateUsableArea(scr);
2877 return 0;
2880 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2882 return REFRESH_MENU_TEXTURE;
2885 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2887 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2889 RCopyArea(img, image, x, y, w, h, 0, 0);
2891 return img;
2894 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2896 char *path;
2897 RImage *bgimage;
2898 int cwidth, cheight;
2899 WPreferences *prefs = (WPreferences *) foo;
2901 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2902 if (prefs->swtileImage)
2903 RReleaseImage(prefs->swtileImage);
2904 prefs->swtileImage = NULL;
2906 WMReleasePropList(array);
2907 return 0;
2910 switch (WMGetPropListItemCount(array)) {
2911 case 4:
2912 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2913 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2914 break;
2915 } else
2916 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2918 if (!path) {
2919 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2920 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2921 } else {
2922 bgimage = RLoadImage(scr->rcontext, path, 0);
2923 if (!bgimage) {
2924 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2925 wfree(path);
2926 } else {
2927 wfree(path);
2929 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2930 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2932 if (cwidth <= 0 || cheight <= 0 ||
2933 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2934 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2935 else {
2936 int i;
2937 int swidth, theight;
2938 for (i = 0; i < 9; i++) {
2939 if (prefs->swbackImage[i])
2940 RReleaseImage(prefs->swbackImage[i]);
2941 prefs->swbackImage[i] = NULL;
2943 swidth = (bgimage->width - cwidth) / 2;
2944 theight = (bgimage->height - cheight) / 2;
2946 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2947 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2948 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2949 swidth, theight);
2951 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2952 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2953 cwidth, cheight);
2954 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2955 swidth, cheight);
2957 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2958 swidth, theight);
2959 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2960 cwidth, theight);
2961 prefs->swbackImage[8] =
2962 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2963 theight);
2965 // check if anything failed
2966 for (i = 0; i < 9; i++) {
2967 if (!prefs->swbackImage[i]) {
2968 for (; i >= 0; --i) {
2969 RReleaseImage(prefs->swbackImage[i]);
2970 prefs->swbackImage[i] = NULL;
2972 break;
2976 RReleaseImage(bgimage);
2980 case 1:
2981 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
2982 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2983 break;
2984 } else
2985 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
2987 if (!path) {
2988 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2989 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
2990 } else {
2991 if (prefs->swtileImage)
2992 RReleaseImage(prefs->swtileImage);
2994 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
2995 if (!prefs->swtileImage) {
2996 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2998 wfree(path);
3000 break;
3002 default:
3003 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3004 break;
3007 WMReleasePropList(array);
3009 return 0;
3013 * Very ugly kluge.
3014 * Need access to the double click variables, so that all widgets in
3015 * wmaker panels will have the same dbl-click values.
3016 * TODO: figure a better way of dealing with it.
3018 #include <WINGs/WINGsP.h>
3020 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3022 extern _WINGsConfiguration WINGsConfiguration;
3024 if (*value <= 0)
3025 *(int *)foo = 1;
3027 WINGsConfiguration.doubleClickDelay = *value;
3029 return 0;
3032 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3034 if (wCursor[widx] != None) {
3035 XFreeCursor(dpy, wCursor[widx]);
3038 wCursor[widx] = *cursor;
3040 if (widx == WCUR_ROOT && *cursor != None) {
3041 XDefineCursor(dpy, scr->root_win, *cursor);
3044 return 0;