Remove texture plugins
[wmaker-crm.git] / src / defaults.c
bloba02a03b15063c622a844e413ef32929332f6f1f9
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},
314 {"DisableDithering", "NO", NULL,
315 &wPreferences.no_dithering, getBool, NULL},
316 /* static by laziness */
317 {"IconSize", "64", NULL,
318 &wPreferences.icon_size, getInt, NULL},
319 {"ModifierKey", "Mod1", NULL,
320 &wPreferences.modifier_mask, getModMask, NULL},
321 {"DisableWSMouseActions", "NO", NULL,
322 &wPreferences.disable_root_mouse, getBool, NULL},
323 {"FocusMode", "manual", seFocusModes,
324 &wPreferences.focus_mode, getEnum, NULL}, /* have a problem when switching from manual to sloppy without restart */
325 {"NewStyle", "NO", NULL,
326 &wPreferences.new_style, getBool, NULL},
327 {"DisableDock", "NO", (void *)WM_DOCK,
328 NULL, getBool, setIfDockPresent},
329 {"DisableClip", "NO", (void *)WM_CLIP,
330 NULL, getBool, setIfDockPresent},
331 {"DisableMiniwindows", "NO", NULL,
332 &wPreferences.disable_miniwindows, getBool, NULL}
335 WDefaultEntry optionList[] = {
336 /* dynamic options */
337 {"IconPosition", "blh", seIconPositions,
338 &wPreferences.icon_yard, getEnum, setIconPosition},
339 {"IconificationStyle", "Zoom", seIconificationStyles,
340 &wPreferences.iconification_style, getEnum, NULL},
341 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
342 &wPreferences.mouse_button1, getEnum, NULL},
343 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
344 &wPreferences.mouse_button2, getEnum, NULL},
345 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
346 &wPreferences.mouse_button3, getEnum, NULL},
347 {"MouseWheelAction", "None", seMouseWheelActions,
348 &wPreferences.mouse_wheel, getEnum, NULL},
349 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
350 &wPreferences.pixmap_path, getPathList, NULL},
351 {"IconPath", DEF_ICON_PATHS, NULL,
352 &wPreferences.icon_path, getPathList, NULL},
353 {"ColormapMode", "auto", seColormapModes,
354 &wPreferences.colormap_mode, getEnum, NULL},
355 {"AutoFocus", "NO", NULL,
356 &wPreferences.auto_focus, getBool, NULL},
357 {"RaiseDelay", "0", NULL,
358 &wPreferences.raise_delay, getInt, NULL},
359 {"CirculateRaise", "NO", NULL,
360 &wPreferences.circ_raise, getBool, NULL},
361 {"Superfluous", "NO", NULL,
362 &wPreferences.superfluous, getBool, NULL},
363 {"AdvanceToNewWorkspace", "NO", NULL,
364 &wPreferences.ws_advance, getBool, NULL},
365 {"CycleWorkspaces", "NO", NULL,
366 &wPreferences.ws_cycle, getBool, NULL},
367 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
368 &wPreferences.workspace_name_display_position, getEnum, NULL},
369 {"WorkspaceBorder", "None", seWorkspaceBorder,
370 &wPreferences.workspace_border_position, getEnum, updateUsableArea},
371 {"WorkspaceBorderSize", "0", NULL,
372 &wPreferences.workspace_border_size, getInt, updateUsableArea},
373 {"StickyIcons", "NO", NULL,
374 &wPreferences.sticky_icons, getBool, setStickyIcons},
375 {"SaveSessionOnExit", "NO", NULL,
376 &wPreferences.save_session_on_exit, getBool, NULL},
377 {"WrapMenus", "NO", NULL,
378 &wPreferences.wrap_menus, getBool, NULL},
379 {"ScrollableMenus", "NO", NULL,
380 &wPreferences.scrollable_menus, getBool, NULL},
381 {"MenuScrollSpeed", "medium", seSpeeds,
382 &wPreferences.menu_scroll_speed, getEnum, NULL},
383 {"IconSlideSpeed", "medium", seSpeeds,
384 &wPreferences.icon_slide_speed, getEnum, NULL},
385 {"ShadeSpeed", "medium", seSpeeds,
386 &wPreferences.shade_speed, getEnum, NULL},
387 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
388 &wPreferences.dblclick_time, getInt, setDoubleClick,
390 {"AlignSubmenus", "NO", NULL,
391 &wPreferences.align_menus, getBool, NULL},
392 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
393 &wPreferences.open_transients_with_parent, getBool, NULL},
394 {"WindowPlacement", "auto", sePlacements,
395 &wPreferences.window_placement, getEnum, NULL},
396 {"IgnoreFocusClick", "NO", NULL,
397 &wPreferences.ignore_focus_click, getBool, NULL},
398 {"UseSaveUnders", "NO", NULL,
399 &wPreferences.use_saveunders, getBool, NULL},
400 {"OpaqueMove", "NO", NULL,
401 &wPreferences.opaque_move, getBool, NULL},
402 {"DisableAnimations", "NO", NULL,
403 &wPreferences.no_animations, getBool, NULL},
404 {"DontLinkWorkspaces", "NO", NULL,
405 &wPreferences.no_autowrap, getBool, NULL},
406 {"AutoArrangeIcons", "NO", NULL,
407 &wPreferences.auto_arrange_icons, getBool, NULL},
408 {"NoWindowOverDock", "NO", NULL,
409 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
410 {"NoWindowOverIcons", "NO", NULL,
411 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
412 {"WindowPlaceOrigin", "(0, 0)", NULL,
413 &wPreferences.window_place_origin, getCoord, NULL},
414 {"ResizeDisplay", "corner", seGeomDisplays,
415 &wPreferences.size_display, getEnum, NULL},
416 {"MoveDisplay", "corner", seGeomDisplays,
417 &wPreferences.move_display, getEnum, NULL},
418 {"DontConfirmKill", "NO", NULL,
419 &wPreferences.dont_confirm_kill, getBool, NULL},
420 {"WindowTitleBalloons", "NO", NULL,
421 &wPreferences.window_balloon, getBool, NULL},
422 {"MiniwindowTitleBalloons", "NO", NULL,
423 &wPreferences.miniwin_balloon, getBool, NULL},
424 {"AppIconBalloons", "NO", NULL,
425 &wPreferences.appicon_balloon, getBool, NULL},
426 {"HelpBalloons", "NO", NULL,
427 &wPreferences.help_balloon, getBool, NULL},
428 {"EdgeResistance", "30", NULL,
429 &wPreferences.edge_resistance, getInt, NULL},
430 {"ResizeIncrement", "32", NULL,
431 &wPreferences.resize_increment, getInt, NULL},
432 {"Attraction", "NO", NULL,
433 &wPreferences.attract, getBool, NULL},
434 {"DisableBlinking", "NO", NULL,
435 &wPreferences.dont_blink, getBool, NULL},
436 {"SingleClickLaunch", "NO", NULL,
437 &wPreferences.single_click, getBool, NULL},
438 /* style options */
439 {"MenuStyle", "normal", seMenuStyles,
440 &wPreferences.menu_style, getEnum, setMenuStyle},
441 {"WidgetColor", "(solid, gray)", NULL,
442 NULL, getTexture, setWidgetColor,
444 {"WorkspaceSpecificBack", "()", NULL,
445 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
446 /* WorkspaceBack must come after WorkspaceSpecificBack or
447 * WorkspaceBack wont know WorkspaceSpecificBack was also
448 * specified and 2 copies of wmsetbg will be launched */
449 {"WorkspaceBack", "(solid, black)", NULL,
450 NULL, getWSBackground, setWorkspaceBack},
451 {"SmoothWorkspaceBack", "NO", NULL,
452 NULL, getBool, NULL},
453 {"IconBack", "(solid, gray)", NULL,
454 NULL, getTexture, setIconTile},
455 {"TitleJustify", "center", seJustifications,
456 &wPreferences.title_justification, getEnum, setJustify},
457 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
458 NULL, getFont, setWinTitleFont,
460 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
461 &wPreferences.window_title_clearance, getInt, setClearance},
462 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
463 &wPreferences.menu_title_clearance, getInt, setClearance},
464 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
465 &wPreferences.menu_text_clearance, getInt, setClearance},
466 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
467 NULL, getFont, setMenuTitleFont},
468 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
469 NULL, getFont, setMenuTextFont},
470 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
471 NULL, getFont, setIconTitleFont},
472 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
473 NULL, getFont, setClipTitleFont},
474 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
475 NULL, getFont, setLargeDisplayFont},
476 {"HighlightColor", "white", NULL,
477 NULL, getColor, setHightlight},
478 {"HighlightTextColor", "black", NULL,
479 NULL, getColor, setHightlightText},
480 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
481 NULL, getColor, setClipTitleColor},
482 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
483 NULL, getColor, setClipTitleColor},
484 {"FTitleColor", "white", (void *)WS_FOCUSED,
485 NULL, getColor, setWTitleColor},
486 {"PTitleColor", "white", (void *)WS_PFOCUSED,
487 NULL, getColor, setWTitleColor},
488 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
489 NULL, getColor, setWTitleColor},
490 {"FTitleBack", "(solid, black)", NULL,
491 NULL, getTexture, setFTitleBack},
492 {"PTitleBack", "(solid, \"#616161\")", NULL,
493 NULL, getTexture, setPTitleBack},
494 {"UTitleBack", "(solid, gray)", NULL,
495 NULL, getTexture, setUTitleBack},
496 {"ResizebarBack", "(solid, gray)", NULL,
497 NULL, getTexture, setResizebarBack},
498 {"MenuTitleColor", "white", NULL,
499 NULL, getColor, setMenuTitleColor},
500 {"MenuTextColor", "black", NULL,
501 NULL, getColor, setMenuTextColor},
502 {"MenuDisabledColor", "\"#616161\"", NULL,
503 NULL, getColor, setMenuDisabledColor},
504 {"MenuTitleBack", "(solid, black)", NULL,
505 NULL, getTexture, setMenuTitleBack},
506 {"MenuTextBack", "(solid, gray)", NULL,
507 NULL, getTexture, setMenuTextBack},
508 {"IconTitleColor", "white", NULL,
509 NULL, getColor, setIconTitleColor},
510 {"IconTitleBack", "black", NULL,
511 NULL, getColor, setIconTitleBack},
512 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
513 NULL, getPropList, setSwPOptions},
514 /* keybindings */
515 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
516 NULL, getKeybind, setKeyGrab},
517 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
518 NULL, getKeybind, setKeyGrab},
519 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
520 NULL, getKeybind, setKeyGrab},
521 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
522 NULL, getKeybind, setKeyGrab},
523 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
524 NULL, getKeybind, setKeyGrab},
525 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
526 NULL, getKeybind, setKeyGrab},
527 {"HideKey", "None", (void *)WKBD_HIDE,
528 NULL, getKeybind, setKeyGrab},
529 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
530 NULL, getKeybind, setKeyGrab},
531 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
532 NULL, getKeybind, setKeyGrab},
533 {"CloseKey", "None", (void *)WKBD_CLOSE,
534 NULL, getKeybind, setKeyGrab},
535 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
536 NULL, getKeybind, setKeyGrab},
537 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
538 NULL, getKeybind, setKeyGrab},
539 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
540 NULL, getKeybind, setKeyGrab},
541 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
542 NULL, getKeybind, setKeyGrab},
543 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
544 NULL, getKeybind, setKeyGrab},
545 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
546 NULL, getKeybind, setKeyGrab},
547 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
548 NULL, getKeybind, setKeyGrab},
549 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
550 NULL, getKeybind, setKeyGrab},
551 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
552 NULL, getKeybind, setKeyGrab},
553 {"ShadeKey", "None", (void *)WKBD_SHADE,
554 NULL, getKeybind, setKeyGrab},
555 {"SelectKey", "None", (void *)WKBD_SELECT,
556 NULL, getKeybind, setKeyGrab},
557 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
558 NULL, getKeybind, setKeyGrab},
559 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
560 NULL, getKeybind, setKeyGrab},
561 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
562 NULL, getKeybind, setKeyGrab},
563 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
564 NULL, getKeybind, setKeyGrab},
565 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
566 NULL, getKeybind, setKeyGrab},
567 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
568 NULL, getKeybind, setKeyGrab},
569 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
570 NULL, getKeybind, setKeyGrab},
571 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
572 NULL, getKeybind, setKeyGrab},
573 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
574 NULL, getKeybind, setKeyGrab},
575 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
576 NULL, getKeybind, setKeyGrab},
577 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
578 NULL, getKeybind, setKeyGrab},
579 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
580 NULL, getKeybind, setKeyGrab},
581 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
582 NULL, getKeybind, setKeyGrab},
583 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
584 NULL, getKeybind, setKeyGrab},
585 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
586 NULL, getKeybind, setKeyGrab},
587 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
588 NULL, getKeybind, setKeyGrab},
589 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
590 NULL, getKeybind, setKeyGrab},
591 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
592 NULL, getKeybind, setKeyGrab},
593 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
594 NULL, getKeybind, setKeyGrab},
595 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
596 NULL, getKeybind, setKeyGrab},
597 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
598 NULL, getKeybind, setKeyGrab},
599 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
600 NULL, getKeybind, setKeyGrab}
601 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
602 NULL, getKeybind, setKeyGrab},
603 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
604 NULL, getKeybind, setKeyGrab},
605 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
606 NULL, getKeybind, setKeyGrab},
607 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
608 NULL, getKeybind, setKeyGrab},
609 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
610 NULL, getKeybind, setKeyGrab},
611 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
612 NULL, getKeybind, setKeyGrab},
613 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
614 NULL, getKeybind, setKeyGrab},
616 #ifdef KEEP_XKB_LOCK_STATUS
617 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
618 NULL, getKeybind, setKeyGrab},
619 {"KbdModeLock", "NO", NULL,
620 &wPreferences.modelock, getBool, NULL},
621 #endif /* KEEP_XKB_LOCK_STATUS */
623 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
624 NULL, getCursor, setCursor},
625 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
626 NULL, getCursor, setCursor},
627 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
628 NULL, getCursor, setCursor},
629 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
630 NULL, getCursor, setCursor},
631 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
632 (void *)WCUR_TOPLEFTRESIZE,
633 NULL, getCursor, setCursor},
634 {"TopRightResizeCursor", "(builtin, top_right_corner)",
635 (void *)WCUR_TOPRIGHTRESIZE,
636 NULL, getCursor, setCursor},
637 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
638 (void *)WCUR_BOTTOMLEFTRESIZE,
639 NULL, getCursor, setCursor},
640 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
641 (void *)WCUR_BOTTOMRIGHTRESIZE,
642 NULL, getCursor, setCursor},
643 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
644 (void *)WCUR_VERTICALRESIZE,
645 NULL, getCursor, setCursor},
646 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
647 (void *)WCUR_HORIZONRESIZE,
648 NULL, getCursor, setCursor},
649 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
650 NULL, getCursor, setCursor},
651 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
652 NULL, getCursor, setCursor},
653 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
654 NULL, getCursor, setCursor},
655 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
656 NULL, getCursor, setCursor},
657 {"DialogHistoryLines", "500", NULL,
658 &wPreferences.history_lines, getInt, NULL}
661 #if 0
662 static void rereadDefaults(void)
664 /* must defer the update because accessing X data from a
665 * signal handler can mess up Xlib */
668 #endif
670 static void initDefaults()
672 unsigned int i;
673 WDefaultEntry *entry;
675 WMPLSetCaseSensitive(False);
677 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
678 entry = &optionList[i];
680 entry->plkey = WMCreatePLString(entry->key);
681 if (entry->default_value)
682 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
683 else
684 entry->plvalue = NULL;
687 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
688 entry = &staticOptionList[i];
690 entry->plkey = WMCreatePLString(entry->key);
691 if (entry->default_value)
692 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
693 else
694 entry->plvalue = NULL;
698 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
699 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
701 PLRegister(wDomainName, rereadDefaults);
702 PLRegister(wAttributeDomainName, rereadDefaults);
706 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
708 WMPropList *globalDict = NULL;
709 char path[PATH_MAX];
710 struct stat stbuf;
712 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
713 if (stat(path, &stbuf) >= 0) {
714 globalDict = WMReadPropListFromFile(path);
715 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
716 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
717 WMReleasePropList(globalDict);
718 globalDict = NULL;
719 } else if (!globalDict) {
720 wwarning(_("could not load domain %s from global defaults database"), domainName);
724 return globalDict;
727 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
728 static void prependMenu(WMPropList * destarr, WMPropList * array)
730 WMPropList *item;
731 int i;
733 for (i = 0; i < WMGetPropListItemCount(array); i++) {
734 item = WMGetFromPLArray(array, i);
735 if (item)
736 WMInsertInPLArray(destarr, i + 1, item);
740 static void appendMenu(WMPropList * destarr, WMPropList * array)
742 WMPropList *item;
743 int i;
745 for (i = 0; i < WMGetPropListItemCount(array); i++) {
746 item = WMGetFromPLArray(array, i);
747 if (item)
748 WMAddToPLArray(destarr, item);
751 #endif
753 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
755 WMPropList *menu = menuDomain->dictionary;
756 WMPropList *submenu;
758 if (!menu || !WMIsPLArray(menu))
759 return;
761 #ifdef GLOBAL_PREAMBLE_MENU_FILE
762 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
764 if (submenu && !WMIsPLArray(submenu)) {
765 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
766 WMReleasePropList(submenu);
767 submenu = NULL;
769 if (submenu) {
770 prependMenu(menu, submenu);
771 WMReleasePropList(submenu);
773 #endif
775 #ifdef GLOBAL_EPILOGUE_MENU_FILE
776 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
778 if (submenu && !WMIsPLArray(submenu)) {
779 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
780 WMReleasePropList(submenu);
781 submenu = NULL;
783 if (submenu) {
784 appendMenu(menu, submenu);
785 WMReleasePropList(submenu);
787 #endif
789 menuDomain->dictionary = menu;
792 void wDefaultsDestroyDomain(WDDomain * domain)
794 if (domain->dictionary)
795 WMReleasePropList(domain->dictionary);
796 wfree(domain->path);
797 wfree(domain);
800 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
802 WDDomain *db;
803 struct stat stbuf;
804 static int inited = 0;
805 char path[PATH_MAX];
806 char *the_path;
807 WMPropList *shared_dict = NULL;
809 if (!inited) {
810 inited = 1;
811 initDefaults();
814 db = wmalloc(sizeof(WDDomain));
815 memset(db, 0, sizeof(WDDomain));
816 db->domain_name = domain;
817 db->path = wdefaultspathfordomain(domain);
818 the_path = db->path;
820 if (the_path && stat(the_path, &stbuf) >= 0) {
821 db->dictionary = WMReadPropListFromFile(the_path);
822 if (db->dictionary) {
823 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
824 WMReleasePropList(db->dictionary);
825 db->dictionary = NULL;
826 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
828 db->timestamp = stbuf.st_mtime;
829 } else {
830 wwarning(_("could not load domain %s from user defaults database"), domain);
834 /* global system dictionary */
835 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
836 if (stat(path, &stbuf) >= 0) {
837 shared_dict = WMReadPropListFromFile(path);
838 if (shared_dict) {
839 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
840 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
841 domain, path);
842 WMReleasePropList(shared_dict);
843 shared_dict = NULL;
844 } else {
845 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
846 WMIsPLDictionary(db->dictionary)) {
847 WMMergePLDictionaries(shared_dict, db->dictionary, True);
848 WMReleasePropList(db->dictionary);
849 db->dictionary = shared_dict;
850 if (stbuf.st_mtime > db->timestamp)
851 db->timestamp = stbuf.st_mtime;
852 } else if (!db->dictionary) {
853 db->dictionary = shared_dict;
854 if (stbuf.st_mtime > db->timestamp)
855 db->timestamp = stbuf.st_mtime;
858 } else {
859 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
863 return db;
866 void wReadStaticDefaults(WMPropList * dict)
868 WMPropList *plvalue;
869 WDefaultEntry *entry;
870 unsigned int i;
871 void *tdata;
873 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
874 entry = &staticOptionList[i];
876 if (dict)
877 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
878 else
879 plvalue = NULL;
881 if (!plvalue) {
882 /* no default in the DB. Use builtin default */
883 plvalue = entry->plvalue;
886 if (plvalue) {
887 /* convert data */
888 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
889 if (entry->update) {
890 (*entry->update) (NULL, entry, tdata, entry->extra_data);
896 void wDefaultsCheckDomains(void* arg)
898 WScreen *scr;
899 struct stat stbuf;
900 WMPropList *shared_dict = NULL;
901 WMPropList *dict;
902 int i;
904 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
905 WDWindowMaker->timestamp = stbuf.st_mtime;
907 /* global dictionary */
908 shared_dict = readGlobalDomain("WindowMaker", True);
909 /* user dictionary */
910 dict = WMReadPropListFromFile(WDWindowMaker->path);
911 if (dict) {
912 if (!WMIsPLDictionary(dict)) {
913 WMReleasePropList(dict);
914 dict = NULL;
915 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
916 "WindowMaker", WDWindowMaker->path);
917 } else {
918 if (shared_dict) {
919 WMMergePLDictionaries(shared_dict, dict, True);
920 WMReleasePropList(dict);
921 dict = shared_dict;
922 shared_dict = NULL;
924 for (i = 0; i < wScreenCount; i++) {
925 scr = wScreenWithNumber(i);
926 if (scr)
927 wReadDefaults(scr, dict);
929 if (WDWindowMaker->dictionary) {
930 WMReleasePropList(WDWindowMaker->dictionary);
932 WDWindowMaker->dictionary = dict;
934 } else {
935 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
937 if (shared_dict) {
938 WMReleasePropList(shared_dict);
942 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
943 /* global dictionary */
944 shared_dict = readGlobalDomain("WMWindowAttributes", True);
945 /* user dictionary */
946 dict = WMReadPropListFromFile(WDWindowAttributes->path);
947 if (dict) {
948 if (!WMIsPLDictionary(dict)) {
949 WMReleasePropList(dict);
950 dict = NULL;
951 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
952 "WMWindowAttributes", WDWindowAttributes->path);
953 } else {
954 if (shared_dict) {
955 WMMergePLDictionaries(shared_dict, dict, True);
956 WMReleasePropList(dict);
957 dict = shared_dict;
958 shared_dict = NULL;
960 if (WDWindowAttributes->dictionary) {
961 WMReleasePropList(WDWindowAttributes->dictionary);
963 WDWindowAttributes->dictionary = dict;
964 for (i = 0; i < wScreenCount; i++) {
965 scr = wScreenWithNumber(i);
966 if (scr) {
967 RImage *image;
969 wDefaultUpdateIcons(scr);
971 /* Update the panel image if changed */
972 /* Don't worry. If the image is the same these
973 * functions will have no performance impact. */
974 image = wDefaultGetImage(scr, "Logo", "WMPanel");
976 if (!image) {
977 wwarning(_("could not load logo image for panels: %s"),
978 RMessageForError(RErrorCode));
979 } else {
980 WMSetApplicationIconImage(scr->wmscreen, image);
981 RReleaseImage(image);
986 } else {
987 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
989 WDWindowAttributes->timestamp = stbuf.st_mtime;
990 if (shared_dict) {
991 WMReleasePropList(shared_dict);
995 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
996 dict = WMReadPropListFromFile(WDRootMenu->path);
997 if (dict) {
998 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
999 WMReleasePropList(dict);
1000 dict = NULL;
1001 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1002 "WMRootMenu", WDRootMenu->path);
1003 } else {
1004 if (WDRootMenu->dictionary) {
1005 WMReleasePropList(WDRootMenu->dictionary);
1007 WDRootMenu->dictionary = dict;
1008 wDefaultsMergeGlobalMenus(WDRootMenu);
1010 } else {
1011 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1013 WDRootMenu->timestamp = stbuf.st_mtime;
1015 #ifndef HAVE_INOTIFY
1016 if (!arg)
1017 WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
1018 #endif
1021 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1023 WMPropList *plvalue, *old_value;
1024 WDefaultEntry *entry;
1025 unsigned int i, must_update;
1026 int update_workspace_back = 0; /* kluge :/ */
1027 unsigned int needs_refresh;
1028 void *tdata;
1029 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1031 must_update = 0;
1033 needs_refresh = 0;
1035 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1036 entry = &optionList[i];
1038 if (new_dict)
1039 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1040 else
1041 plvalue = NULL;
1043 if (!old_dict)
1044 old_value = NULL;
1045 else
1046 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1048 if (!plvalue && !old_value) {
1049 /* no default in the DB. Use builtin default */
1050 plvalue = entry->plvalue;
1051 if (plvalue && new_dict) {
1052 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1053 must_update = 1;
1055 } else if (!plvalue) {
1056 /* value was deleted from DB. Keep current value */
1057 continue;
1058 } else if (!old_value) {
1059 /* set value for the 1st time */
1060 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1061 /* value has changed */
1062 } else {
1064 if (strcmp(entry->key, "WorkspaceBack") == 0
1065 && update_workspace_back && scr->flags.backimage_helper_launched) {
1066 } else {
1067 /* value was not changed since last time */
1068 continue;
1072 if (plvalue) {
1073 /* convert data */
1074 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1076 * If the WorkspaceSpecificBack data has been changed
1077 * so that the helper will be launched now, we must be
1078 * sure to send the default background texture config
1079 * to the helper.
1081 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1082 && !scr->flags.backimage_helper_launched) {
1083 update_workspace_back = 1;
1085 if (entry->update) {
1086 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1092 if (needs_refresh != 0 && !scr->flags.startup) {
1093 int foo;
1095 foo = 0;
1096 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1097 foo |= WTextureSettings;
1098 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1099 foo |= WFontSettings;
1100 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1101 foo |= WColorSettings;
1102 if (foo)
1103 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1104 (void *)(uintptr_t) foo);
1106 foo = 0;
1107 if (needs_refresh & REFRESH_MENU_TEXTURE)
1108 foo |= WTextureSettings;
1109 if (needs_refresh & REFRESH_MENU_FONT)
1110 foo |= WFontSettings;
1111 if (needs_refresh & REFRESH_MENU_COLOR)
1112 foo |= WColorSettings;
1113 if (foo)
1114 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1116 foo = 0;
1117 if (needs_refresh & REFRESH_WINDOW_FONT) {
1118 foo |= WFontSettings;
1120 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1121 foo |= WTextureSettings;
1123 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1124 foo |= WColorSettings;
1126 if (foo)
1127 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1129 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1130 foo = 0;
1131 if (needs_refresh & REFRESH_ICON_FONT) {
1132 foo |= WFontSettings;
1134 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1135 foo |= WTextureSettings;
1137 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1138 foo |= WTextureSettings;
1140 if (foo)
1141 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1142 (void *)(uintptr_t) foo);
1144 if (needs_refresh & REFRESH_ICON_TILE)
1145 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1149 void wDefaultUpdateIcons(WScreen * scr)
1151 WAppIcon *aicon = scr->app_icon_list;
1152 WWindow *wwin = scr->focused_window;
1153 char *file;
1155 while (aicon) {
1156 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1157 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1158 || (file && !aicon->icon->file)) {
1159 RImage *new_image;
1161 if (aicon->icon->file)
1162 wfree(aicon->icon->file);
1163 aicon->icon->file = wstrdup(file);
1165 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1166 if (new_image) {
1167 wIconChangeImage(aicon->icon, new_image);
1168 wAppIconPaint(aicon);
1171 aicon = aicon->next;
1174 if (!wPreferences.flags.noclip)
1175 wClipIconPaint(scr->clip_icon);
1177 while (wwin) {
1178 if (wwin->icon && wwin->flags.miniaturized) {
1179 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1180 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1181 || (file && !wwin->icon->file)) {
1182 RImage *new_image;
1184 if (wwin->icon->file)
1185 wfree(wwin->icon->file);
1186 wwin->icon->file = wstrdup(file);
1188 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1189 if (new_image)
1190 wIconChangeImage(wwin->icon, new_image);
1193 wwin = wwin->prev;
1197 /* --------------------------- Local ----------------------- */
1199 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1200 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1201 entry->key, x); \
1202 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1203 var = entry->default_value;\
1204 } else var = WMGetFromPLString(value)\
1207 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1209 char *str;
1210 WOptionEnumeration *v;
1211 char buffer[TOTAL_VALUES_LENGTH];
1213 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1214 for (v = values; v->string != NULL; v++) {
1215 if (strcasecmp(v->string, str) == 0)
1216 return v->value;
1220 buffer[0] = 0;
1221 for (v = values; v->string != NULL; v++) {
1222 if (!v->is_alias) {
1223 if (buffer[0] != 0)
1224 strcat(buffer, ", ");
1225 strcat(buffer, v->string);
1228 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1230 if (def) {
1231 return string2index(key, val, NULL, values);
1234 return -1;
1238 * value - is the value in the defaults DB
1239 * addr - is the address to store the data
1240 * ret - is the address to store a pointer to a temporary buffer. ret
1241 * must not be freed and is used by the set functions
1243 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1245 static char data;
1246 char *val;
1247 int second_pass = 0;
1249 GET_STRING_OR_DEFAULT("Boolean", val);
1251 again:
1252 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1253 || strcasecmp(val, "YES") == 0) {
1255 data = 1;
1256 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1257 || strcasecmp(val, "NO") == 0) {
1258 data = 0;
1259 } else {
1260 int i;
1261 if (sscanf(val, "%i", &i) == 1) {
1262 if (i != 0)
1263 data = 1;
1264 else
1265 data = 0;
1266 } else {
1267 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1268 if (second_pass == 0) {
1269 val = WMGetFromPLString(entry->plvalue);
1270 second_pass = 1;
1271 wwarning(_("using default \"%s\" instead"), val);
1272 goto again;
1274 return False;
1278 if (ret)
1279 *ret = &data;
1280 if (addr)
1281 *(char *)addr = data;
1283 return True;
1286 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1288 static int data;
1289 char *val;
1291 GET_STRING_OR_DEFAULT("Integer", val);
1293 if (sscanf(val, "%i", &data) != 1) {
1294 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1295 val = WMGetFromPLString(entry->plvalue);
1296 wwarning(_("using default \"%s\" instead"), val);
1297 if (sscanf(val, "%i", &data) != 1) {
1298 return False;
1302 if (ret)
1303 *ret = &data;
1304 if (addr)
1305 *(int *)addr = data;
1307 return True;
1310 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1312 static WCoord data;
1313 char *val_x, *val_y;
1314 int nelem, changed = 0;
1315 WMPropList *elem_x, *elem_y;
1317 again:
1318 if (!WMIsPLArray(value)) {
1319 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1320 if (changed == 0) {
1321 value = entry->plvalue;
1322 changed = 1;
1323 wwarning(_("using default \"%s\" instead"), entry->default_value);
1324 goto again;
1326 return False;
1329 nelem = WMGetPropListItemCount(value);
1330 if (nelem != 2) {
1331 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1332 if (changed == 0) {
1333 value = entry->plvalue;
1334 changed = 1;
1335 wwarning(_("using default \"%s\" instead"), entry->default_value);
1336 goto again;
1338 return False;
1341 elem_x = WMGetFromPLArray(value, 0);
1342 elem_y = WMGetFromPLArray(value, 1);
1344 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1345 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1346 if (changed == 0) {
1347 value = entry->plvalue;
1348 changed = 1;
1349 wwarning(_("using default \"%s\" instead"), entry->default_value);
1350 goto again;
1352 return False;
1355 val_x = WMGetFromPLString(elem_x);
1356 val_y = WMGetFromPLString(elem_y);
1358 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1359 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1360 if (changed == 0) {
1361 value = entry->plvalue;
1362 changed = 1;
1363 wwarning(_("using default \"%s\" instead"), entry->default_value);
1364 goto again;
1366 return False;
1369 if (data.x < 0)
1370 data.x = 0;
1371 else if (data.x > scr->scr_width / 3)
1372 data.x = scr->scr_width / 3;
1373 if (data.y < 0)
1374 data.y = 0;
1375 else if (data.y > scr->scr_height / 3)
1376 data.y = scr->scr_height / 3;
1378 if (ret)
1379 *ret = &data;
1380 if (addr)
1381 *(WCoord *) addr = data;
1383 return True;
1386 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1388 WMRetainPropList(value);
1390 *ret = value;
1392 return True;
1395 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1397 static char *data;
1398 int i, count, len;
1399 char *ptr;
1400 WMPropList *d;
1401 int changed = 0;
1403 again:
1404 if (!WMIsPLArray(value)) {
1405 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1406 if (changed == 0) {
1407 value = entry->plvalue;
1408 changed = 1;
1409 wwarning(_("using default \"%s\" instead"), entry->default_value);
1410 goto again;
1412 return False;
1415 i = 0;
1416 count = WMGetPropListItemCount(value);
1417 if (count < 1) {
1418 if (changed == 0) {
1419 value = entry->plvalue;
1420 changed = 1;
1421 wwarning(_("using default \"%s\" instead"), entry->default_value);
1422 goto again;
1424 return False;
1427 len = 0;
1428 for (i = 0; i < count; i++) {
1429 d = WMGetFromPLArray(value, i);
1430 if (!d || !WMIsPLString(d)) {
1431 count = i;
1432 break;
1434 len += strlen(WMGetFromPLString(d)) + 1;
1437 ptr = data = wmalloc(len + 1);
1439 for (i = 0; i < count; i++) {
1440 d = WMGetFromPLArray(value, i);
1441 if (!d || !WMIsPLString(d)) {
1442 break;
1444 strcpy(ptr, WMGetFromPLString(d));
1445 ptr += strlen(WMGetFromPLString(d));
1446 *ptr = ':';
1447 ptr++;
1449 ptr--;
1450 *(ptr--) = 0;
1452 if (*(char **)addr != NULL) {
1453 wfree(*(char **)addr);
1455 *(char **)addr = data;
1457 return True;
1460 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1462 static signed char data;
1464 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1465 if (data < 0)
1466 return False;
1468 if (ret)
1469 *ret = &data;
1470 if (addr)
1471 *(signed char *)addr = data;
1473 return True;
1477 * (solid <color>)
1478 * (hgradient <color> <color>)
1479 * (vgradient <color> <color>)
1480 * (dgradient <color> <color>)
1481 * (mhgradient <color> <color> ...)
1482 * (mvgradient <color> <color> ...)
1483 * (mdgradient <color> <color> ...)
1484 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1485 * (tpixmap <file> <color>)
1486 * (spixmap <file> <color>)
1487 * (cpixmap <file> <color>)
1488 * (thgradient <file> <opaqueness> <color> <color>)
1489 * (tvgradient <file> <opaqueness> <color> <color>)
1490 * (tdgradient <file> <opaqueness> <color> <color>)
1491 * (function <lib> <function> ...)
1494 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1496 WMPropList *elem;
1497 char *val;
1498 int nelem;
1499 WTexture *texture = NULL;
1501 nelem = WMGetPropListItemCount(pl);
1502 if (nelem < 1)
1503 return NULL;
1505 elem = WMGetFromPLArray(pl, 0);
1506 if (!elem || !WMIsPLString(elem))
1507 return NULL;
1508 val = WMGetFromPLString(elem);
1510 if (strcasecmp(val, "solid") == 0) {
1511 XColor color;
1513 if (nelem != 2)
1514 return NULL;
1516 /* get color */
1518 elem = WMGetFromPLArray(pl, 1);
1519 if (!elem || !WMIsPLString(elem))
1520 return NULL;
1521 val = WMGetFromPLString(elem);
1523 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1524 wwarning(_("\"%s\" is not a valid color name"), val);
1525 return NULL;
1528 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1529 } else if (strcasecmp(val, "dgradient") == 0
1530 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1531 RColor color1, color2;
1532 XColor xcolor;
1533 int type;
1535 if (nelem != 3) {
1536 wwarning(_("bad number of arguments in gradient specification"));
1537 return NULL;
1540 if (val[0] == 'd' || val[0] == 'D')
1541 type = WTEX_DGRADIENT;
1542 else if (val[0] == 'h' || val[0] == 'H')
1543 type = WTEX_HGRADIENT;
1544 else
1545 type = WTEX_VGRADIENT;
1547 /* get from color */
1548 elem = WMGetFromPLArray(pl, 1);
1549 if (!elem || !WMIsPLString(elem))
1550 return NULL;
1551 val = WMGetFromPLString(elem);
1553 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1554 wwarning(_("\"%s\" is not a valid color name"), val);
1555 return NULL;
1557 color1.alpha = 255;
1558 color1.red = xcolor.red >> 8;
1559 color1.green = xcolor.green >> 8;
1560 color1.blue = xcolor.blue >> 8;
1562 /* get to color */
1563 elem = WMGetFromPLArray(pl, 2);
1564 if (!elem || !WMIsPLString(elem)) {
1565 return NULL;
1567 val = WMGetFromPLString(elem);
1569 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1570 wwarning(_("\"%s\" is not a valid color name"), val);
1571 return NULL;
1573 color2.alpha = 255;
1574 color2.red = xcolor.red >> 8;
1575 color2.green = xcolor.green >> 8;
1576 color2.blue = xcolor.blue >> 8;
1578 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1580 } else if (strcasecmp(val, "igradient") == 0) {
1581 RColor colors1[2], colors2[2];
1582 int th1, th2;
1583 XColor xcolor;
1584 int i;
1586 if (nelem != 7) {
1587 wwarning(_("bad number of arguments in gradient specification"));
1588 return NULL;
1591 /* get from color */
1592 for (i = 0; i < 2; i++) {
1593 elem = WMGetFromPLArray(pl, 1 + i);
1594 if (!elem || !WMIsPLString(elem))
1595 return NULL;
1596 val = WMGetFromPLString(elem);
1598 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1599 wwarning(_("\"%s\" is not a valid color name"), val);
1600 return NULL;
1602 colors1[i].alpha = 255;
1603 colors1[i].red = xcolor.red >> 8;
1604 colors1[i].green = xcolor.green >> 8;
1605 colors1[i].blue = xcolor.blue >> 8;
1607 elem = WMGetFromPLArray(pl, 3);
1608 if (!elem || !WMIsPLString(elem))
1609 return NULL;
1610 val = WMGetFromPLString(elem);
1611 th1 = atoi(val);
1613 /* get from color */
1614 for (i = 0; i < 2; i++) {
1615 elem = WMGetFromPLArray(pl, 4 + i);
1616 if (!elem || !WMIsPLString(elem))
1617 return NULL;
1618 val = WMGetFromPLString(elem);
1620 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1621 wwarning(_("\"%s\" is not a valid color name"), val);
1622 return NULL;
1624 colors2[i].alpha = 255;
1625 colors2[i].red = xcolor.red >> 8;
1626 colors2[i].green = xcolor.green >> 8;
1627 colors2[i].blue = xcolor.blue >> 8;
1629 elem = WMGetFromPLArray(pl, 6);
1630 if (!elem || !WMIsPLString(elem))
1631 return NULL;
1632 val = WMGetFromPLString(elem);
1633 th2 = atoi(val);
1635 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1637 } else if (strcasecmp(val, "mhgradient") == 0
1638 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1639 XColor color;
1640 RColor **colors;
1641 int i, count;
1642 int type;
1644 if (nelem < 3) {
1645 wwarning(_("too few arguments in multicolor gradient specification"));
1646 return NULL;
1649 if (val[1] == 'h' || val[1] == 'H')
1650 type = WTEX_MHGRADIENT;
1651 else if (val[1] == 'v' || val[1] == 'V')
1652 type = WTEX_MVGRADIENT;
1653 else
1654 type = WTEX_MDGRADIENT;
1656 count = nelem - 1;
1658 colors = wmalloc(sizeof(RColor *) * (count + 1));
1660 for (i = 0; i < count; i++) {
1661 elem = WMGetFromPLArray(pl, i + 1);
1662 if (!elem || !WMIsPLString(elem)) {
1663 for (--i; i >= 0; --i) {
1664 wfree(colors[i]);
1666 wfree(colors);
1667 return NULL;
1669 val = WMGetFromPLString(elem);
1671 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1672 wwarning(_("\"%s\" is not a valid color name"), val);
1673 for (--i; i >= 0; --i) {
1674 wfree(colors[i]);
1676 wfree(colors);
1677 return NULL;
1678 } else {
1679 colors[i] = wmalloc(sizeof(RColor));
1680 colors[i]->red = color.red >> 8;
1681 colors[i]->green = color.green >> 8;
1682 colors[i]->blue = color.blue >> 8;
1685 colors[i] = NULL;
1687 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1688 } else if (strcasecmp(val, "spixmap") == 0 ||
1689 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1690 XColor color;
1691 int type;
1693 if (nelem != 3)
1694 return NULL;
1696 if (val[0] == 's' || val[0] == 'S')
1697 type = WTP_SCALE;
1698 else if (val[0] == 'c' || val[0] == 'C')
1699 type = WTP_CENTER;
1700 else
1701 type = WTP_TILE;
1703 /* get color */
1704 elem = WMGetFromPLArray(pl, 2);
1705 if (!elem || !WMIsPLString(elem)) {
1706 return NULL;
1708 val = WMGetFromPLString(elem);
1710 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1711 wwarning(_("\"%s\" is not a valid color name"), val);
1712 return NULL;
1715 /* file name */
1716 elem = WMGetFromPLArray(pl, 1);
1717 if (!elem || !WMIsPLString(elem))
1718 return NULL;
1719 val = WMGetFromPLString(elem);
1721 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1722 } else if (strcasecmp(val, "thgradient") == 0
1723 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1724 RColor color1, color2;
1725 XColor xcolor;
1726 int opacity;
1727 int style;
1729 if (val[1] == 'h' || val[1] == 'H')
1730 style = WTEX_THGRADIENT;
1731 else if (val[1] == 'v' || val[1] == 'V')
1732 style = WTEX_TVGRADIENT;
1733 else
1734 style = WTEX_TDGRADIENT;
1736 if (nelem != 5) {
1737 wwarning(_("bad number of arguments in textured gradient specification"));
1738 return NULL;
1741 /* get from color */
1742 elem = WMGetFromPLArray(pl, 3);
1743 if (!elem || !WMIsPLString(elem))
1744 return NULL;
1745 val = WMGetFromPLString(elem);
1747 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1748 wwarning(_("\"%s\" is not a valid color name"), val);
1749 return NULL;
1751 color1.alpha = 255;
1752 color1.red = xcolor.red >> 8;
1753 color1.green = xcolor.green >> 8;
1754 color1.blue = xcolor.blue >> 8;
1756 /* get to color */
1757 elem = WMGetFromPLArray(pl, 4);
1758 if (!elem || !WMIsPLString(elem)) {
1759 return NULL;
1761 val = WMGetFromPLString(elem);
1763 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1764 wwarning(_("\"%s\" is not a valid color name"), val);
1765 return NULL;
1767 color2.alpha = 255;
1768 color2.red = xcolor.red >> 8;
1769 color2.green = xcolor.green >> 8;
1770 color2.blue = xcolor.blue >> 8;
1772 /* get opacity */
1773 elem = WMGetFromPLArray(pl, 2);
1774 if (!elem || !WMIsPLString(elem))
1775 opacity = 128;
1776 else
1777 val = WMGetFromPLString(elem);
1779 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1780 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1781 opacity = 128;
1784 /* get file name */
1785 elem = WMGetFromPLArray(pl, 1);
1786 if (!elem || !WMIsPLString(elem))
1787 return NULL;
1788 val = WMGetFromPLString(elem);
1790 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1791 } else if (strcasecmp(val, "function") == 0) {
1792 /* Leave this in to handle the unlikely case of
1793 * someone actually having function textures configured */
1794 wwarning("function texture support has been removed");
1795 return NULL;
1796 } else {
1797 wwarning(_("invalid texture type %s"), val);
1798 return NULL;
1800 return texture;
1803 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1805 static WTexture *texture;
1806 int changed = 0;
1808 again:
1809 if (!WMIsPLArray(value)) {
1810 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1811 if (changed == 0) {
1812 value = entry->plvalue;
1813 changed = 1;
1814 wwarning(_("using default \"%s\" instead"), entry->default_value);
1815 goto again;
1817 return False;
1820 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1821 WMPropList *pl;
1823 pl = WMGetFromPLArray(value, 0);
1824 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1825 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1826 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1827 entry->key, "Solid Texture");
1829 value = entry->plvalue;
1830 changed = 1;
1831 wwarning(_("using default \"%s\" instead"), entry->default_value);
1832 goto again;
1836 texture = parse_texture(scr, value);
1838 if (!texture) {
1839 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1840 if (changed == 0) {
1841 value = entry->plvalue;
1842 changed = 1;
1843 wwarning(_("using default \"%s\" instead"), entry->default_value);
1844 goto again;
1846 return False;
1849 if (ret)
1850 *ret = &texture;
1852 if (addr)
1853 *(WTexture **) addr = texture;
1855 return True;
1858 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1860 WMPropList *elem;
1861 int changed = 0;
1862 char *val;
1863 int nelem;
1865 again:
1866 if (!WMIsPLArray(value)) {
1867 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1868 "WorkspaceBack", "Texture or None");
1869 if (changed == 0) {
1870 value = entry->plvalue;
1871 changed = 1;
1872 wwarning(_("using default \"%s\" instead"), entry->default_value);
1873 goto again;
1875 return False;
1878 /* only do basic error checking and verify for None texture */
1880 nelem = WMGetPropListItemCount(value);
1881 if (nelem > 0) {
1882 elem = WMGetFromPLArray(value, 0);
1883 if (!elem || !WMIsPLString(elem)) {
1884 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1885 if (changed == 0) {
1886 value = entry->plvalue;
1887 changed = 1;
1888 wwarning(_("using default \"%s\" instead"), entry->default_value);
1889 goto again;
1891 return False;
1893 val = WMGetFromPLString(elem);
1895 if (strcasecmp(val, "None") == 0)
1896 return True;
1898 *ret = WMRetainPropList(value);
1900 return True;
1903 static int
1904 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1906 WMPropList *elem;
1907 int nelem;
1908 int changed = 0;
1910 again:
1911 if (!WMIsPLArray(value)) {
1912 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1913 "WorkspaceSpecificBack", "an array of textures");
1914 if (changed == 0) {
1915 value = entry->plvalue;
1916 changed = 1;
1917 wwarning(_("using default \"%s\" instead"), entry->default_value);
1918 goto again;
1920 return False;
1923 /* only do basic error checking and verify for None texture */
1925 nelem = WMGetPropListItemCount(value);
1926 if (nelem > 0) {
1927 while (nelem--) {
1928 elem = WMGetFromPLArray(value, nelem);
1929 if (!elem || !WMIsPLArray(elem)) {
1930 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1931 nelem);
1936 *ret = WMRetainPropList(value);
1938 #ifdef notworking
1940 * Kluge to force wmsetbg helper to set the default background.
1941 * If the WorkspaceSpecificBack is changed once wmaker has started,
1942 * the WorkspaceBack won't be sent to the helper, unless the user
1943 * changes it's value too. So, we must force this by removing the
1944 * value from the defaults DB.
1946 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
1947 WMPropList *key = WMCreatePLString("WorkspaceBack");
1949 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
1951 WMReleasePropList(key);
1953 #endif
1954 return True;
1957 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1959 static WMFont *font;
1960 char *val;
1962 GET_STRING_OR_DEFAULT("Font", val);
1964 font = WMCreateFont(scr->wmscreen, val);
1965 if (!font)
1966 font = WMCreateFont(scr->wmscreen, "fixed");
1968 if (!font) {
1969 wfatal(_("could not load any usable font!!!"));
1970 exit(1);
1973 if (ret)
1974 *ret = font;
1976 /* can't assign font value outside update function */
1977 wassertrv(addr == NULL, True);
1979 return True;
1982 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1984 static XColor color;
1985 char *val;
1986 int second_pass = 0;
1988 GET_STRING_OR_DEFAULT("Color", val);
1990 again:
1991 if (!wGetColor(scr, val, &color)) {
1992 wwarning(_("could not get color for key \"%s\""), entry->key);
1993 if (second_pass == 0) {
1994 val = WMGetFromPLString(entry->plvalue);
1995 second_pass = 1;
1996 wwarning(_("using default \"%s\" instead"), val);
1997 goto again;
1999 return False;
2002 if (ret)
2003 *ret = &color;
2005 assert(addr == NULL);
2007 if (addr)
2008 *(unsigned long*)addr = pixel;
2011 return True;
2014 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2016 static WShortKey shortcut;
2017 KeySym ksym;
2018 char *val;
2019 char *k;
2020 char buf[MAX_SHORTCUT_LENGTH], *b;
2022 GET_STRING_OR_DEFAULT("Key spec", val);
2024 if (!val || strcasecmp(val, "NONE") == 0) {
2025 shortcut.keycode = 0;
2026 shortcut.modifier = 0;
2027 if (ret)
2028 *ret = &shortcut;
2029 return True;
2032 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2034 b = (char *)buf;
2036 /* get modifiers */
2037 shortcut.modifier = 0;
2038 while ((k = strchr(b, '+')) != NULL) {
2039 int mod;
2041 *k = 0;
2042 mod = wXModifierFromKey(b);
2043 if (mod < 0) {
2044 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2045 return False;
2047 shortcut.modifier |= mod;
2049 b = k + 1;
2052 /* get key */
2053 ksym = XStringToKeysym(b);
2055 if (ksym == NoSymbol) {
2056 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2057 return False;
2060 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2061 if (shortcut.keycode == 0) {
2062 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2063 return False;
2066 if (ret)
2067 *ret = &shortcut;
2069 return True;
2072 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2074 static int mask;
2075 char *str;
2077 GET_STRING_OR_DEFAULT("Modifier Key", str);
2079 if (!str)
2080 return False;
2082 mask = wXModifierFromKey(str);
2083 if (mask < 0) {
2084 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2085 mask = 0;
2086 return False;
2089 if (addr)
2090 *(int *)addr = mask;
2092 if (ret)
2093 *ret = &mask;
2095 return True;
2098 # include <X11/cursorfont.h>
2099 typedef struct {
2100 char *name;
2101 int id;
2102 } WCursorLookup;
2104 #define CURSOR_ID_NONE (XC_num_glyphs)
2106 static WCursorLookup cursor_table[] = {
2107 {"X_cursor", XC_X_cursor},
2108 {"arrow", XC_arrow},
2109 {"based_arrow_down", XC_based_arrow_down},
2110 {"based_arrow_up", XC_based_arrow_up},
2111 {"boat", XC_boat},
2112 {"bogosity", XC_bogosity},
2113 {"bottom_left_corner", XC_bottom_left_corner},
2114 {"bottom_right_corner", XC_bottom_right_corner},
2115 {"bottom_side", XC_bottom_side},
2116 {"bottom_tee", XC_bottom_tee},
2117 {"box_spiral", XC_box_spiral},
2118 {"center_ptr", XC_center_ptr},
2119 {"circle", XC_circle},
2120 {"clock", XC_clock},
2121 {"coffee_mug", XC_coffee_mug},
2122 {"cross", XC_cross},
2123 {"cross_reverse", XC_cross_reverse},
2124 {"crosshair", XC_crosshair},
2125 {"diamond_cross", XC_diamond_cross},
2126 {"dot", XC_dot},
2127 {"dotbox", XC_dotbox},
2128 {"double_arrow", XC_double_arrow},
2129 {"draft_large", XC_draft_large},
2130 {"draft_small", XC_draft_small},
2131 {"draped_box", XC_draped_box},
2132 {"exchange", XC_exchange},
2133 {"fleur", XC_fleur},
2134 {"gobbler", XC_gobbler},
2135 {"gumby", XC_gumby},
2136 {"hand1", XC_hand1},
2137 {"hand2", XC_hand2},
2138 {"heart", XC_heart},
2139 {"icon", XC_icon},
2140 {"iron_cross", XC_iron_cross},
2141 {"left_ptr", XC_left_ptr},
2142 {"left_side", XC_left_side},
2143 {"left_tee", XC_left_tee},
2144 {"leftbutton", XC_leftbutton},
2145 {"ll_angle", XC_ll_angle},
2146 {"lr_angle", XC_lr_angle},
2147 {"man", XC_man},
2148 {"middlebutton", XC_middlebutton},
2149 {"mouse", XC_mouse},
2150 {"pencil", XC_pencil},
2151 {"pirate", XC_pirate},
2152 {"plus", XC_plus},
2153 {"question_arrow", XC_question_arrow},
2154 {"right_ptr", XC_right_ptr},
2155 {"right_side", XC_right_side},
2156 {"right_tee", XC_right_tee},
2157 {"rightbutton", XC_rightbutton},
2158 {"rtl_logo", XC_rtl_logo},
2159 {"sailboat", XC_sailboat},
2160 {"sb_down_arrow", XC_sb_down_arrow},
2161 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2162 {"sb_left_arrow", XC_sb_left_arrow},
2163 {"sb_right_arrow", XC_sb_right_arrow},
2164 {"sb_up_arrow", XC_sb_up_arrow},
2165 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2166 {"shuttle", XC_shuttle},
2167 {"sizing", XC_sizing},
2168 {"spider", XC_spider},
2169 {"spraycan", XC_spraycan},
2170 {"star", XC_star},
2171 {"target", XC_target},
2172 {"tcross", XC_tcross},
2173 {"top_left_arrow", XC_top_left_arrow},
2174 {"top_left_corner", XC_top_left_corner},
2175 {"top_right_corner", XC_top_right_corner},
2176 {"top_side", XC_top_side},
2177 {"top_tee", XC_top_tee},
2178 {"trek", XC_trek},
2179 {"ul_angle", XC_ul_angle},
2180 {"umbrella", XC_umbrella},
2181 {"ur_angle", XC_ur_angle},
2182 {"watch", XC_watch},
2183 {"xterm", XC_xterm},
2184 {NULL, CURSOR_ID_NONE}
2187 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2189 switch (status) {
2190 case BitmapOpenFailed:
2191 wwarning(_("failed to open bitmap file \"%s\""), filename);
2192 break;
2193 case BitmapFileInvalid:
2194 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2195 break;
2196 case BitmapNoMemory:
2197 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2198 break;
2199 case BitmapSuccess:
2200 XFreePixmap(dpy, bitmap);
2201 break;
2206 * (none)
2207 * (builtin, <cursor_name>)
2208 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2210 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2212 WMPropList *elem;
2213 char *val;
2214 int nelem;
2215 int status = 0;
2217 nelem = WMGetPropListItemCount(pl);
2218 if (nelem < 1) {
2219 return (status);
2221 elem = WMGetFromPLArray(pl, 0);
2222 if (!elem || !WMIsPLString(elem)) {
2223 return (status);
2225 val = WMGetFromPLString(elem);
2227 if (0 == strcasecmp(val, "none")) {
2228 status = 1;
2229 *cursor = None;
2230 } else if (0 == strcasecmp(val, "builtin")) {
2231 int i;
2232 int cursor_id = CURSOR_ID_NONE;
2234 if (2 != nelem) {
2235 wwarning(_("bad number of arguments in cursor specification"));
2236 return (status);
2238 elem = WMGetFromPLArray(pl, 1);
2239 if (!elem || !WMIsPLString(elem)) {
2240 return (status);
2242 val = WMGetFromPLString(elem);
2244 for (i = 0; NULL != cursor_table[i].name; i++) {
2245 if (0 == strcasecmp(val, cursor_table[i].name)) {
2246 cursor_id = cursor_table[i].id;
2247 break;
2250 if (CURSOR_ID_NONE == cursor_id) {
2251 wwarning(_("unknown builtin cursor name \"%s\""), val);
2252 } else {
2253 *cursor = XCreateFontCursor(dpy, cursor_id);
2254 status = 1;
2256 } else if (0 == strcasecmp(val, "bitmap")) {
2257 char *bitmap_name;
2258 char *mask_name;
2259 int bitmap_status;
2260 int mask_status;
2261 Pixmap bitmap;
2262 Pixmap mask;
2263 unsigned int w, h;
2264 int x, y;
2265 XColor fg, bg;
2267 if (3 != nelem) {
2268 wwarning(_("bad number of arguments in cursor specification"));
2269 return (status);
2271 elem = WMGetFromPLArray(pl, 1);
2272 if (!elem || !WMIsPLString(elem)) {
2273 return (status);
2275 val = WMGetFromPLString(elem);
2276 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2277 if (!bitmap_name) {
2278 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2279 return (status);
2281 elem = WMGetFromPLArray(pl, 2);
2282 if (!elem || !WMIsPLString(elem)) {
2283 wfree(bitmap_name);
2284 return (status);
2286 val = WMGetFromPLString(elem);
2287 mask_name = FindImage(wPreferences.pixmap_path, val);
2288 if (!mask_name) {
2289 wfree(bitmap_name);
2290 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2291 return (status);
2293 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2294 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2295 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2296 fg.pixel = scr->black_pixel;
2297 bg.pixel = scr->white_pixel;
2298 XQueryColor(dpy, scr->w_colormap, &fg);
2299 XQueryColor(dpy, scr->w_colormap, &bg);
2300 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2301 status = 1;
2303 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2304 check_bitmap_status(mask_status, mask_name, mask);
2305 wfree(bitmap_name);
2306 wfree(mask_name);
2308 return (status);
2311 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2313 static Cursor cursor;
2314 int status;
2315 int changed = 0;
2317 again:
2318 if (!WMIsPLArray(value)) {
2319 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2320 entry->key, "cursor specification");
2321 if (!changed) {
2322 value = entry->plvalue;
2323 changed = 1;
2324 wwarning(_("using default \"%s\" instead"), entry->default_value);
2325 goto again;
2327 return (False);
2329 status = parse_cursor(scr, value, &cursor);
2330 if (!status) {
2331 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2332 if (!changed) {
2333 value = entry->plvalue;
2334 changed = 1;
2335 wwarning(_("using default \"%s\" instead"), entry->default_value);
2336 goto again;
2338 return (False);
2340 if (ret) {
2341 *ret = &cursor;
2343 if (addr) {
2344 *(Cursor *) addr = cursor;
2346 return (True);
2349 #undef CURSOR_ID_NONE
2351 /* ---------------- value setting functions --------------- */
2352 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2354 return REFRESH_WINDOW_TITLE_COLOR;
2357 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2359 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2362 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2364 switch (which) {
2365 case WM_DOCK:
2366 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2367 break;
2368 case WM_CLIP:
2369 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2370 break;
2371 default:
2372 break;
2374 return 0;
2377 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2379 if (scr->workspaces) {
2380 wWorkspaceForceChange(scr, scr->current_workspace);
2381 wArrangeIcons(scr, False);
2383 return 0;
2386 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2388 Pixmap pixmap;
2389 RImage *img;
2390 int reset = 0;
2392 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2393 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2394 ? WREL_ICON : WREL_FLAT);
2395 if (!img) {
2396 wwarning(_("could not render texture for icon background"));
2397 if (!entry->addr)
2398 wTextureDestroy(scr, *texture);
2399 return 0;
2401 RConvertImage(scr->rcontext, img, &pixmap);
2403 if (scr->icon_tile) {
2404 reset = 1;
2405 RReleaseImage(scr->icon_tile);
2406 XFreePixmap(dpy, scr->icon_tile_pixmap);
2409 scr->icon_tile = img;
2411 /* put the icon in the noticeboard hint */
2412 PropSetIconTileHint(scr, img);
2414 if (!wPreferences.flags.noclip) {
2415 if (scr->clip_tile) {
2416 RReleaseImage(scr->clip_tile);
2418 scr->clip_tile = wClipMakeTile(scr, img);
2421 scr->icon_tile_pixmap = pixmap;
2423 if (scr->def_icon_pixmap) {
2424 XFreePixmap(dpy, scr->def_icon_pixmap);
2425 scr->def_icon_pixmap = None;
2427 if (scr->def_ticon_pixmap) {
2428 XFreePixmap(dpy, scr->def_ticon_pixmap);
2429 scr->def_ticon_pixmap = None;
2432 if (scr->icon_back_texture) {
2433 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2435 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2437 if (scr->clip_balloon)
2438 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2441 * Free the texture as nobody else will use it, nor refer to it.
2443 if (!entry->addr)
2444 wTextureDestroy(scr, *texture);
2446 return (reset ? REFRESH_ICON_TILE : 0);
2449 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2451 if (scr->title_font) {
2452 WMReleaseFont(scr->title_font);
2454 scr->title_font = font;
2456 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2459 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2461 if (scr->menu_title_font) {
2462 WMReleaseFont(scr->menu_title_font);
2465 scr->menu_title_font = font;
2467 return REFRESH_MENU_TITLE_FONT;
2470 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2472 if (scr->menu_entry_font) {
2473 WMReleaseFont(scr->menu_entry_font);
2475 scr->menu_entry_font = font;
2477 return REFRESH_MENU_FONT;
2480 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2482 if (scr->icon_title_font) {
2483 WMReleaseFont(scr->icon_title_font);
2486 scr->icon_title_font = font;
2488 return REFRESH_ICON_FONT;
2491 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2493 if (scr->clip_title_font) {
2494 WMReleaseFont(scr->clip_title_font);
2497 scr->clip_title_font = font;
2499 return REFRESH_ICON_FONT;
2502 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2504 if (scr->workspace_name_font) {
2505 WMReleaseFont(scr->workspace_name_font);
2508 scr->workspace_name_font = font;
2510 return 0;
2513 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2515 if (scr->select_color)
2516 WMReleaseColor(scr->select_color);
2518 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2520 wFreeColor(scr, color->pixel);
2522 return REFRESH_MENU_COLOR;
2525 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2527 if (scr->select_text_color)
2528 WMReleaseColor(scr->select_text_color);
2530 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2532 wFreeColor(scr, color->pixel);
2534 return REFRESH_MENU_COLOR;
2537 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2539 if (scr->clip_title_color[widx])
2540 WMReleaseColor(scr->clip_title_color[widx]);
2541 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2542 #ifdef GRADIENT_CLIP_ARROW
2543 if (widx == CLIP_NORMAL) {
2544 RImage *image;
2545 RColor color1, color2;
2546 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2547 int as = pt - 15; /* 15 = 5+5+5 */
2549 FREE_PIXMAP(scr->clip_arrow_gradient);
2551 color1.red = (color->red >> 8) * 6 / 10;
2552 color1.green = (color->green >> 8) * 6 / 10;
2553 color1.blue = (color->blue >> 8) * 6 / 10;
2555 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2556 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2557 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2559 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2560 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2561 RReleaseImage(image);
2563 #endif /* GRADIENT_CLIP_ARROW */
2565 wFreeColor(scr, color->pixel);
2567 return REFRESH_ICON_TITLE_COLOR;
2570 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2572 if (scr->window_title_color[widx])
2573 WMReleaseColor(scr->window_title_color[widx]);
2575 scr->window_title_color[widx] =
2576 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2578 wFreeColor(scr, color->pixel);
2580 return REFRESH_WINDOW_TITLE_COLOR;
2583 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2585 if (scr->menu_title_color[0])
2586 WMReleaseColor(scr->menu_title_color[0]);
2588 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2590 wFreeColor(scr, color->pixel);
2592 return REFRESH_MENU_TITLE_COLOR;
2595 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2597 if (scr->mtext_color)
2598 WMReleaseColor(scr->mtext_color);
2600 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2602 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2603 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2604 } else {
2605 WMSetColorAlpha(scr->dtext_color, 0xffff);
2608 wFreeColor(scr, color->pixel);
2610 return REFRESH_MENU_COLOR;
2613 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2615 if (scr->dtext_color)
2616 WMReleaseColor(scr->dtext_color);
2618 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2620 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2621 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2622 } else {
2623 WMSetColorAlpha(scr->dtext_color, 0xffff);
2626 wFreeColor(scr, color->pixel);
2628 return REFRESH_MENU_COLOR;
2631 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2633 if (scr->icon_title_color)
2634 WMReleaseColor(scr->icon_title_color);
2635 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2637 wFreeColor(scr, color->pixel);
2639 return REFRESH_ICON_TITLE_COLOR;
2642 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2644 if (scr->icon_title_texture) {
2645 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2647 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2649 return REFRESH_ICON_TITLE_BACK;
2652 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2654 close(scr->helper_fd);
2655 scr->helper_fd = 0;
2656 scr->helper_pid = 0;
2657 scr->flags.backimage_helper_launched = 0;
2660 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2662 WMPropList *val;
2663 char *str;
2664 int i;
2666 if (scr->flags.backimage_helper_launched) {
2667 if (WMGetPropListItemCount(value) == 0) {
2668 SendHelperMessage(scr, 'C', 0, NULL);
2669 SendHelperMessage(scr, 'K', 0, NULL);
2671 WMReleasePropList(value);
2672 return 0;
2674 } else {
2675 pid_t pid;
2676 int filedes[2];
2678 if (WMGetPropListItemCount(value) == 0)
2679 return 0;
2681 if (pipe(filedes) < 0) {
2682 wsyserror("pipe() failed:can't set workspace specific background image");
2684 WMReleasePropList(value);
2685 return 0;
2688 pid = fork();
2689 if (pid < 0) {
2690 wsyserror("fork() failed:can't set workspace specific background image");
2691 if (close(filedes[0]) < 0)
2692 wsyserror("could not close pipe");
2693 if (close(filedes[1]) < 0)
2694 wsyserror("could not close pipe");
2696 } else if (pid == 0) {
2697 char *dither;
2699 SetupEnvironment(scr);
2701 if (close(0) < 0)
2702 wsyserror("could not close pipe");
2703 if (dup(filedes[0]) < 0) {
2704 wsyserror("dup() failed:can't set workspace specific background image");
2706 dither = wPreferences.no_dithering ? "-m" : "-d";
2707 if (wPreferences.smooth_workspace_back)
2708 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2709 else
2710 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2711 wsyserror("could not execute wmsetbg");
2712 exit(1);
2713 } else {
2715 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2716 wsyserror("error setting close-on-exec flag");
2718 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2719 wsyserror("error setting close-on-exec flag");
2722 scr->helper_fd = filedes[1];
2723 scr->helper_pid = pid;
2724 scr->flags.backimage_helper_launched = 1;
2726 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2728 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2733 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2734 val = WMGetFromPLArray(value, i);
2735 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2736 str = WMGetPropListDescription(val, False);
2738 SendHelperMessage(scr, 'S', i + 1, str);
2740 wfree(str);
2741 } else {
2742 SendHelperMessage(scr, 'U', i + 1, NULL);
2745 sleep(1);
2747 WMReleasePropList(value);
2748 return 0;
2751 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2753 if (scr->flags.backimage_helper_launched) {
2754 char *str;
2756 if (WMGetPropListItemCount(value) == 0) {
2757 SendHelperMessage(scr, 'U', 0, NULL);
2758 } else {
2759 /* set the default workspace background to this one */
2760 str = WMGetPropListDescription(value, False);
2761 if (str) {
2762 SendHelperMessage(scr, 'S', 0, str);
2763 wfree(str);
2764 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2765 } else {
2766 SendHelperMessage(scr, 'U', 0, NULL);
2769 } else if (WMGetPropListItemCount(value) > 0) {
2770 char *command;
2771 char *text;
2772 char *dither;
2773 int len;
2775 text = WMGetPropListDescription(value, False);
2776 len = strlen(text) + 40;
2777 command = wmalloc(len);
2778 dither = wPreferences.no_dithering ? "-m" : "-d";
2779 if (wPreferences.smooth_workspace_back)
2780 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2781 else
2782 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2783 wfree(text);
2784 ExecuteShellCommand(scr, command);
2785 wfree(command);
2787 WMReleasePropList(value);
2789 return 0;
2792 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2794 if (scr->widget_texture) {
2795 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2797 scr->widget_texture = *(WTexSolid **) texture;
2799 return 0;
2802 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2804 if (scr->window_title_texture[WS_FOCUSED]) {
2805 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2807 scr->window_title_texture[WS_FOCUSED] = *texture;
2809 return REFRESH_WINDOW_TEXTURES;
2812 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2814 if (scr->window_title_texture[WS_PFOCUSED]) {
2815 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2817 scr->window_title_texture[WS_PFOCUSED] = *texture;
2819 return REFRESH_WINDOW_TEXTURES;
2822 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2824 if (scr->window_title_texture[WS_UNFOCUSED]) {
2825 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2827 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2829 return REFRESH_WINDOW_TEXTURES;
2832 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2834 if (scr->resizebar_texture[0]) {
2835 wTextureDestroy(scr, scr->resizebar_texture[0]);
2837 scr->resizebar_texture[0] = *texture;
2839 return REFRESH_WINDOW_TEXTURES;
2842 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2844 if (scr->menu_title_texture[0]) {
2845 wTextureDestroy(scr, scr->menu_title_texture[0]);
2847 scr->menu_title_texture[0] = *texture;
2849 return REFRESH_MENU_TITLE_TEXTURE;
2852 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2854 if (scr->menu_item_texture) {
2855 wTextureDestroy(scr, scr->menu_item_texture);
2856 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2858 scr->menu_item_texture = *texture;
2860 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2862 return REFRESH_MENU_TEXTURE;
2865 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2867 WWindow *wwin;
2868 wKeyBindings[widx] = *shortcut;
2870 wwin = scr->focused_window;
2872 while (wwin != NULL) {
2873 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2875 if (!WFLAGP(wwin, no_bind_keys)) {
2876 wWindowSetKeyGrabs(wwin);
2878 wwin = wwin->prev;
2881 return 0;
2884 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2886 wScreenUpdateUsableArea(scr);
2887 wArrangeIcons(scr, True);
2889 return 0;
2892 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2894 wScreenUpdateUsableArea(scr);
2896 return 0;
2899 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2901 return REFRESH_MENU_TEXTURE;
2904 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2906 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2908 RCopyArea(img, image, x, y, w, h, 0, 0);
2910 return img;
2913 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2915 char *path;
2916 RImage *bgimage;
2917 int cwidth, cheight;
2918 WPreferences *prefs = (WPreferences *) foo;
2920 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2921 if (prefs->swtileImage)
2922 RReleaseImage(prefs->swtileImage);
2923 prefs->swtileImage = NULL;
2925 WMReleasePropList(array);
2926 return 0;
2929 switch (WMGetPropListItemCount(array)) {
2930 case 4:
2931 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2932 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2933 break;
2934 } else
2935 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2937 if (!path) {
2938 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2939 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2940 } else {
2941 bgimage = RLoadImage(scr->rcontext, path, 0);
2942 if (!bgimage) {
2943 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
2944 wfree(path);
2945 } else {
2946 wfree(path);
2948 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
2949 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
2951 if (cwidth <= 0 || cheight <= 0 ||
2952 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
2953 wwarning(_("Invalid split sizes for SwitchPanel back image."));
2954 else {
2955 int i;
2956 int swidth, theight;
2957 for (i = 0; i < 9; i++) {
2958 if (prefs->swbackImage[i])
2959 RReleaseImage(prefs->swbackImage[i]);
2960 prefs->swbackImage[i] = NULL;
2962 swidth = (bgimage->width - cwidth) / 2;
2963 theight = (bgimage->height - cheight) / 2;
2965 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
2966 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
2967 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
2968 swidth, theight);
2970 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
2971 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
2972 cwidth, cheight);
2973 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
2974 swidth, cheight);
2976 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
2977 swidth, theight);
2978 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
2979 cwidth, theight);
2980 prefs->swbackImage[8] =
2981 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
2982 theight);
2984 // check if anything failed
2985 for (i = 0; i < 9; i++) {
2986 if (!prefs->swbackImage[i]) {
2987 for (; i >= 0; --i) {
2988 RReleaseImage(prefs->swbackImage[i]);
2989 prefs->swbackImage[i] = NULL;
2991 break;
2995 RReleaseImage(bgimage);
2999 case 1:
3000 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3001 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3002 break;
3003 } else
3004 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3006 if (!path) {
3007 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3008 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3009 } else {
3010 if (prefs->swtileImage)
3011 RReleaseImage(prefs->swtileImage);
3013 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3014 if (!prefs->swtileImage) {
3015 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3017 wfree(path);
3019 break;
3021 default:
3022 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3023 break;
3026 WMReleasePropList(array);
3028 return 0;
3032 * Very ugly kluge.
3033 * Need access to the double click variables, so that all widgets in
3034 * wmaker panels will have the same dbl-click values.
3035 * TODO: figure a better way of dealing with it.
3037 #include <WINGs/WINGsP.h>
3039 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3041 extern _WINGsConfiguration WINGsConfiguration;
3043 if (*value <= 0)
3044 *(int *)foo = 1;
3046 WINGsConfiguration.doubleClickDelay = *value;
3048 return 0;
3051 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3053 if (wCursor[widx] != None) {
3054 XFreeCursor(dpy, wCursor[widx]);
3057 wCursor[widx] = *cursor;
3059 if (widx == WCUR_ROOT && *cursor != None) {
3060 XDefineCursor(dpy, scr->root_win, *cursor);
3063 return 0;