Remove unused stuff from src/defaults.c
[wmaker-crm.git] / src / defaults.c
blob79dc33e9bfb79dd32b7832c89f0cd1daccd798e2
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 #ifdef HEARTBEAT
910 puts("Checking domains...");
911 #endif
912 if (stat(WDWindowMaker->path, &stbuf) >= 0 && WDWindowMaker->timestamp < stbuf.st_mtime) {
913 #ifdef HEARTBEAT
914 puts("Checking WindowMaker domain");
915 #endif
916 WDWindowMaker->timestamp = stbuf.st_mtime;
918 /* global dictionary */
919 shared_dict = readGlobalDomain("WindowMaker", True);
920 /* user dictionary */
921 dict = WMReadPropListFromFile(WDWindowMaker->path);
922 if (dict) {
923 if (!WMIsPLDictionary(dict)) {
924 WMReleasePropList(dict);
925 dict = NULL;
926 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
927 "WindowMaker", WDWindowMaker->path);
928 } else {
929 if (shared_dict) {
930 WMMergePLDictionaries(shared_dict, dict, True);
931 WMReleasePropList(dict);
932 dict = shared_dict;
933 shared_dict = NULL;
935 for (i = 0; i < wScreenCount; i++) {
936 scr = wScreenWithNumber(i);
937 if (scr)
938 wReadDefaults(scr, dict);
940 if (WDWindowMaker->dictionary) {
941 WMReleasePropList(WDWindowMaker->dictionary);
943 WDWindowMaker->dictionary = dict;
945 } else {
946 wwarning(_("could not load domain %s from user defaults database"), "WindowMaker");
948 if (shared_dict) {
949 WMReleasePropList(shared_dict);
953 if (stat(WDWindowAttributes->path, &stbuf) >= 0 && WDWindowAttributes->timestamp < stbuf.st_mtime) {
954 #ifdef HEARTBEAT
955 puts("Checking WMWindowAttributes domain");
956 #endif
957 /* global dictionary */
958 shared_dict = readGlobalDomain("WMWindowAttributes", True);
959 /* user dictionary */
960 dict = WMReadPropListFromFile(WDWindowAttributes->path);
961 if (dict) {
962 if (!WMIsPLDictionary(dict)) {
963 WMReleasePropList(dict);
964 dict = NULL;
965 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
966 "WMWindowAttributes", WDWindowAttributes->path);
967 } else {
968 if (shared_dict) {
969 WMMergePLDictionaries(shared_dict, dict, True);
970 WMReleasePropList(dict);
971 dict = shared_dict;
972 shared_dict = NULL;
974 if (WDWindowAttributes->dictionary) {
975 WMReleasePropList(WDWindowAttributes->dictionary);
977 WDWindowAttributes->dictionary = dict;
978 for (i = 0; i < wScreenCount; i++) {
979 scr = wScreenWithNumber(i);
980 if (scr) {
981 RImage *image;
983 wDefaultUpdateIcons(scr);
985 /* Update the panel image if changed */
986 /* Don't worry. If the image is the same these
987 * functions will have no performance impact. */
988 image = wDefaultGetImage(scr, "Logo", "WMPanel");
990 if (!image) {
991 wwarning(_("could not load logo image for panels: %s"),
992 RMessageForError(RErrorCode));
993 } else {
994 WMSetApplicationIconImage(scr->wmscreen, image);
995 RReleaseImage(image);
1000 } else {
1001 wwarning(_("could not load domain %s from user defaults database"), "WMWindowAttributes");
1003 WDWindowAttributes->timestamp = stbuf.st_mtime;
1004 if (shared_dict) {
1005 WMReleasePropList(shared_dict);
1009 if (stat(WDRootMenu->path, &stbuf) >= 0 && WDRootMenu->timestamp < stbuf.st_mtime) {
1010 dict = WMReadPropListFromFile(WDRootMenu->path);
1011 #ifdef HEARTBEAT
1012 puts("Checking WMRootMenu domain");
1013 #endif
1014 if (dict) {
1015 if (!WMIsPLArray(dict) && !WMIsPLString(dict)) {
1016 WMReleasePropList(dict);
1017 dict = NULL;
1018 wwarning(_("Domain %s (%s) of defaults database is corrupted!"),
1019 "WMRootMenu", WDRootMenu->path);
1020 } else {
1021 if (WDRootMenu->dictionary) {
1022 WMReleasePropList(WDRootMenu->dictionary);
1024 WDRootMenu->dictionary = dict;
1025 wDefaultsMergeGlobalMenus(WDRootMenu);
1027 } else {
1028 wwarning(_("could not load domain %s from user defaults database"), "WMRootMenu");
1030 WDRootMenu->timestamp = stbuf.st_mtime;
1034 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
1036 WMPropList *plvalue, *old_value;
1037 WDefaultEntry *entry;
1038 unsigned int i, must_update;
1039 int update_workspace_back = 0; /* kluge :/ */
1040 unsigned int needs_refresh;
1041 void *tdata;
1042 WMPropList *old_dict = (WDWindowMaker->dictionary != new_dict ? WDWindowMaker->dictionary : NULL);
1044 must_update = 0;
1046 needs_refresh = 0;
1048 for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
1049 entry = &optionList[i];
1051 if (new_dict)
1052 plvalue = WMGetFromPLDictionary(new_dict, entry->plkey);
1053 else
1054 plvalue = NULL;
1056 if (!old_dict)
1057 old_value = NULL;
1058 else
1059 old_value = WMGetFromPLDictionary(old_dict, entry->plkey);
1061 if (!plvalue && !old_value) {
1062 /* no default in the DB. Use builtin default */
1063 plvalue = entry->plvalue;
1064 if (plvalue && new_dict) {
1065 WMPutInPLDictionary(new_dict, entry->plkey, plvalue);
1066 must_update = 1;
1068 } else if (!plvalue) {
1069 /* value was deleted from DB. Keep current value */
1070 continue;
1071 } else if (!old_value) {
1072 /* set value for the 1st time */
1073 } else if (!WMIsPropListEqualTo(plvalue, old_value)) {
1074 /* value has changed */
1075 } else {
1077 if (strcmp(entry->key, "WorkspaceBack") == 0
1078 && update_workspace_back && scr->flags.backimage_helper_launched) {
1079 } else {
1080 /* value was not changed since last time */
1081 continue;
1085 if (plvalue) {
1086 #ifdef DEBUG
1087 printf("Updating %s to %s\n", entry->key, WMGetPropListDescription(plvalue, False));
1088 #endif
1089 /* convert data */
1090 if ((*entry->convert) (scr, entry, plvalue, entry->addr, &tdata)) {
1092 * If the WorkspaceSpecificBack data has been changed
1093 * so that the helper will be launched now, we must be
1094 * sure to send the default background texture config
1095 * to the helper.
1097 if (strcmp(entry->key, "WorkspaceSpecificBack") == 0
1098 && !scr->flags.backimage_helper_launched) {
1099 update_workspace_back = 1;
1101 if (entry->update) {
1102 needs_refresh |= (*entry->update) (scr, entry, tdata, entry->extra_data);
1108 if (needs_refresh != 0 && !scr->flags.startup) {
1109 int foo;
1111 foo = 0;
1112 if (needs_refresh & REFRESH_MENU_TITLE_TEXTURE)
1113 foo |= WTextureSettings;
1114 if (needs_refresh & REFRESH_MENU_TITLE_FONT)
1115 foo |= WFontSettings;
1116 if (needs_refresh & REFRESH_MENU_TITLE_COLOR)
1117 foo |= WColorSettings;
1118 if (foo)
1119 WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
1120 (void *)(uintptr_t) foo);
1122 foo = 0;
1123 if (needs_refresh & REFRESH_MENU_TEXTURE)
1124 foo |= WTextureSettings;
1125 if (needs_refresh & REFRESH_MENU_FONT)
1126 foo |= WFontSettings;
1127 if (needs_refresh & REFRESH_MENU_COLOR)
1128 foo |= WColorSettings;
1129 if (foo)
1130 WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1132 foo = 0;
1133 if (needs_refresh & REFRESH_WINDOW_FONT) {
1134 foo |= WFontSettings;
1136 if (needs_refresh & REFRESH_WINDOW_TEXTURES) {
1137 foo |= WTextureSettings;
1139 if (needs_refresh & REFRESH_WINDOW_TITLE_COLOR) {
1140 foo |= WColorSettings;
1142 if (foo)
1143 WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL, (void *)(uintptr_t) foo);
1145 if (!(needs_refresh & REFRESH_ICON_TILE)) {
1146 foo = 0;
1147 if (needs_refresh & REFRESH_ICON_FONT) {
1148 foo |= WFontSettings;
1150 if (needs_refresh & REFRESH_ICON_TITLE_COLOR) {
1151 foo |= WTextureSettings;
1153 if (needs_refresh & REFRESH_ICON_TITLE_BACK) {
1154 foo |= WTextureSettings;
1156 if (foo)
1157 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
1158 (void *)(uintptr_t) foo);
1160 if (needs_refresh & REFRESH_ICON_TILE)
1161 WMPostNotificationName(WNIconTileSettingsChanged, NULL, NULL);
1165 void wDefaultUpdateIcons(WScreen * scr)
1167 WAppIcon *aicon = scr->app_icon_list;
1168 WWindow *wwin = scr->focused_window;
1169 char *file;
1171 while (aicon) {
1172 file = wDefaultGetIconFile(scr, aicon->wm_instance, aicon->wm_class, False);
1173 if ((file && aicon->icon->file && strcmp(file, aicon->icon->file) != 0)
1174 || (file && !aicon->icon->file)) {
1175 RImage *new_image;
1177 if (aicon->icon->file)
1178 wfree(aicon->icon->file);
1179 aicon->icon->file = wstrdup(file);
1181 new_image = wDefaultGetImage(scr, aicon->wm_instance, aicon->wm_class);
1182 if (new_image) {
1183 wIconChangeImage(aicon->icon, new_image);
1184 wAppIconPaint(aicon);
1187 aicon = aicon->next;
1190 if (!wPreferences.flags.noclip)
1191 wClipIconPaint(scr->clip_icon);
1193 while (wwin) {
1194 if (wwin->icon && wwin->flags.miniaturized) {
1195 file = wDefaultGetIconFile(scr, wwin->wm_instance, wwin->wm_class, False);
1196 if ((file && wwin->icon->file && strcmp(file, wwin->icon->file) != 0)
1197 || (file && !wwin->icon->file)) {
1198 RImage *new_image;
1200 if (wwin->icon->file)
1201 wfree(wwin->icon->file);
1202 wwin->icon->file = wstrdup(file);
1204 new_image = wDefaultGetImage(scr, wwin->wm_instance, wwin->wm_class);
1205 if (new_image)
1206 wIconChangeImage(wwin->icon, new_image);
1209 wwin = wwin->prev;
1213 /* --------------------------- Local ----------------------- */
1215 #define GET_STRING_OR_DEFAULT(x, var) if (!WMIsPLString(value)) { \
1216 wwarning(_("Wrong option format for key \"%s\". Should be %s."), \
1217 entry->key, x); \
1218 wwarning(_("using default \"%s\" instead"), entry->default_value); \
1219 var = entry->default_value;\
1220 } else var = WMGetFromPLString(value)\
1223 static int string2index(WMPropList * key, WMPropList * val, char *def, WOptionEnumeration * values)
1225 char *str;
1226 WOptionEnumeration *v;
1227 char buffer[TOTAL_VALUES_LENGTH];
1229 if (WMIsPLString(val) && (str = WMGetFromPLString(val))) {
1230 for (v = values; v->string != NULL; v++) {
1231 if (strcasecmp(v->string, str) == 0)
1232 return v->value;
1236 buffer[0] = 0;
1237 for (v = values; v->string != NULL; v++) {
1238 if (!v->is_alias) {
1239 if (buffer[0] != 0)
1240 strcat(buffer, ", ");
1241 strcat(buffer, v->string);
1244 wwarning(_("wrong option value for key \"%s\". Should be one of %s"), WMGetFromPLString(key), buffer);
1246 if (def) {
1247 return string2index(key, val, NULL, values);
1250 return -1;
1254 * value - is the value in the defaults DB
1255 * addr - is the address to store the data
1256 * ret - is the address to store a pointer to a temporary buffer. ret
1257 * must not be freed and is used by the set functions
1259 static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1261 static char data;
1262 char *val;
1263 int second_pass = 0;
1265 GET_STRING_OR_DEFAULT("Boolean", val);
1267 again:
1268 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
1269 || strcasecmp(val, "YES") == 0) {
1271 data = 1;
1272 } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N'))
1273 || strcasecmp(val, "NO") == 0) {
1274 data = 0;
1275 } else {
1276 int i;
1277 if (sscanf(val, "%i", &i) == 1) {
1278 if (i != 0)
1279 data = 1;
1280 else
1281 data = 0;
1282 } else {
1283 wwarning(_("can't convert \"%s\" to boolean for key \"%s\""), val, entry->key);
1284 if (second_pass == 0) {
1285 val = WMGetFromPLString(entry->plvalue);
1286 second_pass = 1;
1287 wwarning(_("using default \"%s\" instead"), val);
1288 goto again;
1290 return False;
1294 if (ret)
1295 *ret = &data;
1296 if (addr)
1297 *(char *)addr = data;
1299 return True;
1302 static int getInt(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1304 static int data;
1305 char *val;
1307 GET_STRING_OR_DEFAULT("Integer", val);
1309 if (sscanf(val, "%i", &data) != 1) {
1310 wwarning(_("can't convert \"%s\" to integer for key \"%s\""), val, entry->key);
1311 val = WMGetFromPLString(entry->plvalue);
1312 wwarning(_("using default \"%s\" instead"), val);
1313 if (sscanf(val, "%i", &data) != 1) {
1314 return False;
1318 if (ret)
1319 *ret = &data;
1320 if (addr)
1321 *(int *)addr = data;
1323 return True;
1326 static int getCoord(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1328 static WCoord data;
1329 char *val_x, *val_y;
1330 int nelem, changed = 0;
1331 WMPropList *elem_x, *elem_y;
1333 again:
1334 if (!WMIsPLArray(value)) {
1335 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Coordinate");
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 nelem = WMGetPropListItemCount(value);
1346 if (nelem != 2) {
1347 wwarning(_("Incorrect number of elements in array for key \"%s\"."), entry->key);
1348 if (changed == 0) {
1349 value = entry->plvalue;
1350 changed = 1;
1351 wwarning(_("using default \"%s\" instead"), entry->default_value);
1352 goto again;
1354 return False;
1357 elem_x = WMGetFromPLArray(value, 0);
1358 elem_y = WMGetFromPLArray(value, 1);
1360 if (!elem_x || !elem_y || !WMIsPLString(elem_x) || !WMIsPLString(elem_y)) {
1361 wwarning(_("Wrong value for key \"%s\". Should be Coordinate."), entry->key);
1362 if (changed == 0) {
1363 value = entry->plvalue;
1364 changed = 1;
1365 wwarning(_("using default \"%s\" instead"), entry->default_value);
1366 goto again;
1368 return False;
1371 val_x = WMGetFromPLString(elem_x);
1372 val_y = WMGetFromPLString(elem_y);
1374 if (sscanf(val_x, "%i", &data.x) != 1 || sscanf(val_y, "%i", &data.y) != 1) {
1375 wwarning(_("can't convert array to integers for \"%s\"."), entry->key);
1376 if (changed == 0) {
1377 value = entry->plvalue;
1378 changed = 1;
1379 wwarning(_("using default \"%s\" instead"), entry->default_value);
1380 goto again;
1382 return False;
1385 if (data.x < 0)
1386 data.x = 0;
1387 else if (data.x > scr->scr_width / 3)
1388 data.x = scr->scr_width / 3;
1389 if (data.y < 0)
1390 data.y = 0;
1391 else if (data.y > scr->scr_height / 3)
1392 data.y = scr->scr_height / 3;
1394 if (ret)
1395 *ret = &data;
1396 if (addr)
1397 *(WCoord *) addr = data;
1399 return True;
1402 static int getPropList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1404 WMRetainPropList(value);
1406 *ret = value;
1408 return True;
1411 static int getPathList(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1413 static char *data;
1414 int i, count, len;
1415 char *ptr;
1416 WMPropList *d;
1417 int changed = 0;
1419 again:
1420 if (!WMIsPLArray(value)) {
1421 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "an array of paths");
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 i = 0;
1432 count = WMGetPropListItemCount(value);
1433 if (count < 1) {
1434 if (changed == 0) {
1435 value = entry->plvalue;
1436 changed = 1;
1437 wwarning(_("using default \"%s\" instead"), entry->default_value);
1438 goto again;
1440 return False;
1443 len = 0;
1444 for (i = 0; i < count; i++) {
1445 d = WMGetFromPLArray(value, i);
1446 if (!d || !WMIsPLString(d)) {
1447 count = i;
1448 break;
1450 len += strlen(WMGetFromPLString(d)) + 1;
1453 ptr = data = wmalloc(len + 1);
1455 for (i = 0; i < count; i++) {
1456 d = WMGetFromPLArray(value, i);
1457 if (!d || !WMIsPLString(d)) {
1458 break;
1460 strcpy(ptr, WMGetFromPLString(d));
1461 ptr += strlen(WMGetFromPLString(d));
1462 *ptr = ':';
1463 ptr++;
1465 ptr--;
1466 *(ptr--) = 0;
1468 if (*(char **)addr != NULL) {
1469 wfree(*(char **)addr);
1471 *(char **)addr = data;
1473 return True;
1476 static int getEnum(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1478 static signed char data;
1480 data = string2index(entry->plkey, value, entry->default_value, (WOptionEnumeration *) entry->extra_data);
1481 if (data < 0)
1482 return False;
1484 if (ret)
1485 *ret = &data;
1486 if (addr)
1487 *(signed char *)addr = data;
1489 return True;
1493 * (solid <color>)
1494 * (hgradient <color> <color>)
1495 * (vgradient <color> <color>)
1496 * (dgradient <color> <color>)
1497 * (mhgradient <color> <color> ...)
1498 * (mvgradient <color> <color> ...)
1499 * (mdgradient <color> <color> ...)
1500 * (igradient <color1> <color1> <thickness1> <color2> <color2> <thickness2>)
1501 * (tpixmap <file> <color>)
1502 * (spixmap <file> <color>)
1503 * (cpixmap <file> <color>)
1504 * (thgradient <file> <opaqueness> <color> <color>)
1505 * (tvgradient <file> <opaqueness> <color> <color>)
1506 * (tdgradient <file> <opaqueness> <color> <color>)
1507 * (function <lib> <function> ...)
1510 static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
1512 WMPropList *elem;
1513 char *val;
1514 int nelem;
1515 WTexture *texture = NULL;
1517 nelem = WMGetPropListItemCount(pl);
1518 if (nelem < 1)
1519 return NULL;
1521 elem = WMGetFromPLArray(pl, 0);
1522 if (!elem || !WMIsPLString(elem))
1523 return NULL;
1524 val = WMGetFromPLString(elem);
1526 if (strcasecmp(val, "solid") == 0) {
1527 XColor color;
1529 if (nelem != 2)
1530 return NULL;
1532 /* get color */
1534 elem = WMGetFromPLArray(pl, 1);
1535 if (!elem || !WMIsPLString(elem))
1536 return NULL;
1537 val = WMGetFromPLString(elem);
1539 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1540 wwarning(_("\"%s\" is not a valid color name"), val);
1541 return NULL;
1544 texture = (WTexture *) wTextureMakeSolid(scr, &color);
1545 } else if (strcasecmp(val, "dgradient") == 0
1546 || strcasecmp(val, "vgradient") == 0 || strcasecmp(val, "hgradient") == 0) {
1547 RColor color1, color2;
1548 XColor xcolor;
1549 int type;
1551 if (nelem != 3) {
1552 wwarning(_("bad number of arguments in gradient specification"));
1553 return NULL;
1556 if (val[0] == 'd' || val[0] == 'D')
1557 type = WTEX_DGRADIENT;
1558 else if (val[0] == 'h' || val[0] == 'H')
1559 type = WTEX_HGRADIENT;
1560 else
1561 type = WTEX_VGRADIENT;
1563 /* get from color */
1564 elem = WMGetFromPLArray(pl, 1);
1565 if (!elem || !WMIsPLString(elem))
1566 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 color1.alpha = 255;
1574 color1.red = xcolor.red >> 8;
1575 color1.green = xcolor.green >> 8;
1576 color1.blue = xcolor.blue >> 8;
1578 /* get to color */
1579 elem = WMGetFromPLArray(pl, 2);
1580 if (!elem || !WMIsPLString(elem)) {
1581 return NULL;
1583 val = WMGetFromPLString(elem);
1585 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1586 wwarning(_("\"%s\" is not a valid color name"), val);
1587 return NULL;
1589 color2.alpha = 255;
1590 color2.red = xcolor.red >> 8;
1591 color2.green = xcolor.green >> 8;
1592 color2.blue = xcolor.blue >> 8;
1594 texture = (WTexture *) wTextureMakeGradient(scr, type, &color1, &color2);
1596 } else if (strcasecmp(val, "igradient") == 0) {
1597 RColor colors1[2], colors2[2];
1598 int th1, th2;
1599 XColor xcolor;
1600 int i;
1602 if (nelem != 7) {
1603 wwarning(_("bad number of arguments in gradient specification"));
1604 return NULL;
1607 /* get from color */
1608 for (i = 0; i < 2; i++) {
1609 elem = WMGetFromPLArray(pl, 1 + i);
1610 if (!elem || !WMIsPLString(elem))
1611 return NULL;
1612 val = WMGetFromPLString(elem);
1614 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1615 wwarning(_("\"%s\" is not a valid color name"), val);
1616 return NULL;
1618 colors1[i].alpha = 255;
1619 colors1[i].red = xcolor.red >> 8;
1620 colors1[i].green = xcolor.green >> 8;
1621 colors1[i].blue = xcolor.blue >> 8;
1623 elem = WMGetFromPLArray(pl, 3);
1624 if (!elem || !WMIsPLString(elem))
1625 return NULL;
1626 val = WMGetFromPLString(elem);
1627 th1 = atoi(val);
1629 /* get from color */
1630 for (i = 0; i < 2; i++) {
1631 elem = WMGetFromPLArray(pl, 4 + i);
1632 if (!elem || !WMIsPLString(elem))
1633 return NULL;
1634 val = WMGetFromPLString(elem);
1636 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1637 wwarning(_("\"%s\" is not a valid color name"), val);
1638 return NULL;
1640 colors2[i].alpha = 255;
1641 colors2[i].red = xcolor.red >> 8;
1642 colors2[i].green = xcolor.green >> 8;
1643 colors2[i].blue = xcolor.blue >> 8;
1645 elem = WMGetFromPLArray(pl, 6);
1646 if (!elem || !WMIsPLString(elem))
1647 return NULL;
1648 val = WMGetFromPLString(elem);
1649 th2 = atoi(val);
1651 texture = (WTexture *) wTextureMakeIGradient(scr, th1, colors1, th2, colors2);
1653 } else if (strcasecmp(val, "mhgradient") == 0
1654 || strcasecmp(val, "mvgradient") == 0 || strcasecmp(val, "mdgradient") == 0) {
1655 XColor color;
1656 RColor **colors;
1657 int i, count;
1658 int type;
1660 if (nelem < 3) {
1661 wwarning(_("too few arguments in multicolor gradient specification"));
1662 return NULL;
1665 if (val[1] == 'h' || val[1] == 'H')
1666 type = WTEX_MHGRADIENT;
1667 else if (val[1] == 'v' || val[1] == 'V')
1668 type = WTEX_MVGRADIENT;
1669 else
1670 type = WTEX_MDGRADIENT;
1672 count = nelem - 1;
1674 colors = wmalloc(sizeof(RColor *) * (count + 1));
1676 for (i = 0; i < count; i++) {
1677 elem = WMGetFromPLArray(pl, i + 1);
1678 if (!elem || !WMIsPLString(elem)) {
1679 for (--i; i >= 0; --i) {
1680 wfree(colors[i]);
1682 wfree(colors);
1683 return NULL;
1685 val = WMGetFromPLString(elem);
1687 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1688 wwarning(_("\"%s\" is not a valid color name"), val);
1689 for (--i; i >= 0; --i) {
1690 wfree(colors[i]);
1692 wfree(colors);
1693 return NULL;
1694 } else {
1695 colors[i] = wmalloc(sizeof(RColor));
1696 colors[i]->red = color.red >> 8;
1697 colors[i]->green = color.green >> 8;
1698 colors[i]->blue = color.blue >> 8;
1701 colors[i] = NULL;
1703 texture = (WTexture *) wTextureMakeMGradient(scr, type, colors);
1704 } else if (strcasecmp(val, "spixmap") == 0 ||
1705 strcasecmp(val, "cpixmap") == 0 || strcasecmp(val, "tpixmap") == 0) {
1706 XColor color;
1707 int type;
1709 if (nelem != 3)
1710 return NULL;
1712 if (val[0] == 's' || val[0] == 'S')
1713 type = WTP_SCALE;
1714 else if (val[0] == 'c' || val[0] == 'C')
1715 type = WTP_CENTER;
1716 else
1717 type = WTP_TILE;
1719 /* get color */
1720 elem = WMGetFromPLArray(pl, 2);
1721 if (!elem || !WMIsPLString(elem)) {
1722 return NULL;
1724 val = WMGetFromPLString(elem);
1726 if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
1727 wwarning(_("\"%s\" is not a valid color name"), val);
1728 return NULL;
1731 /* file name */
1732 elem = WMGetFromPLArray(pl, 1);
1733 if (!elem || !WMIsPLString(elem))
1734 return NULL;
1735 val = WMGetFromPLString(elem);
1737 texture = (WTexture *) wTextureMakePixmap(scr, type, val, &color);
1738 } else if (strcasecmp(val, "thgradient") == 0
1739 || strcasecmp(val, "tvgradient") == 0 || strcasecmp(val, "tdgradient") == 0) {
1740 RColor color1, color2;
1741 XColor xcolor;
1742 int opacity;
1743 int style;
1745 if (val[1] == 'h' || val[1] == 'H')
1746 style = WTEX_THGRADIENT;
1747 else if (val[1] == 'v' || val[1] == 'V')
1748 style = WTEX_TVGRADIENT;
1749 else
1750 style = WTEX_TDGRADIENT;
1752 if (nelem != 5) {
1753 wwarning(_("bad number of arguments in textured gradient specification"));
1754 return NULL;
1757 /* get from color */
1758 elem = WMGetFromPLArray(pl, 3);
1759 if (!elem || !WMIsPLString(elem))
1760 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 color1.alpha = 255;
1768 color1.red = xcolor.red >> 8;
1769 color1.green = xcolor.green >> 8;
1770 color1.blue = xcolor.blue >> 8;
1772 /* get to color */
1773 elem = WMGetFromPLArray(pl, 4);
1774 if (!elem || !WMIsPLString(elem)) {
1775 return NULL;
1777 val = WMGetFromPLString(elem);
1779 if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
1780 wwarning(_("\"%s\" is not a valid color name"), val);
1781 return NULL;
1783 color2.alpha = 255;
1784 color2.red = xcolor.red >> 8;
1785 color2.green = xcolor.green >> 8;
1786 color2.blue = xcolor.blue >> 8;
1788 /* get opacity */
1789 elem = WMGetFromPLArray(pl, 2);
1790 if (!elem || !WMIsPLString(elem))
1791 opacity = 128;
1792 else
1793 val = WMGetFromPLString(elem);
1795 if (!val || (opacity = atoi(val)) < 0 || opacity > 255) {
1796 wwarning(_("bad opacity value for tgradient texture \"%s\". Should be [0..255]"), val);
1797 opacity = 128;
1800 /* get file name */
1801 elem = WMGetFromPLArray(pl, 1);
1802 if (!elem || !WMIsPLString(elem))
1803 return NULL;
1804 val = WMGetFromPLString(elem);
1806 texture = (WTexture *) wTextureMakeTGradient(scr, style, &color1, &color2, val, opacity);
1808 #ifdef TEXTURE_PLUGIN
1809 else if (strcasecmp(val, "function") == 0) {
1810 WTexFunction *function;
1811 void (*initFunc) (Display *, Colormap);
1812 char *lib, *func, **argv;
1813 int i, argc;
1815 if (nelem < 3)
1816 return NULL;
1818 /* get the library name */
1819 elem = WMGetFromPLArray(pl, 1);
1820 if (!elem || !WMIsPLString(elem)) {
1821 return NULL;
1823 lib = WMGetFromPLString(elem);
1825 /* get the function name */
1826 elem = WMGetFromPLArray(pl, 2);
1827 if (!elem || !WMIsPLString(elem)) {
1828 return NULL;
1830 func = WMGetFromPLString(elem);
1832 argc = nelem - 2;
1833 argv = (char **)wmalloc(argc * sizeof(char *));
1835 /* get the parameters */
1836 argv[0] = wstrdup(func);
1837 for (i = 0; i < argc - 1; i++) {
1838 elem = WMGetFromPLArray(pl, 3 + i);
1839 if (!elem || !WMIsPLString(elem)) {
1840 wfree(argv);
1842 return NULL;
1844 argv[i + 1] = wstrdup(WMGetFromPLString(elem));
1847 function = wTextureMakeFunction(scr, lib, func, argc, argv);
1849 #ifdef HAVE_DLFCN_H
1850 if (function) {
1851 initFunc = dlsym(function->handle, "initWindowMaker");
1852 if (initFunc) {
1853 initFunc(dpy, scr->w_colormap);
1854 } else {
1855 wwarning(_("could not initialize library %s"), lib);
1857 } else {
1858 wwarning(_("could not find function %s::%s"), lib, func);
1860 #endif /* HAVE_DLFCN_H */
1861 texture = (WTexture *) function;
1863 #endif /* TEXTURE_PLUGIN */
1864 else {
1865 wwarning(_("invalid texture type %s"), val);
1866 return NULL;
1868 return texture;
1871 static int getTexture(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1873 static WTexture *texture;
1874 int changed = 0;
1876 again:
1877 if (!WMIsPLArray(value)) {
1878 wwarning(_("Wrong option format for key \"%s\". Should be %s."), entry->key, "Texture");
1879 if (changed == 0) {
1880 value = entry->plvalue;
1881 changed = 1;
1882 wwarning(_("using default \"%s\" instead"), entry->default_value);
1883 goto again;
1885 return False;
1888 if (strcmp(entry->key, "WidgetColor") == 0 && !changed) {
1889 WMPropList *pl;
1891 pl = WMGetFromPLArray(value, 0);
1892 if (!pl || !WMIsPLString(pl) || !WMGetFromPLString(pl)
1893 || strcasecmp(WMGetFromPLString(pl), "solid") != 0) {
1894 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1895 entry->key, "Solid Texture");
1897 value = entry->plvalue;
1898 changed = 1;
1899 wwarning(_("using default \"%s\" instead"), entry->default_value);
1900 goto again;
1904 texture = parse_texture(scr, value);
1906 if (!texture) {
1907 wwarning(_("Error in texture specification for key \"%s\""), entry->key);
1908 if (changed == 0) {
1909 value = entry->plvalue;
1910 changed = 1;
1911 wwarning(_("using default \"%s\" instead"), entry->default_value);
1912 goto again;
1914 return False;
1917 if (ret)
1918 *ret = &texture;
1920 if (addr)
1921 *(WTexture **) addr = texture;
1923 return True;
1926 static int getWSBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1928 WMPropList *elem;
1929 int changed = 0;
1930 char *val;
1931 int nelem;
1933 again:
1934 if (!WMIsPLArray(value)) {
1935 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1936 "WorkspaceBack", "Texture or None");
1937 if (changed == 0) {
1938 value = entry->plvalue;
1939 changed = 1;
1940 wwarning(_("using default \"%s\" instead"), entry->default_value);
1941 goto again;
1943 return False;
1946 /* only do basic error checking and verify for None texture */
1948 nelem = WMGetPropListItemCount(value);
1949 if (nelem > 0) {
1950 elem = WMGetFromPLArray(value, 0);
1951 if (!elem || !WMIsPLString(elem)) {
1952 wwarning(_("Wrong type for workspace background. Should be a texture type."));
1953 if (changed == 0) {
1954 value = entry->plvalue;
1955 changed = 1;
1956 wwarning(_("using default \"%s\" instead"), entry->default_value);
1957 goto again;
1959 return False;
1961 val = WMGetFromPLString(elem);
1963 if (strcasecmp(val, "None") == 0)
1964 return True;
1966 *ret = WMRetainPropList(value);
1968 return True;
1971 static int
1972 getWSSpecificBackground(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
1974 WMPropList *elem;
1975 int nelem;
1976 int changed = 0;
1978 again:
1979 if (!WMIsPLArray(value)) {
1980 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
1981 "WorkspaceSpecificBack", "an array of textures");
1982 if (changed == 0) {
1983 value = entry->plvalue;
1984 changed = 1;
1985 wwarning(_("using default \"%s\" instead"), entry->default_value);
1986 goto again;
1988 return False;
1991 /* only do basic error checking and verify for None texture */
1993 nelem = WMGetPropListItemCount(value);
1994 if (nelem > 0) {
1995 while (nelem--) {
1996 elem = WMGetFromPLArray(value, nelem);
1997 if (!elem || !WMIsPLArray(elem)) {
1998 wwarning(_("Wrong type for background of workspace %i. Should be a texture."),
1999 nelem);
2004 *ret = WMRetainPropList(value);
2006 #ifdef notworking
2008 * Kluge to force wmsetbg helper to set the default background.
2009 * If the WorkspaceSpecificBack is changed once wmaker has started,
2010 * the WorkspaceBack won't be sent to the helper, unless the user
2011 * changes it's value too. So, we must force this by removing the
2012 * value from the defaults DB.
2014 if (!scr->flags.backimage_helper_launched && !scr->flags.startup) {
2015 WMPropList *key = WMCreatePLString("WorkspaceBack");
2017 WMRemoveFromPLDictionary(WDWindowMaker->dictionary, key);
2019 WMReleasePropList(key);
2021 #endif
2022 return True;
2025 static int getFont(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2027 static WMFont *font;
2028 char *val;
2030 GET_STRING_OR_DEFAULT("Font", val);
2032 font = WMCreateFont(scr->wmscreen, val);
2033 if (!font)
2034 font = WMCreateFont(scr->wmscreen, "fixed");
2036 if (!font) {
2037 wfatal(_("could not load any usable font!!!"));
2038 exit(1);
2041 if (ret)
2042 *ret = font;
2044 /* can't assign font value outside update function */
2045 wassertrv(addr == NULL, True);
2047 return True;
2050 static int getColor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2052 static XColor color;
2053 char *val;
2054 int second_pass = 0;
2056 GET_STRING_OR_DEFAULT("Color", val);
2058 again:
2059 if (!wGetColor(scr, val, &color)) {
2060 wwarning(_("could not get color for key \"%s\""), entry->key);
2061 if (second_pass == 0) {
2062 val = WMGetFromPLString(entry->plvalue);
2063 second_pass = 1;
2064 wwarning(_("using default \"%s\" instead"), val);
2065 goto again;
2067 return False;
2070 if (ret)
2071 *ret = &color;
2073 assert(addr == NULL);
2075 if (addr)
2076 *(unsigned long*)addr = pixel;
2079 return True;
2082 static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2084 static WShortKey shortcut;
2085 KeySym ksym;
2086 char *val;
2087 char *k;
2088 char buf[MAX_SHORTCUT_LENGTH], *b;
2090 GET_STRING_OR_DEFAULT("Key spec", val);
2092 if (!val || strcasecmp(val, "NONE") == 0) {
2093 shortcut.keycode = 0;
2094 shortcut.modifier = 0;
2095 if (ret)
2096 *ret = &shortcut;
2097 return True;
2100 strncpy(buf, val, MAX_SHORTCUT_LENGTH);
2102 b = (char *)buf;
2104 /* get modifiers */
2105 shortcut.modifier = 0;
2106 while ((k = strchr(b, '+')) != NULL) {
2107 int mod;
2109 *k = 0;
2110 mod = wXModifierFromKey(b);
2111 if (mod < 0) {
2112 wwarning(_("%s: invalid key modifier \"%s\""), entry->key, b);
2113 return False;
2115 shortcut.modifier |= mod;
2117 b = k + 1;
2120 /* get key */
2121 ksym = XStringToKeysym(b);
2123 if (ksym == NoSymbol) {
2124 wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
2125 return False;
2128 shortcut.keycode = XKeysymToKeycode(dpy, ksym);
2129 if (shortcut.keycode == 0) {
2130 wwarning(_("%s:invalid key in shortcut \"%s\""), entry->key, val);
2131 return False;
2134 if (ret)
2135 *ret = &shortcut;
2137 return True;
2140 static int getModMask(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2142 static int mask;
2143 char *str;
2145 GET_STRING_OR_DEFAULT("Modifier Key", str);
2147 if (!str)
2148 return False;
2150 mask = wXModifierFromKey(str);
2151 if (mask < 0) {
2152 wwarning(_("%s: modifier key %s is not valid"), entry->key, str);
2153 mask = 0;
2154 return False;
2157 if (addr)
2158 *(int *)addr = mask;
2160 if (ret)
2161 *ret = &mask;
2163 return True;
2166 # include <X11/cursorfont.h>
2167 typedef struct {
2168 char *name;
2169 int id;
2170 } WCursorLookup;
2172 #define CURSOR_ID_NONE (XC_num_glyphs)
2174 static WCursorLookup cursor_table[] = {
2175 {"X_cursor", XC_X_cursor},
2176 {"arrow", XC_arrow},
2177 {"based_arrow_down", XC_based_arrow_down},
2178 {"based_arrow_up", XC_based_arrow_up},
2179 {"boat", XC_boat},
2180 {"bogosity", XC_bogosity},
2181 {"bottom_left_corner", XC_bottom_left_corner},
2182 {"bottom_right_corner", XC_bottom_right_corner},
2183 {"bottom_side", XC_bottom_side},
2184 {"bottom_tee", XC_bottom_tee},
2185 {"box_spiral", XC_box_spiral},
2186 {"center_ptr", XC_center_ptr},
2187 {"circle", XC_circle},
2188 {"clock", XC_clock},
2189 {"coffee_mug", XC_coffee_mug},
2190 {"cross", XC_cross},
2191 {"cross_reverse", XC_cross_reverse},
2192 {"crosshair", XC_crosshair},
2193 {"diamond_cross", XC_diamond_cross},
2194 {"dot", XC_dot},
2195 {"dotbox", XC_dotbox},
2196 {"double_arrow", XC_double_arrow},
2197 {"draft_large", XC_draft_large},
2198 {"draft_small", XC_draft_small},
2199 {"draped_box", XC_draped_box},
2200 {"exchange", XC_exchange},
2201 {"fleur", XC_fleur},
2202 {"gobbler", XC_gobbler},
2203 {"gumby", XC_gumby},
2204 {"hand1", XC_hand1},
2205 {"hand2", XC_hand2},
2206 {"heart", XC_heart},
2207 {"icon", XC_icon},
2208 {"iron_cross", XC_iron_cross},
2209 {"left_ptr", XC_left_ptr},
2210 {"left_side", XC_left_side},
2211 {"left_tee", XC_left_tee},
2212 {"leftbutton", XC_leftbutton},
2213 {"ll_angle", XC_ll_angle},
2214 {"lr_angle", XC_lr_angle},
2215 {"man", XC_man},
2216 {"middlebutton", XC_middlebutton},
2217 {"mouse", XC_mouse},
2218 {"pencil", XC_pencil},
2219 {"pirate", XC_pirate},
2220 {"plus", XC_plus},
2221 {"question_arrow", XC_question_arrow},
2222 {"right_ptr", XC_right_ptr},
2223 {"right_side", XC_right_side},
2224 {"right_tee", XC_right_tee},
2225 {"rightbutton", XC_rightbutton},
2226 {"rtl_logo", XC_rtl_logo},
2227 {"sailboat", XC_sailboat},
2228 {"sb_down_arrow", XC_sb_down_arrow},
2229 {"sb_h_double_arrow", XC_sb_h_double_arrow},
2230 {"sb_left_arrow", XC_sb_left_arrow},
2231 {"sb_right_arrow", XC_sb_right_arrow},
2232 {"sb_up_arrow", XC_sb_up_arrow},
2233 {"sb_v_double_arrow", XC_sb_v_double_arrow},
2234 {"shuttle", XC_shuttle},
2235 {"sizing", XC_sizing},
2236 {"spider", XC_spider},
2237 {"spraycan", XC_spraycan},
2238 {"star", XC_star},
2239 {"target", XC_target},
2240 {"tcross", XC_tcross},
2241 {"top_left_arrow", XC_top_left_arrow},
2242 {"top_left_corner", XC_top_left_corner},
2243 {"top_right_corner", XC_top_right_corner},
2244 {"top_side", XC_top_side},
2245 {"top_tee", XC_top_tee},
2246 {"trek", XC_trek},
2247 {"ul_angle", XC_ul_angle},
2248 {"umbrella", XC_umbrella},
2249 {"ur_angle", XC_ur_angle},
2250 {"watch", XC_watch},
2251 {"xterm", XC_xterm},
2252 {NULL, CURSOR_ID_NONE}
2255 static void check_bitmap_status(int status, char *filename, Pixmap bitmap)
2257 switch (status) {
2258 case BitmapOpenFailed:
2259 wwarning(_("failed to open bitmap file \"%s\""), filename);
2260 break;
2261 case BitmapFileInvalid:
2262 wwarning(_("\"%s\" is not a valid bitmap file"), filename);
2263 break;
2264 case BitmapNoMemory:
2265 wwarning(_("out of memory reading bitmap file \"%s\""), filename);
2266 break;
2267 case BitmapSuccess:
2268 XFreePixmap(dpy, bitmap);
2269 break;
2274 * (none)
2275 * (builtin, <cursor_name>)
2276 * (bitmap, <cursor_bitmap>, <cursor_mask>)
2278 static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
2280 WMPropList *elem;
2281 char *val;
2282 int nelem;
2283 int status = 0;
2285 nelem = WMGetPropListItemCount(pl);
2286 if (nelem < 1) {
2287 return (status);
2289 elem = WMGetFromPLArray(pl, 0);
2290 if (!elem || !WMIsPLString(elem)) {
2291 return (status);
2293 val = WMGetFromPLString(elem);
2295 if (0 == strcasecmp(val, "none")) {
2296 status = 1;
2297 *cursor = None;
2298 } else if (0 == strcasecmp(val, "builtin")) {
2299 int i;
2300 int cursor_id = CURSOR_ID_NONE;
2302 if (2 != nelem) {
2303 wwarning(_("bad number of arguments in cursor specification"));
2304 return (status);
2306 elem = WMGetFromPLArray(pl, 1);
2307 if (!elem || !WMIsPLString(elem)) {
2308 return (status);
2310 val = WMGetFromPLString(elem);
2312 for (i = 0; NULL != cursor_table[i].name; i++) {
2313 if (0 == strcasecmp(val, cursor_table[i].name)) {
2314 cursor_id = cursor_table[i].id;
2315 break;
2318 if (CURSOR_ID_NONE == cursor_id) {
2319 wwarning(_("unknown builtin cursor name \"%s\""), val);
2320 } else {
2321 *cursor = XCreateFontCursor(dpy, cursor_id);
2322 status = 1;
2324 } else if (0 == strcasecmp(val, "bitmap")) {
2325 char *bitmap_name;
2326 char *mask_name;
2327 int bitmap_status;
2328 int mask_status;
2329 Pixmap bitmap;
2330 Pixmap mask;
2331 unsigned int w, h;
2332 int x, y;
2333 XColor fg, bg;
2335 if (3 != nelem) {
2336 wwarning(_("bad number of arguments in cursor specification"));
2337 return (status);
2339 elem = WMGetFromPLArray(pl, 1);
2340 if (!elem || !WMIsPLString(elem)) {
2341 return (status);
2343 val = WMGetFromPLString(elem);
2344 bitmap_name = FindImage(wPreferences.pixmap_path, val);
2345 if (!bitmap_name) {
2346 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2347 return (status);
2349 elem = WMGetFromPLArray(pl, 2);
2350 if (!elem || !WMIsPLString(elem)) {
2351 wfree(bitmap_name);
2352 return (status);
2354 val = WMGetFromPLString(elem);
2355 mask_name = FindImage(wPreferences.pixmap_path, val);
2356 if (!mask_name) {
2357 wfree(bitmap_name);
2358 wwarning(_("could not find cursor bitmap file \"%s\""), val);
2359 return (status);
2361 mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
2362 bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
2363 if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
2364 fg.pixel = scr->black_pixel;
2365 bg.pixel = scr->white_pixel;
2366 XQueryColor(dpy, scr->w_colormap, &fg);
2367 XQueryColor(dpy, scr->w_colormap, &bg);
2368 *cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
2369 status = 1;
2371 check_bitmap_status(bitmap_status, bitmap_name, bitmap);
2372 check_bitmap_status(mask_status, mask_name, mask);
2373 wfree(bitmap_name);
2374 wfree(mask_name);
2376 return (status);
2379 static int getCursor(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret)
2381 static Cursor cursor;
2382 int status;
2383 int changed = 0;
2385 again:
2386 if (!WMIsPLArray(value)) {
2387 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
2388 entry->key, "cursor specification");
2389 if (!changed) {
2390 value = entry->plvalue;
2391 changed = 1;
2392 wwarning(_("using default \"%s\" instead"), entry->default_value);
2393 goto again;
2395 return (False);
2397 status = parse_cursor(scr, value, &cursor);
2398 if (!status) {
2399 wwarning(_("Error in cursor specification for key \"%s\""), entry->key);
2400 if (!changed) {
2401 value = entry->plvalue;
2402 changed = 1;
2403 wwarning(_("using default \"%s\" instead"), entry->default_value);
2404 goto again;
2406 return (False);
2408 if (ret) {
2409 *ret = &cursor;
2411 if (addr) {
2412 *(Cursor *) addr = cursor;
2414 return (True);
2417 #undef CURSOR_ID_NONE
2419 /* ---------------- value setting functions --------------- */
2420 static int setJustify(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2422 return REFRESH_WINDOW_TITLE_COLOR;
2425 static int setClearance(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2427 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES | REFRESH_MENU_TITLE_FONT | REFRESH_MENU_FONT;
2430 static int setIfDockPresent(WScreen * scr, WDefaultEntry * entry, char *flag, long which)
2432 switch (which) {
2433 case WM_DOCK:
2434 wPreferences.flags.nodock = wPreferences.flags.nodock || *flag;
2435 break;
2436 case WM_CLIP:
2437 wPreferences.flags.noclip = wPreferences.flags.noclip || *flag;
2438 break;
2439 default:
2440 break;
2442 return 0;
2445 static int setStickyIcons(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2447 if (scr->workspaces) {
2448 wWorkspaceForceChange(scr, scr->current_workspace);
2449 wArrangeIcons(scr, False);
2451 return 0;
2454 static int setIconTile(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2456 Pixmap pixmap;
2457 RImage *img;
2458 int reset = 0;
2460 img = wTextureRenderImage(*texture, wPreferences.icon_size,
2461 wPreferences.icon_size, ((*texture)->any.type & WREL_BORDER_MASK)
2462 ? WREL_ICON : WREL_FLAT);
2463 if (!img) {
2464 wwarning(_("could not render texture for icon background"));
2465 if (!entry->addr)
2466 wTextureDestroy(scr, *texture);
2467 return 0;
2469 RConvertImage(scr->rcontext, img, &pixmap);
2471 if (scr->icon_tile) {
2472 reset = 1;
2473 RReleaseImage(scr->icon_tile);
2474 XFreePixmap(dpy, scr->icon_tile_pixmap);
2477 scr->icon_tile = img;
2479 /* put the icon in the noticeboard hint */
2480 PropSetIconTileHint(scr, img);
2482 if (!wPreferences.flags.noclip) {
2483 if (scr->clip_tile) {
2484 RReleaseImage(scr->clip_tile);
2486 scr->clip_tile = wClipMakeTile(scr, img);
2489 scr->icon_tile_pixmap = pixmap;
2491 if (scr->def_icon_pixmap) {
2492 XFreePixmap(dpy, scr->def_icon_pixmap);
2493 scr->def_icon_pixmap = None;
2495 if (scr->def_ticon_pixmap) {
2496 XFreePixmap(dpy, scr->def_ticon_pixmap);
2497 scr->def_ticon_pixmap = None;
2500 if (scr->icon_back_texture) {
2501 wTextureDestroy(scr, (WTexture *) scr->icon_back_texture);
2503 scr->icon_back_texture = wTextureMakeSolid(scr, &((*texture)->any.color));
2505 if (scr->clip_balloon)
2506 XSetWindowBackground(dpy, scr->clip_balloon, (*texture)->any.color.pixel);
2509 * Free the texture as nobody else will use it, nor refer to it.
2511 if (!entry->addr)
2512 wTextureDestroy(scr, *texture);
2514 return (reset ? REFRESH_ICON_TILE : 0);
2517 static int setWinTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2519 if (scr->title_font) {
2520 WMReleaseFont(scr->title_font);
2522 scr->title_font = font;
2524 return REFRESH_WINDOW_FONT | REFRESH_BUTTON_IMAGES;
2527 static int setMenuTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2529 if (scr->menu_title_font) {
2530 WMReleaseFont(scr->menu_title_font);
2533 scr->menu_title_font = font;
2535 return REFRESH_MENU_TITLE_FONT;
2538 static int setMenuTextFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2540 if (scr->menu_entry_font) {
2541 WMReleaseFont(scr->menu_entry_font);
2543 scr->menu_entry_font = font;
2545 return REFRESH_MENU_FONT;
2548 static int setIconTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2550 if (scr->icon_title_font) {
2551 WMReleaseFont(scr->icon_title_font);
2554 scr->icon_title_font = font;
2556 return REFRESH_ICON_FONT;
2559 static int setClipTitleFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2561 if (scr->clip_title_font) {
2562 WMReleaseFont(scr->clip_title_font);
2565 scr->clip_title_font = font;
2567 return REFRESH_ICON_FONT;
2570 static int setLargeDisplayFont(WScreen * scr, WDefaultEntry * entry, WMFont * font, void *foo)
2572 if (scr->workspace_name_font) {
2573 WMReleaseFont(scr->workspace_name_font);
2576 scr->workspace_name_font = font;
2578 return 0;
2581 static int setHightlight(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2583 if (scr->select_color)
2584 WMReleaseColor(scr->select_color);
2586 scr->select_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2588 wFreeColor(scr, color->pixel);
2590 return REFRESH_MENU_COLOR;
2593 static int setHightlightText(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2595 if (scr->select_text_color)
2596 WMReleaseColor(scr->select_text_color);
2598 scr->select_text_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2600 wFreeColor(scr, color->pixel);
2602 return REFRESH_MENU_COLOR;
2605 static int setClipTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2607 if (scr->clip_title_color[widx])
2608 WMReleaseColor(scr->clip_title_color[widx]);
2609 scr->clip_title_color[widx] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2610 #ifdef GRADIENT_CLIP_ARROW
2611 if (widx == CLIP_NORMAL) {
2612 RImage *image;
2613 RColor color1, color2;
2614 int pt = CLIP_BUTTON_SIZE * wPreferences.icon_size / 64;
2615 int as = pt - 15; /* 15 = 5+5+5 */
2617 FREE_PIXMAP(scr->clip_arrow_gradient);
2619 color1.red = (color->red >> 8) * 6 / 10;
2620 color1.green = (color->green >> 8) * 6 / 10;
2621 color1.blue = (color->blue >> 8) * 6 / 10;
2623 color2.red = WMIN((color->red >> 8) * 20 / 10, 255);
2624 color2.green = WMIN((color->green >> 8) * 20 / 10, 255);
2625 color2.blue = WMIN((color->blue >> 8) * 20 / 10, 255);
2627 image = RRenderGradient(as + 1, as + 1, &color1, &color2, RDiagonalGradient);
2628 RConvertImage(scr->rcontext, image, &scr->clip_arrow_gradient);
2629 RReleaseImage(image);
2631 #endif /* GRADIENT_CLIP_ARROW */
2633 wFreeColor(scr, color->pixel);
2635 return REFRESH_ICON_TITLE_COLOR;
2638 static int setWTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2640 if (scr->window_title_color[widx])
2641 WMReleaseColor(scr->window_title_color[widx]);
2643 scr->window_title_color[widx] =
2644 WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2646 wFreeColor(scr, color->pixel);
2648 return REFRESH_WINDOW_TITLE_COLOR;
2651 static int setMenuTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, long widx)
2653 if (scr->menu_title_color[0])
2654 WMReleaseColor(scr->menu_title_color[0]);
2656 scr->menu_title_color[0] = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2658 wFreeColor(scr, color->pixel);
2660 return REFRESH_MENU_TITLE_COLOR;
2663 static int setMenuTextColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2665 if (scr->mtext_color)
2666 WMReleaseColor(scr->mtext_color);
2668 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2670 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2671 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2672 } else {
2673 WMSetColorAlpha(scr->dtext_color, 0xffff);
2676 wFreeColor(scr, color->pixel);
2678 return REFRESH_MENU_COLOR;
2681 static int setMenuDisabledColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2683 if (scr->dtext_color)
2684 WMReleaseColor(scr->dtext_color);
2686 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2688 if (WMColorPixel(scr->dtext_color) == WMColorPixel(scr->mtext_color)) {
2689 WMSetColorAlpha(scr->dtext_color, 0x7fff);
2690 } else {
2691 WMSetColorAlpha(scr->dtext_color, 0xffff);
2694 wFreeColor(scr, color->pixel);
2696 return REFRESH_MENU_COLOR;
2699 static int setIconTitleColor(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2701 if (scr->icon_title_color)
2702 WMReleaseColor(scr->icon_title_color);
2703 scr->icon_title_color = WMCreateRGBColor(scr->wmscreen, color->red, color->green, color->blue, True);
2705 wFreeColor(scr, color->pixel);
2707 return REFRESH_ICON_TITLE_COLOR;
2710 static int setIconTitleBack(WScreen * scr, WDefaultEntry * entry, XColor * color, void *foo)
2712 if (scr->icon_title_texture) {
2713 wTextureDestroy(scr, (WTexture *) scr->icon_title_texture);
2715 scr->icon_title_texture = wTextureMakeSolid(scr, color);
2717 return REFRESH_ICON_TITLE_BACK;
2720 static void trackDeadProcess(pid_t pid, unsigned char status, WScreen * scr)
2722 close(scr->helper_fd);
2723 scr->helper_fd = 0;
2724 scr->helper_pid = 0;
2725 scr->flags.backimage_helper_launched = 0;
2728 static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2730 WMPropList *val;
2731 char *str;
2732 int i;
2734 if (scr->flags.backimage_helper_launched) {
2735 if (WMGetPropListItemCount(value) == 0) {
2736 SendHelperMessage(scr, 'C', 0, NULL);
2737 SendHelperMessage(scr, 'K', 0, NULL);
2739 WMReleasePropList(value);
2740 return 0;
2742 } else {
2743 pid_t pid;
2744 int filedes[2];
2746 if (WMGetPropListItemCount(value) == 0)
2747 return 0;
2749 if (pipe(filedes) < 0) {
2750 wsyserror("pipe() failed:can't set workspace specific background image");
2752 WMReleasePropList(value);
2753 return 0;
2756 pid = fork();
2757 if (pid < 0) {
2758 wsyserror("fork() failed:can't set workspace specific background image");
2759 if (close(filedes[0]) < 0)
2760 wsyserror("could not close pipe");
2761 if (close(filedes[1]) < 0)
2762 wsyserror("could not close pipe");
2764 } else if (pid == 0) {
2765 char *dither;
2767 SetupEnvironment(scr);
2769 if (close(0) < 0)
2770 wsyserror("could not close pipe");
2771 if (dup(filedes[0]) < 0) {
2772 wsyserror("dup() failed:can't set workspace specific background image");
2774 dither = wPreferences.no_dithering ? "-m" : "-d";
2775 if (wPreferences.smooth_workspace_back)
2776 execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
2777 else
2778 execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
2779 wsyserror("could not execute wmsetbg");
2780 exit(1);
2781 } else {
2783 if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
2784 wsyserror("error setting close-on-exec flag");
2786 if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
2787 wsyserror("error setting close-on-exec flag");
2790 scr->helper_fd = filedes[1];
2791 scr->helper_pid = pid;
2792 scr->flags.backimage_helper_launched = 1;
2794 wAddDeathHandler(pid, (WDeathHandler *) trackDeadProcess, scr);
2796 SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
2801 for (i = 0; i < WMGetPropListItemCount(value); i++) {
2802 val = WMGetFromPLArray(value, i);
2803 if (val && WMIsPLArray(val) && WMGetPropListItemCount(val) > 0) {
2804 str = WMGetPropListDescription(val, False);
2806 SendHelperMessage(scr, 'S', i + 1, str);
2808 wfree(str);
2809 } else {
2810 SendHelperMessage(scr, 'U', i + 1, NULL);
2813 sleep(1);
2815 WMReleasePropList(value);
2816 return 0;
2819 static int setWorkspaceBack(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *bar)
2821 if (scr->flags.backimage_helper_launched) {
2822 char *str;
2824 if (WMGetPropListItemCount(value) == 0) {
2825 SendHelperMessage(scr, 'U', 0, NULL);
2826 } else {
2827 /* set the default workspace background to this one */
2828 str = WMGetPropListDescription(value, False);
2829 if (str) {
2830 SendHelperMessage(scr, 'S', 0, str);
2831 wfree(str);
2832 SendHelperMessage(scr, 'C', scr->current_workspace + 1, NULL);
2833 } else {
2834 SendHelperMessage(scr, 'U', 0, NULL);
2837 } else if (WMGetPropListItemCount(value) > 0) {
2838 char *command;
2839 char *text;
2840 char *dither;
2841 int len;
2843 text = WMGetPropListDescription(value, False);
2844 len = strlen(text) + 40;
2845 command = wmalloc(len);
2846 dither = wPreferences.no_dithering ? "-m" : "-d";
2847 if (wPreferences.smooth_workspace_back)
2848 snprintf(command, len, "wmsetbg %s -S -p '%s' &", dither, text);
2849 else
2850 snprintf(command, len, "wmsetbg %s -p '%s' &", dither, text);
2851 wfree(text);
2852 ExecuteShellCommand(scr, command);
2853 wfree(command);
2855 WMReleasePropList(value);
2857 return 0;
2860 static int setWidgetColor(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2862 if (scr->widget_texture) {
2863 wTextureDestroy(scr, (WTexture *) scr->widget_texture);
2865 scr->widget_texture = *(WTexSolid **) texture;
2867 return 0;
2870 static int setFTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2872 if (scr->window_title_texture[WS_FOCUSED]) {
2873 wTextureDestroy(scr, scr->window_title_texture[WS_FOCUSED]);
2875 scr->window_title_texture[WS_FOCUSED] = *texture;
2877 return REFRESH_WINDOW_TEXTURES;
2880 static int setPTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2882 if (scr->window_title_texture[WS_PFOCUSED]) {
2883 wTextureDestroy(scr, scr->window_title_texture[WS_PFOCUSED]);
2885 scr->window_title_texture[WS_PFOCUSED] = *texture;
2887 return REFRESH_WINDOW_TEXTURES;
2890 static int setUTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2892 if (scr->window_title_texture[WS_UNFOCUSED]) {
2893 wTextureDestroy(scr, scr->window_title_texture[WS_UNFOCUSED]);
2895 scr->window_title_texture[WS_UNFOCUSED] = *texture;
2897 return REFRESH_WINDOW_TEXTURES;
2900 static int setResizebarBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2902 if (scr->resizebar_texture[0]) {
2903 wTextureDestroy(scr, scr->resizebar_texture[0]);
2905 scr->resizebar_texture[0] = *texture;
2907 return REFRESH_WINDOW_TEXTURES;
2910 static int setMenuTitleBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2912 if (scr->menu_title_texture[0]) {
2913 wTextureDestroy(scr, scr->menu_title_texture[0]);
2915 scr->menu_title_texture[0] = *texture;
2917 return REFRESH_MENU_TITLE_TEXTURE;
2920 static int setMenuTextBack(WScreen * scr, WDefaultEntry * entry, WTexture ** texture, void *foo)
2922 if (scr->menu_item_texture) {
2923 wTextureDestroy(scr, scr->menu_item_texture);
2924 wTextureDestroy(scr, (WTexture *) scr->menu_item_auxtexture);
2926 scr->menu_item_texture = *texture;
2928 scr->menu_item_auxtexture = wTextureMakeSolid(scr, &scr->menu_item_texture->any.color);
2930 return REFRESH_MENU_TEXTURE;
2933 static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, WShortKey * shortcut, long widx)
2935 WWindow *wwin;
2936 wKeyBindings[widx] = *shortcut;
2938 wwin = scr->focused_window;
2940 while (wwin != NULL) {
2941 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
2943 if (!WFLAGP(wwin, no_bind_keys)) {
2944 wWindowSetKeyGrabs(wwin);
2946 wwin = wwin->prev;
2949 return 0;
2952 static int setIconPosition(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2954 wScreenUpdateUsableArea(scr);
2955 wArrangeIcons(scr, True);
2957 return 0;
2960 static int updateUsableArea(WScreen * scr, WDefaultEntry * entry, void *bar, void *foo)
2962 wScreenUpdateUsableArea(scr);
2964 return 0;
2967 static int setMenuStyle(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
2969 return REFRESH_MENU_TEXTURE;
2972 static RImage *chopOffImage(RImage * image, int x, int y, int w, int h)
2974 RImage *img = RCreateImage(w, h, image->format == RRGBAFormat);
2976 RCopyArea(img, image, x, y, w, h, 0, 0);
2978 return img;
2981 static int setSwPOptions(WScreen * scr, WDefaultEntry * entry, WMPropList * array, void *foo)
2983 char *path;
2984 RImage *bgimage;
2985 int cwidth, cheight;
2986 WPreferences *prefs = (WPreferences *) foo;
2988 if (!WMIsPLArray(array) || WMGetPropListItemCount(array) == 0) {
2989 if (prefs->swtileImage)
2990 RReleaseImage(prefs->swtileImage);
2991 prefs->swtileImage = NULL;
2993 WMReleasePropList(array);
2994 return 0;
2997 switch (WMGetPropListItemCount(array)) {
2998 case 4:
2999 if (!WMIsPLString(WMGetFromPLArray(array, 1))) {
3000 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3001 break;
3002 } else
3003 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 1)));
3005 if (!path) {
3006 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3007 WMGetFromPLString(WMGetFromPLArray(array, 1)), entry->key);
3008 } else {
3009 bgimage = RLoadImage(scr->rcontext, path, 0);
3010 if (!bgimage) {
3011 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3012 wfree(path);
3013 } else {
3014 wfree(path);
3016 cwidth = atoi(WMGetFromPLString(WMGetFromPLArray(array, 2)));
3017 cheight = atoi(WMGetFromPLString(WMGetFromPLArray(array, 3)));
3019 if (cwidth <= 0 || cheight <= 0 ||
3020 cwidth >= bgimage->width - 2 || cheight >= bgimage->height - 2)
3021 wwarning(_("Invalid split sizes for SwitchPanel back image."));
3022 else {
3023 int i;
3024 int swidth, theight;
3025 for (i = 0; i < 9; i++) {
3026 if (prefs->swbackImage[i])
3027 RReleaseImage(prefs->swbackImage[i]);
3028 prefs->swbackImage[i] = NULL;
3030 swidth = (bgimage->width - cwidth) / 2;
3031 theight = (bgimage->height - cheight) / 2;
3033 prefs->swbackImage[0] = chopOffImage(bgimage, 0, 0, swidth, theight);
3034 prefs->swbackImage[1] = chopOffImage(bgimage, swidth, 0, cwidth, theight);
3035 prefs->swbackImage[2] = chopOffImage(bgimage, swidth + cwidth, 0,
3036 swidth, theight);
3038 prefs->swbackImage[3] = chopOffImage(bgimage, 0, theight, swidth, cheight);
3039 prefs->swbackImage[4] = chopOffImage(bgimage, swidth, theight,
3040 cwidth, cheight);
3041 prefs->swbackImage[5] = chopOffImage(bgimage, swidth + cwidth, theight,
3042 swidth, cheight);
3044 prefs->swbackImage[6] = chopOffImage(bgimage, 0, theight + cheight,
3045 swidth, theight);
3046 prefs->swbackImage[7] = chopOffImage(bgimage, swidth, theight + cheight,
3047 cwidth, theight);
3048 prefs->swbackImage[8] =
3049 chopOffImage(bgimage, swidth + cwidth, theight + cheight, swidth,
3050 theight);
3052 // check if anything failed
3053 for (i = 0; i < 9; i++) {
3054 if (!prefs->swbackImage[i]) {
3055 for (; i >= 0; --i) {
3056 RReleaseImage(prefs->swbackImage[i]);
3057 prefs->swbackImage[i] = NULL;
3059 break;
3063 RReleaseImage(bgimage);
3067 case 1:
3068 if (!WMIsPLString(WMGetFromPLArray(array, 0))) {
3069 wwarning(_("Invalid arguments for option \"%s\""), entry->key);
3070 break;
3071 } else
3072 path = FindImage(wPreferences.pixmap_path, WMGetFromPLString(WMGetFromPLArray(array, 0)));
3074 if (!path) {
3075 wwarning(_("Could not find image \"%s\" for option \"%s\""),
3076 WMGetFromPLString(WMGetFromPLArray(array, 0)), entry->key);
3077 } else {
3078 if (prefs->swtileImage)
3079 RReleaseImage(prefs->swtileImage);
3081 prefs->swtileImage = RLoadImage(scr->rcontext, path, 0);
3082 if (!prefs->swtileImage) {
3083 wwarning(_("Could not load image \"%s\" for option \"%s\""), path, entry->key);
3085 wfree(path);
3087 break;
3089 default:
3090 wwarning(_("Invalid number of arguments for option \"%s\""), entry->key);
3091 break;
3094 WMReleasePropList(array);
3096 return 0;
3100 * Very ugly kluge.
3101 * Need access to the double click variables, so that all widgets in
3102 * wmaker panels will have the same dbl-click values.
3103 * TODO: figure a better way of dealing with it.
3105 #include <WINGs/WINGsP.h>
3107 static int setDoubleClick(WScreen * scr, WDefaultEntry * entry, int *value, void *foo)
3109 extern _WINGsConfiguration WINGsConfiguration;
3111 if (*value <= 0)
3112 *(int *)foo = 1;
3114 WINGsConfiguration.doubleClickDelay = *value;
3116 return 0;
3119 static int setCursor(WScreen * scr, WDefaultEntry * entry, Cursor * cursor, long widx)
3121 if (wCursor[widx] != None) {
3122 XFreeCursor(dpy, wCursor[widx]);
3125 wCursor[widx] = *cursor;
3127 if (widx == WCUR_ROOT && *cursor != None) {
3128 XDefineCursor(dpy, scr->root_win, *cursor);
3131 return 0;