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
)
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
);
109 if (strcasecmp(t
, "tpixmap")==0
110 || strcasecmp(t
, "spixmap")==0
111 || strcasecmp(t
, "mpixmap")==0
112 || strcasecmp(t
, "cpixmap")==0
113 || strcasecmp(t
, "tvgradient")==0
114 || strcasecmp(t
, "thgradient")==0
115 || strcasecmp(t
, "tdgradient")==0) {
119 /* get pixmap file path */
120 file
= PLGetArrayElement(texture
, 1);
121 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
122 /* replace path with full path */
123 PLRemoveArrayElement(texture
, 1);
124 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
125 } else if (strcasecmp(t
, "bitmap") == 0) {
129 /* get bitmap file path */
130 file
= PLGetArrayElement(texture
, 1);
131 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
132 /* replace path with full path */
133 PLRemoveArrayElement(texture
, 1);
134 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
136 /* get mask file path */
137 file
= PLGetArrayElement(texture
, 2);
138 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
139 /* replace path with full path */
140 PLRemoveArrayElement(texture
, 2);
141 PLInsertArrayElement(texture
, PLMakeString(buffer
), 2);
147 hackPaths(proplist_t style
, char *prefix
)
155 keys
= PLGetAllDictionaryKeys(style
);
157 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
158 key
= PLGetArrayElement(keys
, i
);
160 value
= PLGetDictionaryEntry(style
, key
);
164 if (strcasecmp(PLGetString(key
), "WorkspaceSpecificBack")==0) {
165 if (PLIsArray(value
)) {
169 for (j
= 0; j
< PLGetNumberOfElements(value
); j
++) {
170 texture
= PLGetArrayElement(value
, j
);
172 if (texture
&& PLIsArray(texture
)
173 && PLGetNumberOfElements(texture
) > 2) {
175 hackPathInTexture(texture
, prefix
);
181 if (PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
183 hackPathInTexture(value
, prefix
);
192 getColor(proplist_t texture
)
194 proplist_t value
, type
;
197 type
= PLGetArrayElement(texture
, 0);
203 str
= PLGetString(type
);
204 if (strcasecmp(str
, "solid")==0) {
205 value
= PLGetArrayElement(texture
, 1);
206 } else if (strcasecmp(str
, "dgradient")==0
207 || strcasecmp(str
, "hgradient")==0
208 || strcasecmp(str
, "vgradient")==0) {
210 int r1
, g1
, b1
, r2
, g2
, b2
;
213 c1
= PLGetArrayElement(texture
, 1);
214 c2
= PLGetArrayElement(texture
, 2);
216 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
217 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
218 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
220 value
= PLMakeString(buffer
);
228 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
229 PLGetString(c1
), &color1
);
230 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
231 PLGetString(c2
), &color2
);
233 sprintf(buffer
, "#%02x%02x%02x",
234 (color1
.red
+color2
.red
)>>9,
235 (color1
.green
+color2
.green
)>>9,
236 (color1
.blue
+color2
.blue
)>>9);
237 value
= PLMakeString(buffer
);
239 } else if (strcasecmp(str
, "mdgradient")==0
240 || strcasecmp(str
, "mhgradient")==0
241 || strcasecmp(str
, "mvgradient")==0) {
243 value
= PLGetArrayElement(texture
, 1);
245 } else if (strcasecmp(str
, "tpixmap")==0
246 || strcasecmp(str
, "cpixmap")==0
247 || strcasecmp(str
, "spixmap")==0) {
249 value
= PLGetArrayElement(texture
, 2);
257 * since some of the options introduce incompatibilities, we will need
258 * to do a kluge here or the themes ppl will get real annoying.
259 * So, treat for the absence of the following options:
264 hackStyle(proplist_t style
)
269 int foundIconTitle
= 0;
270 int foundResizebarBack
= 0;
272 keys
= PLGetAllDictionaryKeys(style
);
274 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
277 tmp
= PLGetArrayElement(keys
, i
);
278 str
= PLGetString(tmp
);
283 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
284 if (strcasecmp(str
, FontOptions
[j
])==0) {
285 PLRemoveDictionaryEntry(style
, tmp
);
294 if (strcasecmp(str
, "IconTitleColor")==0
295 || strcasecmp(str
, "IconTitleBack")==0) {
297 } else if (strcasecmp(str
, "ResizebarBack")==0) {
298 foundResizebarBack
= 1;
303 if (!foundIconTitle
) {
304 /* set the default values */
305 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
307 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
311 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
315 value
= getColor(tmp
);
318 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
324 if (!foundResizebarBack
) {
325 /* set the default values */
326 tmp
= PLGetDictionaryEntry(style
, PLMakeString("UTitleBack"));
330 value
= getColor(tmp
);
335 t
= PLMakeArrayFromElements(PLMakeString("solid"), value
,
337 PLInsertDictionaryEntry(style
, PLMakeString("ResizebarBack"),
344 if (!PLGetDictionaryEntry(style
, PLMakeString("MenuStyle"))) {
345 PLInsertDictionaryEntry(style
, PLMakeString("MenuStyle"),
346 PLMakeString("normal"));
352 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
356 str1
= PLGetString(pl1
);
357 str2
= PLGetString(pl2
);
359 if (strcasecmp(str1
, str2
)==0)
369 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
370 puts("Reads style/theme configuration from FILE and updates Window Maker.");
372 puts(" --no-fonts ignore font related options");
373 puts(" --ignore <option> ignore changes in the specified option");
374 puts(" --help display this help and exit");
376 puts(" --format <format> specifies the format of the theme to be converted");
378 puts(" --version output version information and exit");
380 puts("Supported formats: blackbox");
387 main(int argc
, char **argv
)
389 proplist_t prop
, style
;
395 char *ignoreList
[MAX_OPTIONS
];
397 dpy
= XOpenDisplay("");
402 printf("%s: missing argument\n", ProgName
);
403 printf("Try '%s --help' for more information\n", ProgName
);
407 for (i
= 1; i
< argc
; i
++) {
408 if (strcmp("--ignore", argv
[i
])==0) {
411 printf("%s: missing argument for option --ignore\n", ProgName
);
414 ignoreList
[ignoreCount
++] = argv
[i
];
416 } else if (strcmp("--no-fonts", argv
[i
])==0) {
418 } else if (strcmp("--version", argv
[i
])==0) {
421 } else if (strcmp("--help", argv
[i
])==0) {
425 } else if (strcmp("--format", argv
[i
])==0) {
428 printf("%s: missing argument for option --format\n", ProgName
);
431 if (strcasecmp(argv
[i
], "blackbox")==0) {
434 printf("%s: unknown theme format '%s'\n", ProgName
, argv
[i
]);
440 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
441 printf("Try '%s --help' for more information\n", ProgName
);
448 PLSetStringCmpHook(StringCompareHook
);
450 path
= defaultsPathForDomain("WindowMaker");
452 prop
= PLGetProplistWithPath(path
);
455 printf("%s:could not load WindowMaker configuration file.\n",
460 if (stat(file
, &statbuf
) < 0) {
465 if (format
== F_BLACKBOX
) {
466 style
= readBlackBoxStyle(file
);
468 printf("%s: could not open style file\n", ProgName
);
474 if (S_ISDIR(statbuf
.st_mode
)) {
479 if (*argv
[argc
-1] != '/') {
480 if (!getcwd(buffer
, 4000)) {
481 printf("%s: complete path for %s is too long\n", ProgName
,
485 if (strlen(buffer
) + strlen(file
) > 4000) {
486 printf("%s: complete path for %s is too long\n", ProgName
,
494 strcat(buffer
, file
);
496 prefix
= malloc(strlen(buffer
)+10);
498 printf("%s: out of memory\n", ProgName
);
501 strcpy(prefix
, buffer
);
503 strcat(buffer
, "/style");
505 style
= PLGetProplistWithPath(buffer
);
508 printf("%s:could not load style file.\n", ProgName
);
512 hackPaths(style
, prefix
);
515 /* normal style file */
517 style
= PLGetProplistWithPath(file
);
520 printf("%s:could not load style file.\n", ProgName
);
526 if (!PLIsDictionary(style
)) {
527 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
533 if (ignoreCount
> 0) {
534 for (i
= 0; i
< ignoreCount
; i
++) {
535 PLRemoveDictionaryEntry(style
, PLMakeString(ignoreList
[i
]));
539 PLMergeDictionaries(prop
, style
);
547 char *msg
= "Reconfigure";
549 memset(&ev
, 0, sizeof(XEvent
));
551 ev
.xclient
.type
= ClientMessage
;
552 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
554 ev
.xclient
.window
= DefaultRootWindow(dpy
);
555 ev
.xclient
.format
= 8;
557 for (i
= 0; i
<= strlen(msg
); i
++) {
558 ev
.xclient
.data
.b
[i
] = msg
[i
];
560 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
561 SubstructureRedirectMask
, &ev
);
572 getToken(char *str
, int i
, char *buf
)
579 readBlackBoxStyle(char *path
)
582 char buffer
[128], char token
[128];
586 f
= fopen(path
, "r");
593 if (!fgets(buffer
, 127, f
))
596 if (strncasecmp(buffer
, "menu.title:", 11)==0) {