1 /**
2 * @file settings.c
3 * @author Joe Wingbermuehle
4 * @date 2012
5 *
6 * @brief JWM settings.
7 *
8 */
9
10 #include "jwm.h"
11 #include "settings.h"
12 #include "misc.h"
13
14 Settings settings;
15
16 static void FixRange(unsigned int *value,
17 unsigned int min_value,
18 unsigned int max_value,
19 unsigned int def_value);
20
21 /** Initialize settings. */
InitializeSettings(void)22 void InitializeSettings(void)
23 {
24 settings.moveMask = (1 << Mod1MapIndex);
25 settings.doubleClickSpeed = 400;
26 settings.doubleClickDelta = 2;
27 settings.snapMode = SNAP_BORDER;
28 settings.snapDistance = 5;
29 settings.moveMode = MOVE_OPAQUE;
30 settings.moveStatusType = SW_SCREEN;
31 settings.resizeStatusType = SW_SCREEN;
32 settings.focusModel = FOCUS_SLOPPY;
33 settings.resizeMode = RESIZE_OPAQUE;
34 settings.popupDelay = 600;
35 settings.desktopDelay = 1000;
36 settings.trayOpacity = UINT_MAX;
37 settings.popupMask = POPUP_ALL;
38 settings.activeClientOpacity = UINT_MAX;
39 settings.inactiveClientOpacity = (unsigned int)(0.75 * UINT_MAX);
40 settings.borderWidth = 5;
41 settings.titleHeight = 0;
42 settings.titleTextAlignment = ALIGN_LEFT;
43 settings.desktopWidth = 4;
44 settings.desktopHeight = 1;
45 settings.menuOpacity = UINT_MAX;
46 settings.windowDecorations = DECO_FLAT;
47 settings.trayDecorations = DECO_FLAT;
48 settings.taskListDecorations = DECO_UNSET;
49 settings.menuDecorations = DECO_FLAT;
50 settings.cornerRadius = 4;
51 settings.groupTasks = 0;
52 settings.listAllTasks = 0;
53 settings.dockSpacing = 0;
54 }
55
56 /** Make sure settings are reasonable. */
StartupSettings(void)57 void StartupSettings(void)
58 {
59
60 FixRange(&settings.cornerRadius, 0, 5, 4);
61
62 FixRange(&settings.borderWidth, 1, 128, 4);
63 FixRange(&settings.titleHeight, 0, 256, 0);
64
65 FixRange(&settings.doubleClickDelta, 0, 64, 2);
66 FixRange(&settings.doubleClickSpeed, 1, 2000, 400);
67
68 FixRange(&settings.desktopWidth, 1, 64, 4);
69 FixRange(&settings.desktopHeight, 1, 64, 1);
70 settings.desktopCount = settings.desktopWidth * settings.desktopHeight;
71
72 if(settings.taskListDecorations == DECO_UNSET) {
73 settings.taskListDecorations = settings.trayDecorations;
74 }
75
76 FixRange(&settings.dockSpacing, 0, 64, 0);
77 }
78
79 /** Update a string setting. */
SetPathString(char ** dest,const char * src)80 void SetPathString(char **dest, const char *src)
81 {
82 if(*dest) {
83 Release(*dest);
84 }
85 *dest = CopyString(src);
86 if(JLIKELY(*dest)) {
87 ExpandPath(dest);
88 }
89 }
90
91 /** Make sure a value is in range. */
FixRange(unsigned int * value,unsigned int min_value,unsigned int max_value,unsigned int def_value)92 void FixRange(unsigned int *value,
93 unsigned int min_value,
94 unsigned int max_value,
95 unsigned int def_value)
96 {
97 if(JUNLIKELY(*value < min_value || *value > max_value)) {
98 *value = def_value;
99 }
100 }
101