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 */
28 #include <sys/types.h>
43 #ifdef HAVE_STDNORETURN
44 #include <stdnoreturn.h>
47 #include <WINGs/WUtil.h>
51 #define RETRY( x ) do { \
53 } while (errno == EINTR);
59 #include "../src/wconfig.h"
61 #ifndef GLOBAL_DEFAULTS_SUBDIR
62 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
65 /* table of style related options */
66 static char *options
[] = {
75 "WindowTitleExtendSpace",
76 "MenuTitleExtendSpace",
77 "MenuTextExtendSpace",
99 "FrameSelectedBorderColor",
101 "WindowTitleExtendSpace",
102 "MenuTitleExtendSpace",
103 "MenuTextExtendSpace",
107 /* table of theme related options */
108 static char *theme_options
[] = {
114 "TopLeftResizeCursor",
115 "TopRightResizeCursor",
116 "BottomLeftResizeCursor",
117 "BottomRightResizeCursor",
118 "VerticalResizeCursor",
119 "HorizontalResizeCursor",
127 /* table of style related fonts */
129 static char *font_options
[] = {
140 extern char *__progname
;
142 WMPropList
*PixmapPath
= NULL
;
144 char *ThemePath
= NULL
;
147 static noreturn
void print_help(int print_usage
, int exitval
)
149 printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname
);
151 puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
153 puts(" -h, --help display this help and exit");
154 puts(" -v, --version output version information and exit");
155 puts(" -t, --theme-options output theme related options when producing a style file");
156 puts(" -p, --pack produce output as a theme pack");
161 static Bool
isFontOption(const char *option
)
165 for (i
= 0; font_options
[i
] != NULL
; i
++) {
166 if (strcasecmp(option
, font_options
[i
]) == 0) {
174 static void findCopyFile(const char *dir
, const char *file
)
178 fullPath
= wfindfileinarray(PixmapPath
, file
);
180 wwarning("Could not find file %s", file
);
182 (void)wrmdirhier(ThemePath
);
184 wcopy_file(dir
, fullPath
, fullPath
);
188 static void makeThemePack(WMPropList
* style
, const char *themeName
)
198 if ((t
= wusergnusteppath()) == NULL
)
200 themeNameLen
= strlen(t
) + strlen(themeName
) + 50;
201 themeDir
= wmalloc(themeNameLen
);
202 snprintf(themeDir
, themeNameLen
, "%s/Library/WindowMaker/Themes/%s.themed/", t
, themeName
);
203 ThemePath
= themeDir
;
205 if (!wmkdirhier(themeDir
)) {
206 wwarning("Could not make theme dir %s\n", themeDir
);
210 keys
= WMGetPLDictionaryKeys(style
);
212 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
213 key
= WMGetFromPLArray(keys
, i
);
215 value
= WMGetFromPLDictionary(style
, key
);
216 if (value
&& WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
220 type
= WMGetFromPLArray(value
, 0);
221 t
= WMGetFromPLString(type
);
225 if (strcasecmp(t
, "tpixmap") == 0 ||
226 strcasecmp(t
, "spixmap") == 0 ||
227 strcasecmp(t
, "cpixmap") == 0 ||
228 strcasecmp(t
, "mpixmap") == 0 ||
229 strcasecmp(t
, "tdgradient") == 0 ||
230 strcasecmp(t
, "tvgradient") == 0 ||
231 strcasecmp(t
, "thgradient") == 0) {
237 file
= WMGetFromPLArray(value
, 1);
239 p
= strrchr(WMGetFromPLString(file
), '/');
241 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
243 newPath
= wstrdup(p
+ 1);
244 WMDeleteFromPLArray(value
, 1);
245 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
248 findCopyFile(themeDir
, WMGetFromPLString(file
));
250 } else if (strcasecmp(t
, "bitmap") == 0) {
256 file
= WMGetFromPLArray(value
, 1);
258 p
= strrchr(WMGetFromPLString(file
), '/');
260 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
262 newPath
= wstrdup(p
+ 1);
263 WMDeleteFromPLArray(value
, 1);
264 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
267 findCopyFile(themeDir
, WMGetFromPLString(file
));
270 file
= WMGetFromPLArray(value
, 2);
272 p
= strrchr(WMGetFromPLString(file
), '/');
274 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
276 newPath
= wstrdup(p
+ 1);
277 WMDeleteFromPLArray(value
, 2);
278 WMInsertInPLArray(value
, 2, WMCreatePLString(newPath
));
281 findCopyFile(themeDir
, WMGetFromPLString(file
));
288 int main(int argc
, char **argv
)
290 WMPropList
*prop
, *style
, *key
, *val
;
292 int i
, ch
, theme_too
= 0, make_pack
= 0;
293 char *style_file
= NULL
;
295 struct option longopts
[] = {
296 { "pack", no_argument
, NULL
, 'p' },
297 { "theme-options", no_argument
, NULL
, 't' },
298 { "version", no_argument
, NULL
, 'v' },
299 { "help", no_argument
, NULL
, 'h' },
303 while ((ch
= getopt_long(argc
, argv
, "ptvh", longopts
, NULL
)) != -1)
306 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
325 /* At most one non-option ARGV-element is accepted (the theme name) */
326 if (argc
- optind
> 1)
329 if (argc
- optind
== 1)
330 style_file
= argv
[argc
- 1];
332 if (make_pack
&& !style_file
) {
333 printf("%s: you must supply a name for the theme pack\n", __progname
);
337 WMPLSetCaseSensitive(False
);
339 path
= wdefaultspathfordomain("WindowMaker");
341 prop
= WMReadPropListFromFile(path
);
343 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname
, path
);
347 /* get global value */
348 path
= wglobaldefaultspathfordomain("WindowMaker");
350 val
= WMReadPropListFromFile(path
);
352 WMMergePLDictionaries(val
, prop
, True
);
353 WMReleasePropList(prop
);
357 style
= WMCreatePLDictionary(NULL
, NULL
);
359 for (i
= 0; options
[i
] != NULL
; i
++) {
360 key
= WMCreatePLString(options
[i
]);
362 val
= WMGetFromPLDictionary(prop
, key
);
364 WMRetainPropList(val
);
365 if (isFontOption(options
[i
])) {
366 char *newfont
, *oldfont
;
368 oldfont
= WMGetFromPLString(val
);
369 newfont
= convertFont(oldfont
, False
);
370 /* newfont is a reference to old if conversion is not needed */
371 if (newfont
!= oldfont
) {
372 WMReleasePropList(val
);
373 val
= WMCreatePLString(newfont
);
377 WMPutInPLDictionary(style
, key
, val
);
378 WMReleasePropList(val
);
380 WMReleasePropList(key
);
383 val
= WMGetFromPLDictionary(prop
, WMCreatePLString("PixmapPath"));
388 for (i
= 0; theme_options
[i
] != NULL
; i
++) {
389 key
= WMCreatePLString(theme_options
[i
]);
391 val
= WMGetFromPLDictionary(prop
, key
);
393 WMPutInPLDictionary(style
, key
, val
);
400 makeThemePack(style
, style_file
);
402 path
= wmalloc(strlen(ThemePath
) + 32);
403 strcpy(path
, ThemePath
);
404 strcat(path
, "/style");
405 WMWritePropListToFile(style
, path
);
409 WMWritePropListToFile(style
, style_file
);
411 puts(WMGetPropListDescription(style
, True
));