1 /* setstyle.c - loads style related options to wmaker
3 * WindowMaker window manager
5 * Copyright (c) 1997~2000 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.6"
36 #include "../src/wconfig.h"
38 #define MAX_OPTIONS 128
40 char *FontOptions
[] = {
60 proplist_t
readBlackBoxStyle(char *path
);
65 defaultsPathForDomain(char *domain
)
67 static char path
[1024];
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
);
96 hackPathInTexture(proplist_t texture
, char *prefix
)
101 /* get texture type */
102 type
= PLGetArrayElement(texture
, 0);
103 t
= PLGetString(type
);
106 if (strcasecmp(t
, "tpixmap")==0
107 || strcasecmp(t
, "spixmap")==0
108 || strcasecmp(t
, "mpixmap")==0
109 || strcasecmp(t
, "cpixmap")==0
110 || strcasecmp(t
, "tvgradient")==0
111 || strcasecmp(t
, "thgradient")==0
112 || strcasecmp(t
, "tdgradient")==0) {
116 /* get pixmap file path */
117 file
= PLGetArrayElement(texture
, 1);
118 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
119 /* replace path with full path */
120 PLRemoveArrayElement(texture
, 1);
121 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
122 } else if (strcasecmp(t
, "bitmap") == 0) {
126 /* get bitmap file path */
127 file
= PLGetArrayElement(texture
, 1);
128 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
129 /* replace path with full path */
130 PLRemoveArrayElement(texture
, 1);
131 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
133 /* get mask file path */
134 file
= PLGetArrayElement(texture
, 2);
135 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
136 /* replace path with full path */
137 PLRemoveArrayElement(texture
, 2);
138 PLInsertArrayElement(texture
, PLMakeString(buffer
), 2);
144 hackPaths(proplist_t style
, char *prefix
)
152 keys
= PLGetAllDictionaryKeys(style
);
154 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
155 key
= PLGetArrayElement(keys
, i
);
157 value
= PLGetDictionaryEntry(style
, key
);
161 if (strcasecmp(PLGetString(key
), "WorkspaceSpecificBack")==0) {
162 if (PLIsArray(value
)) {
166 for (j
= 0; j
< PLGetNumberOfElements(value
); j
++) {
167 texture
= PLGetArrayElement(value
, j
);
169 if (texture
&& PLIsArray(texture
)
170 && PLGetNumberOfElements(texture
) > 2) {
172 hackPathInTexture(texture
, prefix
);
178 if (PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
180 hackPathInTexture(value
, prefix
);
189 getColor(proplist_t texture
)
191 proplist_t value
, type
;
194 type
= PLGetArrayElement(texture
, 0);
200 str
= PLGetString(type
);
201 if (strcasecmp(str
, "solid")==0) {
202 value
= PLGetArrayElement(texture
, 1);
203 } else if (strcasecmp(str
, "dgradient")==0
204 || strcasecmp(str
, "hgradient")==0
205 || strcasecmp(str
, "vgradient")==0) {
207 int r1
, g1
, b1
, r2
, g2
, b2
;
210 c1
= PLGetArrayElement(texture
, 1);
211 c2
= PLGetArrayElement(texture
, 2);
213 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
214 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
215 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
217 value
= PLMakeString(buffer
);
225 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
226 PLGetString(c1
), &color1
);
227 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
228 PLGetString(c2
), &color2
);
230 sprintf(buffer
, "#%02x%02x%02x",
231 (color1
.red
+color2
.red
)>>9,
232 (color1
.green
+color2
.green
)>>9,
233 (color1
.blue
+color2
.blue
)>>9);
234 value
= PLMakeString(buffer
);
236 } else if (strcasecmp(str
, "mdgradient")==0
237 || strcasecmp(str
, "mhgradient")==0
238 || strcasecmp(str
, "mvgradient")==0) {
240 value
= PLGetArrayElement(texture
, 1);
242 } else if (strcasecmp(str
, "tpixmap")==0
243 || strcasecmp(str
, "cpixmap")==0
244 || strcasecmp(str
, "spixmap")==0) {
246 value
= PLGetArrayElement(texture
, 2);
254 * since some of the options introduce incompatibilities, we will need
255 * to do a kluge here or the themes ppl will get real annoying.
256 * So, treat for the absence of the following options:
261 hackStyle(proplist_t style
)
266 int foundIconTitle
= 0;
267 int foundResizebarBack
= 0;
269 keys
= PLGetAllDictionaryKeys(style
);
271 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
274 tmp
= PLGetArrayElement(keys
, i
);
275 str
= PLGetString(tmp
);
280 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
281 if (strcasecmp(str
, FontOptions
[j
])==0) {
282 PLRemoveDictionaryEntry(style
, tmp
);
291 if (strcasecmp(str
, "IconTitleColor")==0
292 || strcasecmp(str
, "IconTitleBack")==0) {
294 } else if (strcasecmp(str
, "ResizebarBack")==0) {
295 foundResizebarBack
= 1;
300 if (!foundIconTitle
) {
301 /* set the default values */
302 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
304 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
308 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
312 value
= getColor(tmp
);
315 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
321 if (!foundResizebarBack
) {
322 /* set the default values */
323 tmp
= PLGetDictionaryEntry(style
, PLMakeString("UTitleBack"));
327 value
= getColor(tmp
);
332 t
= PLMakeArrayFromElements(PLMakeString("solid"), value
,
334 PLInsertDictionaryEntry(style
, PLMakeString("ResizebarBack"),
341 if (!PLGetDictionaryEntry(style
, PLMakeString("MenuStyle"))) {
342 PLInsertDictionaryEntry(style
, PLMakeString("MenuStyle"),
343 PLMakeString("normal"));
349 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
353 str1
= PLGetString(pl1
);
354 str2
= PLGetString(pl2
);
356 if (strcasecmp(str1
, str2
)==0)
366 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
367 puts("Reads style/theme configuration from FILE and updates Window Maker.");
369 puts(" --no-fonts ignore font related options");
370 puts(" --ignore <option> ignore changes in the specified option");
371 puts(" --help display this help and exit");
373 puts(" --format <format> specifies the format of the theme to be converted");
375 puts(" --version output version information and exit");
377 puts("Supported formats: blackbox");
384 main(int argc
, char **argv
)
386 proplist_t prop
, style
;
392 char *ignoreList
[MAX_OPTIONS
];
394 dpy
= XOpenDisplay("");
399 printf("%s: missing argument\n", ProgName
);
400 printf("Try '%s --help' for more information\n", ProgName
);
404 for (i
= 1; i
< argc
; i
++) {
405 if (strcmp("--ignore", argv
[i
])==0) {
408 printf("%s: missing argument for option --ignore\n", ProgName
);
411 ignoreList
[ignoreCount
++] = argv
[i
];
413 } else if (strcmp("--no-fonts", argv
[i
])==0) {
415 } else if (strcmp("--version", argv
[i
])==0) {
418 } else if (strcmp("--help", argv
[i
])==0) {
422 } else if (strcmp("--format", argv
[i
])==0) {
425 printf("%s: missing argument for option --format\n", ProgName
);
428 if (strcasecmp(argv
[i
], "blackbox")==0) {
431 printf("%s: unknown theme format '%s'\n", ProgName
, argv
[i
]);
437 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
438 printf("Try '%s --help' for more information\n", ProgName
);
445 PLSetStringCmpHook(StringCompareHook
);
447 path
= defaultsPathForDomain("WindowMaker");
449 prop
= PLGetProplistWithPath(path
);
452 printf("%s:could not load WindowMaker configuration file.\n",
457 if (stat(file
, &statbuf
) < 0) {
462 if (format
== F_BLACKBOX
) {
463 style
= readBlackBoxStyle(file
);
465 printf("%s: could not open style file\n", ProgName
);
471 if (S_ISDIR(statbuf
.st_mode
)) {
476 if (*argv
[argc
-1] != '/') {
477 if (!getcwd(buffer
, 4000)) {
478 printf("%s: complete path for %s is too long\n", ProgName
,
482 if (strlen(buffer
) + strlen(file
) > 4000) {
483 printf("%s: complete path for %s is too long\n", ProgName
,
491 strcat(buffer
, file
);
493 prefix
= malloc(strlen(buffer
)+10);
495 printf("%s: out of memory\n", ProgName
);
498 strcpy(prefix
, buffer
);
500 strcat(buffer
, "/style");
502 style
= PLGetProplistWithPath(buffer
);
505 printf("%s:could not load style file.\n", ProgName
);
509 hackPaths(style
, prefix
);
512 /* normal style file */
514 style
= PLGetProplistWithPath(file
);
517 printf("%s:could not load style file.\n", ProgName
);
523 if (!PLIsDictionary(style
)) {
524 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
530 if (ignoreCount
> 0) {
531 for (i
= 0; i
< ignoreCount
; i
++) {
532 PLRemoveDictionaryEntry(style
, PLMakeString(ignoreList
[i
]));
536 PLMergeDictionaries(prop
, style
);
544 char *msg
= "Reconfigure";
546 memset(&ev
, 0, sizeof(XEvent
));
548 ev
.xclient
.type
= ClientMessage
;
549 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
551 ev
.xclient
.window
= DefaultRootWindow(dpy
);
552 ev
.xclient
.format
= 8;
554 for (i
= 0; i
<= strlen(msg
); i
++) {
555 ev
.xclient
.data
.b
[i
] = msg
[i
];
557 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
558 SubstructureRedirectMask
, &ev
);
569 getToken(char *str
, int i
, char *buf
)
576 readBlackBoxStyle(char *path
)
579 char buffer
[128], char token
[128];
583 f
= fopen(path
, "r");
590 if (!fgets(buffer
, 127, f
))
593 if (strncasecmp(buffer
, "menu.title:", 11)==0) {