1 /* getstyle.c - outputs style related options from WindowMaker to stdout
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #define _GNU_SOURCE /* getopt_long */
26 #include <sys/types.h>
41 #include <WINGs/WUtil.h>
43 #define RETRY( x ) do { \
45 } while (errno == EINTR);
51 #include "../src/wconfig.h"
53 #ifndef GLOBAL_DEFAULTS_SUBDIR
54 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
57 /* table of style related options */
58 static char *options
[] = {
67 "WindowTitleExtendSpace",
68 "MenuTitleExtendSpace",
69 "MenuTextExtendSpace",
90 "WindowTitleExtendSpace",
91 "MenuTitleExtendSpace",
92 "MenuTextExtendSpace",
96 /* table of theme related options */
97 static char *theme_options
[] = {
103 "TopLeftResizeCursor",
104 "TopRightResizeCursor",
105 "BottomLeftResizeCursor",
106 "BottomRightResizeCursor",
107 "VerticalResizeCursor",
108 "HorizontalResizeCursor",
116 /* table of style related fonts */
118 static char *font_options
[] = {
129 extern char *__progname
;
131 WMPropList
*PixmapPath
= NULL
;
133 char *ThemePath
= NULL
;
135 extern char *convertFont(char *font
, Bool keepXLFD
);
137 void print_help(int print_usage
, int exitval
)
139 printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname
);
141 puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
143 puts(" -h, --help display this help and exit");
144 puts(" -v, --version output version information and exit");
145 puts(" -t, --theme-options output theme related options when producing a style file");
146 puts(" -p, --pack produce output as a theme pack");
151 static Bool
isFontOption(char *option
)
155 for (i
= 0; font_options
[i
] != NULL
; i
++) {
156 if (strcasecmp(option
, font_options
[i
]) == 0) {
164 void findCopyFile(char *dir
, char *file
)
168 fullPath
= wfindfileinarray(PixmapPath
, file
);
170 wwarning("Could not find file %s", file
);
172 (void)wrmdirhier(ThemePath
);
174 wcopy_file(dir
, fullPath
, fullPath
);
178 void makeThemePack(WMPropList
* style
, char *themeName
)
187 if ((t
= wusergnusteppath()) == NULL
)
189 themeNameLen
= strlen(t
) + strlen(themeName
) + 50;
190 themeDir
= wmalloc(themeNameLen
);
191 snprintf(themeDir
, themeNameLen
, "%s/Library/WindowMaker/Themes/%s.themed/", t
, themeName
);
192 ThemePath
= themeDir
;
194 if (!wmkdirhier(themeDir
)) {
195 wwarning("Could not make theme dir %s\n", themeDir
);
199 keys
= WMGetPLDictionaryKeys(style
);
201 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
202 key
= WMGetFromPLArray(keys
, i
);
204 value
= WMGetFromPLDictionary(style
, key
);
205 if (value
&& WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
209 type
= WMGetFromPLArray(value
, 0);
210 t
= WMGetFromPLString(type
);
214 if (strcasecmp(t
, "tpixmap") == 0 ||
215 strcasecmp(t
, "spixmap") == 0 ||
216 strcasecmp(t
, "cpixmap") == 0 ||
217 strcasecmp(t
, "mpixmap") == 0 ||
218 strcasecmp(t
, "tdgradient") == 0 ||
219 strcasecmp(t
, "tvgradient") == 0 ||
220 strcasecmp(t
, "thgradient") == 0) {
226 file
= WMGetFromPLArray(value
, 1);
228 p
= strrchr(WMGetFromPLString(file
), '/');
230 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
232 newPath
= wstrdup(p
+ 1);
233 WMDeleteFromPLArray(value
, 1);
234 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
237 findCopyFile(themeDir
, WMGetFromPLString(file
));
239 } else if (strcasecmp(t
, "bitmap") == 0) {
245 file
= WMGetFromPLArray(value
, 1);
247 p
= strrchr(WMGetFromPLString(file
), '/');
249 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
251 newPath
= wstrdup(p
+ 1);
252 WMDeleteFromPLArray(value
, 1);
253 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
256 findCopyFile(themeDir
, WMGetFromPLString(file
));
259 file
= WMGetFromPLArray(value
, 2);
261 p
= strrchr(WMGetFromPLString(file
), '/');
263 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
265 newPath
= wstrdup(p
+ 1);
266 WMDeleteFromPLArray(value
, 2);
267 WMInsertInPLArray(value
, 2, WMCreatePLString(newPath
));
270 findCopyFile(themeDir
, WMGetFromPLString(file
));
277 int main(int argc
, char **argv
)
279 WMPropList
*prop
, *style
, *key
, *val
;
281 int i
, ch
, theme_too
= 0, make_pack
= 0;
282 char *style_file
= NULL
;
284 struct option longopts
[] = {
285 { "pack", no_argument
, NULL
, 'p' },
286 { "theme-options", no_argument
, NULL
, 't' },
287 { "version", no_argument
, NULL
, 'v' },
288 { "help", no_argument
, NULL
, 'h' },
292 while ((ch
= getopt_long(argc
, argv
, "ptvh", longopts
, NULL
)) != -1)
295 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
314 /* At most one non-option ARGV-element is accepted (the theme name) */
315 if (argc
- optind
> 1)
318 if (argc
- optind
== 1)
319 style_file
= argv
[argc
- 1];
321 if (make_pack
&& !style_file
) {
322 printf("%s: you must supply a name for the theme pack\n", __progname
);
326 WMPLSetCaseSensitive(False
);
328 path
= wdefaultspathfordomain("WindowMaker");
330 prop
= WMReadPropListFromFile(path
);
332 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname
, path
);
336 /* get global value */
337 path
= wglobaldefaultspathfordomain("WindowMaker");
339 val
= WMReadPropListFromFile(path
);
341 WMMergePLDictionaries(val
, prop
, True
);
342 WMReleasePropList(prop
);
346 style
= WMCreatePLDictionary(NULL
, NULL
);
348 for (i
= 0; options
[i
] != NULL
; i
++) {
349 key
= WMCreatePLString(options
[i
]);
351 val
= WMGetFromPLDictionary(prop
, key
);
353 WMRetainPropList(val
);
354 if (isFontOption(options
[i
])) {
355 char *newfont
, *oldfont
;
357 oldfont
= WMGetFromPLString(val
);
358 newfont
= convertFont(oldfont
, False
);
359 /* newfont is a reference to old if conversion is not needed */
360 if (newfont
!= oldfont
) {
361 WMReleasePropList(val
);
362 val
= WMCreatePLString(newfont
);
366 WMPutInPLDictionary(style
, key
, val
);
367 WMReleasePropList(val
);
369 WMReleasePropList(key
);
372 val
= WMGetFromPLDictionary(prop
, WMCreatePLString("PixmapPath"));
377 for (i
= 0; theme_options
[i
] != NULL
; i
++) {
378 key
= WMCreatePLString(theme_options
[i
]);
380 val
= WMGetFromPLDictionary(prop
, key
);
382 WMPutInPLDictionary(style
, key
, val
);
389 makeThemePack(style
, style_file
);
391 path
= wmalloc(strlen(ThemePath
) + 32);
392 strcpy(path
, ThemePath
);
393 strcat(path
, "/style");
394 WMWritePropListToFile(style
, path
);
398 WMWritePropListToFile(style
, style_file
);
400 puts(WMGetPropListDescription(style
, True
));