- Removed support for legacy systems: OpenLook, KDE-2.x, Gnome-1.x
[wmaker-crm.git] / WINGs / configuration.c
blob24df488daf18dcbbb7322863534c9d5c346f71b6
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 WINGsConfiguration.antialiasedText =
107 WMGetUDBoolForKey(defaults, "AntialiasedText");
109 WINGsConfiguration.useMultiByte = False;
110 str = WMGetUDStringForKey(defaults, "MultiByteText");
111 if (str) {
112 if (strcasecmp(str, "YES") == 0) {
113 WINGsConfiguration.useMultiByte = True;
114 } else if (strcasecmp(str, "AUTO") == 0) {
115 char *locale;
117 /* if it's a multibyte language (japanese, chinese or korean)
118 * then set it to True */
119 locale = setlocale(LC_CTYPE, NULL);
120 if (locale != NULL
121 && (strncmp(locale, "ja", 2) == 0
122 || strncmp(locale, "zh", 2) == 0
123 || strncmp(locale, "ru", 2) == 0
124 || strncmp(locale, "ko", 2) == 0)) {
126 WINGsConfiguration.useMultiByte = True;
131 WINGsConfiguration.doubleClickDelay =
132 WMGetUDIntegerForKey(defaults, "DoubleClickTime");
134 WINGsConfiguration.floppyPath =
135 WMGetUDStringForKey(defaults, "FloppyPath");
137 buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
138 if (buttonName) {
139 button = getButtonWithName(buttonName, Button4);
140 wfree(buttonName);
141 } else {
142 button = Button4;
144 WINGsConfiguration.mouseWheelUp = button;
146 buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
147 if (buttonName) {
148 button = getButtonWithName(buttonName, Button5);
149 wfree(buttonName);
150 } else {
151 button = Button5;
153 WINGsConfiguration.mouseWheelDown = button;
155 if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) {
156 WINGsConfiguration.mouseWheelUp = Button4;
157 WINGsConfiguration.mouseWheelDown = Button5;
160 WINGsConfiguration.defaultFontSize =
161 WMGetUDIntegerForKey(defaults, "DefaultFontSize");
164 if (missingOrInvalidXLFD(WINGsConfiguration.systemFont)) {
165 WINGsConfiguration.systemFont = SYSTEM_FONT;
167 if (missingOrInvalidXLFD(WINGsConfiguration.boldSystemFont)) {
168 WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
170 if (!WINGsConfiguration.floppyPath) {
171 WINGsConfiguration.floppyPath = FLOPPY_PATH;
173 if (WINGsConfiguration.doubleClickDelay == 0) {
174 WINGsConfiguration.doubleClickDelay = 250;
176 if (WINGsConfiguration.mouseWheelUp == 0) {
177 WINGsConfiguration.mouseWheelUp = Button4;
179 if (WINGsConfiguration.mouseWheelDown == 0) {
180 WINGsConfiguration.mouseWheelDown = Button5;
182 if (WINGsConfiguration.defaultFontSize == 0) {
183 WINGsConfiguration.defaultFontSize = 12;