1 /* setstyle.c - loads style related options to wmaker
3 * WindowMaker window manager
5 * Copyright (c) 1997-2003 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"
32 #include <WINGs/WUtil.h>
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;
77 extern char* convertFont(char *font
, Bool keepXLFD
);
79 WMPropList
*readBlackBoxStyle(char *path
);
83 isCursorOption(char *option
)
87 for (i
=0; CursorOptions
[i
]!=NULL
; i
++) {
88 if (strcasecmp(option
, CursorOptions
[i
])==0) {
98 isFontOption(char *option
)
102 for (i
=0; FontOptions
[i
]!=NULL
; i
++) {
103 if (strcasecmp(option
, FontOptions
[i
])==0) {
113 defaultsPathForDomain(char *domain
)
115 static char path
[1024];
118 gspath
= getenv("GNUSTEP_USER_ROOT");
120 strcpy(path
, gspath
);
125 home
= getenv("HOME");
127 printf("%s:could not get HOME environment variable!\n", ProgName
);
132 strcat(path
, "/GNUstep/");
134 strcat(path
, DEFAULTS_DIR
);
136 strcat(path
, domain
);
144 hackPathInTexture(WMPropList
*texture
, char *prefix
)
149 /* get texture type */
150 type
= WMGetFromPLArray(texture
, 0);
151 t
= WMGetFromPLString(type
);
154 if (strcasecmp(t
, "tpixmap")==0
155 || strcasecmp(t
, "spixmap")==0
156 || strcasecmp(t
, "mpixmap")==0
157 || strcasecmp(t
, "cpixmap")==0
158 || strcasecmp(t
, "tvgradient")==0
159 || strcasecmp(t
, "thgradient")==0
160 || strcasecmp(t
, "tdgradient")==0) {
164 /* get pixmap file path */
165 file
= WMGetFromPLArray(texture
, 1);
166 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
167 /* replace path with full path */
168 WMDeleteFromPLArray(texture
, 1);
169 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
170 } else if (strcasecmp(t
, "bitmap") == 0) {
174 /* get bitmap file path */
175 file
= WMGetFromPLArray(texture
, 1);
176 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
177 /* replace path with full path */
178 WMDeleteFromPLArray(texture
, 1);
179 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
181 /* get mask file path */
182 file
= WMGetFromPLArray(texture
, 2);
183 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
184 /* replace path with full path */
185 WMDeleteFromPLArray(texture
, 2);
186 WMInsertInPLArray(texture
, 2, WMCreatePLString(buffer
));
192 hackPaths(WMPropList
*style
, char *prefix
)
200 keys
= WMGetPLDictionaryKeys(style
);
202 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
203 key
= WMGetFromPLArray(keys
, i
);
205 value
= WMGetFromPLDictionary(style
, key
);
209 if (strcasecmp(WMGetFromPLString(key
), "WorkspaceSpecificBack")==0) {
210 if (WMIsPLArray(value
)) {
214 for (j
= 0; j
< WMGetPropListItemCount(value
); j
++) {
215 texture
= WMGetFromPLArray(value
, j
);
217 if (texture
&& WMIsPLArray(texture
)
218 && WMGetPropListItemCount(texture
) > 2) {
220 hackPathInTexture(texture
, prefix
);
226 if (WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
228 hackPathInTexture(value
, prefix
);
237 getColor(WMPropList
*texture
)
239 WMPropList
*value
, *type
;
242 type
= WMGetFromPLArray(texture
, 0);
248 str
= WMGetFromPLString(type
);
249 if (strcasecmp(str
, "solid")==0) {
250 value
= WMGetFromPLArray(texture
, 1);
251 } else if (strcasecmp(str
, "dgradient")==0
252 || strcasecmp(str
, "hgradient")==0
253 || strcasecmp(str
, "vgradient")==0) {
255 int r1
, g1
, b1
, r2
, g2
, b2
;
258 c1
= WMGetFromPLArray(texture
, 1);
259 c2
= WMGetFromPLArray(texture
, 2);
261 if (sscanf(WMGetFromPLString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
262 && sscanf(WMGetFromPLString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
263 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
265 value
= WMCreatePLString(buffer
);
273 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
274 WMGetFromPLString(c1
), &color1
);
275 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
276 WMGetFromPLString(c2
), &color2
);
278 sprintf(buffer
, "#%02x%02x%02x",
279 (color1
.red
+color2
.red
)>>9,
280 (color1
.green
+color2
.green
)>>9,
281 (color1
.blue
+color2
.blue
)>>9);
282 value
= WMCreatePLString(buffer
);
284 } else if (strcasecmp(str
, "mdgradient")==0
285 || strcasecmp(str
, "mhgradient")==0
286 || strcasecmp(str
, "mvgradient")==0) {
288 value
= WMGetFromPLArray(texture
, 1);
290 } else if (strcasecmp(str
, "tpixmap")==0
291 || strcasecmp(str
, "cpixmap")==0
292 || strcasecmp(str
, "spixmap")==0) {
294 value
= WMGetFromPLArray(texture
, 2);
302 * since some of the options introduce incompatibilities, we will need
303 * to do a kluge here or the themes ppl will get real annoying.
304 * So, treat for the absence of the following options:
309 hackStyle(WMPropList
*style
)
311 WMPropList
*keys
, *tmp
;
312 int foundIconTitle
= 0, foundResizebarBack
= 0;
315 keys
= WMGetPLDictionaryKeys(style
);
317 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
320 tmp
= WMGetFromPLArray(keys
, i
);
321 str
= WMGetFromPLString(tmp
);
323 if (ignoreFonts
&& isFontOption(str
)) {
324 WMRemoveFromPLDictionary(style
, tmp
);
327 if (ignoreCursors
&& isCursorOption(str
)) {
328 WMRemoveFromPLDictionary(style
, tmp
);
331 if (isFontOption(str
)) {
333 char *newfont
, *oldfont
;
335 value
= WMGetFromPLDictionary(style
, tmp
);
337 oldfont
= WMGetFromPLString(value
);
338 newfont
= convertFont(oldfont
, False
);
339 if (newfont
!= oldfont
) {
340 value
= WMCreatePLString(newfont
);
341 WMPutInPLDictionary(style
, tmp
, value
);
342 WMReleasePropList(value
);
347 if (strcasecmp(str
, "IconTitleColor")==0
348 || strcasecmp(str
, "IconTitleBack")==0) {
350 } else if (strcasecmp(str
, "ResizebarBack")==0) {
351 foundResizebarBack
= 1;
356 if (!foundIconTitle
) {
357 /* set the default values */
358 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleColor"));
360 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleColor"),
364 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleBack"));
368 value
= getColor(tmp
);
371 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleBack"),
377 if (!foundResizebarBack
) {
378 /* set the default values */
379 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("UTitleBack"));
383 value
= getColor(tmp
);
388 t
= WMCreatePLArray(WMCreatePLString("solid"), value
,
390 WMPutInPLDictionary(style
, WMCreatePLString("ResizebarBack"),
397 if (!WMGetFromPLDictionary(style
, WMCreatePLString("MenuStyle"))) {
398 WMPutInPLDictionary(style
, WMCreatePLString("MenuStyle"),
399 WMCreatePLString("normal"));
407 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
408 puts("Reads style/theme configuration from FILE and updates Window Maker.");
410 puts(" --no-fonts ignore font related options");
411 puts(" --no-cursors ignore cursor related options");
412 puts(" --ignore <option> ignore changes in the specified option");
413 puts(" --help display this help and exit");
415 puts(" --format <format> specifies the format of the theme to be converted");
417 puts(" --version output version information and exit");
419 puts("Supported formats: blackbox");*/
426 main(int argc
, char **argv
)
428 WMPropList
*prop
, *style
;
434 char *ignoreList
[MAX_OPTIONS
];
436 dpy
= XOpenDisplay("");
441 printf("%s: missing argument\n", ProgName
);
442 printf("Try '%s --help' for more information\n", ProgName
);
446 for (i
= 1; i
< argc
; i
++) {
447 if (strcmp("--ignore", argv
[i
])==0) {
450 printf("%s: missing argument for option --ignore\n", ProgName
);
453 ignoreList
[ignoreCount
++] = argv
[i
];
455 } else if (strcmp("--no-fonts", argv
[i
])==0) {
457 } else if (strcmp("--no-cursors", argv
[i
])==0) {
459 } else if (strcmp("--version", argv
[i
])==0) {
462 } else if (strcmp("--help", argv
[i
])==0) {
466 } else if (strcmp("--format", argv
[i
])==0) {
469 printf("%s: missing argument for option --format\n", ProgName
);
472 if (strcasecmp(argv
[i
], "blackbox")==0) {
475 printf("%s: unknown theme format '%s'\n", ProgName
, argv
[i
]);
481 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
482 printf("Try '%s --help' for more information\n", ProgName
);
489 WMPLSetCaseSensitive(False
);
491 path
= defaultsPathForDomain("WindowMaker");
493 prop
= WMReadPropListFromFile(path
);
496 printf("%s:could not load WindowMaker configuration file.\n",
501 if (stat(file
, &statbuf
) < 0) {
506 if (format
== F_BLACKBOX
) {
507 style
= readBlackBoxStyle(file
);
509 printf("%s: could not open style file\n", ProgName
);
515 if (S_ISDIR(statbuf
.st_mode
)) {
520 if (*argv
[argc
-1] != '/') {
521 if (!getcwd(buffer
, 4000)) {
522 printf("%s: complete path for %s is too long\n", ProgName
,
526 if (strlen(buffer
) + strlen(file
) > 4000) {
527 printf("%s: complete path for %s is too long\n", ProgName
,
535 strcat(buffer
, file
);
537 prefix
= malloc(strlen(buffer
)+10);
539 printf("%s: out of memory\n", ProgName
);
542 strcpy(prefix
, buffer
);
544 strcat(buffer
, "/style");
546 style
= WMReadPropListFromFile(buffer
);
549 printf("%s:could not load style file.\n", ProgName
);
553 hackPaths(style
, prefix
);
556 /* normal style file */
558 style
= WMReadPropListFromFile(file
);
561 printf("%s:could not load style file.\n", ProgName
);
567 if (!WMIsPLDictionary(style
)) {
568 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
574 if (ignoreCount
> 0) {
575 for (i
= 0; i
< ignoreCount
; i
++) {
576 WMRemoveFromPLDictionary(style
, WMCreatePLString(ignoreList
[i
]));
580 WMMergePLDictionaries(prop
, style
, True
);
582 WMWritePropListToFile(prop
, path
, True
);
588 char *msg
= "Reconfigure";
590 memset(&ev
, 0, sizeof(XEvent
));
592 ev
.xclient
.type
= ClientMessage
;
593 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
595 ev
.xclient
.window
= DefaultRootWindow(dpy
);
596 ev
.xclient
.format
= 8;
598 for (i
= 0; i
<= strlen(msg
); i
++) {
599 ev
.xclient
.data
.b
[i
] = msg
[i
];
601 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
602 SubstructureRedirectMask
, &ev
);
613 getToken(char *str
, int i
, char *buf
)
620 readBlackBoxStyle(char *path
)
623 char buffer
[128], char token
[128];
624 WMPropList
*style
, *p
;
626 f
= fopen(path
, "rb");
633 if (!fgets(buffer
, 127, f
))
636 if (strncasecmp(buffer
, "menu.title:", 11)==0) {