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
[] = {
52 defaultsPathForDomain(char *domain
)
57 gspath
= getenv("GNUSTEP_USER_ROOT");
64 home
= getenv("HOME");
66 printf("%s:could not get HOME environment variable!\n", ProgName
);
71 strcat(path
, "/GNUstep/");
73 strcat(path
, DEFAULTS_DIR
);
77 tmp
= malloc(strlen(path
)+2);
85 hackPaths(proplist_t style
, char *prefix
)
93 keys
= PLGetAllDictionaryKeys(style
);
95 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
96 key
= PLGetArrayElement(keys
, i
);
98 value
= PLGetDictionaryEntry(style
, key
);
99 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
103 type
= PLGetArrayElement(value
, 0);
104 t
= PLGetString(type
);
105 if (t
&& (strcasecmp(t
, "tpixmap")==0
106 || strcasecmp(t
, "spixmap")==0
107 || strcasecmp(t
, "mpixmap")==0
108 || strcasecmp(t
, "cpixmap")==0
109 || strcasecmp(t
, "tvgradient")==0
110 || strcasecmp(t
, "thgradient")==0
111 || strcasecmp(t
, "tdgradient")==0)) {
115 file
= PLGetArrayElement(value
, 1);
116 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
117 PLRemoveArrayElement(value
, 1);
118 PLInsertArrayElement(value
, PLMakeString(buffer
), 1);
128 * since some of the options introduce incompatibilities, we will need
129 * to do a kluge here or the themes ppl will get real annoying.
130 * So, treat for the absence of the following options:
135 hackStyle(proplist_t style
)
140 int foundIconTitle
= 0;
142 keys
= PLGetAllDictionaryKeys(style
);
144 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
147 tmp
= PLGetArrayElement(keys
, i
);
148 str
= PLGetString(tmp
);
153 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
154 if (strcasecmp(str
, FontOptions
[j
])==0) {
155 PLRemoveDictionaryEntry(style
, tmp
);
164 if (strcasecmp(str
, "IconTitleColor")==0
165 || strcasecmp(str
, "IconTitleBack")==0) {
171 if (!foundIconTitle
) {
172 /* set the default values */
173 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
175 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
179 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
185 type
= PLGetArrayElement(tmp
, 0);
191 str
= PLGetString(type
);
192 if (strcasecmp(str
, "solid")==0) {
193 value
= PLGetArrayElement(tmp
, 1);
194 } else if (strcasecmp(str
, "dgradient")==0
195 || strcasecmp(str
, "hgradient")==0
196 || strcasecmp(str
, "vgradient")==0) {
198 int r1
, g1
, b1
, r2
, g2
, b2
;
201 c1
= PLGetArrayElement(tmp
, 1);
202 c2
= PLGetArrayElement(tmp
, 2);
203 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
204 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
205 sprintf(buffer
, "#%2x%2x%2x", (r1
+r2
)/2, (g1
+g2
)/2,
207 value
= PLMakeString(buffer
);
211 } else if (strcasecmp(str
, "mdgradient")==0
212 || strcasecmp(str
, "mhgradient")==0
213 || strcasecmp(str
, "mvgradient")==0) {
215 value
= PLGetArrayElement(tmp
, 1);
217 } else if (strcasecmp(str
, "tpixmap")==0
218 || strcasecmp(str
, "cpixmap")==0
219 || strcasecmp(str
, "spixmap")==0) {
221 value
= PLGetArrayElement(tmp
, 2);
225 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
234 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
238 str1
= PLGetString(pl1
);
239 str2
= PLGetString(pl2
);
241 if (strcasecmp(str1
, str2
)==0)
251 main(int argc
, char **argv
)
253 proplist_t prop
, style
;
260 printf("Syntax:\n%s [-nofonts] <style file>\n", argv
[0]);
265 if (strcmp(argv
[1], "-nofonts")==0) {
268 printf("Syntax:\n%s <style file> [-nofonts]\n", argv
[0]);
273 PLSetStringCmpHook(StringCompareHook
);
275 path
= defaultsPathForDomain("WindowMaker");
277 prop
= PLGetProplistWithPath(path
);
279 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
284 if (stat(argv
[argc
-1], &statbuf
) < 0) {
285 perror(argv
[argc
-1]);
289 if (S_ISDIR(statbuf
.st_mode
)) {
293 if (*argv
[argc
-1] != '/') {
294 if (!getcwd(buffer
, 4000)) {
295 printf("%s: complete path for %s is too long\n", ProgName
,
299 if (strlen(buffer
) + strlen(argv
[argc
-1]) > 4000) {
300 printf("%s: complete path for %s is too long\n", ProgName
,
308 strcat(buffer
, argv
[argc
-1]);
310 prefix
= malloc(strlen(buffer
)+10);
312 printf("%s: out of memory\n", ProgName
);
315 strcpy(prefix
, buffer
);
317 strcat(buffer
, "/style");
319 style
= PLGetProplistWithPath(buffer
);
321 printf("%s:could not load style file \"%s\".\n", ProgName
,
326 hackPaths(style
, prefix
);
329 style
= PLGetProplistWithPath(argv
[argc
-1]);
331 printf("%s:could not load style file \"%s\".\n", ProgName
,
339 PLMergeDictionaries(prop
, style
);