- Added xdnd v3 support in WINGs (Sylvain Reynal <sreynal@nerim.net>)
[wmaker-crm.git] / WINGs / configuration.c
blob0baf60bf13c1238528f2088d2a141c22864278de
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 {
79 ptr = "Unknown System Font";
81 wwarning(_("Invalid %s specification: '%s' (only %%d is allowed and "
82 "at most once for each font in a fontset)."), ptr, xlfd);
85 return broken;
89 void
90 W_ReadConfigurations(void)
92 WMUserDefaults *defaults;
94 memset(&WINGsConfiguration, 0, sizeof(_WINGsConfiguration));
96 defaults = WMGetStandardUserDefaults();
98 if (defaults) {
99 char *buttonName;
100 unsigned button;
101 char *str;
103 WINGsConfiguration.systemFont =
104 WMGetUDStringForKey(defaults, "SystemFont");
106 WINGsConfiguration.boldSystemFont =
107 WMGetUDStringForKey(defaults, "BoldSystemFont");
109 #ifdef XFT
110 WINGsConfiguration.antialiasedText =
111 WMGetUDBoolForKey(defaults, "AntialiasedText");
112 #else
113 WINGsConfiguration.antialiasedText = False;
114 #endif
116 WINGsConfiguration.useMultiByte = False;
117 str = WMGetUDStringForKey(defaults, "MultiByteText");
118 if (str) {
119 if (strcasecmp(str, "YES") == 0) {
120 WINGsConfiguration.useMultiByte = True;
121 } else if (strcasecmp(str, "AUTO") == 0) {
122 char *locale;
124 /* if it's a multibyte language (japanese, chinese or korean)
125 * then set it to True */
126 locale = setlocale(LC_CTYPE, NULL);
127 if (locale != NULL
128 && (strncmp(locale, "ja", 2) == 0
129 || strncmp(locale, "zh", 2) == 0
130 || strncmp(locale, "ru", 2) == 0
131 || strncmp(locale, "ko", 2) == 0)) {
133 WINGsConfiguration.useMultiByte = True;
138 WINGsConfiguration.doubleClickDelay =
139 WMGetUDIntegerForKey(defaults, "DoubleClickTime");
141 WINGsConfiguration.floppyPath =
142 WMGetUDStringForKey(defaults, "FloppyPath");
144 buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
145 if (buttonName) {
146 button = getButtonWithName(buttonName, Button4);
147 wfree(buttonName);
148 } else {
149 button = Button4;
151 WINGsConfiguration.mouseWheelUp = button;
153 buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
154 if (buttonName) {
155 button = getButtonWithName(buttonName, Button5);
156 wfree(buttonName);
157 } else {
158 button = Button5;
160 WINGsConfiguration.mouseWheelDown = button;
162 if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) {
163 WINGsConfiguration.mouseWheelUp = Button4;
164 WINGsConfiguration.mouseWheelDown = Button5;
167 WINGsConfiguration.defaultFontSize =
168 WMGetUDIntegerForKey(defaults, "DefaultFontSize");
171 if (missingOrInvalidXLFD(WINGsConfiguration.systemFont)) {
172 WINGsConfiguration.systemFont = SYSTEM_FONT;
174 if (missingOrInvalidXLFD(WINGsConfiguration.boldSystemFont)) {
175 WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
177 if (!WINGsConfiguration.floppyPath) {
178 WINGsConfiguration.floppyPath = FLOPPY_PATH;
180 if (WINGsConfiguration.doubleClickDelay == 0) {
181 WINGsConfiguration.doubleClickDelay = 250;
183 if (WINGsConfiguration.mouseWheelUp == 0) {
184 WINGsConfiguration.mouseWheelUp = Button4;
186 if (WINGsConfiguration.mouseWheelDown == 0) {
187 WINGsConfiguration.mouseWheelDown = Button5;
189 if (WINGsConfiguration.defaultFontSize == 0) {
190 WINGsConfiguration.defaultFontSize = 12;