1 /* setstyle.c - loads style related options to wmaker
3 * WindowMaker window manager
5 * Copyright (c) 1997, 1998, 1999 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.5"
36 #include "../src/wconfig.h"
38 #define MAX_OPTIONS 128
40 char *FontOptions
[] = {
60 proplist_t
readBlackBoxStyle(char *path
);
65 defaultsPathForDomain(char *domain
)
70 gspath
= getenv("GNUSTEP_USER_ROOT");
77 home
= getenv("HOME");
79 printf("%s:could not get HOME environment variable!\n", ProgName
);
84 strcat(path
, "/GNUstep/");
86 strcat(path
, DEFAULTS_DIR
);
90 tmp
= malloc(strlen(path
)+2);
99 hackPathInTexture(proplist_t texture
, char *prefix
)
104 /* get texture type */
105 type
= PLGetArrayElement(texture
, 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 /* get pixmap file path */
118 file
= PLGetArrayElement(texture
, 1);
119 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
120 /* replace path with full path */
121 PLRemoveArrayElement(texture
, 1);
122 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
128 hackPaths(proplist_t style
, char *prefix
)
136 keys
= PLGetAllDictionaryKeys(style
);
138 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
139 key
= PLGetArrayElement(keys
, i
);
141 value
= PLGetDictionaryEntry(style
, key
);
145 if (strcasecmp(PLGetString(key
), "WorkspaceSpecificBack")==0) {
146 if (PLIsArray(value
)) {
150 for (j
= 0; j
< PLGetNumberOfElements(value
); j
++) {
151 texture
= PLGetArrayElement(value
, j
);
153 if (texture
&& PLIsArray(texture
)
154 && PLGetNumberOfElements(texture
) > 2) {
156 hackPathInTexture(texture
, prefix
);
162 if (PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
164 hackPathInTexture(value
, prefix
);
173 getColor(proplist_t texture
)
175 proplist_t value
, type
;
178 type
= PLGetArrayElement(texture
, 0);
184 str
= PLGetString(type
);
185 if (strcasecmp(str
, "solid")==0) {
186 value
= PLGetArrayElement(texture
, 1);
187 } else if (strcasecmp(str
, "dgradient")==0
188 || strcasecmp(str
, "hgradient")==0
189 || strcasecmp(str
, "vgradient")==0) {
191 int r1
, g1
, b1
, r2
, g2
, b2
;
194 c1
= PLGetArrayElement(texture
, 1);
195 c2
= PLGetArrayElement(texture
, 2);
197 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
198 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
199 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
201 value
= PLMakeString(buffer
);
209 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
210 PLGetString(c1
), &color1
);
211 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
212 PLGetString(c2
), &color2
);
214 sprintf(buffer
, "#%02x%02x%02x",
215 (color1
.red
+color2
.red
)>>9,
216 (color1
.green
+color2
.green
)>>9,
217 (color1
.blue
+color2
.blue
)>>9);
218 value
= PLMakeString(buffer
);
220 } else if (strcasecmp(str
, "mdgradient")==0
221 || strcasecmp(str
, "mhgradient")==0
222 || strcasecmp(str
, "mvgradient")==0) {
224 value
= PLGetArrayElement(texture
, 1);
226 } else if (strcasecmp(str
, "tpixmap")==0
227 || strcasecmp(str
, "cpixmap")==0
228 || strcasecmp(str
, "spixmap")==0) {
230 value
= PLGetArrayElement(texture
, 2);
238 * since some of the options introduce incompatibilities, we will need
239 * to do a kluge here or the themes ppl will get real annoying.
240 * So, treat for the absence of the following options:
245 hackStyle(proplist_t style
)
250 int foundIconTitle
= 0;
251 int foundResizebarBack
= 0;
253 keys
= PLGetAllDictionaryKeys(style
);
255 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
258 tmp
= PLGetArrayElement(keys
, i
);
259 str
= PLGetString(tmp
);
264 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
265 if (strcasecmp(str
, FontOptions
[j
])==0) {
266 PLRemoveDictionaryEntry(style
, tmp
);
275 if (strcasecmp(str
, "IconTitleColor")==0
276 || strcasecmp(str
, "IconTitleBack")==0) {
278 } else if (strcasecmp(str
, "ResizebarBack")==0) {
279 foundResizebarBack
= 1;
284 if (!foundIconTitle
) {
285 /* set the default values */
286 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
288 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
292 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
296 value
= getColor(tmp
);
299 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
305 if (!foundResizebarBack
) {
306 /* set the default values */
307 tmp
= PLGetDictionaryEntry(style
, PLMakeString("UTitleBack"));
311 value
= getColor(tmp
);
316 t
= PLMakeArrayFromElements(PLMakeString("solid"), value
,
318 PLInsertDictionaryEntry(style
, PLMakeString("ResizebarBack"),
325 if (!PLGetDictionaryEntry(style
, PLMakeString("MenuStyle"))) {
326 PLInsertDictionaryEntry(style
, PLMakeString("MenuStyle"),
327 PLMakeString("normal"));
333 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
337 str1
= PLGetString(pl1
);
338 str2
= PLGetString(pl2
);
340 if (strcasecmp(str1
, str2
)==0)
350 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
351 puts("Reads style/theme configuration from FILE and updates Window Maker.");
353 puts(" --no-fonts ignore font related options");
354 puts(" --ignore <option> ignore changes in the specified option");
355 puts(" --help display this help and exit");
357 puts(" --format <format> specifies the format of the theme to be converted");
359 puts(" --version output version information and exit");
361 puts("Supported formats: blackbox");
368 main(int argc
, char **argv
)
370 proplist_t prop
, style
;
376 char *ignoreList
[MAX_OPTIONS
];
378 dpy
= XOpenDisplay("");
383 printf("%s: missing argument\n", ProgName
);
384 printf("Try '%s --help' for more information\n", ProgName
);
388 for (i
= 1; i
< argc
; i
++) {
389 if (strcmp("--ignore", argv
[i
])==0) {
392 printf("%s: missing argument for option --ignore\n", ProgName
);
395 ignoreList
[ignoreCount
++] = argv
[i
];
397 } else if (strcmp("--no-fonts", argv
[i
])==0) {
399 } else if (strcmp("--version", argv
[i
])==0) {
402 } else if (strcmp("--help", argv
[i
])==0) {
406 } else if (strcmp("--format", argv
[i
])==0) {
409 printf("%s: missing argument for option --format\n", ProgName
);
412 if (strcasecmp(argv
[i
], "blackbox")==0) {
415 printf("%s: unknown theme format '%s'\n", ProgName
, argv
[i
]);
421 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
422 printf("Try '%s --help' for more information\n", ProgName
);
429 PLSetStringCmpHook(StringCompareHook
);
431 path
= defaultsPathForDomain("WindowMaker");
433 prop
= PLGetProplistWithPath(path
);
436 printf("%s:could not load WindowMaker configuration file.\n",
441 if (stat(file
, &statbuf
) < 0) {
446 if (format
== F_BLACKBOX
) {
447 style
= readBlackBoxStyle(file
);
449 printf("%s: could not open style file\n", ProgName
);
455 if (S_ISDIR(statbuf
.st_mode
)) {
460 if (*argv
[argc
-1] != '/') {
461 if (!getcwd(buffer
, 4000)) {
462 printf("%s: complete path for %s is too long\n", ProgName
,
466 if (strlen(buffer
) + strlen(file
) > 4000) {
467 printf("%s: complete path for %s is too long\n", ProgName
,
475 strcat(buffer
, file
);
477 prefix
= malloc(strlen(buffer
)+10);
479 printf("%s: out of memory\n", ProgName
);
482 strcpy(prefix
, buffer
);
484 strcat(buffer
, "/style");
486 style
= PLGetProplistWithPath(buffer
);
489 printf("%s:could not load style file.\n", ProgName
);
493 hackPaths(style
, prefix
);
496 /* normal style file */
498 style
= PLGetProplistWithPath(file
);
501 printf("%s:could not load style file.\n", ProgName
);
507 if (!PLIsDictionary(style
)) {
508 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
514 if (ignoreCount
> 0) {
515 for (i
= 0; i
< ignoreCount
; i
++) {
516 PLRemoveDictionaryEntry(style
, PLMakeString(ignoreList
[i
]));
520 PLMergeDictionaries(prop
, style
);
528 char *msg
= "Reconfigure";
530 memset(&ev
, 0, sizeof(XEvent
));
532 ev
.xclient
.type
= ClientMessage
;
533 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
535 ev
.xclient
.window
= DefaultRootWindow(dpy
);
536 ev
.xclient
.format
= 8;
538 for (i
= 0; i
<= strlen(msg
); i
++) {
539 ev
.xclient
.data
.b
[i
] = msg
[i
];
541 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
542 SubstructureRedirectMask
, &ev
);
553 getToken(char *str
, int i
, char *buf
)
560 readBlackBoxStyle(char *path
)
563 char buffer
[128], char token
[128];
567 f
= fopen(path
, "r");
574 if (!fgets(buffer
, 127, f
))
577 if (strncasecmp(buffer
, "menu.title:", 11)==0) {