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.3"
36 #include "../src/wconfig.h"
39 char *FontOptions
[] = {
57 defaultsPathForDomain(char *domain
)
62 gspath
= getenv("GNUSTEP_USER_ROOT");
69 home
= getenv("HOME");
71 printf("%s:could not get HOME environment variable!\n", ProgName
);
76 strcat(path
, "/GNUstep/");
78 strcat(path
, DEFAULTS_DIR
);
82 tmp
= malloc(strlen(path
)+2);
90 hackPaths(proplist_t style
, char *prefix
)
98 keys
= PLGetAllDictionaryKeys(style
);
100 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
101 key
= PLGetArrayElement(keys
, i
);
103 value
= PLGetDictionaryEntry(style
, key
);
104 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
108 type
= PLGetArrayElement(value
, 0);
109 t
= PLGetString(type
);
110 if (t
&& (strcasecmp(t
, "tpixmap")==0
111 || strcasecmp(t
, "spixmap")==0
112 || strcasecmp(t
, "mpixmap")==0
113 || strcasecmp(t
, "cpixmap")==0
114 || strcasecmp(t
, "tvgradient")==0
115 || strcasecmp(t
, "thgradient")==0
116 || strcasecmp(t
, "tdgradient")==0)) {
120 file
= PLGetArrayElement(value
, 1);
121 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
122 PLRemoveArrayElement(value
, 1);
123 PLInsertArrayElement(value
, PLMakeString(buffer
), 1);
132 getColor(proplist_t texture
)
134 proplist_t value
, type
;
137 type
= PLGetArrayElement(texture
, 0);
143 str
= PLGetString(type
);
144 if (strcasecmp(str
, "solid")==0) {
145 value
= PLGetArrayElement(texture
, 1);
146 } else if (strcasecmp(str
, "dgradient")==0
147 || strcasecmp(str
, "hgradient")==0
148 || strcasecmp(str
, "vgradient")==0) {
150 int r1
, g1
, b1
, r2
, g2
, b2
;
153 c1
= PLGetArrayElement(texture
, 1);
154 c2
= PLGetArrayElement(texture
, 2);
156 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
157 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
158 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
160 value
= PLMakeString(buffer
);
168 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
169 PLGetString(c1
), &color1
);
170 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
171 PLGetString(c2
), &color2
);
173 sprintf(buffer
, "#%02x%02x%02x",
174 (color1
.red
+color2
.red
)>>9,
175 (color1
.green
+color2
.green
)>>9,
176 (color1
.blue
+color2
.blue
)>>9);
177 value
= PLMakeString(buffer
);
179 } else if (strcasecmp(str
, "mdgradient")==0
180 || strcasecmp(str
, "mhgradient")==0
181 || strcasecmp(str
, "mvgradient")==0) {
183 value
= PLGetArrayElement(texture
, 1);
185 } else if (strcasecmp(str
, "tpixmap")==0
186 || strcasecmp(str
, "cpixmap")==0
187 || strcasecmp(str
, "spixmap")==0) {
189 value
= PLGetArrayElement(texture
, 2);
197 * since some of the options introduce incompatibilities, we will need
198 * to do a kluge here or the themes ppl will get real annoying.
199 * So, treat for the absence of the following options:
204 hackStyle(proplist_t style
)
209 int foundIconTitle
= 0;
210 int foundResizebarBack
= 0;
212 keys
= PLGetAllDictionaryKeys(style
);
214 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
217 tmp
= PLGetArrayElement(keys
, i
);
218 str
= PLGetString(tmp
);
223 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
224 if (strcasecmp(str
, FontOptions
[j
])==0) {
225 PLRemoveDictionaryEntry(style
, tmp
);
234 if (strcasecmp(str
, "IconTitleColor")==0
235 || strcasecmp(str
, "IconTitleBack")==0) {
237 } else if (strcasecmp(str
, "ResizebarBack")==0) {
238 foundResizebarBack
= 1;
243 if (!foundIconTitle
) {
244 /* set the default values */
245 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
247 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
251 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
255 value
= getColor(tmp
);
258 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
264 if (!foundResizebarBack
) {
265 /* set the default values */
266 tmp
= PLGetDictionaryEntry(style
, PLMakeString("UTitleBack"));
270 value
= getColor(tmp
);
275 t
= PLMakeArrayFromElements(PLMakeString("solid"), value
,
277 PLInsertDictionaryEntry(style
, PLMakeString("ResizebarBack"),
284 if (!PLGetDictionaryEntry(style
, PLMakeString("MenuStyle"))) {
285 PLInsertDictionaryEntry(style
, PLMakeString("MenuStyle"),
286 PLMakeString("normal"));
292 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
296 str1
= PLGetString(pl1
);
297 str2
= PLGetString(pl2
);
299 if (strcasecmp(str1
, str2
)==0)
310 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
311 puts("Reads style/theme configuration from FILE and updates Window Maker.");
313 puts(" --no-fonts ignore font related options");
314 puts(" --help display this help and exit");
315 puts(" --version output version information and exit");
321 main(int argc
, char **argv
)
323 proplist_t prop
, style
;
329 dpy
= XOpenDisplay("");
334 printf("%s: missing argument\n", ProgName
);
335 printf("Try '%s --help' for more information\n", ProgName
);
339 for (i
= 1; i
< argc
; i
++) {
340 if (strcmp("--no-fonts", argv
[i
])==0) {
342 } else if (strcmp("--version", argv
[i
])==0) {
345 } else if (strcmp("--help", argv
[i
])==0) {
350 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
351 printf("Try '%s --help' for more information\n", ProgName
);
358 PLSetStringCmpHook(StringCompareHook
);
360 path
= defaultsPathForDomain("WindowMaker");
362 prop
= PLGetProplistWithPath(path
);
365 printf("%s:could not load WindowMaker configuration file.\n",
370 if (stat(file
, &statbuf
) < 0) {
375 if (S_ISDIR(statbuf
.st_mode
)) {
379 if (*argv
[argc
-1] != '/') {
380 if (!getcwd(buffer
, 4000)) {
381 printf("%s: complete path for %s is too long\n", ProgName
,
385 if (strlen(buffer
) + strlen(file
) > 4000) {
386 printf("%s: complete path for %s is too long\n", ProgName
,
394 strcat(buffer
, file
);
396 prefix
= malloc(strlen(buffer
)+10);
398 printf("%s: out of memory\n", ProgName
);
401 strcpy(prefix
, buffer
);
403 strcat(buffer
, "/style");
405 style
= PLGetProplistWithPath(buffer
);
408 printf("%s:could not load style file.\n", ProgName
);
412 hackPaths(style
, prefix
);
415 style
= PLGetProplistWithPath(file
);
418 printf("%s:could not load style file.\n", ProgName
);
423 if (!PLIsDictionary(style
)) {
424 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
430 PLMergeDictionaries(prop
, style
);
438 char *msg
= "Reconfigure";
440 memset(&ev
, 0, sizeof(XEvent
));
442 ev
.xclient
.type
= ClientMessage
;
443 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
445 ev
.xclient
.window
= DefaultRootWindow(dpy
);
446 ev
.xclient
.format
= 8;
448 for (i
= 0; i
<= strlen(msg
); i
++) {
449 ev
.xclient
.data
.b
[i
] = msg
[i
];
451 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
452 SubstructureRedirectMask
, &ev
);