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,
24 #define PROG_VERSION "setstyle (Window Maker) 0.2"
34 #include "../src/wconfig.h"
37 char *FontOptions
[] = {
54 defaultsPathForDomain(char *domain
)
59 gspath
= getenv("GNUSTEP_USER_ROOT");
66 home
= getenv("HOME");
68 printf("%s:could not get HOME environment variable!\n", ProgName
);
73 strcat(path
, "/GNUstep/");
75 strcat(path
, DEFAULTS_DIR
);
79 tmp
= malloc(strlen(path
)+2);
87 hackPaths(proplist_t style
, char *prefix
)
95 keys
= PLGetAllDictionaryKeys(style
);
97 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
98 key
= PLGetArrayElement(keys
, i
);
100 value
= PLGetDictionaryEntry(style
, key
);
101 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
105 type
= PLGetArrayElement(value
, 0);
106 t
= PLGetString(type
);
107 if (t
&& (strcasecmp(t
, "tpixmap")==0
108 || strcasecmp(t
, "spixmap")==0
109 || strcasecmp(t
, "mpixmap")==0
110 || strcasecmp(t
, "cpixmap")==0
111 || strcasecmp(t
, "tvgradient")==0
112 || strcasecmp(t
, "thgradient")==0
113 || strcasecmp(t
, "tdgradient")==0)) {
117 file
= PLGetArrayElement(value
, 1);
118 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
119 PLRemoveArrayElement(value
, 1);
120 PLInsertArrayElement(value
, PLMakeString(buffer
), 1);
130 * since some of the options introduce incompatibilities, we will need
131 * to do a kluge here or the themes ppl will get real annoying.
132 * So, treat for the absence of the following options:
137 hackStyle(proplist_t style
)
142 int foundIconTitle
= 0;
144 keys
= PLGetAllDictionaryKeys(style
);
146 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
149 tmp
= PLGetArrayElement(keys
, i
);
150 str
= PLGetString(tmp
);
155 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
156 if (strcasecmp(str
, FontOptions
[j
])==0) {
157 PLRemoveDictionaryEntry(style
, tmp
);
166 if (strcasecmp(str
, "IconTitleColor")==0
167 || strcasecmp(str
, "IconTitleBack")==0) {
173 if (!foundIconTitle
) {
174 /* set the default values */
175 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
177 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
181 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
187 type
= PLGetArrayElement(tmp
, 0);
193 str
= PLGetString(type
);
194 if (strcasecmp(str
, "solid")==0) {
195 value
= PLGetArrayElement(tmp
, 1);
196 } else if (strcasecmp(str
, "dgradient")==0
197 || strcasecmp(str
, "hgradient")==0
198 || strcasecmp(str
, "vgradient")==0) {
200 int r1
, g1
, b1
, r2
, g2
, b2
;
203 c1
= PLGetArrayElement(tmp
, 1);
204 c2
= PLGetArrayElement(tmp
, 2);
205 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
206 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
207 sprintf(buffer
, "#%2x%2x%2x", (r1
+r2
)/2, (g1
+g2
)/2,
209 value
= PLMakeString(buffer
);
213 } else if (strcasecmp(str
, "mdgradient")==0
214 || strcasecmp(str
, "mhgradient")==0
215 || strcasecmp(str
, "mvgradient")==0) {
217 value
= PLGetArrayElement(tmp
, 1);
219 } else if (strcasecmp(str
, "tpixmap")==0
220 || strcasecmp(str
, "cpixmap")==0
221 || strcasecmp(str
, "spixmap")==0) {
223 value
= PLGetArrayElement(tmp
, 2);
227 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
236 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
240 str1
= PLGetString(pl1
);
241 str2
= PLGetString(pl2
);
243 if (strcasecmp(str1
, str2
)==0)
254 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
255 puts("Reads style/theme configuration from FILE and updates Window Maker.");
257 puts(" --no-fonts ignore font related options");
258 puts(" --help display this help and exit");
259 puts(" --version output version information and exit");
265 main(int argc
, char **argv
)
267 proplist_t prop
, style
;
276 printf("%s: missing argument\n", ProgName
);
277 printf("Try '%s --help' for more information\n", ProgName
);
281 for (i
= 1; i
< argc
; i
++) {
282 if (strcmp("--no-fonts", argv
[i
])==0) {
284 } else if (strcmp("--version", argv
[i
])==0) {
287 } else if (strcmp("--help", argv
[i
])==0) {
292 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
293 printf("Try '%s --help' for more information\n", ProgName
);
300 PLSetStringCmpHook(StringCompareHook
);
302 path
= defaultsPathForDomain("WindowMaker");
304 prop
= PLGetProplistWithPath(path
);
306 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
311 if (stat(file
, &statbuf
) < 0) {
316 if (S_ISDIR(statbuf
.st_mode
)) {
320 if (*argv
[argc
-1] != '/') {
321 if (!getcwd(buffer
, 4000)) {
322 printf("%s: complete path for %s is too long\n", ProgName
,
326 if (strlen(buffer
) + strlen(file
) > 4000) {
327 printf("%s: complete path for %s is too long\n", ProgName
,
335 strcat(buffer
, file
);
337 prefix
= malloc(strlen(buffer
)+10);
339 printf("%s: out of memory\n", ProgName
);
342 strcpy(prefix
, buffer
);
344 strcat(buffer
, "/style");
346 style
= PLGetProplistWithPath(buffer
);
348 printf("%s:could not load style file \"%s\".\n", ProgName
,
353 hackPaths(style
, prefix
);
356 style
= PLGetProplistWithPath(file
);
358 printf("%s:could not load style file \"%s\".\n", ProgName
, file
);
365 PLMergeDictionaries(prop
, style
);