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
[] = {
51 char *CursorOptions
[] = {
56 ,"TopLeftResizeCursor"
57 ,"TopRightResizeCursor"
58 ,"BottomLeftResizeCursor"
59 ,"BottomRightResizeCursor"
60 ,"VerticalResizeCursor"
61 ,"HorizontalResizeCursor"
73 int ignoreCursors
= 0;
79 proplist_t
readBlackBoxStyle(char *path
);
84 defaultsPathForDomain(char *domain
)
86 static char path
[1024];
89 gspath
= getenv("GNUSTEP_USER_ROOT");
96 home
= getenv("HOME");
98 printf("%s:could not get HOME environment variable!\n", ProgName
);
103 strcat(path
, "/GNUstep/");
105 strcat(path
, DEFAULTS_DIR
);
107 strcat(path
, domain
);
115 hackPathInTexture(proplist_t texture
, char *prefix
)
120 /* get texture type */
121 type
= PLGetArrayElement(texture
, 0);
122 t
= PLGetString(type
);
125 if (strcasecmp(t
, "tpixmap")==0
126 || strcasecmp(t
, "spixmap")==0
127 || strcasecmp(t
, "mpixmap")==0
128 || strcasecmp(t
, "cpixmap")==0
129 || strcasecmp(t
, "tvgradient")==0
130 || strcasecmp(t
, "thgradient")==0
131 || strcasecmp(t
, "tdgradient")==0) {
135 /* get pixmap file path */
136 file
= PLGetArrayElement(texture
, 1);
137 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
138 /* replace path with full path */
139 PLRemoveArrayElement(texture
, 1);
140 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
141 } else if (strcasecmp(t
, "bitmap") == 0) {
145 /* get bitmap file path */
146 file
= PLGetArrayElement(texture
, 1);
147 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
148 /* replace path with full path */
149 PLRemoveArrayElement(texture
, 1);
150 PLInsertArrayElement(texture
, PLMakeString(buffer
), 1);
152 /* get mask file path */
153 file
= PLGetArrayElement(texture
, 2);
154 sprintf(buffer
, "%s/%s", prefix
, PLGetString(file
));
155 /* replace path with full path */
156 PLRemoveArrayElement(texture
, 2);
157 PLInsertArrayElement(texture
, PLMakeString(buffer
), 2);
163 hackPaths(proplist_t style
, char *prefix
)
171 keys
= PLGetAllDictionaryKeys(style
);
173 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
174 key
= PLGetArrayElement(keys
, i
);
176 value
= PLGetDictionaryEntry(style
, key
);
180 if (strcasecmp(PLGetString(key
), "WorkspaceSpecificBack")==0) {
181 if (PLIsArray(value
)) {
185 for (j
= 0; j
< PLGetNumberOfElements(value
); j
++) {
186 texture
= PLGetArrayElement(value
, j
);
188 if (texture
&& PLIsArray(texture
)
189 && PLGetNumberOfElements(texture
) > 2) {
191 hackPathInTexture(texture
, prefix
);
197 if (PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
199 hackPathInTexture(value
, prefix
);
208 getColor(proplist_t texture
)
210 proplist_t value
, type
;
213 type
= PLGetArrayElement(texture
, 0);
219 str
= PLGetString(type
);
220 if (strcasecmp(str
, "solid")==0) {
221 value
= PLGetArrayElement(texture
, 1);
222 } else if (strcasecmp(str
, "dgradient")==0
223 || strcasecmp(str
, "hgradient")==0
224 || strcasecmp(str
, "vgradient")==0) {
226 int r1
, g1
, b1
, r2
, g2
, b2
;
229 c1
= PLGetArrayElement(texture
, 1);
230 c2
= PLGetArrayElement(texture
, 2);
232 if (sscanf(PLGetString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
233 && sscanf(PLGetString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
234 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
236 value
= PLMakeString(buffer
);
244 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
245 PLGetString(c1
), &color1
);
246 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
247 PLGetString(c2
), &color2
);
249 sprintf(buffer
, "#%02x%02x%02x",
250 (color1
.red
+color2
.red
)>>9,
251 (color1
.green
+color2
.green
)>>9,
252 (color1
.blue
+color2
.blue
)>>9);
253 value
= PLMakeString(buffer
);
255 } else if (strcasecmp(str
, "mdgradient")==0
256 || strcasecmp(str
, "mhgradient")==0
257 || strcasecmp(str
, "mvgradient")==0) {
259 value
= PLGetArrayElement(texture
, 1);
261 } else if (strcasecmp(str
, "tpixmap")==0
262 || strcasecmp(str
, "cpixmap")==0
263 || strcasecmp(str
, "spixmap")==0) {
265 value
= PLGetArrayElement(texture
, 2);
273 * since some of the options introduce incompatibilities, we will need
274 * to do a kluge here or the themes ppl will get real annoying.
275 * So, treat for the absence of the following options:
280 hackStyle(proplist_t style
)
285 int foundIconTitle
= 0;
286 int foundResizebarBack
= 0;
288 keys
= PLGetAllDictionaryKeys(style
);
290 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
293 tmp
= PLGetArrayElement(keys
, i
);
294 str
= PLGetString(tmp
);
299 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
300 if (strcasecmp(str
, FontOptions
[j
])==0) {
301 PLRemoveDictionaryEntry(style
, tmp
);
310 for (j
= 0, found
= 0; CursorOptions
[j
] != NULL
; j
++) {
311 if (strcasecmp(str
, CursorOptions
[j
]) == 0) {
312 PLRemoveDictionaryEntry(style
, tmp
);
321 if (strcasecmp(str
, "IconTitleColor")==0
322 || strcasecmp(str
, "IconTitleBack")==0) {
324 } else if (strcasecmp(str
, "ResizebarBack")==0) {
325 foundResizebarBack
= 1;
330 if (!foundIconTitle
) {
331 /* set the default values */
332 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleColor"));
334 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleColor"),
338 tmp
= PLGetDictionaryEntry(style
, PLMakeString("FTitleBack"));
342 value
= getColor(tmp
);
345 PLInsertDictionaryEntry(style
, PLMakeString("IconTitleBack"),
351 if (!foundResizebarBack
) {
352 /* set the default values */
353 tmp
= PLGetDictionaryEntry(style
, PLMakeString("UTitleBack"));
357 value
= getColor(tmp
);
362 t
= PLMakeArrayFromElements(PLMakeString("solid"), value
,
364 PLInsertDictionaryEntry(style
, PLMakeString("ResizebarBack"),
371 if (!PLGetDictionaryEntry(style
, PLMakeString("MenuStyle"))) {
372 PLInsertDictionaryEntry(style
, PLMakeString("MenuStyle"),
373 PLMakeString("normal"));
379 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
383 str1
= PLGetString(pl1
);
384 str2
= PLGetString(pl2
);
386 if (strcasecmp(str1
, str2
)==0)
396 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
397 puts("Reads style/theme configuration from FILE and updates Window Maker.");
399 puts(" --no-fonts ignore font related options");
400 /* Why these stupid tabs? They're misleading to the programmer,
401 * and they don't do any better than aligning via spaces: If you
402 * have a proportional font, all bets are off anyway. Sheesh.
404 puts(" --no-cursors ignore cursor related options");
405 puts(" --ignore <option> ignore changes in the specified option");
406 puts(" --help display this help and exit");
408 puts(" --format <format> specifies the format of the theme to be converted");
410 puts(" --version output version information and exit");
412 puts("Supported formats: blackbox");
419 main(int argc
, char **argv
)
421 proplist_t prop
, style
;
427 char *ignoreList
[MAX_OPTIONS
];
429 dpy
= XOpenDisplay("");
434 printf("%s: missing argument\n", ProgName
);
435 printf("Try '%s --help' for more information\n", ProgName
);
439 for (i
= 1; i
< argc
; i
++) {
440 if (strcmp("--ignore", argv
[i
])==0) {
443 printf("%s: missing argument for option --ignore\n", ProgName
);
446 ignoreList
[ignoreCount
++] = argv
[i
];
448 } else if (strcmp("--no-fonts", argv
[i
])==0) {
450 } else if (strcmp("--no-cursors", argv
[i
])==0) {
452 } else if (strcmp("--version", argv
[i
])==0) {
455 } else if (strcmp("--help", argv
[i
])==0) {
459 } else if (strcmp("--format", argv
[i
])==0) {
462 printf("%s: missing argument for option --format\n", ProgName
);
465 if (strcasecmp(argv
[i
], "blackbox")==0) {
468 printf("%s: unknown theme format '%s'\n", ProgName
, argv
[i
]);
474 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
475 printf("Try '%s --help' for more information\n", ProgName
);
482 PLSetStringCmpHook(StringCompareHook
);
484 path
= defaultsPathForDomain("WindowMaker");
486 prop
= PLGetProplistWithPath(path
);
489 printf("%s:could not load WindowMaker configuration file.\n",
494 if (stat(file
, &statbuf
) < 0) {
499 if (format
== F_BLACKBOX
) {
500 style
= readBlackBoxStyle(file
);
502 printf("%s: could not open style file\n", ProgName
);
508 if (S_ISDIR(statbuf
.st_mode
)) {
513 if (*argv
[argc
-1] != '/') {
514 if (!getcwd(buffer
, 4000)) {
515 printf("%s: complete path for %s is too long\n", ProgName
,
519 if (strlen(buffer
) + strlen(file
) > 4000) {
520 printf("%s: complete path for %s is too long\n", ProgName
,
528 strcat(buffer
, file
);
530 prefix
= malloc(strlen(buffer
)+10);
532 printf("%s: out of memory\n", ProgName
);
535 strcpy(prefix
, buffer
);
537 strcat(buffer
, "/style");
539 style
= PLGetProplistWithPath(buffer
);
542 printf("%s:could not load style file.\n", ProgName
);
546 hackPaths(style
, prefix
);
549 /* normal style file */
551 style
= PLGetProplistWithPath(file
);
554 printf("%s:could not load style file.\n", ProgName
);
560 if (!PLIsDictionary(style
)) {
561 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
567 if (ignoreCount
> 0) {
568 for (i
= 0; i
< ignoreCount
; i
++) {
569 PLRemoveDictionaryEntry(style
, PLMakeString(ignoreList
[i
]));
573 PLMergeDictionaries(prop
, style
);
581 char *msg
= "Reconfigure";
583 memset(&ev
, 0, sizeof(XEvent
));
585 ev
.xclient
.type
= ClientMessage
;
586 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
588 ev
.xclient
.window
= DefaultRootWindow(dpy
);
589 ev
.xclient
.format
= 8;
591 for (i
= 0; i
<= strlen(msg
); i
++) {
592 ev
.xclient
.data
.b
[i
] = msg
[i
];
594 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
595 SubstructureRedirectMask
, &ev
);
606 getToken(char *str
, int i
, char *buf
)
613 readBlackBoxStyle(char *path
)
616 char buffer
[128], char token
[128];
620 f
= fopen(path
, "r");
627 if (!fgets(buffer
, 127, f
))
630 if (strncasecmp(buffer
, "menu.title:", 11)==0) {