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
[] = {
59 defaultsPathForDomain(char *domain
)
64 gspath
= getenv("GNUSTEP_USER_ROOT");
71 home
= getenv("HOME");
73 printf("%s:could not get HOME environment variable!\n", ProgName
);
78 strcat(path
, "/GNUstep/");
80 strcat(path
, DEFAULTS_DIR
);
84 tmp
= malloc(strlen(path
)+2);
93 hackPathInTexture(proplist_t texture
, char *prefix
)
98 /* get texture type */
99 type
= PLGetArrayElement(texture
, 0);
100 t
= PLGetString(type
);
101 if (t
&& (strcasecmp(t
, "tpixmap")==0
102 || strcasecmp(t
, "spixmap")==0
103 || strcasecmp(t
, "mpixmap")==0
104 || strcasecmp(t
, "cpixmap")==0
105 || strcasecmp(t
, "tvgradient")==0
106 || strcasecmp(t
, "thgradient")==0
107 || strcasecmp(t
, "tdgradient")==0)) {
111 /* get pixmap file path */
112 file
= PLGetArrayElement(texture
, 1);
113 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
114 /* replace path with full path */
115 PLRemoveArrayElement(texture
, 1);
116 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
122 hackPaths(proplist_t style
, char *prefix
)
130 keys
= PLGetAllDictionaryKeys(style
);
132 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
133 key
= PLGetArrayElement(keys
, i
);
135 value
= PLGetDictionaryEntry(style
, key
);
139 if (strcasecmp(PLGetString(key
), "WorkspaceSpecificBack")==0) {
140 if (PLIsArray(value
)) {
144 for (j
= 0; j
< PLGetNumberOfElements(value
); j
++) {
145 texture
= PLGetArrayElement(value
, j
);
147 if (texture
&& PLIsArray(texture
)
148 && PLGetNumberOfElements(texture
) > 2) {
150 hackPathInTexture(texture
, prefix
);
156 if (PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
158 hackPathInTexture(value
, prefix
);
167 getColor(proplist_t texture
)
169 proplist_t value
, type
;
172 type
= PLGetArrayElement(texture
, 0);
178 str
= PLGetString(type
);
179 if (strcasecmp(str
, "solid")==0) {
180 value
= PLGetArrayElement(texture
, 1);
181 } else if (strcasecmp(str
, "dgradient")==0
182 || strcasecmp(str
, "hgradient")==0
183 || strcasecmp(str
, "vgradient")==0) {
185 int r1
, g1
, b1
, r2
, g2
, b2
;
188 c1
= PLGetArrayElement(texture
, 1);
189 c2
= PLGetArrayElement(texture
, 2);
191 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
192 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
193 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
195 value
= PLMakeString(buffer
);
203 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
204 PLGetString(c1
), &color1
);
205 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
206 PLGetString(c2
), &color2
);
208 sprintf(buffer
, "#%02x%02x%02x",
209 (color1
.red
+color2
.red
)>>9,
210 (color1
.green
+color2
.green
)>>9,
211 (color1
.blue
+color2
.blue
)>>9);
212 value
= PLMakeString(buffer
);
214 } else if (strcasecmp(str
, "mdgradient")==0
215 || strcasecmp(str
, "mhgradient")==0
216 || strcasecmp(str
, "mvgradient")==0) {
218 value
= PLGetArrayElement(texture
, 1);
220 } else if (strcasecmp(str
, "tpixmap")==0
221 || strcasecmp(str
, "cpixmap")==0
222 || strcasecmp(str
, "spixmap")==0) {
224 value
= PLGetArrayElement(texture
, 2);
232 * since some of the options introduce incompatibilities, we will need
233 * to do a kluge here or the themes ppl will get real annoying.
234 * So, treat for the absence of the following options:
239 hackStyle(proplist_t style
)
244 int foundIconTitle
= 0;
245 int foundResizebarBack
= 0;
247 keys
= PLGetAllDictionaryKeys(style
);
249 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
252 tmp
= PLGetArrayElement(keys
, i
);
253 str
= PLGetString(tmp
);
258 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
259 if (strcasecmp(str
, FontOptions
[j
])==0) {
260 PLRemoveDictionaryEntry(style
, tmp
);
269 if (strcasecmp(str
, "IconTitleColor")==0
270 || strcasecmp(str
, "IconTitleBack")==0) {
272 } else if (strcasecmp(str
, "ResizebarBack")==0) {
273 foundResizebarBack
= 1;
278 if (!foundIconTitle
) {
279 /* set the default values */
280 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
282 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
286 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
290 value
= getColor(tmp
);
293 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
299 if (!foundResizebarBack
) {
300 /* set the default values */
301 tmp
= PLGetDictionaryEntry(style
, PLMakeString("UTitleBack"));
305 value
= getColor(tmp
);
310 t
= PLMakeArrayFromElements(PLMakeString("solid"), value
,
312 PLInsertDictionaryEntry(style
, PLMakeString("ResizebarBack"),
319 if (!PLGetDictionaryEntry(style
, PLMakeString("MenuStyle"))) {
320 PLInsertDictionaryEntry(style
, PLMakeString("MenuStyle"),
321 PLMakeString("normal"));
327 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
331 str1
= PLGetString(pl1
);
332 str2
= PLGetString(pl2
);
334 if (strcasecmp(str1
, str2
)==0)
345 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
346 puts("Reads style/theme configuration from FILE and updates Window Maker.");
348 puts(" --no-fonts ignore font related options");
349 puts(" --ignore <option> ignore changes in the specified option");
350 puts(" --help display this help and exit");
351 puts(" --version output version information and exit");
356 main(int argc
, char **argv
)
358 proplist_t prop
, style
;
364 char *ignoreList
[MAX_OPTIONS
];
366 dpy
= XOpenDisplay("");
371 printf("%s: missing argument\n", ProgName
);
372 printf("Try '%s --help' for more information\n", ProgName
);
376 for (i
= 1; i
< argc
; i
++) {
377 if (strcmp("--ignore", argv
[i
])==0) {
380 printf("%s: missing argument for option --ignore", ProgName
);
383 ignoreList
[ignoreCount
++] = argv
[i
];
385 } else if (strcmp("--no-fonts", argv
[i
])==0) {
387 } else if (strcmp("--version", argv
[i
])==0) {
390 } else if (strcmp("--help", argv
[i
])==0) {
395 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
396 printf("Try '%s --help' for more information\n", ProgName
);
403 PLSetStringCmpHook(StringCompareHook
);
405 path
= defaultsPathForDomain("WindowMaker");
407 prop
= PLGetProplistWithPath(path
);
410 printf("%s:could not load WindowMaker configuration file.\n",
415 if (stat(file
, &statbuf
) < 0) {
420 if (S_ISDIR(statbuf
.st_mode
)) {
424 if (*argv
[argc
-1] != '/') {
425 if (!getcwd(buffer
, 4000)) {
426 printf("%s: complete path for %s is too long\n", ProgName
,
430 if (strlen(buffer
) + strlen(file
) > 4000) {
431 printf("%s: complete path for %s is too long\n", ProgName
,
439 strcat(buffer
, file
);
441 prefix
= malloc(strlen(buffer
)+10);
443 printf("%s: out of memory\n", ProgName
);
446 strcpy(prefix
, buffer
);
448 strcat(buffer
, "/style");
450 style
= PLGetProplistWithPath(buffer
);
453 printf("%s:could not load style file.\n", ProgName
);
457 hackPaths(style
, prefix
);
460 style
= PLGetProplistWithPath(file
);
463 printf("%s:could not load style file.\n", ProgName
);
468 if (!PLIsDictionary(style
)) {
469 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
475 if (ignoreCount
> 0) {
476 for (i
= 0; i
< ignoreCount
; i
++) {
477 PLRemoveDictionaryEntry(style
, PLMakeString(ignoreList
[i
]));
481 PLMergeDictionaries(prop
, style
);
489 char *msg
= "Reconfigure";
491 memset(&ev
, 0, sizeof(XEvent
));
493 ev
.xclient
.type
= ClientMessage
;
494 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
496 ev
.xclient
.window
= DefaultRootWindow(dpy
);
497 ev
.xclient
.format
= 8;
499 for (i
= 0; i
<= strlen(msg
); i
++) {
500 ev
.xclient
.data
.b
[i
] = msg
[i
];
502 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
503 SubstructureRedirectMask
, &ev
);