- Removed obsoleted options from WMGLOBAL and from the WINGs internal
[wmaker-crm.git] / WINGs / configuration.c
blob31af58d211731a42ed9d6bf50eeef7bcea273fa6
3 #include "WINGsP.h"
4 #include "wconfig.h"
6 #include <X11/Xlocale.h>
9 _WINGsConfiguration WINGsConfiguration;
13 #define SYSTEM_FONT "sans:pixelsize=12"
15 #define BOLD_SYSTEM_FONT "sans:bold:pixelsize=12"
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.doubleClickDelay =
110 WMGetUDIntegerForKey(defaults, "DoubleClickTime");
112 WINGsConfiguration.floppyPath =
113 WMGetUDStringForKey(defaults, "FloppyPath");
115 buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
116 if (buttonName) {
117 button = getButtonWithName(buttonName, Button4);
118 wfree(buttonName);
119 } else {
120 button = Button4;
122 WINGsConfiguration.mouseWheelUp = button;
124 buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
125 if (buttonName) {
126 button = getButtonWithName(buttonName, Button5);
127 wfree(buttonName);
128 } else {
129 button = Button5;
131 WINGsConfiguration.mouseWheelDown = button;
133 if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) {
134 WINGsConfiguration.mouseWheelUp = Button4;
135 WINGsConfiguration.mouseWheelDown = Button5;
138 WINGsConfiguration.defaultFontSize =
139 WMGetUDIntegerForKey(defaults, "DefaultFontSize");
142 if (missingOrInvalidXLFD(WINGsConfiguration.systemFont)) {
143 WINGsConfiguration.systemFont = SYSTEM_FONT;
145 if (missingOrInvalidXLFD(WINGsConfiguration.boldSystemFont)) {
146 WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
148 if (!WINGsConfiguration.floppyPath) {
149 WINGsConfiguration.floppyPath = FLOPPY_PATH;
151 if (WINGsConfiguration.doubleClickDelay == 0) {
152 WINGsConfiguration.doubleClickDelay = 250;
154 if (WINGsConfiguration.mouseWheelUp == 0) {
155 WINGsConfiguration.mouseWheelUp = Button4;
157 if (WINGsConfiguration.mouseWheelDown == 0) {
158 WINGsConfiguration.mouseWheelDown = Button5;
160 if (WINGsConfiguration.defaultFontSize == 0) {
161 WINGsConfiguration.defaultFontSize = 12;