- Check whether libXft is at least version 2.1.2 else refuse to compile.
[wmaker-crm.git] / WINGs / configuration.c
blob7d8d0c1586a2720e5296cb1ea7afda95c8b5e4cf
3 #include "WINGsP.h"
4 #include "wconfig.h"
6 #include <X11/Xlocale.h>
9 _WINGsConfiguration WINGsConfiguration;
13 #define SYSTEM_FONT "-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-*-*-%d-*-*-*-*-*-*-*"
15 #define BOLD_SYSTEM_FONT "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-bold-r-*-*-%d-*-*-*-*-*-*-*"
17 #define FLOPPY_PATH "/floppy"
20 static unsigned
21 getButtonWithName(const char *name, unsigned defaultButton)
23 if (strncmp(name, "Button", 6)==0 && strlen(name)==7) {
24 switch (name[6]) {
25 case '1':
26 return Button1;
27 case '2':
28 return Button2;
29 case '3':
30 return Button3;
31 case '4':
32 return Button4;
33 case '5':
34 return Button5;
35 default:
36 break;
40 return defaultButton;
44 // fix this
45 static Bool
46 missingOrInvalidXLFD(char *xlfd)
48 char *ptr = xlfd;
49 Bool broken = False;
50 int count = 0;
52 if (!xlfd)
53 return True;
55 while (*ptr) {
56 if (*ptr=='%') {
57 ptr++;
58 if ((*ptr=='d' || *ptr=='i') && count==0) {
59 count++;
60 } else {
61 broken = True;
62 break;
64 } else if (*ptr==',') {
65 count = 0;
67 ptr++;
70 if (broken) {
71 if (xlfd == WINGsConfiguration.systemFont) {
72 ptr = "system font";
73 } else if (xlfd == WINGsConfiguration.boldSystemFont) {
74 ptr = "bold system font";
75 } else {
76 ptr = "Unknown System Font";
78 wwarning(_("Invalid %s specification: '%s' (only %%d is allowed and "
79 "at most once for each font in a fontset)."), ptr, xlfd);
82 return broken;
86 void
87 W_ReadConfigurations(void)
89 WMUserDefaults *defaults;
91 memset(&WINGsConfiguration, 0, sizeof(_WINGsConfiguration));
93 defaults = WMGetStandardUserDefaults();
95 if (defaults) {
96 char *buttonName;
97 unsigned button;
98 char *str;
100 WINGsConfiguration.systemFont =
101 WMGetUDStringForKey(defaults, "SystemFont");
103 WINGsConfiguration.boldSystemFont =
104 WMGetUDStringForKey(defaults, "BoldSystemFont");
106 #ifdef XFT
107 WINGsConfiguration.antialiasedText =
108 WMGetUDBoolForKey(defaults, "AntialiasedText");
109 #else
110 WINGsConfiguration.antialiasedText = False;
111 #endif
113 WINGsConfiguration.useMultiByte = False;
114 str = WMGetUDStringForKey(defaults, "MultiByteText");
115 if (str) {
116 if (strcasecmp(str, "YES") == 0) {
117 WINGsConfiguration.useMultiByte = True;
118 } else if (strcasecmp(str, "AUTO") == 0) {
119 char *locale;
121 /* if it's a multibyte language (japanese, chinese or korean)
122 * then set it to True */
123 locale = setlocale(LC_CTYPE, NULL);
124 if (locale != NULL
125 && (strncmp(locale, "ja", 2) == 0
126 || strncmp(locale, "zh", 2) == 0
127 || strncmp(locale, "ru", 2) == 0
128 || strncmp(locale, "ko", 2) == 0)) {
130 WINGsConfiguration.useMultiByte = True;
135 WINGsConfiguration.doubleClickDelay =
136 WMGetUDIntegerForKey(defaults, "DoubleClickTime");
138 WINGsConfiguration.floppyPath =
139 WMGetUDStringForKey(defaults, "FloppyPath");
141 buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
142 if (buttonName) {
143 button = getButtonWithName(buttonName, Button4);
144 wfree(buttonName);
145 } else {
146 button = Button4;
148 WINGsConfiguration.mouseWheelUp = button;
150 buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
151 if (buttonName) {
152 button = getButtonWithName(buttonName, Button5);
153 wfree(buttonName);
154 } else {
155 button = Button5;
157 WINGsConfiguration.mouseWheelDown = button;
159 if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) {
160 WINGsConfiguration.mouseWheelUp = Button4;
161 WINGsConfiguration.mouseWheelDown = Button5;
164 WINGsConfiguration.defaultFontSize =
165 WMGetUDIntegerForKey(defaults, "DefaultFontSize");
168 if (missingOrInvalidXLFD(WINGsConfiguration.systemFont)) {
169 WINGsConfiguration.systemFont = SYSTEM_FONT;
171 if (missingOrInvalidXLFD(WINGsConfiguration.boldSystemFont)) {
172 WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
174 if (!WINGsConfiguration.floppyPath) {
175 WINGsConfiguration.floppyPath = FLOPPY_PATH;
177 if (WINGsConfiguration.doubleClickDelay == 0) {
178 WINGsConfiguration.doubleClickDelay = 250;
180 if (WINGsConfiguration.mouseWheelUp == 0) {
181 WINGsConfiguration.mouseWheelUp = Button4;
183 if (WINGsConfiguration.mouseWheelDown == 0) {
184 WINGsConfiguration.mouseWheelDown = Button5;
186 if (WINGsConfiguration.defaultFontSize == 0) {
187 WINGsConfiguration.defaultFontSize = 12;