1 /* setstyle.c - loads style related options to wmaker
3 * WindowMaker window manager
5 * Copyright (c) 1997-2002 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;
79 WMPropList
*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(WMPropList
*texture
, char *prefix
)
120 /* get texture type */
121 type
= WMGetFromPLArray(texture
, 0);
122 t
= WMGetFromPLString(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
= WMGetFromPLArray(texture
, 1);
137 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
138 /* replace path with full path */
139 WMDeleteFromPLArray(texture
, 1);
140 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
141 } else if (strcasecmp(t
, "bitmap") == 0) {
145 /* get bitmap file path */
146 file
= WMGetFromPLArray(texture
, 1);
147 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
148 /* replace path with full path */
149 WMDeleteFromPLArray(texture
, 1);
150 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
152 /* get mask file path */
153 file
= WMGetFromPLArray(texture
, 2);
154 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
155 /* replace path with full path */
156 WMDeleteFromPLArray(texture
, 2);
157 WMInsertInPLArray(texture
, 2, WMCreatePLString(buffer
));
163 hackPaths(WMPropList
*style
, char *prefix
)
171 keys
= WMGetPLDictionaryKeys(style
);
173 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
174 key
= WMGetFromPLArray(keys
, i
);
176 value
= WMGetFromPLDictionary(style
, key
);
180 if (strcasecmp(WMGetFromPLString(key
), "WorkspaceSpecificBack")==0) {
181 if (WMIsPLArray(value
)) {
185 for (j
= 0; j
< WMGetPropListItemCount(value
); j
++) {
186 texture
= WMGetFromPLArray(value
, j
);
188 if (texture
&& WMIsPLArray(texture
)
189 && WMGetPropListItemCount(texture
) > 2) {
191 hackPathInTexture(texture
, prefix
);
197 if (WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
199 hackPathInTexture(value
, prefix
);
208 getColor(WMPropList
*texture
)
210 WMPropList
*value
, *type
;
213 type
= WMGetFromPLArray(texture
, 0);
219 str
= WMGetFromPLString(type
);
220 if (strcasecmp(str
, "solid")==0) {
221 value
= WMGetFromPLArray(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
= WMGetFromPLArray(texture
, 1);
230 c2
= WMGetFromPLArray(texture
, 2);
232 if (sscanf(WMGetFromPLString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
233 && sscanf(WMGetFromPLString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
234 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
236 value
= WMCreatePLString(buffer
);
244 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
245 WMGetFromPLString(c1
), &color1
);
246 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
247 WMGetFromPLString(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
= WMCreatePLString(buffer
);
255 } else if (strcasecmp(str
, "mdgradient")==0
256 || strcasecmp(str
, "mhgradient")==0
257 || strcasecmp(str
, "mvgradient")==0) {
259 value
= WMGetFromPLArray(texture
, 1);
261 } else if (strcasecmp(str
, "tpixmap")==0
262 || strcasecmp(str
, "cpixmap")==0
263 || strcasecmp(str
, "spixmap")==0) {
265 value
= WMGetFromPLArray(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(WMPropList
*style
)
282 WMPropList
*keys
, *tmp
;
283 int foundIconTitle
= 0, foundResizebarBack
= 0;
286 keys
= WMGetPLDictionaryKeys(style
);
288 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
291 tmp
= WMGetFromPLArray(keys
, i
);
292 str
= WMGetFromPLString(tmp
);
297 for (j
= 0, found
= 0; FontOptions
[j
]!=NULL
; j
++) {
298 if (strcasecmp(str
, FontOptions
[j
])==0) {
299 WMRemoveFromPLDictionary(style
, tmp
);
308 for (j
= 0, found
= 0; CursorOptions
[j
] != NULL
; j
++) {
309 if (strcasecmp(str
, CursorOptions
[j
]) == 0) {
310 WMRemoveFromPLDictionary(style
, tmp
);
319 if (strcasecmp(str
, "IconTitleColor")==0
320 || strcasecmp(str
, "IconTitleBack")==0) {
322 } else if (strcasecmp(str
, "ResizebarBack")==0) {
323 foundResizebarBack
= 1;
328 if (!foundIconTitle
) {
329 /* set the default values */
330 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleColor"));
332 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleColor"),
336 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleBack"));
340 value
= getColor(tmp
);
343 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleBack"),
349 if (!foundResizebarBack
) {
350 /* set the default values */
351 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("UTitleBack"));
355 value
= getColor(tmp
);
360 t
= WMCreatePLArray(WMCreatePLString("solid"), value
,
362 WMPutInPLDictionary(style
, WMCreatePLString("ResizebarBack"),
369 if (!WMGetFromPLDictionary(style
, WMCreatePLString("MenuStyle"))) {
370 WMPutInPLDictionary(style
, WMCreatePLString("MenuStyle"),
371 WMCreatePLString("normal"));
379 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
380 puts("Reads style/theme configuration from FILE and updates Window Maker.");
382 puts(" --no-fonts ignore font related options");
383 puts(" --no-cursors ignore cursor related options");
384 puts(" --ignore <option> ignore changes in the specified option");
385 puts(" --help display this help and exit");
387 puts(" --format <format> specifies the format of the theme to be converted");
389 puts(" --version output version information and exit");
391 puts("Supported formats: blackbox");*/
398 main(int argc
, char **argv
)
400 WMPropList
*prop
, *style
;
406 char *ignoreList
[MAX_OPTIONS
];
408 dpy
= XOpenDisplay("");
413 printf("%s: missing argument\n", ProgName
);
414 printf("Try '%s --help' for more information\n", ProgName
);
418 for (i
= 1; i
< argc
; i
++) {
419 if (strcmp("--ignore", argv
[i
])==0) {
422 printf("%s: missing argument for option --ignore\n", ProgName
);
425 ignoreList
[ignoreCount
++] = argv
[i
];
427 } else if (strcmp("--no-fonts", argv
[i
])==0) {
429 } else if (strcmp("--no-cursors", argv
[i
])==0) {
431 } else if (strcmp("--version", argv
[i
])==0) {
434 } else if (strcmp("--help", argv
[i
])==0) {
438 } else if (strcmp("--format", argv
[i
])==0) {
441 printf("%s: missing argument for option --format\n", ProgName
);
444 if (strcasecmp(argv
[i
], "blackbox")==0) {
447 printf("%s: unknown theme format '%s'\n", ProgName
, argv
[i
]);
453 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
454 printf("Try '%s --help' for more information\n", ProgName
);
461 WMPLSetCaseSensitive(False
);
463 path
= defaultsPathForDomain("WindowMaker");
465 prop
= WMReadPropListFromFile(path
);
468 printf("%s:could not load WindowMaker configuration file.\n",
473 if (stat(file
, &statbuf
) < 0) {
478 if (format
== F_BLACKBOX
) {
479 style
= readBlackBoxStyle(file
);
481 printf("%s: could not open style file\n", ProgName
);
487 if (S_ISDIR(statbuf
.st_mode
)) {
492 if (*argv
[argc
-1] != '/') {
493 if (!getcwd(buffer
, 4000)) {
494 printf("%s: complete path for %s is too long\n", ProgName
,
498 if (strlen(buffer
) + strlen(file
) > 4000) {
499 printf("%s: complete path for %s is too long\n", ProgName
,
507 strcat(buffer
, file
);
509 prefix
= malloc(strlen(buffer
)+10);
511 printf("%s: out of memory\n", ProgName
);
514 strcpy(prefix
, buffer
);
516 strcat(buffer
, "/style");
518 style
= WMReadPropListFromFile(buffer
);
521 printf("%s:could not load style file.\n", ProgName
);
525 hackPaths(style
, prefix
);
528 /* normal style file */
530 style
= WMReadPropListFromFile(file
);
533 printf("%s:could not load style file.\n", ProgName
);
539 if (!WMIsPLDictionary(style
)) {
540 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
546 if (ignoreCount
> 0) {
547 for (i
= 0; i
< ignoreCount
; i
++) {
548 WMRemoveFromPLDictionary(style
, WMCreatePLString(ignoreList
[i
]));
552 WMMergePLDictionaries(prop
, style
, True
);
554 WMWritePropListToFile(prop
, path
, True
);
560 char *msg
= "Reconfigure";
562 memset(&ev
, 0, sizeof(XEvent
));
564 ev
.xclient
.type
= ClientMessage
;
565 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
567 ev
.xclient
.window
= DefaultRootWindow(dpy
);
568 ev
.xclient
.format
= 8;
570 for (i
= 0; i
<= strlen(msg
); i
++) {
571 ev
.xclient
.data
.b
[i
] = msg
[i
];
573 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
574 SubstructureRedirectMask
, &ev
);
585 getToken(char *str
, int i
, char *buf
)
592 readBlackBoxStyle(char *path
)
595 char buffer
[128], char token
[128];
596 WMPropList
*style
, *p
;
598 f
= fopen(path
, "rb");
605 if (!fgets(buffer
, 127, f
))
608 if (strncasecmp(buffer
, "menu.title:", 11)==0) {