Remove HEARTBEAT #ifdef's
[wmaker-crm.git] / src / defaults.c
blob8108c98ed66ef8c95c6b7b48103c995aac9c0cff
1 /* defaults.c - manage configuration through defaults db
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <limits.h>
37 #include <signal.h>
39 #ifdef HAVE_DLFCN_H
40 # include <dlfcn.h>
41 #endif
43 #ifndef PATH_MAX
44 #define PATH_MAX DEFAULT_PATH_MAX
45 #endif
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49 #include <X11/keysym.h>
51 #include <wraster.h>
53 #include "WindowMaker.h"
54 #include "wcore.h"
55 #include "framewin.h"
56 #include "window.h"
57 #include "texture.h"
58 #include "screen.h"
59 #include "resources.h"
60 #include "defaults.h"
61 #include "keybind.h"
62 #include "xmodifier.h"
63 #include "icon.h"
64 #include "funcs.h"
65 #include "actions.h"
66 #include "dock.h"
67 #include "workspace.h"
68 #include "properties.h"
70 #define MAX_SHORTCUT_LENGTH 32
72 #ifndef GLOBAL_DEFAULTS_SUBDIR
73 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
74 #endif
76 /***** Global *****/
78 extern WDDomain *WDWindowMaker;
79 extern WDDomain *WDWindowAttributes;
80 extern WDDomain *WDRootMenu;
82 extern int wScreenCount;
84 extern Atom _XA_WINDOWMAKER_ICON_SIZE;
85 extern Atom _XA_WINDOWMAKER_ICON_TILE;
87 extern WPreferences wPreferences;
89 extern WShortKey wKeyBindings[WKBD_LAST];
91 typedef struct {
92 char *key;
93 char *default_value;
94 void *extra_data;
95 void *addr;
96 int (*convert) ();
97 int (*update) ();
98 WMPropList *plkey;
99 WMPropList *plvalue; /* default value */
100 } WDefaultEntry;
102 /* used to map strings to integers */
103 typedef struct {
104 char *string;
105 short value;
106 char is_alias;
107 } WOptionEnumeration;
109 /* type converters */
110 static int getBool();
111 static int getInt();
112 static int getCoord();
113 static int getPathList();
114 static int getEnum();
115 static int getTexture();
116 static int getWSBackground();
117 static int getWSSpecificBackground();
118 static int getFont();
119 static int getColor();
120 static int getKeybind();
121 static int getModMask();
122 #ifdef NEWSTUFF
123 static int getRImage();
124 #endif
125 static int getPropList();
127 /* value setting functions */
128 static int setJustify();
129 static int setClearance();
130 static int setIfDockPresent();
131 static int setStickyIcons();
132 static int setWidgetColor();
133 static int setIconTile();
134 static int setWinTitleFont();
135 static int setMenuTitleFont();
136 static int setMenuTextFont();
137 static int setIconTitleFont();
138 static int setIconTitleColor();
139 static int setIconTitleBack();
140 static int setLargeDisplayFont();
141 static int setWTitleColor();
142 static int setFTitleBack();
143 static int setPTitleBack();
144 static int setUTitleBack();
145 static int setResizebarBack();
146 static int setWorkspaceBack();
147 static int setWorkspaceSpecificBack();
148 static int setMenuTitleColor();
149 static int setMenuTextColor();
150 static int setMenuDisabledColor();
151 static int setMenuTitleBack();
152 static int setMenuTextBack();
153 static int setHightlight();
154 static int setHightlightText();
155 static int setKeyGrab();
156 static int setDoubleClick();
157 static int setIconPosition();
159 static int setClipTitleFont();
160 static int setClipTitleColor();
162 static int setMenuStyle();
163 static int setSwPOptions();
164 static int updateUsableArea();
166 extern Cursor wCursor[WCUR_LAST];
167 static int getCursor();
168 static int setCursor();
171 * Tables to convert strings to enumeration values.
172 * Values stored are char
175 /* WARNING: sum of length of all value strings must not exceed
176 * this value */
177 #define TOTAL_VALUES_LENGTH 80
179 #define REFRESH_WINDOW_TEXTURES (1<<0)
180 #define REFRESH_MENU_TEXTURE (1<<1)
181 #define REFRESH_MENU_FONT (1<<2)
182 #define REFRESH_MENU_COLOR (1<<3)
183 #define REFRESH_MENU_TITLE_TEXTURE (1<<4)
184 #define REFRESH_MENU_TITLE_FONT (1<<5)
185 #define REFRESH_MENU_TITLE_COLOR (1<<6)
186 #define REFRESH_WINDOW_TITLE_COLOR (1<<7)
187 #define REFRESH_WINDOW_FONT (1<<8)
188 #define REFRESH_ICON_TILE (1<<9)
189 #define REFRESH_ICON_FONT (1<<10)
190 #define REFRESH_WORKSPACE_BACK (1<<11)
192 #define REFRESH_BUTTON_IMAGES (1<<12)
194 #define REFRESH_ICON_TITLE_COLOR (1<<13)
195 #define REFRESH_ICON_TITLE_BACK (1<<14)
197 static WOptionEnumeration seFocusModes[] = {
198 {"Manual", WKF_CLICK, 0}, {"ClickToFocus", WKF_CLICK, 1},
199 {"Sloppy", WKF_SLOPPY, 0}, {"SemiAuto", WKF_SLOPPY, 1}, {"Auto", WKF_SLOPPY, 1},
200 {NULL, 0, 0}
203 static WOptionEnumeration seColormapModes[] = {
204 {"Manual", WCM_CLICK, 0}, {"ClickToFocus", WCM_CLICK, 1},
205 {"Auto", WCM_POINTER, 0}, {"FocusFollowMouse", WCM_POINTER, 1},
206 {NULL, 0, 0}
209 static WOptionEnumeration sePlacements[] = {
210 {"Auto", WPM_AUTO, 0},
211 {"Smart", WPM_SMART, 0},
212 {"Cascade", WPM_CASCADE, 0},
213 {"Random", WPM_RANDOM, 0},
214 {"Manual", WPM_MANUAL, 0},
215 {NULL, 0, 0}
218 static WOptionEnumeration seGeomDisplays[] = {
219 {"None", WDIS_NONE, 0},
220 {"Center", WDIS_CENTER, 0},
221 {"Corner", WDIS_TOPLEFT, 0},
222 {"Floating", WDIS_FRAME_CENTER, 0},
223 {"Line", WDIS_NEW, 0},
224 {NULL, 0, 0}
227 static WOptionEnumeration seSpeeds[] = {
228 {"UltraFast", SPEED_ULTRAFAST, 0},
229 {"Fast", SPEED_FAST, 0},
230 {"Medium", SPEED_MEDIUM, 0},
231 {"Slow", SPEED_SLOW, 0},
232 {"UltraSlow", SPEED_ULTRASLOW, 0},
233 {NULL, 0, 0}
236 static WOptionEnumeration seMouseButtonActions[] = {
237 {"None", WA_NONE, 0},
238 {"SelectWindows", WA_SELECT_WINDOWS, 0},
239 {"OpenApplicationsMenu", WA_OPEN_APPMENU, 0},
240 {"OpenWindowListMenu", WA_OPEN_WINLISTMENU, 0},
241 {NULL, 0, 0}
244 static WOptionEnumeration seMouseWheelActions[] = {
245 {"None", WA_NONE, 0},
246 {"SwitchWorkspaces", WA_SWITCH_WORKSPACES, 0},
247 {NULL, 0, 0}
250 static WOptionEnumeration seIconificationStyles[] = {
251 {"Zoom", WIS_ZOOM, 0},
252 {"Twist", WIS_TWIST, 0},
253 {"Flip", WIS_FLIP, 0},
254 {"None", WIS_NONE, 0},
255 {"random", WIS_RANDOM, 0},
256 {NULL, 0, 0}
259 static WOptionEnumeration seJustifications[] = {
260 {"Left", WTJ_LEFT, 0},
261 {"Center", WTJ_CENTER, 0},
262 {"Right", WTJ_RIGHT, 0},
263 {NULL, 0, 0}
266 static WOptionEnumeration seIconPositions[] = {
267 {"blv", IY_BOTTOM | IY_LEFT | IY_VERT, 0},
268 {"blh", IY_BOTTOM | IY_LEFT | IY_HORIZ, 0},
269 {"brv", IY_BOTTOM | IY_RIGHT | IY_VERT, 0},
270 {"brh", IY_BOTTOM | IY_RIGHT | IY_HORIZ, 0},
271 {"tlv", IY_TOP | IY_LEFT | IY_VERT, 0},
272 {"tlh", IY_TOP | IY_LEFT | IY_HORIZ, 0},
273 {"trv", IY_TOP | IY_RIGHT | IY_VERT, 0},
274 {"trh", IY_TOP | IY_RIGHT | IY_HORIZ, 0},
275 {NULL, 0, 0}
278 static WOptionEnumeration seMenuStyles[] = {
279 {"normal", MS_NORMAL, 0},
280 {"singletexture", MS_SINGLE_TEXTURE, 0},
281 {"flat", MS_FLAT, 0},
282 {NULL, 0, 0}
285 static WOptionEnumeration seDisplayPositions[] = {
286 {"none", WD_NONE, 0},
287 {"center", WD_CENTER, 0},
288 {"top", WD_TOP, 0},
289 {"bottom", WD_BOTTOM, 0},
290 {"topleft", WD_TOPLEFT, 0},
291 {"topright", WD_TOPRIGHT, 0},
292 {"bottomleft", WD_BOTTOMLEFT, 0},
293 {"bottomright", WD_BOTTOMRIGHT, 0},
294 {NULL, 0, 0}
297 static WOptionEnumeration seWorkspaceBorder[] = {
298 {"None", WB_NONE, 0},
299 {"LeftRight", WB_LEFTRIGHT, 0},
300 {"TopBottom", WB_TOPBOTTOM, 0},
301 {"AllDirections", WB_ALLDIRS, 0},
302 {NULL, 0, 0}
306 * ALL entries in the tables bellow, NEED to have a default value
307 * defined, and this value needs to be correct.
310 /* these options will only affect the window manager on startup
312 * static defaults can't access the screen data, because it is
313 * created after these defaults are read
315 WDefaultEntry staticOptionList[] = {
317 {"ColormapSize", "4", NULL,
318 &wPreferences.cmap_size, getInt, NULL},
319 {"DisableDithering", "NO", NULL,
320 &wPreferences.no_dithering, getBool, NULL},
321 /* static by laziness */
322 {"IconSize", "64", NULL,
323 &wPreferences.icon_size, getInt, NULL},
324 {"ModifierKey", "Mod1", NULL,
325 &wPreferences.modifier_mask, getModMask, NULL},
326 {"DisableWSMouseActions", "NO", NULL,
327 &wPreferences.disable_root_mouse, getBool, NULL},
328 {"FocusMode", "manual", seFocusModes,
329 &wPreferences.focus_mode, getEnum, NULL}, /* have a problem when switching from manual to sloppy without restart */
330 {"NewStyle", "NO", NULL,
331 &wPreferences.new_style, getBool, NULL},
332 {"DisableDock", "NO", (void *)WM_DOCK,
333 NULL, getBool, setIfDockPresent},
334 {"DisableClip", "NO", (void *)WM_CLIP,
335 NULL, getBool, setIfDockPresent},
336 {"DisableMiniwindows", "NO", NULL,
337 &wPreferences.disable_miniwindows, getBool, NULL}
340 WDefaultEntry optionList[] = {
341 /* dynamic options */
342 {"IconPosition", "blh", seIconPositions,
343 &wPreferences.icon_yard, getEnum, setIconPosition},
344 {"IconificationStyle", "Zoom", seIconificationStyles,
345 &wPreferences.iconification_style, getEnum, NULL},
346 {"MouseLeftButtonAction", "SelectWindows", seMouseButtonActions,
347 &wPreferences.mouse_button1, getEnum, NULL},
348 {"MouseMiddleButtonAction", "OpenWindowListMenu", seMouseButtonActions,
349 &wPreferences.mouse_button2, getEnum, NULL},
350 {"MouseRightButtonAction", "OpenApplicationsMenu", seMouseButtonActions,
351 &wPreferences.mouse_button3, getEnum, NULL},
352 {"MouseWheelAction", "None", seMouseWheelActions,
353 &wPreferences.mouse_wheel, getEnum, NULL},
354 {"PixmapPath", DEF_PIXMAP_PATHS, NULL,
355 &wPreferences.pixmap_path, getPathList, NULL},
356 {"IconPath", DEF_ICON_PATHS, NULL,
357 &wPreferences.icon_path, getPathList, NULL},
358 {"ColormapMode", "auto", seColormapModes,
359 &wPreferences.colormap_mode, getEnum, NULL},
360 {"AutoFocus", "NO", NULL,
361 &wPreferences.auto_focus, getBool, NULL},
362 {"RaiseDelay", "0", NULL,
363 &wPreferences.raise_delay, getInt, NULL},
364 {"CirculateRaise", "NO", NULL,
365 &wPreferences.circ_raise, getBool, NULL},
366 {"Superfluous", "NO", NULL,
367 &wPreferences.superfluous, getBool, NULL},
368 {"AdvanceToNewWorkspace", "NO", NULL,
369 &wPreferences.ws_advance, getBool, NULL},
370 {"CycleWorkspaces", "NO", NULL,
371 &wPreferences.ws_cycle, getBool, NULL},
372 {"WorkspaceNameDisplayPosition", "center", seDisplayPositions,
373 &wPreferences.workspace_name_display_position, getEnum, NULL},
374 {"WorkspaceBorder", "None", seWorkspaceBorder,
375 &wPreferences.workspace_border_position, getEnum, updateUsableArea},
376 {"WorkspaceBorderSize", "0", NULL,
377 &wPreferences.workspace_border_size, getInt, updateUsableArea},
378 {"StickyIcons", "NO", NULL,
379 &wPreferences.sticky_icons, getBool, setStickyIcons},
380 {"SaveSessionOnExit", "NO", NULL,
381 &wPreferences.save_session_on_exit, getBool, NULL},
382 {"WrapMenus", "NO", NULL,
383 &wPreferences.wrap_menus, getBool, NULL},
384 {"ScrollableMenus", "NO", NULL,
385 &wPreferences.scrollable_menus, getBool, NULL},
386 {"MenuScrollSpeed", "medium", seSpeeds,
387 &wPreferences.menu_scroll_speed, getEnum, NULL},
388 {"IconSlideSpeed", "medium", seSpeeds,
389 &wPreferences.icon_slide_speed, getEnum, NULL},
390 {"ShadeSpeed", "medium", seSpeeds,
391 &wPreferences.shade_speed, getEnum, NULL},
392 {"DoubleClickTime", "250", (void *)&wPreferences.dblclick_time,
393 &wPreferences.dblclick_time, getInt, setDoubleClick,
395 {"AlignSubmenus", "NO", NULL,
396 &wPreferences.align_menus, getBool, NULL},
397 {"OpenTransientOnOwnerWorkspace", "NO", NULL,
398 &wPreferences.open_transients_with_parent, getBool, NULL},
399 {"WindowPlacement", "auto", sePlacements,
400 &wPreferences.window_placement, getEnum, NULL},
401 {"IgnoreFocusClick", "NO", NULL,
402 &wPreferences.ignore_focus_click, getBool, NULL},
403 {"UseSaveUnders", "NO", NULL,
404 &wPreferences.use_saveunders, getBool, NULL},
405 {"OpaqueMove", "NO", NULL,
406 &wPreferences.opaque_move, getBool, NULL},
407 {"DisableAnimations", "NO", NULL,
408 &wPreferences.no_animations, getBool, NULL},
409 {"DontLinkWorkspaces", "NO", NULL,
410 &wPreferences.no_autowrap, getBool, NULL},
411 {"AutoArrangeIcons", "NO", NULL,
412 &wPreferences.auto_arrange_icons, getBool, NULL},
413 {"NoWindowOverDock", "NO", NULL,
414 &wPreferences.no_window_over_dock, getBool, updateUsableArea},
415 {"NoWindowOverIcons", "NO", NULL,
416 &wPreferences.no_window_over_icons, getBool, updateUsableArea},
417 {"WindowPlaceOrigin", "(0, 0)", NULL,
418 &wPreferences.window_place_origin, getCoord, NULL},
419 {"ResizeDisplay", "corner", seGeomDisplays,
420 &wPreferences.size_display, getEnum, NULL},
421 {"MoveDisplay", "corner", seGeomDisplays,
422 &wPreferences.move_display, getEnum, NULL},
423 {"DontConfirmKill", "NO", NULL,
424 &wPreferences.dont_confirm_kill, getBool, NULL},
425 {"WindowTitleBalloons", "NO", NULL,
426 &wPreferences.window_balloon, getBool, NULL},
427 {"MiniwindowTitleBalloons", "NO", NULL,
428 &wPreferences.miniwin_balloon, getBool, NULL},
429 {"AppIconBalloons", "NO", NULL,
430 &wPreferences.appicon_balloon, getBool, NULL},
431 {"HelpBalloons", "NO", NULL,
432 &wPreferences.help_balloon, getBool, NULL},
433 {"EdgeResistance", "30", NULL,
434 &wPreferences.edge_resistance, getInt, NULL},
435 {"ResizeIncrement", "32", NULL,
436 &wPreferences.resize_increment, getInt, NULL},
437 {"Attraction", "NO", NULL,
438 &wPreferences.attract, getBool, NULL},
439 {"DisableBlinking", "NO", NULL,
440 &wPreferences.dont_blink, getBool, NULL},
441 {"SingleClickLaunch", "NO", NULL,
442 &wPreferences.single_click, getBool, NULL},
443 /* style options */
444 {"MenuStyle", "normal", seMenuStyles,
445 &wPreferences.menu_style, getEnum, setMenuStyle},
446 {"WidgetColor", "(solid, gray)", NULL,
447 NULL, getTexture, setWidgetColor,
449 {"WorkspaceSpecificBack", "()", NULL,
450 NULL, getWSSpecificBackground, setWorkspaceSpecificBack},
451 /* WorkspaceBack must come after WorkspaceSpecificBack or
452 * WorkspaceBack wont know WorkspaceSpecificBack was also
453 * specified and 2 copies of wmsetbg will be launched */
454 {"WorkspaceBack", "(solid, black)", NULL,
455 NULL, getWSBackground, setWorkspaceBack},
456 {"SmoothWorkspaceBack", "NO", NULL,
457 NULL, getBool, NULL},
458 {"IconBack", "(solid, gray)", NULL,
459 NULL, getTexture, setIconTile},
460 {"TitleJustify", "center", seJustifications,
461 &wPreferences.title_justification, getEnum, setJustify},
462 {"WindowTitleFont", DEF_TITLE_FONT, NULL,
463 NULL, getFont, setWinTitleFont,
465 {"WindowTitleExtendSpace", DEF_WINDOW_TITLE_EXTEND_SPACE, NULL,
466 &wPreferences.window_title_clearance, getInt, setClearance},
467 {"MenuTitleExtendSpace", DEF_MENU_TITLE_EXTEND_SPACE, NULL,
468 &wPreferences.menu_title_clearance, getInt, setClearance},
469 {"MenuTextExtendSpace", DEF_MENU_TEXT_EXTEND_SPACE, NULL,
470 &wPreferences.menu_text_clearance, getInt, setClearance},
471 {"MenuTitleFont", DEF_MENU_TITLE_FONT, NULL,
472 NULL, getFont, setMenuTitleFont},
473 {"MenuTextFont", DEF_MENU_ENTRY_FONT, NULL,
474 NULL, getFont, setMenuTextFont},
475 {"IconTitleFont", DEF_ICON_TITLE_FONT, NULL,
476 NULL, getFont, setIconTitleFont},
477 {"ClipTitleFont", DEF_CLIP_TITLE_FONT, NULL,
478 NULL, getFont, setClipTitleFont},
479 {"LargeDisplayFont", DEF_WORKSPACE_NAME_FONT, NULL,
480 NULL, getFont, setLargeDisplayFont},
481 {"HighlightColor", "white", NULL,
482 NULL, getColor, setHightlight},
483 {"HighlightTextColor", "black", NULL,
484 NULL, getColor, setHightlightText},
485 {"ClipTitleColor", "black", (void *)CLIP_NORMAL,
486 NULL, getColor, setClipTitleColor},
487 {"CClipTitleColor", "\"#454045\"", (void *)CLIP_COLLAPSED,
488 NULL, getColor, setClipTitleColor},
489 {"FTitleColor", "white", (void *)WS_FOCUSED,
490 NULL, getColor, setWTitleColor},
491 {"PTitleColor", "white", (void *)WS_PFOCUSED,
492 NULL, getColor, setWTitleColor},
493 {"UTitleColor", "black", (void *)WS_UNFOCUSED,
494 NULL, getColor, setWTitleColor},
495 {"FTitleBack", "(solid, black)", NULL,
496 NULL, getTexture, setFTitleBack},
497 {"PTitleBack", "(solid, \"#616161\")", NULL,
498 NULL, getTexture, setPTitleBack},
499 {"UTitleBack", "(solid, gray)", NULL,
500 NULL, getTexture, setUTitleBack},
501 {"ResizebarBack", "(solid, gray)", NULL,
502 NULL, getTexture, setResizebarBack},
503 {"MenuTitleColor", "white", NULL,
504 NULL, getColor, setMenuTitleColor},
505 {"MenuTextColor", "black", NULL,
506 NULL, getColor, setMenuTextColor},
507 {"MenuDisabledColor", "\"#616161\"", NULL,
508 NULL, getColor, setMenuDisabledColor},
509 {"MenuTitleBack", "(solid, black)", NULL,
510 NULL, getTexture, setMenuTitleBack},
511 {"MenuTextBack", "(solid, gray)", NULL,
512 NULL, getTexture, setMenuTextBack},
513 {"IconTitleColor", "white", NULL,
514 NULL, getColor, setIconTitleColor},
515 {"IconTitleBack", "black", NULL,
516 NULL, getColor, setIconTitleBack},
517 {"SwitchPanelImages", "(swtile.png, swback.png, 30, 40)", &wPreferences,
518 NULL, getPropList, setSwPOptions},
519 /* keybindings */
520 {"RootMenuKey", "None", (void *)WKBD_ROOTMENU,
521 NULL, getKeybind, setKeyGrab},
522 {"WindowListKey", "None", (void *)WKBD_WINDOWLIST,
523 NULL, getKeybind, setKeyGrab},
524 {"WindowMenuKey", "None", (void *)WKBD_WINDOWMENU,
525 NULL, getKeybind, setKeyGrab},
526 {"DockRaiseLowerKey", "None", (void*)WKBD_DOCKRAISELOWER,
527 NULL, getKeybind, setKeyGrab},
528 {"ClipRaiseLowerKey", "None", (void *)WKBD_CLIPRAISELOWER,
529 NULL, getKeybind, setKeyGrab},
530 {"MiniaturizeKey", "None", (void *)WKBD_MINIATURIZE,
531 NULL, getKeybind, setKeyGrab},
532 {"HideKey", "None", (void *)WKBD_HIDE,
533 NULL, getKeybind, setKeyGrab},
534 {"HideOthersKey", "None", (void *)WKBD_HIDE_OTHERS,
535 NULL, getKeybind, setKeyGrab},
536 {"MoveResizeKey", "None", (void *)WKBD_MOVERESIZE,
537 NULL, getKeybind, setKeyGrab},
538 {"CloseKey", "None", (void *)WKBD_CLOSE,
539 NULL, getKeybind, setKeyGrab},
540 {"MaximizeKey", "None", (void *)WKBD_MAXIMIZE,
541 NULL, getKeybind, setKeyGrab},
542 {"VMaximizeKey", "None", (void *)WKBD_VMAXIMIZE,
543 NULL, getKeybind, setKeyGrab},
544 {"HMaximizeKey", "None", (void *)WKBD_HMAXIMIZE,
545 NULL, getKeybind, setKeyGrab},
546 {"LHMaximizeKey", "None", (void*)WKBD_LHMAXIMIZE,
547 NULL, getKeybind, setKeyGrab},
548 {"RHMaximizeKey", "None", (void*)WKBD_RHMAXIMIZE,
549 NULL, getKeybind, setKeyGrab},
550 {"MaximusKey", "None", (void*)WKBD_MAXIMUS,
551 NULL, getKeybind, setKeyGrab},
552 {"RaiseKey", "\"Meta+Up\"", (void *)WKBD_RAISE,
553 NULL, getKeybind, setKeyGrab},
554 {"LowerKey", "\"Meta+Down\"", (void *)WKBD_LOWER,
555 NULL, getKeybind, setKeyGrab},
556 {"RaiseLowerKey", "None", (void *)WKBD_RAISELOWER,
557 NULL, getKeybind, setKeyGrab},
558 {"ShadeKey", "None", (void *)WKBD_SHADE,
559 NULL, getKeybind, setKeyGrab},
560 {"SelectKey", "None", (void *)WKBD_SELECT,
561 NULL, getKeybind, setKeyGrab},
562 {"FocusNextKey", "None", (void *)WKBD_FOCUSNEXT,
563 NULL, getKeybind, setKeyGrab},
564 {"FocusPrevKey", "None", (void *)WKBD_FOCUSPREV,
565 NULL, getKeybind, setKeyGrab},
566 {"GroupNextKey", "None", (void *)WKBD_GROUPNEXT,
567 NULL, getKeybind, setKeyGrab},
568 {"GroupPrevKey", "None", (void *)WKBD_GROUPPREV,
569 NULL, getKeybind, setKeyGrab},
570 {"NextWorkspaceKey", "None", (void *)WKBD_NEXTWORKSPACE,
571 NULL, getKeybind, setKeyGrab},
572 {"PrevWorkspaceKey", "None", (void *)WKBD_PREVWORKSPACE,
573 NULL, getKeybind, setKeyGrab},
574 {"NextWorkspaceLayerKey", "None", (void *)WKBD_NEXTWSLAYER,
575 NULL, getKeybind, setKeyGrab},
576 {"PrevWorkspaceLayerKey", "None", (void *)WKBD_PREVWSLAYER,
577 NULL, getKeybind, setKeyGrab},
578 {"Workspace1Key", "None", (void *)WKBD_WORKSPACE1,
579 NULL, getKeybind, setKeyGrab},
580 {"Workspace2Key", "None", (void *)WKBD_WORKSPACE2,
581 NULL, getKeybind, setKeyGrab},
582 {"Workspace3Key", "None", (void *)WKBD_WORKSPACE3,
583 NULL, getKeybind, setKeyGrab},
584 {"Workspace4Key", "None", (void *)WKBD_WORKSPACE4,
585 NULL, getKeybind, setKeyGrab},
586 {"Workspace5Key", "None", (void *)WKBD_WORKSPACE5,
587 NULL, getKeybind, setKeyGrab},
588 {"Workspace6Key", "None", (void *)WKBD_WORKSPACE6,
589 NULL, getKeybind, setKeyGrab},
590 {"Workspace7Key", "None", (void *)WKBD_WORKSPACE7,
591 NULL, getKeybind, setKeyGrab},
592 {"Workspace8Key", "None", (void *)WKBD_WORKSPACE8,
593 NULL, getKeybind, setKeyGrab},
594 {"Workspace9Key", "None", (void *)WKBD_WORKSPACE9,
595 NULL, getKeybind, setKeyGrab},
596 {"Workspace10Key", "None", (void *)WKBD_WORKSPACE10,
597 NULL, getKeybind, setKeyGrab},
598 {"WindowShortcut1Key", "None", (void *)WKBD_WINDOW1,
599 NULL, getKeybind, setKeyGrab},
600 {"WindowShortcut2Key", "None", (void *)WKBD_WINDOW2,
601 NULL, getKeybind, setKeyGrab},
602 {"WindowShortcut3Key", "None", (void *)WKBD_WINDOW3,
603 NULL, getKeybind, setKeyGrab},
604 {"WindowShortcut4Key", "None", (void *)WKBD_WINDOW4,
605 NULL, getKeybind, setKeyGrab}
606 , {"WindowShortcut5Key", "None", (void *)WKBD_WINDOW5,
607 NULL, getKeybind, setKeyGrab},
608 {"WindowShortcut6Key", "None", (void *)WKBD_WINDOW6,
609 NULL, getKeybind, setKeyGrab},
610 {"WindowShortcut7Key", "None", (void *)WKBD_WINDOW7,
611 NULL, getKeybind, setKeyGrab},
612 {"WindowShortcut8Key", "None", (void *)WKBD_WINDOW8,
613 NULL, getKeybind, setKeyGrab},
614 {"WindowShortcut9Key", "None", (void *)WKBD_WINDOW9,
615 NULL, getKeybind, setKeyGrab},
616 {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
617 NULL, getKeybind, setKeyGrab},
618 {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
619 NULL, getKeybind, setKeyGrab},
621 #ifdef KEEP_XKB_LOCK_STATUS
622 {"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,
623 NULL, getKeybind, setKeyGrab},
624 {"KbdModeLock", "NO", NULL,
625 &wPreferences.modelock, getBool, NULL},
626 #endif /* KEEP_XKB_LOCK_STATUS */
628 {"NormalCursor", "(builtin, left_ptr)", (void *)WCUR_ROOT,
629 NULL, getCursor, setCursor},
630 {"ArrowCursor", "(builtin, top_left_arrow)", (void *)WCUR_ARROW,
631 NULL, getCursor, setCursor},
632 {"MoveCursor", "(builtin, fleur)", (void *)WCUR_MOVE,
633 NULL, getCursor, setCursor},
634 {"ResizeCursor", "(builtin, sizing)", (void *)WCUR_RESIZE,
635 NULL, getCursor, setCursor},
636 {"TopLeftResizeCursor", "(builtin, top_left_corner)",
637 (void *)WCUR_TOPLEFTRESIZE,
638 NULL, getCursor, setCursor},
639 {"TopRightResizeCursor", "(builtin, top_right_corner)",
640 (void *)WCUR_TOPRIGHTRESIZE,
641 NULL, getCursor, setCursor},
642 {"BottomLeftResizeCursor", "(builtin, bottom_left_corner)",
643 (void *)WCUR_BOTTOMLEFTRESIZE,
644 NULL, getCursor, setCursor},
645 {"BottomRightResizeCursor", "(builtin, bottom_right_corner)",
646 (void *)WCUR_BOTTOMRIGHTRESIZE,
647 NULL, getCursor, setCursor},
648 {"VerticalResizeCursor", "(builtin, sb_v_double_arrow)",
649 (void *)WCUR_VERTICALRESIZE,
650 NULL, getCursor, setCursor},
651 {"HorizontalResizeCursor", "(builtin, sb_h_double_arrow)",
652 (void *)WCUR_HORIZONRESIZE,
653 NULL, getCursor, setCursor},
654 {"WaitCursor", "(builtin, watch)", (void *)WCUR_WAIT,
655 NULL, getCursor, setCursor},
656 {"QuestionCursor", "(builtin, question_arrow)", (void *)WCUR_QUESTION,
657 NULL, getCursor, setCursor},
658 {"TextCursor", "(builtin, xterm)", (void *)WCUR_TEXT,
659 NULL, getCursor, setCursor},
660 {"SelectCursor", "(builtin, cross)", (void *)WCUR_SELECT,
661 NULL, getCursor, setCursor},
662 {"DialogHistoryLines", "500", NULL,
663 &wPreferences.history_lines, getInt, NULL}
666 #if 0
667 static void rereadDefaults(void)
669 /* must defer the update because accessing X data from a
670 * signal handler can mess up Xlib */
673 #endif
675 static void initDefaults()
677 unsigned int i;
678 WDefaultEntry *entry;
680 WMPLSetCaseSensitive(False);
682 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
683 entry = &optionList[i];
685 entry->plkey = WMCreatePLString(entry->key);
686 if (entry->default_value)
687 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
688 else
689 entry->plvalue = NULL;
692 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
693 entry = &staticOptionList[i];
695 entry->plkey = WMCreatePLString(entry->key);
696 if (entry->default_value)
697 entry->plvalue = WMCreatePropListFromDescription(entry->default_value);
698 else
699 entry->plvalue = NULL;
703 wDomainName = WMCreatePLString(WMDOMAIN_NAME);
704 wAttributeDomainName = WMCreatePLString(WMATTRIBUTE_DOMAIN_NAME);
706 PLRegister(wDomainName, rereadDefaults);
707 PLRegister(wAttributeDomainName, rereadDefaults);
711 static WMPropList *readGlobalDomain(char *domainName, Bool requireDictionary)
713 WMPropList *globalDict = NULL;
714 char path[PATH_MAX];
715 struct stat stbuf;
717 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domainName);
718 if (stat(path, &stbuf) >= 0) {
719 globalDict = WMReadPropListFromFile(path);
720 if (globalDict && requireDictionary && !WMIsPLDictionary(globalDict)) {
721 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"), domainName, path);
722 WMReleasePropList(globalDict);
723 globalDict = NULL;
724 } else if (!globalDict) {
725 wwarning(_("could not load domain %s from global defaults database"), domainName);
729 return globalDict;
732 #if defined(GLOBAL_PREAMBLE_MENU_FILE) || defined(GLOBAL_EPILOGUE_MENU_FILE)
733 static void prependMenu(WMPropList * destarr, WMPropList * array)
735 WMPropList *item;
736 int i;
738 for (i = 0; i < WMGetPropListItemCount(array); i++) {
739 item = WMGetFromPLArray(array, i);
740 if (item)
741 WMInsertInPLArray(destarr, i + 1, item);
745 static void appendMenu(WMPropList * destarr, WMPropList * array)
747 WMPropList *item;
748 int i;
750 for (i = 0; i < WMGetPropListItemCount(array); i++) {
751 item = WMGetFromPLArray(array, i);
752 if (item)
753 WMAddToPLArray(destarr, item);
756 #endif
758 void wDefaultsMergeGlobalMenus(WDDomain * menuDomain)
760 WMPropList *menu = menuDomain->dictionary;
761 WMPropList *submenu;
763 if (!menu || !WMIsPLArray(menu))
764 return;
766 #ifdef GLOBAL_PREAMBLE_MENU_FILE
767 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_PREAMBLE_MENU_FILE);
769 if (submenu && !WMIsPLArray(submenu)) {
770 wwarning(_("invalid global menu file %s"), GLOBAL_PREAMBLE_MENU_FILE);
771 WMReleasePropList(submenu);
772 submenu = NULL;
774 if (submenu) {
775 prependMenu(menu, submenu);
776 WMReleasePropList(submenu);
778 #endif
780 #ifdef GLOBAL_EPILOGUE_MENU_FILE
781 submenu = WMReadPropListFromFile(SYSCONFDIR "/" GLOBAL_DEFAULTS_SUBDIR "/" GLOBAL_EPILOGUE_MENU_FILE);
783 if (submenu && !WMIsPLArray(submenu)) {
784 wwarning(_("invalid global menu file %s"), GLOBAL_EPILOGUE_MENU_FILE);
785 WMReleasePropList(submenu);
786 submenu = NULL;
788 if (submenu) {
789 appendMenu(menu, submenu);
790 WMReleasePropList(submenu);
792 #endif
794 menuDomain->dictionary = menu;
797 void wDefaultsDestroyDomain(WDDomain * domain)
799 if (domain->dictionary)
800 WMReleasePropList(domain->dictionary);
801 wfree(domain->path);
802 wfree(domain);
805 WDDomain *wDefaultsInitDomain(char *domain, Bool requireDictionary)
807 WDDomain *db;
808 struct stat stbuf;
809 static int inited = 0;
810 char path[PATH_MAX];
811 char *the_path;
812 WMPropList *shared_dict = NULL;
814 if (!inited) {
815 inited = 1;
816 initDefaults();
819 db = wmalloc(sizeof(WDDomain));
820 memset(db, 0, sizeof(WDDomain));
821 db->domain_name = domain;
822 db->path = wdefaultspathfordomain(domain);
823 the_path = db->path;
825 if (the_path && stat(the_path, &stbuf) >= 0) {
826 db->dictionary = WMReadPropListFromFile(the_path);
827 if (db->dictionary) {
828 if (requireDictionary && !WMIsPLDictionary(db->dictionary)) {
829 WMReleasePropList(db->dictionary);
830 db->dictionary = NULL;
831 wwarning(_("Domain %s (%s) of defaults database is corrupted!"), domain, the_path);
833 db->timestamp = stbuf.st_mtime;
834 } else {
835 wwarning(_("could not load domain %s from user defaults database"), domain);
839 /* global system dictionary */
840 snprintf(path, sizeof(path), "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
841 if (stat(path, &stbuf) >= 0) {
842 shared_dict = WMReadPropListFromFile(path);
843 if (shared_dict) {
844 if (requireDictionary && !WMIsPLDictionary(shared_dict)) {
845 wwarning(_("Domain %s (%s) of global defaults database is corrupted!"),
846 domain, path);
847 WMReleasePropList(shared_dict);
848 shared_dict = NULL;
849 } else {
850 if (db->dictionary && WMIsPLDictionary(shared_dict) &&
851 WMIsPLDictionary(db->dictionary)) {
852 WMMergePLDictionaries(shared_dict, db->dictionary, True);
853 WMReleasePropList(db->dictionary);
854 db->dictionary = shared_dict;
855 if (stbuf.st_mtime > db->timestamp)
856 db->timestamp = stbuf.st_mtime;
857 } else if (!db->dictionary) {
858 db->dictionary = shared_dict;
859 if (stbuf.st_mtime > db->timestamp)
860 db->timestamp = stbuf.st_mtime;
863 } else {
864 wwarning(_("could not load domain %s from global defaults database (%s)"), domain, path);
868 return db;
871 void wReadStaticDefaults(WMPropList * dict)
873 WMPropList *plvalue;
874 WDefaultEntry *entry;
875 unsigned int i;
876 void *tdata;
878 for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
879 entry = &staticOptionList[i];
881 if (dict)
882 plvalue = WMGetFromPLDictionary(dict, entry->plkey);
883 else
884 plvalue = NULL;
886 if (!plvalue) {
887 /* no default in the DB. Use builtin default */
888 plvalue = entry->plvalue;
891 if (plvalue) {
892 /* convert data */
893 (*entry->convert) (NULL, entry, plvalue, entry->addr, &tdata);
894 if (entry->update) {
895 (*entry->update) (NULL, entry, tdata, entry->extra_data);
901 void wDefaultsCheckDomains(void)
903 WScreen *scr;
904 struct stat stbuf;
905 WMPropList *shared_dict = NULL;
906 WMPropList *dict;
907 int i;
909 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
910 WDWindowMaker->timestamp = stbuf.st_mtime;
912 /* global dictionary */
913 shared_dict = readGlobalDomain("WindowMaker", True);
914 /* user dictionary */
915 dict = WMReadPropListFromFile(WDWindowMaker->path);
916 if (dict) {
917 if (!WMIsPLDictionary(dict)) {
918 WMReleasePropList(dict);
919 dict = NULL;
920 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
921 "WindowMaker", WDWindowMaker->path);
922 } else {
923 if (shared_dict) {
924 WMMergePLDictionaries(shared_dict, dict, True);
925 WMReleasePropList(dict);
926 dict = shared_dict;
927 shared_dict = NULL;
929 for (i = 0; i < wScreenCount; i++) {
930 scr = wScreenWithNumber(i);
931 if (scr)
932 wReadDefaults(scr, dict);
934 if (WDWindowMaker->dictionary) {
935 WMReleasePropList(WDWindowMaker->dictionary);
937 WDWindowMaker->dictionary = dict;
939 } else {
940 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
942 if (shared_dict) {
943 WMReleasePropList(shared_dict);
947 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
948 /* global dictionary */
949 shared_dict = readGlobalDomain("WMWindowAttributes", True);
950 /* user dictionary */
951 dict = WMReadPropListFromFile(WDWindowAttributes->path);
952 if (dict) {
953 if (!WMIsPLDictionary(dict)) {
954 WMReleasePropList(dict);
955 dict = NULL;
956 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
957 "WMWindowAttributes", WDWindowAttributes->path);
958 } else {
959 if (shared_dict) {
960 WMMergePLDictionaries(shared_dict, dict, True);
961 WMReleasePropList(dict);
962 dict = shared_dict;
963 shared_dict = NULL;
965 if (WDWindowAttributes->dictionary) {
966 WMReleasePropList(WDWindowAttributes->dictionary);
968 WDWindowAttributes->dictionary = dict;
969 for (i = 0; i < wScreenCount; i++) {
970 scr = wScreenWithNumber(i);
971 if (scr) {
972 RImage *image;
974 wDefaultUpdateIcons(scr);
976 /* Update the panel image if changed */
977 /* Don't worry. If the image is the same these
978 * functions will have no performance impact. */
979 image = wDefaultGetImage(scr, "Logo", "WMPanel");
981 if (!image) {
982 wwarning(_("could not load logo image for panels: %s"),
983 RMessageForError(RErrorCode));
984 } else {
985 WMSetApplicationIconImage(scr->wmscreen, image);
986 RReleaseImage(image);
991 } else {
992 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
994 WDWindowAttributes->timestamp = stbuf.st_mtime;
995 if (shared_dict) {
996 WMReleasePropList(shared_dict);
1000 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1001 dict = WMReadPropListFromFile(WDRootMenu->path);
1002 if (dict) {
1003 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1004 WMReleasePropList(dict);
1005 dict = NULL;
1006 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1007 "WMRootMenu", WDRootMenu->path);
1008 } else {
1009 if (WDRootMenu->dictionary) {
1010 WMReleasePropList(WDRootMenu->dictionary);
1012 WDRootMenu->dictionary = dict;
1013 wDefaultsMergeGlobalMenus(WDRootMenu);
1015 } else {
1016 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1018 WDRootMenu->timestamp = stbuf.st_mtime;
1022 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1024 WMPropList *plvalue, *old_value;
1025 WDefaultEntry *entry;
1026 unsigned int i, must_update;
1027 int update_workspace_back = 0; /* kluge :/ */
1028 unsigned int needs_refresh;
1029 void *tdata;
1030 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1032 must_update = 0;
1034 needs_refresh = 0;
1036 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1037 entry = &optionList[i];
1039 if (new_dict)
1040 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1041 else
1042 plvalue = NULL;
1044 if (!old_dict)
1045 old_value = NULL;
1046 else
1047 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1049 if (!plvalue && !old_value) {
1050 /* no default in the DB. Use builtin default */
1051 plvalue = entry->plvalue;
1052 if (plvalue && new_dict) {
1053 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1054 must_update = 1;
1056 } else if (!plvalue) {
1057 /* value was deleted from DB. Keep current value */
1058 continue;
1059 } else if (!old_value) {
1060 /* set value for the 1st time */
1061 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1062 /* value has changed */
1063 } else {
1065 if (strcmp(entry->key, "WorkspaceBack") == 0
1066 && update_workspace_back && scr->flags.backimage_helper_launched) {
1067 } else {
1068 /* value was not changed since last time */
1069 continue;
1073 if (plvalue) {
1074 #ifdef DEBUG
1075 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1076 #endif
1077 /* convert data */
1078 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1080 * If the WorkspaceSpecificBack data has been changed
1081 * so that the helper will be launched now, we must be
1082 * sure to send the default background texture config
1083 * to the helper.
1085 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1086 && !scr->flags.backimage_helper_launched) {
1087 update_workspace_back = 1;
1089 if (entry->update) {
1090 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1096 if (needs_refresh != 0 && !scr->flags.startup) {
1097 int foo;
1099 foo = 0;
1100 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1101 foo |= WTextureSettings;
1102 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1103 foo |= WFontSettings;
1104 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1105 foo |= WColorSettings;
1106 if (foo)
1107 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1108 (void *)(uintptr_t) foo);
1110 foo = 0;
1111 if (needs_refresh & REFRESH_MENU_TEXTURE)
1112 foo |= WTextureSettings;
1113 if (needs_refresh & REFRESH_MENU_FONT)
1114 foo |= WFontSettings;
1115 if (needs_refresh & REFRESH_MENU_COLOR)
1116 foo |= WColorSettings;
1117 if (foo)
1118 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1120 foo = 0;
1121 if (needs_refresh & REFRESH_WINDOW_FONT) {
1122 foo |= WFontSettings;
1124 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1125 foo |= WTextureSettings;
1127 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1128 foo |= WColorSettings;
1130 if (foo)
1131 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1133 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1134 foo = 0;
1135 if (needs_refresh & REFRESH_ICON_FONT) {
1136 foo |= WFontSettings;
1138 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1139 foo |= WTextureSettings;
1141 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1142 foo |= WTextureSettings;
1144 if (foo)
1145 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1146 (void *)(uintptr_t) foo);
1148 if (needs_refresh & REFRESH_ICON_TILE)
1149 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1153 void wDefaultUpdateIcons(WScreen * scr)
1155 WAppIcon *aicon = scr->app_icon_list;
1156 WWindow *wwin = scr->focused_window;
1157 char *file;
1159 while (aicon) {
1160 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1161 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1162 || (file && !aicon->icon->file)) {
1163 RImage *new_image;
1165 if (aicon->icon->file)
1166 wfree(aicon->icon->file);
1167 aicon->icon->file = wstrdup(file);
1169 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1170 if (new_image) {
1171 wIconChangeImage(aicon->icon, new_image);
1172 wAppIconPaint(aicon);
1175 aicon = aicon->next;
1178 if (!wPreferences.flags.noclip)
1179 wClipIconPaint(scr->clip_icon);
1181 while (wwin) {
1182 if (wwin->icon && wwin->flags.miniaturized) {
1183 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1184 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1185 || (file && !wwin->icon->file)) {
1186 RImage *new_image;
1188 if (wwin->icon->file)
1189 wfree(wwin->icon->file);
1190 wwin->icon->file = wstrdup(file);
1192 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1193 if (new_image)
1194 wIconChangeImage(wwin->icon, new_image);
1197 wwin = wwin->prev;
1201 /* --------------------------- Local ----------------------- */
1203 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1204 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1205 entry->key, x); \
1206 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1207 var = entry->default_value;\
1208 } else var = WMGetFromPLString(value)\
1211 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1213 char *str;
1214 WOptionEnumeration *v;
1215 char buffer[TOTAL_VALUES_LENGTH];
1217 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1218 for (v = values; v->string != NULL; v++) {
1219 if (strcasecmp(v->string, str) == 0)
1220 return v->value;
1224 buffer[0] = 0;
1225 for (v = values; v->string != NULL; v++) {
1226 if (!v->is_alias) {
1227 if (buffer[0] != 0)
1228 strcat(buffer, ", ");
1229 strcat(buffer, v->string);
1232 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1234 if (def) {
1235 return string2index(key, val, NULL, values);
1238 return -1;
1242 * value - is the value in the defaults DB
1243 * addr - is the address to store the data
1244 * ret - is the address to store a pointer to a temporary buffer. ret
1245 * must not be freed and is used by the set functions
1247 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1249 static char data;
1250 char *val;
1251 int second_pass = 0;
1253 GET_STRING_OR_DEFAULT("Boolean", val);
1255 again:
1256 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1257 || strcasecmp(val, "YES") == 0) {
1259 data = 1;
1260 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1261 || strcasecmp(val, "NO") == 0) {
1262 data = 0;
1263 } else {
1264 int i;
1265 if (sscanf(val, "%i", &i) == 1) {
1266 if (i != 0)
1267 data = 1;
1268 else
1269 data = 0;
1270 } else {
1271 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1272 if (second_pass == 0) {
1273 val = WMGetFromPLString(entry->plvalue);
1274 second_pass = 1;
1275 wwarning(_("using default \"%s\" instead"), val);
1276 goto again;
1278 return False;
1282 if (ret)
1283 *ret = &data;
1284 if (addr)
1285 *(char *)addr = data;
1287 return True;
1290 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1292 static int data;
1293 char *val;
1295 GET_STRING_OR_DEFAULT("Integer", val);
1297 if (sscanf(val, "%i", &data) != 1) {
1298 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1299 val = WMGetFromPLString(entry->plvalue);
1300 wwarning(_("using default \"%s\" instead"), val);
1301 if (sscanf(val, "%i", &data) != 1) {
1302 return False;
1306 if (ret)
1307 *ret = &data;
1308 if (addr)
1309 *(int *)addr = data;
1311 return True;
1314 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1316 static WCoord data;
1317 char *val_x, *val_y;
1318 int nelem, changed = 0;
1319 WMPropList *elem_x, *elem_y;
1321 again:
1322 if (!WMIsPLArray(value)) {
1323 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
1324 if (changed == 0) {
1325 value = entry->plvalue;
1326 changed = 1;
1327 wwarning(_("using default \"%s\" instead"), entry->default_value);
1328 goto again;
1330 return False;
1333 nelem = WMGetPropListItemCount(value);
1334 if (nelem != 2) {
1335 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1336 if (changed == 0) {
1337 value = entry->plvalue;
1338 changed = 1;
1339 wwarning(_("using default \"%s\" instead"), entry->default_value);
1340 goto again;
1342 return False;
1345 elem_x = WMGetFromPLArray(value, 0);
1346 elem_y = WMGetFromPLArray(value, 1);
1348 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1349 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1350 if (changed == 0) {
1351 value = entry->plvalue;
1352 changed = 1;
1353 wwarning(_("using default \"%s\" instead"), entry->default_value);
1354 goto again;
1356 return False;
1359 val_x = WMGetFromPLString(elem_x);
1360 val_y = WMGetFromPLString(elem_y);
1362 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1363 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1364 if (changed == 0) {
1365 value = entry->plvalue;
1366 changed = 1;
1367 wwarning(_("using default \"%s\" instead"), entry->default_value);
1368 goto again;
1370 return False;
1373 if (data.x < 0)
1374 data.x = 0;
1375 else if (data.x > scr->scr_width / 3)
1376 data.x = scr->scr_width / 3;
1377 if (data.y < 0)
1378 data.y = 0;
1379 else if (data.y > scr->scr_height / 3)
1380 data.y = scr->scr_height / 3;
1382 if (ret)
1383 *ret = &data;
1384 if (addr)
1385 *(WCoord *) addr = data;
1387 return True;
1390 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1392 WMRetainPropList(value);
1394 *ret = value;
1396 return True;
1399 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1401 static char *data;
1402 int i, count, len;
1403 char *ptr;
1404 WMPropList *d;
1405 int changed = 0;
1407 again:
1408 if (!WMIsPLArray(value)) {
1409 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
1410 if (changed == 0) {
1411 value = entry->plvalue;
1412 changed = 1;
1413 wwarning(_("using default \"%s\" instead"), entry->default_value);
1414 goto again;
1416 return False;
1419 i = 0;
1420 count = WMGetPropListItemCount(value);
1421 if (count < 1) {
1422 if (changed == 0) {
1423 value = entry->plvalue;
1424 changed = 1;
1425 wwarning(_("using default \"%s\" instead"), entry->default_value);
1426 goto again;
1428 return False;
1431 len = 0;
1432 for (i = 0; i < count; i++) {
1433 d = WMGetFromPLArray(value, i);
1434 if (!d || !WMIsPLString(d)) {
1435 count = i;
1436 break;
1438 len += strlen(WMGetFromPLString(d)) + 1;
1441 ptr = data = wmalloc(len + 1);
1443 for (i = 0; i < count; i++) {
1444 d = WMGetFromPLArray(value, i);
1445 if (!d || !WMIsPLString(d)) {
1446 break;
1448 strcpy(ptr, WMGetFromPLString(d));
1449 ptr += strlen(WMGetFromPLString(d));
1450 *ptr = ':';
1451 ptr++;
1453 ptr--;
1454 *(ptr--) = 0;
1456 if (*(char **)addr != NULL) {
1457 wfree(*(char **)addr);
1459 *(char **)addr = data;
1461 return True;
1464 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1466 static signed char data;
1468 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1469 if (data < 0)
1470 return False;
1472 if (ret)
1473 *ret = &data;
1474 if (addr)
1475 *(signed char *)addr = data;
1477 return True;
1481 * (solid <color>)
1482 * (hgradient <color> <color>)
1483 * (vgradient <color> <color>)
1484 * (dgradient <color> <color>)
1485 * (mhgradient <color> <color> ...)
1486 * (mvgradient <color> <color> ...)
1487 * (mdgradient <color> <color> ...)
1488 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1489 * (tpixmap <file> <color>)
1490 * (spixmap <file> <color>)
1491 * (cpixmap <file> <color>)
1492 * (thgradient <file> <opaqueness> <color> <color>)
1493 * (tvgradient <file> <opaqueness> <color> <color>)
1494 * (tdgradient <file> <opaqueness> <color> <color>)
1495 * (function <lib> <function> ...)
1498 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1500 WMPropList *elem;
1501 char *val;
1502 int nelem;
1503 WTexture *texture = NULL;
1505 nelem = WMGetPropListItemCount(pl);
1506 if (nelem < 1)
1507 return NULL;
1509 elem = WMGetFromPLArray(pl, 0);
1510 if (!elem || !WMIsPLString(elem))
1511 return NULL;
1512 val = WMGetFromPLString(elem);
1514 if (strcasecmp(val, "solid") == 0) {
1515 XColor color;
1517 if (nelem != 2)
1518 return NULL;
1520 /* get color */
1522 elem = WMGetFromPLArray(pl, 1);
1523 if (!elem || !WMIsPLString(elem))
1524 return NULL;
1525 val = WMGetFromPLString(elem);
1527 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1528 wwarning(_("\"%s\" is not a valid color name"), val);
1529 return NULL;
1532 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1533 } else if (strcasecmp(val, "dgradient") == 0
1534 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1535 RColor color1, color2;
1536 XColor xcolor;
1537 int type;
1539 if (nelem != 3) {
1540 wwarning(_("bad number of arguments in gradient specification"));
1541 return NULL;
1544 if (val[0] == 'd' || val[0] == 'D')
1545 type = WTEX_DGRADIENT;
1546 else if (val[0] == 'h' || val[0] == 'H')
1547 type = WTEX_HGRADIENT;
1548 else
1549 type = WTEX_VGRADIENT;
1551 /* get from color */
1552 elem = WMGetFromPLArray(pl, 1);
1553 if (!elem || !WMIsPLString(elem))
1554 return NULL;
1555 val = WMGetFromPLString(elem);
1557 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1558 wwarning(_("\"%s\" is not a valid color name"), val);
1559 return NULL;
1561 color1.alpha = 255;
1562 color1.red = xcolor.red >> 8;
1563 color1.green = xcolor.green >> 8;
1564 color1.blue = xcolor.blue >> 8;
1566 /* get to color */
1567 elem = WMGetFromPLArray(pl, 2);
1568 if (!elem || !WMIsPLString(elem)) {
1569 return NULL;
1571 val = WMGetFromPLString(elem);
1573 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1574 wwarning(_("\"%s\" is not a valid color name"), val);
1575 return NULL;
1577 color2.alpha = 255;
1578 color2.red = xcolor.red >> 8;
1579 color2.green = xcolor.green >> 8;
1580 color2.blue = xcolor.blue >> 8;
1582 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1584 } else if (strcasecmp(val, "igradient") == 0) {
1585 RColor colors1[2], colors2[2];
1586 int th1, th2;
1587 XColor xcolor;
1588 int i;
1590 if (nelem != 7) {
1591 wwarning(_("bad number of arguments in gradient specification"));
1592 return NULL;
1595 /* get from color */
1596 for (i = 0; i < 2; i++) {
1597 elem = WMGetFromPLArray(pl, 1 + i);
1598 if (!elem || !WMIsPLString(elem))
1599 return NULL;
1600 val = WMGetFromPLString(elem);
1602 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1603 wwarning(_("\"%s\" is not a valid color name"), val);
1604 return NULL;
1606 colors1[i].alpha = 255;
1607 colors1[i].red = xcolor.red >> 8;
1608 colors1[i].green = xcolor.green >> 8;
1609 colors1[i].blue = xcolor.blue >> 8;
1611 elem = WMGetFromPLArray(pl, 3);
1612 if (!elem || !WMIsPLString(elem))
1613 return NULL;
1614 val = WMGetFromPLString(elem);
1615 th1 = atoi(val);
1617 /* get from color */
1618 for (i = 0; i < 2; i++) {
1619 elem = WMGetFromPLArray(pl, 4 + i);
1620 if (!elem || !WMIsPLString(elem))
1621 return NULL;
1622 val = WMGetFromPLString(elem);
1624 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1625 wwarning(_("\"%s\" is not a valid color name"), val);
1626 return NULL;
1628 colors2[i].alpha = 255;
1629 colors2[i].red = xcolor.red >> 8;
1630 colors2[i].green = xcolor.green >> 8;
1631 colors2[i].blue = xcolor.blue >> 8;
1633 elem = WMGetFromPLArray(pl, 6);
1634 if (!elem || !WMIsPLString(elem))
1635 return NULL;
1636 val = WMGetFromPLString(elem);
1637 th2 = atoi(val);
1639 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1641 } else if (strcasecmp(val, "mhgradient") == 0
1642 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1643 XColor color;
1644 RColor **colors;
1645 int i, count;
1646 int type;
1648 if (nelem < 3) {
1649 wwarning(_("too few arguments in multicolor gradient specification"));
1650 return NULL;
1653 if (val[1] == 'h' || val[1] == 'H')
1654 type = WTEX_MHGRADIENT;
1655 else if (val[1] == 'v' || val[1] == 'V')
1656 type = WTEX_MVGRADIENT;
1657 else
1658 type = WTEX_MDGRADIENT;
1660 count = nelem - 1;
1662 colors = wmalloc(sizeof(RColor *) * (count + 1));
1664 for (i = 0; i < count; i++) {
1665 elem = WMGetFromPLArray(pl, i + 1);
1666 if (!elem || !WMIsPLString(elem)) {
1667 for (--i; i >= 0; --i) {
1668 wfree(colors[i]);
1670 wfree(colors);
1671 return NULL;
1673 val = WMGetFromPLString(elem);
1675 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1676 wwarning(_("\"%s\" is not a valid color name"), val);
1677 for (--i; i >= 0; --i) {
1678 wfree(colors[i]);
1680 wfree(colors);
1681 return NULL;
1682 } else {
1683 colors[i] = wmalloc(sizeof(RColor));
1684 colors[i]->red = color.red >> 8;
1685 colors[i]->green = color.green >> 8;
1686 colors[i]->blue = color.blue >> 8;
1689 colors[i] = NULL;
1691 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1692 } else if (strcasecmp(val, "spixmap") == 0 ||
1693 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1694 XColor color;
1695 int type;
1697 if (nelem != 3)
1698 return NULL;
1700 if (val[0] == 's' || val[0] == 'S')
1701 type = WTP_SCALE;
1702 else if (val[0] == 'c' || val[0] == 'C')
1703 type = WTP_CENTER;
1704 else
1705 type = WTP_TILE;
1707 /* get color */
1708 elem = WMGetFromPLArray(pl, 2);
1709 if (!elem || !WMIsPLString(elem)) {
1710 return NULL;
1712 val = WMGetFromPLString(elem);
1714 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1715 wwarning(_("\"%s\" is not a valid color name"), val);
1716 return NULL;
1719 /* file name */
1720 elem = WMGetFromPLArray(pl, 1);
1721 if (!elem || !WMIsPLString(elem))
1722 return NULL;
1723 val = WMGetFromPLString(elem);
1725 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1726 } else if (strcasecmp(val, "thgradient") == 0
1727 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1728 RColor color1, color2;
1729 XColor xcolor;
1730 int opacity;
1731 int style;
1733 if (val[1] == 'h' || val[1] == 'H')
1734 style = WTEX_THGRADIENT;
1735 else if (val[1] == 'v' || val[1] == 'V')
1736 style = WTEX_TVGRADIENT;
1737 else
1738 style = WTEX_TDGRADIENT;
1740 if (nelem != 5) {
1741 wwarning(_("bad number of arguments in textured gradient specification"));
1742 return NULL;
1745 /* get from color */
1746 elem = WMGetFromPLArray(pl, 3);
1747 if (!elem || !WMIsPLString(elem))
1748 return NULL;
1749 val = WMGetFromPLString(elem);
1751 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1752 wwarning(_("\"%s\" is not a valid color name"), val);
1753 return NULL;
1755 color1.alpha = 255;
1756 color1.red = xcolor.red >> 8;
1757 color1.green = xcolor.green >> 8;
1758 color1.blue = xcolor.blue >> 8;
1760 /* get to color */
1761 elem = WMGetFromPLArray(pl, 4);
1762 if (!elem || !WMIsPLString(elem)) {
1763 return NULL;
1765 val = WMGetFromPLString(elem);
1767 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1768 wwarning(_("\"%s\" is not a valid color name"), val);
1769 return NULL;
1771 color2.alpha = 255;
1772 color2.red = xcolor.red >> 8;
1773 color2.green = xcolor.green >> 8;
1774 color2.blue = xcolor.blue >> 8;
1776 /* get opacity */
1777 elem = WMGetFromPLArray(pl, 2);
1778 if (!elem || !WMIsPLString(elem))
1779 opacity = 128;
1780 else
1781 val = WMGetFromPLString(elem);
1783 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1784 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1785 opacity = 128;
1788 /* get file name */
1789 elem = WMGetFromPLArray(pl, 1);
1790 if (!elem || !WMIsPLString(elem))
1791 return NULL;
1792 val = WMGetFromPLString(elem);
1794 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1796 #ifdef TEXTURE_PLUGIN
1797 else if (strcasecmp(val, "function") == 0) {
1798 WTexFunction *function;
1799 void (*initFunc) (Display *, Colormap);
1800 char *lib, *func, **argv;
1801 int i, argc;
1803 if (nelem < 3)
1804 return NULL;
1806 /* get the library name */
1807 elem = WMGetFromPLArray(pl, 1);
1808 if (!elem || !WMIsPLString(elem)) {
1809 return NULL;
1811 lib = WMGetFromPLString(elem);
1813 /* get the function name */
1814 elem = WMGetFromPLArray(pl, 2);
1815 if (!elem || !WMIsPLString(elem)) {
1816 return NULL;
1818 func = WMGetFromPLString(elem);
1820 argc = nelem - 2;
1821 argv = (char **)wmalloc(argc * sizeof(char *));
1823 /* get the parameters */
1824 argv[0] = wstrdup(func);
1825 for (i = 0; i < argc - 1; i++) {
1826 elem = WMGetFromPLArray(pl, 3 + i);
1827 if (!elem || !WMIsPLString(elem)) {
1828 wfree(argv);
1830 return NULL;
1832 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1835 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1837 #ifdef HAVE_DLFCN_H
1838 if (function) {
1839 initFunc = dlsym(function->handle, "initWindowMaker");
1840 if (initFunc) {
1841 initFunc(dpy, scr->w_colormap);
1842 } else {
1843 wwarning(_("could not initialize library %s"), lib);
1845 } else {
1846 wwarning(_("could not find function %s::%s"), lib, func);
1848 #endif /* HAVE_DLFCN_H */
1849 texture = (WTexture *) function;
1851 #endif /* TEXTURE_PLUGIN */
1852 else {
1853 wwarning(_("invalid texture type %s"), val);
1854 return NULL;
1856 return texture;
1859 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1861 static WTexture *texture;
1862 int changed = 0;
1864 again:
1865 if (!WMIsPLArray(value)) {
1866 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1867 if (changed == 0) {
1868 value = entry->plvalue;
1869 changed = 1;
1870 wwarning(_("using default \"%s\" instead"), entry->default_value);
1871 goto again;
1873 return False;
1876 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1877 WMPropList *pl;
1879 pl = WMGetFromPLArray(value, 0);
1880 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1881 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1882 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1883 entry->key, "Solid Texture");
1885 value = entry->plvalue;
1886 changed = 1;
1887 wwarning(_("using default \"%s\" instead"), entry->default_value);
1888 goto again;
1892 texture = parse_texture(scr, value);
1894 if (!texture) {
1895 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1896 if (changed == 0) {
1897 value = entry->plvalue;
1898 changed = 1;
1899 wwarning(_("using default \"%s\" instead"), entry->default_value);
1900 goto again;
1902 return False;
1905 if (ret)
1906 *ret = &texture;
1908 if (addr)
1909 *(WTexture **) addr = texture;
1911 return True;
1914 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1916 WMPropList *elem;
1917 int changed = 0;
1918 char *val;
1919 int nelem;
1921 again:
1922 if (!WMIsPLArray(value)) {
1923 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1924 "WorkspaceBack", "Texture or None");
1925 if (changed == 0) {
1926 value = entry->plvalue;
1927 changed = 1;
1928 wwarning(_("using default \"%s\" instead"), entry->default_value);
1929 goto again;
1931 return False;
1934 /* only do basic error checking and verify for None texture */
1936 nelem = WMGetPropListItemCount(value);
1937 if (nelem > 0) {
1938 elem = WMGetFromPLArray(value, 0);
1939 if (!elem || !WMIsPLString(elem)) {
1940 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1941 if (changed == 0) {
1942 value = entry->plvalue;
1943 changed = 1;
1944 wwarning(_("using default \"%s\" instead"), entry->default_value);
1945 goto again;
1947 return False;
1949 val = WMGetFromPLString(elem);
1951 if (strcasecmp(val, "None") == 0)
1952 return True;
1954 *ret = WMRetainPropList(value);
1956 return True;
1959 static int
1960 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1962 WMPropList *elem;
1963 int nelem;
1964 int changed = 0;
1966 again:
1967 if (!WMIsPLArray(value)) {
1968 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1969 "WorkspaceSpecificBack", "an array of textures");
1970 if (changed == 0) {
1971 value = entry->plvalue;
1972 changed = 1;
1973 wwarning(_("using default \"%s\" instead"), entry->default_value);
1974 goto again;
1976 return False;
1979 /* only do basic error checking and verify for None texture */
1981 nelem = WMGetPropListItemCount(value);
1982 if (nelem > 0) {
1983 while (nelem--) {
1984 elem = WMGetFromPLArray(value, nelem);
1985 if (!elem || !WMIsPLArray(elem)) {
1986 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1987 nelem);
1992 *ret = WMRetainPropList(value);
1994 #ifdef notworking
1996 * Kluge to force wmsetbg helper to set the default background.
1997 * If the WorkspaceSpecificBack is changed once wmaker has started,
1998 * the WorkspaceBack won't be sent to the helper, unless the user
1999 * changes it's value too. So, we must force this by removing the
2000 * value from the defaults DB.
2002 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2003 WMPropList *key = WMCreatePLString("WorkspaceBack");
2005 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2007 WMReleasePropList(key);
2009 #endif
2010 return True;
2013 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2015 static WMFont *font;
2016 char *val;
2018 GET_STRING_OR_DEFAULT("Font", val);
2020 font = WMCreateFont(scr->wmscreen, val);
2021 if (!font)
2022 font = WMCreateFont(scr->wmscreen, "fixed");
2024 if (!font) {
2025 wfatal(_("could not load any usable font!!!"));
2026 exit(1);
2029 if (ret)
2030 *ret = font;
2032 /* can't assign font value outside update function */
2033 wassertrv(addr == NULL, True);
2035 return True;
2038 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2040 static XColor color;
2041 char *val;
2042 int second_pass = 0;
2044 GET_STRING_OR_DEFAULT("Color", val);
2046 again:
2047 if (!wGetColor(scr, val, &color)) {
2048 wwarning(_("could not get color for key \"%s\""), entry->key);
2049 if (second_pass == 0) {
2050 val = WMGetFromPLString(entry->plvalue);
2051 second_pass = 1;
2052 wwarning(_("using default \"%s\" instead"), val);
2053 goto again;
2055 return False;
2058 if (ret)
2059 *ret = &color;
2061 assert(addr == NULL);
2063 if (addr)
2064 *(unsigned long*)addr = pixel;
2067 return True;
2070 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2072 static WShortKey shortcut;
2073 KeySym ksym;
2074 char *val;
2075 char *k;
2076 char buf[MAX_SHORTCUT_LENGTH], *b;
2078 GET_STRING_OR_DEFAULT("Key spec", val);
2080 if (!val || strcasecmp(val, "NONE") == 0) {
2081 shortcut.keycode = 0;
2082 shortcut.modifier = 0;
2083 if (ret)
2084 *ret = &shortcut;
2085 return True;
2088 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2090 b = (char *)buf;
2092 /* get modifiers */
2093 shortcut.modifier = 0;
2094 while ((k = strchr(b, '+')) != NULL) {
2095 int mod;
2097 *k = 0;
2098 mod = wXModifierFromKey(b);
2099 if (mod < 0) {
2100 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2101 return False;
2103 shortcut.modifier |= mod;
2105 b = k + 1;
2108 /* get key */
2109 ksym = XStringToKeysym(b);
2111 if (ksym == NoSymbol) {
2112 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2113 return False;
2116 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2117 if (shortcut.keycode == 0) {
2118 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2119 return False;
2122 if (ret)
2123 *ret = &shortcut;
2125 return True;
2128 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2130 static int mask;
2131 char *str;
2133 GET_STRING_OR_DEFAULT("Modifier Key", str);
2135 if (!str)
2136 return False;
2138 mask = wXModifierFromKey(str);
2139 if (mask < 0) {
2140 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2141 mask = 0;
2142 return False;
2145 if (addr)
2146 *(int *)addr = mask;
2148 if (ret)
2149 *ret = &mask;
2151 return True;
2154 # include <X11/cursorfont.h>
2155 typedef struct {
2156 char *name;
2157 int id;
2158 } WCursorLookup;
2160 #define CURSOR_ID_NONE (XC_num_glyphs)
2162 static WCursorLookup cursor_table[] = {
2163 {"X_cursor", XC_X_cursor},
2164 {"arrow", XC_arrow},
2165 {"based_arrow_down", XC_based_arrow_down},
2166 {"based_arrow_up", XC_based_arrow_up},
2167 {"boat", XC_boat},
2168 {"bogosity", XC_bogosity},
2169 {"bottom_left_corner", XC_bottom_left_corner},
2170 {"bottom_right_corner", XC_bottom_right_corner},
2171 {"bottom_side", XC_bottom_side},
2172 {"bottom_tee", XC_bottom_tee},
2173 {"box_spiral", XC_box_spiral},
2174 {"center_ptr", XC_center_ptr},
2175 {"circle", XC_circle},
2176 {"clock", XC_clock},
2177 {"coffee_mug", XC_coffee_mug},
2178 {"cross", XC_cross},
2179 {"cross_reverse", XC_cross_reverse},
2180 {"crosshair", XC_crosshair},
2181 {"diamond_cross", XC_diamond_cross},
2182 {"dot", XC_dot},
2183 {"dotbox", XC_dotbox},
2184 {"double_arrow", XC_double_arrow},
2185 {"draft_large", XC_draft_large},
2186 {"draft_small", XC_draft_small},
2187 {"draped_box", XC_draped_box},
2188 {"exchange", XC_exchange},
2189 {"fleur", XC_fleur},
2190 {"gobbler", XC_gobbler},
2191 {"gumby", XC_gumby},
2192 {"hand1", XC_hand1},
2193 {"hand2", XC_hand2},
2194 {"heart", XC_heart},
2195 {"icon", XC_icon},
2196 {"iron_cross", XC_iron_cross},
2197 {"left_ptr", XC_left_ptr},
2198 {"left_side", XC_left_side},
2199 {"left_tee", XC_left_tee},
2200 {"leftbutton", XC_leftbutton},
2201 {"ll_angle", XC_ll_angle},
2202 {"lr_angle", XC_lr_angle},
2203 {"man", XC_man},
2204 {"middlebutton", XC_middlebutton},
2205 {"mouse", XC_mouse},
2206 {"pencil", XC_pencil},
2207 {"pirate", XC_pirate},
2208 {"plus", XC_plus},
2209 {"question_arrow", XC_question_arrow},
2210 {"right_ptr", XC_right_ptr},
2211 {"right_side", XC_right_side},
2212 {"right_tee", XC_right_tee},
2213 {"rightbutton", XC_rightbutton},
2214 {"rtl_logo", XC_rtl_logo},
2215 {"sailboat", XC_sailboat},
2216 {"sb_down_arrow", XC_sb_down_arrow},
2217 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2218 {"sb_left_arrow", XC_sb_left_arrow},
2219 {"sb_right_arrow", XC_sb_right_arrow},
2220 {"sb_up_arrow", XC_sb_up_arrow},
2221 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2222 {"shuttle", XC_shuttle},
2223 {"sizing", XC_sizing},
2224 {"spider", XC_spider},
2225 {"spraycan", XC_spraycan},
2226 {"star", XC_star},
2227 {"target", XC_target},
2228 {"tcross", XC_tcross},
2229 {"top_left_arrow", XC_top_left_arrow},
2230 {"top_left_corner", XC_top_left_corner},
2231 {"top_right_corner", XC_top_right_corner},
2232 {"top_side", XC_top_side},
2233 {"top_tee", XC_top_tee},
2234 {"trek", XC_trek},
2235 {"ul_angle", XC_ul_angle},
2236 {"umbrella", XC_umbrella},
2237 {"ur_angle", XC_ur_angle},
2238 {"watch", XC_watch},
2239 {"xterm", XC_xterm},
2240 {NULL, CURSOR_ID_NONE}
2243 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2245 switch (status) {
2246 case BitmapOpenFailed:
2247 wwarning(_("failed to open bitmap file \"%s\""), filename);
2248 break;
2249 case BitmapFileInvalid:
2250 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2251 break;
2252 case BitmapNoMemory:
2253 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2254 break;
2255 case BitmapSuccess:
2256 XFreePixmap(dpy, bitmap);
2257 break;
2262 * (none)
2263 * (builtin, <cursor_name>)
2264 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2266 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2268 WMPropList *elem;
2269 char *val;
2270 int nelem;
2271 int status = 0;
2273 nelem = WMGetPropListItemCount(pl);
2274 if (nelem < 1) {
2275 return (status);
2277 elem = WMGetFromPLArray(pl, 0);
2278 if (!elem || !WMIsPLString(elem)) {
2279 return (status);
2281 val = WMGetFromPLString(elem);
2283 if (0 == strcasecmp(val, "none")) {
2284 status = 1;
2285 *cursor = None;
2286 } else if (0 == strcasecmp(val, "builtin")) {
2287 int i;
2288 int cursor_id = CURSOR_ID_NONE;
2290 if (2 != nelem) {
2291 wwarning(_("bad number of arguments in cursor specification"));
2292 return (status);
2294 elem = WMGetFromPLArray(pl, 1);
2295 if (!elem || !WMIsPLString(elem)) {
2296 return (status);
2298 val = WMGetFromPLString(elem);
2300 for (i = 0; NULL != cursor_table[i].name; i++) {
2301 if (0 == strcasecmp(val, cursor_table[i].name)) {
2302 cursor_id = cursor_table[i].id;
2303 break;
2306 if (CURSOR_ID_NONE == cursor_id) {
2307 wwarning(_("unknown builtin cursor name \"%s\""), val);
2308 } else {
2309 *cursor = XCreateFontCursor(dpy, cursor_id);
2310 status = 1;
2312 } else if (0 == strcasecmp(val, "bitmap")) {
2313 char *bitmap_name;
2314 char *mask_name;
2315 int bitmap_status;
2316 int mask_status;
2317 Pixmap bitmap;
2318 Pixmap mask;
2319 unsigned int w, h;
2320 int x, y;
2321 XColor fg, bg;
2323 if (3 != nelem) {
2324 wwarning(_("bad number of arguments in cursor specification"));
2325 return (status);
2327 elem = WMGetFromPLArray(pl, 1);
2328 if (!elem || !WMIsPLString(elem)) {
2329 return (status);
2331 val = WMGetFromPLString(elem);
2332 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2333 if (!bitmap_name) {
2334 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2335 return (status);
2337 elem = WMGetFromPLArray(pl, 2);
2338 if (!elem || !WMIsPLString(elem)) {
2339 wfree(bitmap_name);
2340 return (status);
2342 val = WMGetFromPLString(elem);
2343 mask_name = FindImage(wPreferences.pixmap_path, val);
2344 if (!mask_name) {
2345 wfree(bitmap_name);
2346 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2347 return (status);
2349 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2350 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2351 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2352 fg.pixel = scr->black_pixel;
2353 bg.pixel = scr->white_pixel;
2354 XQueryColor(dpy, scr->w_colormap, &fg);
2355 XQueryColor(dpy, scr->w_colormap, &bg);
2356 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2357 status = 1;
2359 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2360 check_bitmap_status(mask_status, mask_name, mask);
2361 wfree(bitmap_name);
2362 wfree(mask_name);
2364 return (status);
2367 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2369 static Cursor cursor;
2370 int status;
2371 int changed = 0;
2373 again:
2374 if (!WMIsPLArray(value)) {
2375 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2376 entry->key, "cursor specification");
2377 if (!changed) {
2378 value = entry->plvalue;
2379 changed = 1;
2380 wwarning(_("using default \"%s\" instead"), entry->default_value);
2381 goto again;
2383 return (False);
2385 status = parse_cursor(scr, value, &cursor);
2386 if (!status) {
2387 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2388 if (!changed) {
2389 value = entry->plvalue;
2390 changed = 1;
2391 wwarning(_("using default \"%s\" instead"), entry->default_value);
2392 goto again;
2394 return (False);
2396 if (ret) {
2397 *ret = &cursor;
2399 if (addr) {
2400 *(Cursor *) addr = cursor;
2402 return (True);
2405 #undef CURSOR_ID_NONE
2407 /* ---------------- value setting functions --------------- */
2408 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2410 return REFRESH_WINDOW_TITLE_COLOR;
2413 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2415 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2418 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2420 switch (which) {
2421 case WM_DOCK:
2422 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2423 break;
2424 case WM_CLIP:
2425 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2426 break;
2427 default:
2428 break;
2430 return 0;
2433 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2435 if (scr->workspaces) {
2436 wWorkspaceForceChange(scr, scr->current_workspace);
2437 wArrangeIcons(scr, False);
2439 return 0;
2442 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2444 Pixmap pixmap;
2445 RImage *img;
2446 int reset = 0;
2448 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2449 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2450 ? WREL_ICON : WREL_FLAT);
2451 if (!img) {
2452 wwarning(_("could not render texture for icon background"));
2453 if (!entry->addr)
2454 wTextureDestroy(scr, *texture);
2455 return 0;
2457 RConvertImage(scr->rcontext, img, &pixmap);
2459 if (scr->icon_tile) {
2460 reset = 1;
2461 RReleaseImage(scr->icon_tile);
2462 XFreePixmap(dpy, scr->icon_tile_pixmap);
2465 scr->icon_tile = img;
2467 /* put the icon in the noticeboard hint */
2468 PropSetIconTileHint(scr, img);
2470 if (!wPreferences.flags.noclip) {
2471 if (scr->clip_tile) {
2472 RReleaseImage(scr->clip_tile);
2474 scr->clip_tile = wClipMakeTile(scr, img);
2477 scr->icon_tile_pixmap = pixmap;
2479 if (scr->def_icon_pixmap) {
2480 XFreePixmap(dpy, scr->def_icon_pixmap);
2481 scr->def_icon_pixmap = None;
2483 if (scr->def_ticon_pixmap) {
2484 XFreePixmap(dpy, scr->def_ticon_pixmap);
2485 scr->def_ticon_pixmap = None;
2488 if (scr->icon_back_texture) {
2489 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2491 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2493 if (scr->clip_balloon)
2494 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2497 * Free the texture as nobody else will use it, nor refer to it.
2499 if (!entry->addr)
2500 wTextureDestroy(scr, *texture);
2502 return (reset ? REFRESH_ICON_TILE : 0);
2505 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2507 if (scr->title_font) {
2508 WMReleaseFont(scr->title_font);
2510 scr->title_font = font;
2512 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2515 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2517 if (scr->menu_title_font) {
2518 WMReleaseFont(scr->menu_title_font);
2521 scr->menu_title_font = font;
2523 return REFRESH_MENU_TITLE_FONT;
2526 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2528 if (scr->menu_entry_font) {
2529 WMReleaseFont(scr->menu_entry_font);
2531 scr->menu_entry_font = font;
2533 return REFRESH_MENU_FONT;
2536 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2538 if (scr->icon_title_font) {
2539 WMReleaseFont(scr->icon_title_font);
2542 scr->icon_title_font = font;
2544 return REFRESH_ICON_FONT;
2547 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2549 if (scr->clip_title_font) {
2550 WMReleaseFont(scr->clip_title_font);
2553 scr->clip_title_font = font;
2555 return REFRESH_ICON_FONT;
2558 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2560 if (scr->workspace_name_font) {
2561 WMReleaseFont(scr->workspace_name_font);
2564 scr->workspace_name_font = font;
2566 return 0;
2569 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2571 if (scr->select_color)
2572 WMReleaseColor(scr->select_color);
2574 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2576 wFreeColor(scr, color->pixel);
2578 return REFRESH_MENU_COLOR;
2581 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2583 if (scr->select_text_color)
2584 WMReleaseColor(scr->select_text_color);
2586 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2588 wFreeColor(scr, color->pixel);
2590 return REFRESH_MENU_COLOR;
2593 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2595 if (scr->clip_title_color[widx])
2596 WMReleaseColor(scr->clip_title_color[widx]);
2597 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2598 #ifdef GRADIENT_CLIP_ARROW
2599 if (widx == CLIP_NORMAL) {
2600 RImage *image;
2601 RColor color1, color2;
2602 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2603 int as = pt - 15; /* 15 = 5+5+5 */
2605 FREE_PIXMAP(scr->clip_arrow_gradient);
2607 color1.red = (color->red >> 8) * 6 / 10;
2608 color1.green = (color->green >> 8) * 6 / 10;
2609 color1.blue = (color->blue >> 8) * 6 / 10;
2611 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2612 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2613 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2615 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2616 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2617 RReleaseImage(image);
2619 #endif /* GRADIENT_CLIP_ARROW */
2621 wFreeColor(scr, color->pixel);
2623 return REFRESH_ICON_TITLE_COLOR;
2626 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2628 if (scr->window_title_color[widx])
2629 WMReleaseColor(scr->window_title_color[widx]);
2631 scr->window_title_color[widx] =
2632 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2634 wFreeColor(scr, color->pixel);
2636 return REFRESH_WINDOW_TITLE_COLOR;
2639 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2641 if (scr->menu_title_color[0])
2642 WMReleaseColor(scr->menu_title_color[0]);
2644 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2646 wFreeColor(scr, color->pixel);
2648 return REFRESH_MENU_TITLE_COLOR;
2651 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2653 if (scr->mtext_color)
2654 WMReleaseColor(scr->mtext_color);
2656 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2658 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2659 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2660 } else {
2661 WMSetColorAlpha(scr->dtext_color, 0xffff);
2664 wFreeColor(scr, color->pixel);
2666 return REFRESH_MENU_COLOR;
2669 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2671 if (scr->dtext_color)
2672 WMReleaseColor(scr->dtext_color);
2674 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2676 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2677 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2678 } else {
2679 WMSetColorAlpha(scr->dtext_color, 0xffff);
2682 wFreeColor(scr, color->pixel);
2684 return REFRESH_MENU_COLOR;
2687 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2689 if (scr->icon_title_color)
2690 WMReleaseColor(scr->icon_title_color);
2691 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2693 wFreeColor(scr, color->pixel);
2695 return REFRESH_ICON_TITLE_COLOR;
2698 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2700 if (scr->icon_title_texture) {
2701 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2703 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2705 return REFRESH_ICON_TITLE_BACK;
2708 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2710 close(scr->helper_fd);
2711 scr->helper_fd = 0;
2712 scr->helper_pid = 0;
2713 scr->flags.backimage_helper_launched = 0;
2716 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2718 WMPropList *val;
2719 char *str;
2720 int i;
2722 if (scr->flags.backimage_helper_launched) {
2723 if (WMGetPropListItemCount(value) == 0) {
2724 SendHelperMessage(scr, 'C', 0, NULL);
2725 SendHelperMessage(scr, 'K', 0, NULL);
2727 WMReleasePropList(value);
2728 return 0;
2730 } else {
2731 pid_t pid;
2732 int filedes[2];
2734 if (WMGetPropListItemCount(value) == 0)
2735 return 0;
2737 if (pipe(filedes) < 0) {
2738 wsyserror("pipe() failed:can't set workspace specific background image");
2740 WMReleasePropList(value);
2741 return 0;
2744 pid = fork();
2745 if (pid < 0) {
2746 wsyserror("fork() failed:can't set workspace specific background image");
2747 if (close(filedes[0]) < 0)
2748 wsyserror("could not close pipe");
2749 if (close(filedes[1]) < 0)
2750 wsyserror("could not close pipe");
2752 } else if (pid == 0) {
2753 char *dither;
2755 SetupEnvironment(scr);
2757 if (close(0) < 0)
2758 wsyserror("could not close pipe");
2759 if (dup(filedes[0]) < 0) {
2760 wsyserror("dup() failed:can't set workspace specific background image");
2762 dither = wPreferences.no_dithering ? "-m" : "-d";
2763 if (wPreferences.smooth_workspace_back)
2764 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2765 else
2766 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2767 wsyserror("could not execute wmsetbg");
2768 exit(1);
2769 } else {
2771 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2772 wsyserror("error setting close-on-exec flag");
2774 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2775 wsyserror("error setting close-on-exec flag");
2778 scr->helper_fd = filedes[1];
2779 scr->helper_pid = pid;
2780 scr->flags.backimage_helper_launched = 1;
2782 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2784 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2789 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2790 val = WMGetFromPLArray(value, i);
2791 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2792 str = WMGetPropListDescription(val, False);
2794 SendHelperMessage(scr, 'S', i + 1, str);
2796 wfree(str);
2797 } else {
2798 SendHelperMessage(scr, 'U', i + 1, NULL);
2801 sleep(1);
2803 WMReleasePropList(value);
2804 return 0;
2807 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2809 if (scr->flags.backimage_helper_launched) {
2810 char *str;
2812 if (WMGetPropListItemCount(value) == 0) {
2813 SendHelperMessage(scr, 'U', 0, NULL);
2814 } else {
2815 /* set the default workspace background to this one */
2816 str = WMGetPropListDescription(value, False);
2817 if (str) {
2818 SendHelperMessage(scr, 'S', 0, str);
2819 wfree(str);
2820 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2821 } else {
2822 SendHelperMessage(scr, 'U', 0, NULL);
2825 } else if (WMGetPropListItemCount(value) > 0) {
2826 char *command;
2827 char *text;
2828 char *dither;
2829 int len;
2831 text = WMGetPropListDescription(value, False);
2832 len = strlen(text) + 40;
2833 command = wmalloc(len);
2834 dither = wPreferences.no_dithering ? "-m" : "-d";
2835 if (wPreferences.smooth_workspace_back)
2836 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2837 else
2838 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2839 wfree(text);
2840 ExecuteShellCommand(scr, command);
2841 wfree(command);
2843 WMReleasePropList(value);
2845 return 0;
2848 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2850 if (scr->widget_texture) {
2851 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2853 scr->widget_texture = *(WTexSolid **) texture;
2855 return 0;
2858 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2860 if (scr->window_title_texture[WS_FOCUSED]) {
2861 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2863 scr->window_title_texture[WS_FOCUSED] = *texture;
2865 return REFRESH_WINDOW_TEXTURES;
2868 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2870 if (scr->window_title_texture[WS_PFOCUSED]) {
2871 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2873 scr->window_title_texture[WS_PFOCUSED] = *texture;
2875 return REFRESH_WINDOW_TEXTURES;
2878 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2880 if (scr->window_title_texture[WS_UNFOCUSED]) {
2881 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2883 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2885 return REFRESH_WINDOW_TEXTURES;
2888 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2890 if (scr->resizebar_texture[0]) {
2891 wTextureDestroy(scr, scr->resizebar_texture[0]);
2893 scr->resizebar_texture[0] = *texture;
2895 return REFRESH_WINDOW_TEXTURES;
2898 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2900 if (scr->menu_title_texture[0]) {
2901 wTextureDestroy(scr, scr->menu_title_texture[0]);
2903 scr->menu_title_texture[0] = *texture;
2905 return REFRESH_MENU_TITLE_TEXTURE;
2908 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2910 if (scr->menu_item_texture) {
2911 wTextureDestroy(scr, scr->menu_item_texture);
2912 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2914 scr->menu_item_texture = *texture;
2916 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2918 return REFRESH_MENU_TEXTURE;
2921 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2923 WWindow *wwin;
2924 wKeyBindings[widx] = *shortcut;
2926 wwin = scr->focused_window;
2928 while (wwin != NULL) {
2929 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2931 if (!WFLAGP(wwin, no_bind_keys)) {
2932 wWindowSetKeyGrabs(wwin);
2934 wwin = wwin->prev;
2937 return 0;
2940 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2942 wScreenUpdateUsableArea(scr);
2943 wArrangeIcons(scr, True);
2945 return 0;
2948 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2950 wScreenUpdateUsableArea(scr);
2952 return 0;
2955 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2957 return REFRESH_MENU_TEXTURE;
2960 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2962 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2964 RCopyArea(img, image, x, y, w, h, 0, 0);
2966 return img;
2969 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2971 char *path;
2972 RImage *bgimage;
2973 int cwidth, cheight;
2974 WPreferences *prefs = (WPreferences *) foo;
2976 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2977 if (prefs->swtileImage)
2978 RReleaseImage(prefs->swtileImage);
2979 prefs->swtileImage = NULL;
2981 WMReleasePropList(array);
2982 return 0;
2985 switch (WMGetPropListItemCount(array)) {
2986 case 4:
2987 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
2988 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
2989 break;
2990 } else
2991 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
2993 if (!path) {
2994 wwarning(_("Could not find image \"%s\" for option \"%s\""),
2995 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
2996 } else {
2997 bgimage = RLoadImage(scr->rcontext, path, 0);
2998 if (!bgimage) {
2999 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3000 wfree(path);
3001 } else {
3002 wfree(path);
3004 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3005 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3007 if (cwidth <= 0 || cheight <= 0 ||
3008 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3009 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3010 else {
3011 int i;
3012 int swidth, theight;
3013 for (i = 0; i < 9; i++) {
3014 if (prefs->swbackImage[i])
3015 RReleaseImage(prefs->swbackImage[i]);
3016 prefs->swbackImage[i] = NULL;
3018 swidth = (bgimage->width - cwidth) / 2;
3019 theight = (bgimage->height - cheight) / 2;
3021 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3022 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3023 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3024 swidth, theight);
3026 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3027 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3028 cwidth, cheight);
3029 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3030 swidth, cheight);
3032 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3033 swidth, theight);
3034 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3035 cwidth, theight);
3036 prefs->swbackImage[8] =
3037 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3038 theight);
3040 // check if anything failed
3041 for (i = 0; i < 9; i++) {
3042 if (!prefs->swbackImage[i]) {
3043 for (; i >= 0; --i) {
3044 RReleaseImage(prefs->swbackImage[i]);
3045 prefs->swbackImage[i] = NULL;
3047 break;
3051 RReleaseImage(bgimage);
3055 case 1:
3056 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3057 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3058 break;
3059 } else
3060 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3062 if (!path) {
3063 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3064 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3065 } else {
3066 if (prefs->swtileImage)
3067 RReleaseImage(prefs->swtileImage);
3069 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3070 if (!prefs->swtileImage) {
3071 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3073 wfree(path);
3075 break;
3077 default:
3078 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3079 break;
3082 WMReleasePropList(array);
3084 return 0;
3088 * Very ugly kluge.
3089 * Need access to the double click variables, so that all widgets in
3090 * wmaker panels will have the same dbl-click values.
3091 * TODO: figure a better way of dealing with it.
3093 #include <WINGs/WINGsP.h>
3095 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3097 extern _WINGsConfiguration WINGsConfiguration;
3099 if (*value <= 0)
3100 *(int *)foo = 1;
3102 WINGsConfiguration.doubleClickDelay = *value;
3104 return 0;
3107 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3109 if (wCursor[widx] != None) {
3110 XFreeCursor(dpy, wCursor[widx]);
3113 wCursor[widx] = *cursor;
3115 if (widx == WCUR_ROOT && *cursor != None) {
3116 XDefineCursor(dpy, scr->root_win, *cursor);
3119 return 0;