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,
23 #define PROG_VERSION "setstyle (Window Maker) 0.6"
31 #include <WINGs/WUtil.h>
33 #include "../src/wconfig.h"
35 #define MAX_OPTIONS 128
37 char *FontOptions
[] = {
48 char *CursorOptions
[] = {
53 "TopLeftResizeCursor",
54 "TopRightResizeCursor",
55 "BottomLeftResizeCursor",
56 "BottomRightResizeCursor",
57 "VerticalResizeCursor",
58 "HorizontalResizeCursor",
66 extern char *__progname
;
68 int ignoreCursors
= 0;
72 extern char *convertFont(char *font
, Bool keepXLFD
);
74 static Bool
isCursorOption(char *option
)
78 for (i
= 0; CursorOptions
[i
] != NULL
; i
++) {
79 if (strcasecmp(option
, CursorOptions
[i
]) == 0) {
87 static Bool
isFontOption(char *option
)
91 for (i
= 0; FontOptions
[i
] != NULL
; i
++) {
92 if (strcasecmp(option
, FontOptions
[i
]) == 0) {
100 void hackPathInTexture(WMPropList
* texture
, char *prefix
)
105 /* get texture type */
106 type
= WMGetFromPLArray(texture
, 0);
107 t
= WMGetFromPLString(type
);
110 if (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 || strcasecmp(t
, "tdgradient") == 0) {
119 /* get pixmap file path */
120 file
= WMGetFromPLArray(texture
, 1);
121 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
122 /* replace path with full path */
123 WMDeleteFromPLArray(texture
, 1);
124 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
125 } else if (strcasecmp(t
, "bitmap") == 0) {
129 /* get bitmap file path */
130 file
= WMGetFromPLArray(texture
, 1);
131 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
132 /* replace path with full path */
133 WMDeleteFromPLArray(texture
, 1);
134 WMInsertInPLArray(texture
, 1, WMCreatePLString(buffer
));
136 /* get mask file path */
137 file
= WMGetFromPLArray(texture
, 2);
138 sprintf(buffer
, "%s/%s", prefix
, WMGetFromPLString(file
));
139 /* replace path with full path */
140 WMDeleteFromPLArray(texture
, 2);
141 WMInsertInPLArray(texture
, 2, WMCreatePLString(buffer
));
145 void hackPaths(WMPropList
* style
, char *prefix
)
152 keys
= WMGetPLDictionaryKeys(style
);
154 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
155 key
= WMGetFromPLArray(keys
, i
);
157 value
= WMGetFromPLDictionary(style
, key
);
161 if (strcasecmp(WMGetFromPLString(key
), "WorkspaceSpecificBack") == 0) {
162 if (WMIsPLArray(value
)) {
166 for (j
= 0; j
< WMGetPropListItemCount(value
); j
++) {
167 texture
= WMGetFromPLArray(value
, j
);
169 if (texture
&& WMIsPLArray(texture
)
170 && WMGetPropListItemCount(texture
) > 2) {
172 hackPathInTexture(texture
, prefix
);
178 if (WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
180 hackPathInTexture(value
, prefix
);
187 static WMPropList
*getColor(WMPropList
* texture
)
189 WMPropList
*value
, *type
;
192 type
= WMGetFromPLArray(texture
, 0);
198 str
= WMGetFromPLString(type
);
199 if (strcasecmp(str
, "solid") == 0) {
200 value
= WMGetFromPLArray(texture
, 1);
201 } else if (strcasecmp(str
, "dgradient") == 0
202 || strcasecmp(str
, "hgradient") == 0 || strcasecmp(str
, "vgradient") == 0) {
204 int r1
, g1
, b1
, r2
, g2
, b2
;
207 c1
= WMGetFromPLArray(texture
, 1);
208 c2
= WMGetFromPLArray(texture
, 2);
210 if (sscanf(WMGetFromPLString(c1
), "#%2x%2x%2x", &r1
, &g1
, &b1
) == 3
211 && sscanf(WMGetFromPLString(c2
), "#%2x%2x%2x", &r2
, &g2
, &b2
) == 3) {
212 sprintf(buffer
, "#%02x%02x%02x", (r1
+ r2
) / 2, (g1
+ g2
) / 2, (b1
+ b2
) / 2);
213 value
= WMCreatePLString(buffer
);
221 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)), WMGetFromPLString(c1
), &color1
);
222 XParseColor(dpy
, DefaultColormap(dpy
, DefaultScreen(dpy
)), WMGetFromPLString(c2
), &color2
);
224 sprintf(buffer
, "#%02x%02x%02x",
225 (color1
.red
+ color2
.red
) >> 9,
226 (color1
.green
+ color2
.green
) >> 9, (color1
.blue
+ color2
.blue
) >> 9);
227 value
= WMCreatePLString(buffer
);
229 } else if (strcasecmp(str
, "mdgradient") == 0
230 || strcasecmp(str
, "mhgradient") == 0 || strcasecmp(str
, "mvgradient") == 0) {
232 value
= WMGetFromPLArray(texture
, 1);
234 } else if (strcasecmp(str
, "tpixmap") == 0
235 || strcasecmp(str
, "cpixmap") == 0 || strcasecmp(str
, "spixmap") == 0) {
237 value
= WMGetFromPLArray(texture
, 2);
244 * since some of the options introduce incompatibilities, we will need
245 * to do a kluge here or the themes ppl will get real annoying.
246 * So, treat for the absence of the following options:
250 void hackStyle(WMPropList
* style
)
252 WMPropList
*keys
, *tmp
;
253 int foundIconTitle
= 0, foundResizebarBack
= 0;
256 keys
= WMGetPLDictionaryKeys(style
);
258 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
261 tmp
= WMGetFromPLArray(keys
, i
);
262 str
= WMGetFromPLString(tmp
);
264 if (ignoreFonts
&& isFontOption(str
)) {
265 WMRemoveFromPLDictionary(style
, tmp
);
268 if (ignoreCursors
&& isCursorOption(str
)) {
269 WMRemoveFromPLDictionary(style
, tmp
);
272 if (isFontOption(str
)) {
274 char *newfont
, *oldfont
;
276 value
= WMGetFromPLDictionary(style
, tmp
);
278 oldfont
= WMGetFromPLString(value
);
279 newfont
= convertFont(oldfont
, False
);
280 if (newfont
!= oldfont
) {
281 value
= WMCreatePLString(newfont
);
282 WMPutInPLDictionary(style
, tmp
, value
);
283 WMReleasePropList(value
);
288 if (strcasecmp(str
, "IconTitleColor") == 0 || strcasecmp(str
, "IconTitleBack") == 0) {
290 } else if (strcasecmp(str
, "ResizebarBack") == 0) {
291 foundResizebarBack
= 1;
296 if (!foundIconTitle
) {
297 /* set the default values */
298 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleColor"));
300 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleColor"), tmp
);
303 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("FTitleBack"));
307 value
= getColor(tmp
);
310 WMPutInPLDictionary(style
, WMCreatePLString("IconTitleBack"), value
);
315 if (!foundResizebarBack
) {
316 /* set the default values */
317 tmp
= WMGetFromPLDictionary(style
, WMCreatePLString("UTitleBack"));
321 value
= getColor(tmp
);
326 t
= WMCreatePLArray(WMCreatePLString("solid"), value
, NULL
);
327 WMPutInPLDictionary(style
, WMCreatePLString("ResizebarBack"), t
);
332 if (!WMGetFromPLDictionary(style
, WMCreatePLString("MenuStyle"))) {
333 WMPutInPLDictionary(style
, WMCreatePLString("MenuStyle"), WMCreatePLString("normal"));
339 printf("Usage: %s [OPTIONS] FILE\n", __progname
);
340 puts("Reads style/theme configuration from FILE and updates Window Maker.");
342 puts(" --no-fonts ignore font related options");
343 puts(" --no-cursors ignore cursor related options");
344 puts(" --ignore <option> ignore changes in the specified option");
345 puts(" -h, --help display this help and exit");
346 puts(" -v, --version output version information and exit");
349 int main(int argc
, char **argv
)
351 WMPropList
*prop
, *style
;
357 char *ignoreList
[MAX_OPTIONS
];
359 dpy
= XOpenDisplay("");
362 printf("%s: missing argument\n", __progname
);
363 printf("Try '%s --help' for more information\n", __progname
);
367 for (i
= 1; i
< argc
; i
++) {
368 if (strcmp("--ignore", argv
[i
]) == 0) {
371 printf("%s: missing argument for option --ignore\n", __progname
);
374 ignoreList
[ignoreCount
++] = argv
[i
];
376 } else if (strcmp("--no-fonts", argv
[i
]) == 0) {
378 } else if (strcmp("--no-cursors", argv
[i
]) == 0) {
380 } else if (strcmp("-v", argv
[i
]) == 0 || strcmp("--version", argv
[i
]) == 0) {
383 } else if (strcmp("-h", argv
[i
]) == 0 || strcmp("--help", argv
[i
]) == 0) {
388 printf("%s: invalid argument '%s'\n", __progname
, argv
[i
]);
389 printf("Try '%s --help' for more information\n", __progname
);
396 WMPLSetCaseSensitive(False
);
398 path
= wdefaultspathfordomain("WindowMaker");
400 prop
= WMReadPropListFromFile(path
);
403 printf("%s: could not load WindowMaker configuration file.\n", __progname
);
407 if (stat(file
, &statbuf
) < 0) {
411 if (S_ISDIR(statbuf
.st_mode
)) {
416 if (*argv
[argc
- 1] != '/') {
417 if (!getcwd(buffer
, 4000)) {
418 printf("%s: complete path for %s is too long\n", __progname
, file
);
421 if (strlen(buffer
) + strlen(file
) > 4000) {
422 printf("%s: complete path for %s is too long\n", __progname
, file
);
429 strcat(buffer
, file
);
431 prefix
= malloc(strlen(buffer
) + 10);
433 printf("%s: out of memory\n", __progname
);
436 strcpy(prefix
, buffer
);
438 strcat(buffer
, "/style");
440 style
= WMReadPropListFromFile(buffer
);
443 printf("%s: could not load style file.\n", __progname
);
447 hackPaths(style
, prefix
);
450 /* normal style file */
452 style
= WMReadPropListFromFile(file
);
455 printf("%s:could not load style file.\n", __progname
);
460 if (!WMIsPLDictionary(style
)) {
461 printf("%s: '%s' is not a style file/theme\n", __progname
, file
);
467 if (ignoreCount
> 0) {
468 for (i
= 0; i
< ignoreCount
; i
++) {
469 WMRemoveFromPLDictionary(style
, WMCreatePLString(ignoreList
[i
]));
473 WMMergePLDictionaries(prop
, style
, True
);
475 WMWritePropListToFile(prop
, path
);
481 char *msg
= "Reconfigure";
483 memset(&ev
, 0, sizeof(XEvent
));
485 ev
.xclient
.type
= ClientMessage
;
486 ev
.xclient
.message_type
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND", False
);
487 ev
.xclient
.window
= DefaultRootWindow(dpy
);
488 ev
.xclient
.format
= 8;
490 for (i
= 0; i
<= strlen(msg
); i
++) {
491 ev
.xclient
.data
.b
[i
] = msg
[i
];
493 XSendEvent(dpy
, DefaultRootWindow(dpy
), False
, SubstructureRedirectMask
, &ev
);