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 #define DEFAULT_FONT "sans:pixelsize=12"
42 char *FontOptions
[] = {
53 char *CursorOptions
[] = {
58 "TopLeftResizeCursor",
59 "TopRightResizeCursor",
60 "BottomLeftResizeCursor",
61 "BottomRightResizeCursor",
62 "VerticalResizeCursor",
63 "HorizontalResizeCursor",
75 int ignoreCursors
= 0;
79 extern char* convertFont(char *font
, Bool keepXLFD
);
81 WMPropList
*readBlackBoxStyle(char *path
);
85 isCursorOption(char *option
)
89 for (i
=0; CursorOptions
[i
]!=NULL
; i
++) {
90 if (strcasecmp(option
, CursorOptions
[i
])==0) {
100 isFontOption(char *option
)
104 for (i
=0; FontOptions
[i
]!=NULL
; i
++) {
105 if (strcasecmp(option
, FontOptions
[i
])==0) {
115 defaultsPathForDomain(char *domain
)
117 static char path
[1024];
120 gspath
= getenv("GNUSTEP_USER_ROOT");
122 strcpy(path
, gspath
);
127 home
= getenv("HOME");
129 printf("%s:could not get HOME environment variable!\n", ProgName
);
134 strcat(path
, "/GNUstep/");
136 strcat(path
, DEFAULTS_DIR
);
138 strcat(path
, domain
);
146 hackPathInTexture(WMPropList
*texture
, char *prefix
)
151 /* get texture type */
152 type
= WMGetFromPLArray(texture
, 0);
153 t
= WMGetFromPLString(type
);
156 if (strcasecmp(t
, "tpixmap")==0
157 || strcasecmp(t
, "spixmap")==0
158 || strcasecmp(t
, "mpixmap")==0
159 || strcasecmp(t
, "cpixmap")==0
160 || strcasecmp(t
, "tvgradient")==0
161 || strcasecmp(t
, "thgradient")==0
162 || strcasecmp(t
, "tdgradient")==0) {
166 /* get pixmap file path */
167 file
= WMGetFromPLArray(texture
, 1);
168 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
169 /* replace path with full path */
170 WMDeleteFromPLArray(texture
, 1);
171 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
172 } else if (strcasecmp(t
, "bitmap") == 0) {
176 /* get bitmap file path */
177 file
= WMGetFromPLArray(texture
, 1);
178 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
179 /* replace path with full path */
180 WMDeleteFromPLArray(texture
, 1);
181 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
183 /* get mask file path */
184 file
= WMGetFromPLArray(texture
, 2);
185 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
186 /* replace path with full path */
187 WMDeleteFromPLArray(texture
, 2);
188 WMInsertInPLArray(texture
, 2, WMCreatePLString(buffer
));
194 hackPaths(WMPropList
*style
, char *prefix
)
202 keys
= WMGetPLDictionaryKeys(style
);
204 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
205 key
= WMGetFromPLArray(keys
, i
);
207 value
= WMGetFromPLDictionary(style
, key
);
211 if (strcasecmp(WMGetFromPLString(key
), "WorkspaceSpecificBack")==0) {
212 if (WMIsPLArray(value
)) {
216 for (j
= 0; j
< WMGetPropListItemCount(value
); j
++) {
217 texture
= WMGetFromPLArray(value
, j
);
219 if (texture
&& WMIsPLArray(texture
)
220 && WMGetPropListItemCount(texture
) > 2) {
222 hackPathInTexture(texture
, prefix
);
228 if (WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
230 hackPathInTexture(value
, prefix
);
239 getColor(WMPropList
*texture
)
241 WMPropList
*value
, *type
;
244 type
= WMGetFromPLArray(texture
, 0);
250 str
= WMGetFromPLString(type
);
251 if (strcasecmp(str
, "solid")==0) {
252 value
= WMGetFromPLArray(texture
, 1);
253 } else if (strcasecmp(str
, "dgradient")==0
254 || strcasecmp(str
, "hgradient")==0
255 || strcasecmp(str
, "vgradient")==0) {
257 int r1
, g1
, b1
, r2
, g2
, b2
;
260 c1
= WMGetFromPLArray(texture
, 1);
261 c2
= WMGetFromPLArray(texture
, 2);
263 if (sscanf(WMGetFromPLString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
)==3
264 && sscanf(WMGetFromPLString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
)==3) {
265 sprintf(buffer
, "#%02x%02x%02x", (r1
+r2
)/2, (g1
+g2
)/2,
267 value
= WMCreatePLString(buffer
);
275 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
276 WMGetFromPLString(c1
), &color1
);
277 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)),
278 WMGetFromPLString(c2
), &color2
);
280 sprintf(buffer
, "#%02x%02x%02x",
281 (color1
.red
+color2
.red
)>>9,
282 (color1
.green
+color2
.green
)>>9,
283 (color1
.blue
+color2
.blue
)>>9);
284 value
= WMCreatePLString(buffer
);
286 } else if (strcasecmp(str
, "mdgradient")==0
287 || strcasecmp(str
, "mhgradient")==0
288 || strcasecmp(str
, "mvgradient")==0) {
290 value
= WMGetFromPLArray(texture
, 1);
292 } else if (strcasecmp(str
, "tpixmap")==0
293 || strcasecmp(str
, "cpixmap")==0
294 || strcasecmp(str
, "spixmap")==0) {
296 value
= WMGetFromPLArray(texture
, 2);
304 * since some of the options introduce incompatibilities, we will need
305 * to do a kluge here or the themes ppl will get real annoying.
306 * So, treat for the absence of the following options:
311 hackStyle(WMPropList
*style
)
313 WMPropList
*keys
, *tmp
;
314 int foundIconTitle
= 0, foundResizebarBack
= 0;
317 keys
= WMGetPLDictionaryKeys(style
);
319 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
322 tmp
= WMGetFromPLArray(keys
, i
);
323 str
= WMGetFromPLString(tmp
);
325 if (ignoreFonts
&& isFontOption(str
)) {
326 WMRemoveFromPLDictionary(style
, tmp
);
329 if (ignoreCursors
&& isCursorOption(str
)) {
330 WMRemoveFromPLDictionary(style
, tmp
);
333 if (isFontOption(str
)) {
335 char *newfont
, *oldfont
;
337 value
= WMGetFromPLDictionary(style
, tmp
);
339 oldfont
= WMGetFromPLString(value
);
340 newfont
= convertFont(oldfont
, False
);
341 if (newfont
!= oldfont
) {
342 value
= WMCreatePLString(newfont
);
343 WMPutInPLDictionary(style
, tmp
, value
);
344 WMReleasePropList(value
);
349 if (strcasecmp(str
, "IconTitleColor")==0
350 || strcasecmp(str
, "IconTitleBack")==0) {
352 } else if (strcasecmp(str
, "ResizebarBack")==0) {
353 foundResizebarBack
= 1;
358 if (!foundIconTitle
) {
359 /* set the default values */
360 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleColor"));
362 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleColor"),
366 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleBack"));
370 value
= getColor(tmp
);
373 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleBack"),
379 if (!foundResizebarBack
) {
380 /* set the default values */
381 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("UTitleBack"));
385 value
= getColor(tmp
);
390 t
= WMCreatePLArray(WMCreatePLString("solid"), value
,
392 WMPutInPLDictionary(style
, WMCreatePLString("ResizebarBack"),
399 if (!WMGetFromPLDictionary(style
, WMCreatePLString("MenuStyle"))) {
400 WMPutInPLDictionary(style
, WMCreatePLString("MenuStyle"),
401 WMCreatePLString("normal"));
409 printf("Usage: %s [OPTIONS] FILE\n", ProgName
);
410 puts("Reads style/theme configuration from FILE and updates Window Maker.");
412 puts(" --no-fonts ignore font related options");
413 puts(" --no-cursors ignore cursor related options");
414 puts(" --ignore <option> ignore changes in the specified option");
415 puts(" --help display this help and exit");
417 puts(" --format <format> specifies the format of the theme to be converted");
419 puts(" --version output version information and exit");
421 puts("Supported formats: blackbox");*/
428 main(int argc
, char **argv
)
430 WMPropList
*prop
, *style
;
436 char *ignoreList
[MAX_OPTIONS
];
438 dpy
= XOpenDisplay("");
443 printf("%s: missing argument\n", ProgName
);
444 printf("Try '%s --help' for more information\n", ProgName
);
448 for (i
= 1; i
< argc
; i
++) {
449 if (strcmp("--ignore", argv
[i
])==0) {
452 printf("%s: missing argument for option --ignore\n", ProgName
);
455 ignoreList
[ignoreCount
++] = argv
[i
];
457 } else if (strcmp("--no-fonts", argv
[i
])==0) {
459 } else if (strcmp("--no-cursors", argv
[i
])==0) {
461 } else if (strcmp("--version", argv
[i
])==0) {
464 } else if (strcmp("--help", argv
[i
])==0) {
468 } else if (strcmp("--format", argv
[i
])==0) {
471 printf("%s: missing argument for option --format\n", ProgName
);
474 if (strcasecmp(argv
[i
], "blackbox")==0) {
477 printf("%s: unknown theme format '%s'\n", ProgName
, argv
[i
]);
483 printf("%s: invalid argument '%s'\n", ProgName
, argv
[i
]);
484 printf("Try '%s --help' for more information\n", ProgName
);
491 WMPLSetCaseSensitive(False
);
493 path
= defaultsPathForDomain("WindowMaker");
495 prop
= WMReadPropListFromFile(path
);
498 printf("%s:could not load WindowMaker configuration file.\n",
503 if (stat(file
, &statbuf
) < 0) {
508 if (format
== F_BLACKBOX
) {
509 style
= readBlackBoxStyle(file
);
511 printf("%s: could not open style file\n", ProgName
);
517 if (S_ISDIR(statbuf
.st_mode
)) {
522 if (*argv
[argc
-1] != '/') {
523 if (!getcwd(buffer
, 4000)) {
524 printf("%s: complete path for %s is too long\n", ProgName
,
528 if (strlen(buffer
) + strlen(file
) > 4000) {
529 printf("%s: complete path for %s is too long\n", ProgName
,
537 strcat(buffer
, file
);
539 prefix
= malloc(strlen(buffer
)+10);
541 printf("%s: out of memory\n", ProgName
);
544 strcpy(prefix
, buffer
);
546 strcat(buffer
, "/style");
548 style
= WMReadPropListFromFile(buffer
);
551 printf("%s:could not load style file.\n", ProgName
);
555 hackPaths(style
, prefix
);
558 /* normal style file */
560 style
= WMReadPropListFromFile(file
);
563 printf("%s:could not load style file.\n", ProgName
);
569 if (!WMIsPLDictionary(style
)) {
570 printf("%s: '%s' is not a style file/theme\n", ProgName
, file
);
576 if (ignoreCount
> 0) {
577 for (i
= 0; i
< ignoreCount
; i
++) {
578 WMRemoveFromPLDictionary(style
, WMCreatePLString(ignoreList
[i
]));
582 WMMergePLDictionaries(prop
, style
, True
);
584 WMWritePropListToFile(prop
, path
, True
);
590 char *msg
= "Reconfigure";
592 memset(&ev
, 0, sizeof(XEvent
));
594 ev
.xclient
.type
= ClientMessage
;
595 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND",
597 ev
.xclient
.window
= DefaultRootWindow(dpy
);
598 ev
.xclient
.format
= 8;
600 for (i
= 0; i
<= strlen(msg
); i
++) {
601 ev
.xclient
.data
.b
[i
] = msg
[i
];
603 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
,
604 SubstructureRedirectMask
, &ev
);
615 getToken(char *str
, int i
, char *buf
)
622 readBlackBoxStyle(char *path
)
625 char buffer
[128], char token
[128];
626 WMPropList
*style
, *p
;
628 f
= fopen(path
, "rb");
635 if (!fgets(buffer
, 127, f
))
638 if (strncasecmp(buffer
, "menu.title:", 11)==0) {