1 /* setstyle.c - loads style related options to wmaker
3 * WindowMaker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
32 #include "../src/wconfig.h"
35 char *FontOptions
[] = {
51 defaultsPathForDomain(char *domain
)
56 gspath
= getenv("GNUSTEP_USER_ROOT");
63 home
= getenv("HOME");
65 printf("%s:could not get HOME environment variable!\n", ProgName
);
70 strcat(path
, "/GNUstep/");
72 strcat(path
, DEFAULTS_DIR
);
76 tmp
= malloc(strlen(path
)+2);
84 hackPaths(proplist_t style
, char *prefix
)
92 keys
= PLGetAllDictionaryKeys(style
);
94 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
95 key
= PLGetArrayElement(keys
, i
);
97 value
= PLGetDictionaryEntry(style
, key
);
98 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
102 type
= PLGetArrayElement(value
, 0);
103 t
= PLGetString(type
);
104 if (t
&& (strcasecmp(t
, "tpixmap")==0
105 || strcasecmp(t
, "spixmap")==0
106 || strcasecmp(t
, "cpixmap")==0
107 || strcasecmp(t
, "tvgradient")==0
108 || strcasecmp(t
, "thgradient")==0
109 || strcasecmp(t
, "tdgradient")==0)) {
113 file
= PLGetArrayElement(value
, 1);
114 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
115 PLRemoveArrayElement(value
, 1);
116 PLInsertArrayElement(value
, PLMakeString(buffer
), 1);
126 * since some of the options introduce incompatibilities, we will need
127 * to do a kluge here or the themes ppl will get real annoying.
128 * So, treat for the absence of the following options:
133 hackStyle(proplist_t style
)
138 int foundIconTitle
= 0;
140 keys
= PLGetAllDictionaryKeys(style
);
142 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
145 tmp
= PLGetArrayElement(keys
, i
);
146 str
= PLGetString(tmp
);
150 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
151 if (strcasecmp(str
, FontOptions
[j
])==0) {
152 PLRemoveDictionaryEntry(style
, tmp
);
160 if (strcasecmp(str
, "IconTitleColor")==0
161 || strcasecmp(str
, "IconTitleBack")==0) {
167 if (!foundIconTitle
) {
168 /* set the default values */
169 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
171 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
175 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
181 type
= PLGetArrayElement(tmp
, 0);
187 str
= PLGetString(type
);
188 if (strcasecmp(str
, "solid")==0) {
189 value
= PLGetArrayElement(tmp
, 1);
190 } else if (strcasecmp(str
, "dgradient")==0
191 || strcasecmp(str
, "hgradient")==0
192 || strcasecmp(str
, "vgradient")==0) {
194 int r1
, g1
, b1
, r2
, g2
, b2
;
197 c1
= PLGetArrayElement(tmp
, 1);
198 c2
= PLGetArrayElement(tmp
, 2);
199 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
200 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
201 sprintf(buffer
, "#%2x%2x%2x", (r1
+r2
)/2, (g1
+g2
)/2,
203 value
= PLMakeString(buffer
);
207 } else if (strcasecmp(str
, "mdgradient")==0
208 || strcasecmp(str
, "mhgradient")==0
209 || strcasecmp(str
, "mvgradient")==0) {
211 value
= PLGetArrayElement(tmp
, 1);
213 } else if (strcasecmp(str
, "tpixmap")==0
214 || strcasecmp(str
, "cpixmap")==0
215 || strcasecmp(str
, "spixmap")==0) {
217 value
= PLGetArrayElement(tmp
, 2);
221 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
230 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
234 str1
= PLGetString(pl1
);
235 str2
= PLGetString(pl2
);
237 if (strcasecmp(str1
, str2
)==0)
247 main(int argc
, char **argv
)
249 proplist_t prop
, style
;
256 printf("Syntax:\n%s [-nofonts] <style file>\n", argv
[0]);
261 if (strcmp(argv
[1], "-nofonts")==0) {
264 printf("Syntax:\n%s <style file> [-nofonts]\n", argv
[0]);
269 PLSetStringCmpHook(StringCompareHook
);
271 path
= defaultsPathForDomain("WindowMaker");
273 prop
= PLGetProplistWithPath(path
);
275 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
280 if (stat(argv
[argc
-1], &statbuf
) < 0) {
281 perror(argv
[argc
-1]);
285 if (S_ISDIR(statbuf
.st_mode
)) {
289 if (*argv
[argc
-1] != '/') {
290 if (!getcwd(buffer
, 4000)) {
291 printf("%s: complete path for %s is too long\n", ProgName
,
295 if (strlen(buffer
) + strlen(argv
[argc
-1]) > 4000) {
296 printf("%s: complete path for %s is too long\n", ProgName
,
304 strcat(buffer
, argv
[argc
-1]);
306 prefix
= malloc(strlen(buffer
)+10);
308 printf("%s: out of memory\n", ProgName
);
311 strcpy(prefix
, buffer
);
313 strcat(buffer
, "/style");
315 style
= PLGetProplistWithPath(buffer
);
317 printf("%s:could not load style file \"%s\".\n", ProgName
,
322 hackPaths(style
, prefix
);
325 style
= PLGetProplistWithPath(argv
[argc
-1]);
327 printf("%s:could not load style file \"%s\".\n", ProgName
,
335 PLMergeDictionaries(prop
, style
);