- Added switch to enable/disable antialiased fonts in WPrefs's Expert Settings
[wmaker-crm.git] / WINGs / configuration.c
blob51e1372048f5c42b1585ac57e3323e50adfd6c9a
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 XFTSYSTEM_FONT "-*-arial-medium-r-normal-*-%d-*-*-*-*-*-*-*"
19 #define XFTBOLD_SYSTEM_FONT "-*-arial-bold-r-normal-*-%d-*-*-*-*-*-*-*"
21 #define FLOPPY_PATH "/floppy"
24 static unsigned
25 getButtonWithName(const char *name, unsigned defaultButton)
27 if (strncmp(name, "Button", 6)==0 && strlen(name)==7) {
28 switch (name[6]) {
29 case '1':
30 return Button1;
31 case '2':
32 return Button2;
33 case '3':
34 return Button3;
35 case '4':
36 return Button4;
37 case '5':
38 return Button5;
39 default:
40 break;
44 return defaultButton;
48 static Bool
49 missingOrInvalidXLFD(char *xlfd)
51 char *ptr = xlfd;
52 Bool broken = False;
53 int count = 0;
55 if (!xlfd)
56 return True;
58 while (*ptr) {
59 if (*ptr=='%') {
60 ptr++;
61 if ((*ptr=='d' || *ptr=='i') && count==0) {
62 count++;
63 } else {
64 broken = True;
65 break;
67 } else if (*ptr==',') {
68 count = 0;
70 ptr++;
73 if (broken) {
74 if (xlfd == WINGsConfiguration.systemFont) {
75 ptr = "system font";
76 } else if (xlfd == WINGsConfiguration.boldSystemFont) {
77 ptr = "bold system font";
78 } else if (xlfd == WINGsConfiguration.antialiasedSystemFont) {
79 ptr = "antialiased system font";
80 } else if (xlfd == WINGsConfiguration.antialiasedBoldSystemFont) {
81 ptr = "antialiased bold system font";
82 } else {
83 ptr = "Unknown System Font";
85 wwarning(_("Invalid %s specification: '%s' (only %%d is allowed and "
86 "at most once for each font in a fontset)."), ptr, xlfd);
89 return broken;
93 void
94 W_ReadConfigurations(void)
96 WMUserDefaults *defaults;
98 memset(&WINGsConfiguration, 0, sizeof(_WINGsConfiguration));
100 defaults = WMGetStandardUserDefaults();
102 if (defaults) {
103 char *buttonName;
104 unsigned button;
105 char *str;
107 WINGsConfiguration.systemFont =
108 WMGetUDStringForKey(defaults, "SystemFont");
110 WINGsConfiguration.boldSystemFont =
111 WMGetUDStringForKey(defaults, "BoldSystemFont");
113 WINGsConfiguration.antialiasedSystemFont =
114 WMGetUDStringForKey(defaults, "AntialiasedSystemFont");
116 WINGsConfiguration.antialiasedBoldSystemFont =
117 WMGetUDStringForKey(defaults, "AntialiasedBoldSystemFont");
119 #ifdef XFT
120 WINGsConfiguration.antialiasedText =
121 WMGetUDBoolForKey(defaults, "AntialiasedText");
122 #else
123 WINGsConfiguration.antialiasedText = False;
124 #endif
126 WINGsConfiguration.useMultiByte = False;
127 str = WMGetUDStringForKey(defaults, "MultiByteText");
128 if (str) {
129 if (strcasecmp(str, "YES") == 0) {
130 WINGsConfiguration.useMultiByte = True;
131 } else if (strcasecmp(str, "AUTO") == 0) {
132 char *locale;
134 /* if it's a multibyte language (japanese, chinese or korean)
135 * then set it to True */
136 locale = setlocale(LC_CTYPE, NULL);
137 if (locale != NULL
138 && (strncmp(locale, "ja", 2) == 0
139 || strncmp(locale, "zh", 2) == 0
140 || strncmp(locale, "ru", 2) == 0
141 || strncmp(locale, "ko", 2) == 0)) {
143 WINGsConfiguration.useMultiByte = True;
148 WINGsConfiguration.doubleClickDelay =
149 WMGetUDIntegerForKey(defaults, "DoubleClickTime");
151 WINGsConfiguration.floppyPath =
152 WMGetUDStringForKey(defaults, "FloppyPath");
154 buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
155 if (buttonName) {
156 button = getButtonWithName(buttonName, Button4);
157 wfree(buttonName);
158 } else {
159 button = Button4;
161 WINGsConfiguration.mouseWheelUp = button;
163 buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
164 if (buttonName) {
165 button = getButtonWithName(buttonName, Button5);
166 wfree(buttonName);
167 } else {
168 button = Button5;
170 WINGsConfiguration.mouseWheelDown = button;
172 if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) {
173 WINGsConfiguration.mouseWheelUp = Button4;
174 WINGsConfiguration.mouseWheelDown = Button5;
177 WINGsConfiguration.defaultFontSize =
178 WMGetUDIntegerForKey(defaults, "DefaultFontSize");
181 if (missingOrInvalidXLFD(WINGsConfiguration.systemFont)) {
182 WINGsConfiguration.systemFont = SYSTEM_FONT;
184 if (missingOrInvalidXLFD(WINGsConfiguration.boldSystemFont)) {
185 WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
187 if (missingOrInvalidXLFD(WINGsConfiguration.antialiasedSystemFont)) {
188 WINGsConfiguration.antialiasedSystemFont = XFTSYSTEM_FONT;
190 if (missingOrInvalidXLFD(WINGsConfiguration.antialiasedBoldSystemFont)) {
191 WINGsConfiguration.antialiasedBoldSystemFont = XFTBOLD_SYSTEM_FONT;
193 if (!WINGsConfiguration.floppyPath) {
194 WINGsConfiguration.floppyPath = FLOPPY_PATH;
196 if (WINGsConfiguration.doubleClickDelay == 0) {
197 WINGsConfiguration.doubleClickDelay = 250;
199 if (WINGsConfiguration.mouseWheelUp == 0) {
200 WINGsConfiguration.mouseWheelUp = Button4;
202 if (WINGsConfiguration.mouseWheelDown == 0) {
203 WINGsConfiguration.mouseWheelDown = Button5;
205 if (WINGsConfiguration.defaultFontSize == 0) {
206 WINGsConfiguration.defaultFontSize = 12;