1 
2 #include "WINGsP.h"
3 #include "wconfig.h"
4 
5 #include <X11/Xlocale.h>
6 
7 _WINGsConfiguration WINGsConfiguration;
8 
9 #define SYSTEM_FONT "sans serif"
10 #define BOLD_SYSTEM_FONT "sans serif:bold"
11 #define DEFAULT_FONT_SIZE 12
12 
13 #define FLOPPY_PATH "/floppy"
14 
getButtonWithName(const char * name,unsigned defaultButton)15 static unsigned getButtonWithName(const char *name, unsigned defaultButton)
16 {
17 	if (strncmp(name, "Button", 6) == 0 && strlen(name) == 7) {
18 		switch (name[6]) {
19 		case '1':
20 			return Button1;
21 		case '2':
22 			return Button2;
23 		case '3':
24 			return Button3;
25 		case '4':
26 			return Button4;
27 		case '5':
28 			return Button5;
29 		default:
30 			break;
31 		}
32 	}
33 
34 	return defaultButton;
35 }
36 
W_ReadConfigurations(void)37 void W_ReadConfigurations(void)
38 {
39 	WMUserDefaults *defaults;
40 	Bool aaIsSet = False;
41 
42 	memset(&WINGsConfiguration, 0, sizeof(_WINGsConfiguration));
43 
44 	defaults = WMGetStandardUserDefaults();
45 
46 	if (defaults) {
47 		char *buttonName;
48 		WMPropList *val;
49 		unsigned button;
50 
51 		WINGsConfiguration.systemFont = WMGetUDStringForKey(defaults, "SystemFont");
52 
53 		WINGsConfiguration.boldSystemFont = WMGetUDStringForKey(defaults, "BoldSystemFont");
54 
55 		val = WMGetUDObjectForKey(defaults, "AntialiasedText");
56 		if (val && WMIsPLString(val) && WMGetFromPLString(val)) {
57 			aaIsSet = True;
58 			WINGsConfiguration.antialiasedText =
59 				WMGetUDBoolForKey(defaults, "AntialiasedText");
60 		}
61 
62 		WINGsConfiguration.doubleClickDelay = WMGetUDIntegerForKey(defaults, "DoubleClickTime");
63 
64 		WINGsConfiguration.floppyPath = WMGetUDStringForKey(defaults, "FloppyPath");
65 
66 		buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
67 		if (buttonName) {
68 			button = getButtonWithName(buttonName, Button4);
69 			wfree(buttonName);
70 		} else {
71 			button = Button4;
72 		}
73 		WINGsConfiguration.mouseWheelUp = button;
74 
75 		buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
76 		if (buttonName) {
77 			button = getButtonWithName(buttonName, Button5);
78 			wfree(buttonName);
79 		} else {
80 			button = Button5;
81 		}
82 		WINGsConfiguration.mouseWheelDown = button;
83 
84 		if (WINGsConfiguration.mouseWheelDown == WINGsConfiguration.mouseWheelUp) {
85 			WINGsConfiguration.mouseWheelUp = Button4;
86 			WINGsConfiguration.mouseWheelDown = Button5;
87 		}
88 
89 		WINGsConfiguration.defaultFontSize = WMGetUDIntegerForKey(defaults, "DefaultFontSize");
90 	}
91 
92 	if (!WINGsConfiguration.systemFont) {
93 		WINGsConfiguration.systemFont = SYSTEM_FONT;
94 	}
95 	if (!WINGsConfiguration.boldSystemFont) {
96 		WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
97 	}
98 	if (WINGsConfiguration.defaultFontSize == 0) {
99 		WINGsConfiguration.defaultFontSize = DEFAULT_FONT_SIZE;
100 	}
101 	if (!aaIsSet) {
102 		WINGsConfiguration.antialiasedText = True;
103 	}
104 	if (!WINGsConfiguration.floppyPath) {
105 		WINGsConfiguration.floppyPath = FLOPPY_PATH;
106 	}
107 	if (WINGsConfiguration.doubleClickDelay == 0) {
108 		WINGsConfiguration.doubleClickDelay = 250;
109 	}
110 	if (WINGsConfiguration.mouseWheelUp == 0) {
111 		WINGsConfiguration.mouseWheelUp = Button4;
112 	}
113 	if (WINGsConfiguration.mouseWheelDown == 0) {
114 		WINGsConfiguration.mouseWheelDown = Button5;
115 	}
116 
117 }
118 
W_getconf_mouseWheelUp(void)119 unsigned W_getconf_mouseWheelUp(void)
120 {
121 	return WINGsConfiguration.mouseWheelUp;
122 }
123 
W_getconf_mouseWheelDown(void)124 unsigned W_getconf_mouseWheelDown(void)
125 {
126 	return WINGsConfiguration.mouseWheelDown;
127 }
128 
W_setconf_doubleClickDelay(int value)129 void W_setconf_doubleClickDelay(int value)
130 {
131 	WINGsConfiguration.doubleClickDelay = value;
132 }
133