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>
45 #define RETRY( x ) do { \
47 } while (errno == EINTR);
53 #include "../src/wconfig.h"
55 #ifndef GLOBAL_DEFAULTS_SUBDIR
56 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
59 /* table of style related options */
60 static char *options
[] = {
69 "WindowTitleExtendSpace",
70 "MenuTitleExtendSpace",
71 "MenuTextExtendSpace",
93 "FrameSelectedBorderColor",
95 "WindowTitleExtendSpace",
96 "MenuTitleExtendSpace",
97 "MenuTextExtendSpace",
101 /* table of theme related options */
102 static char *theme_options
[] = {
108 "TopLeftResizeCursor",
109 "TopRightResizeCursor",
110 "BottomLeftResizeCursor",
111 "BottomRightResizeCursor",
112 "VerticalResizeCursor",
113 "HorizontalResizeCursor",
121 /* table of style related fonts */
123 static char *font_options
[] = {
134 extern char *__progname
;
136 WMPropList
*PixmapPath
= NULL
;
138 char *ThemePath
= NULL
;
141 static void print_help(int print_usage
, int exitval
)
143 printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname
);
145 puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
147 puts(" -h, --help display this help and exit");
148 puts(" -v, --version output version information and exit");
149 puts(" -t, --theme-options output theme related options when producing a style file");
150 puts(" -p, --pack produce output as a theme pack");
155 static Bool
isFontOption(const char *option
)
159 for (i
= 0; font_options
[i
] != NULL
; i
++) {
160 if (strcasecmp(option
, font_options
[i
]) == 0) {
168 static void findCopyFile(const char *dir
, const char *file
)
172 fullPath
= wfindfileinarray(PixmapPath
, file
);
174 wwarning("Could not find file %s", file
);
176 (void)wrmdirhier(ThemePath
);
178 wcopy_file(dir
, fullPath
, fullPath
);
182 static void makeThemePack(WMPropList
* style
, const char *themeName
)
192 if ((t
= wusergnusteppath()) == NULL
)
194 themeNameLen
= strlen(t
) + strlen(themeName
) + 50;
195 themeDir
= wmalloc(themeNameLen
);
196 snprintf(themeDir
, themeNameLen
, "%s/Library/WindowMaker/Themes/%s.themed/", t
, themeName
);
197 ThemePath
= themeDir
;
199 if (!wmkdirhier(themeDir
)) {
200 wwarning("Could not make theme dir %s\n", themeDir
);
204 keys
= WMGetPLDictionaryKeys(style
);
206 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
207 key
= WMGetFromPLArray(keys
, i
);
209 value
= WMGetFromPLDictionary(style
, key
);
210 if (value
&& WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
214 type
= WMGetFromPLArray(value
, 0);
215 t
= WMGetFromPLString(type
);
219 if (strcasecmp(t
, "tpixmap") == 0 ||
220 strcasecmp(t
, "spixmap") == 0 ||
221 strcasecmp(t
, "cpixmap") == 0 ||
222 strcasecmp(t
, "mpixmap") == 0 ||
223 strcasecmp(t
, "tdgradient") == 0 ||
224 strcasecmp(t
, "tvgradient") == 0 ||
225 strcasecmp(t
, "thgradient") == 0) {
231 file
= WMGetFromPLArray(value
, 1);
233 p
= strrchr(WMGetFromPLString(file
), '/');
235 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
237 newPath
= wstrdup(p
+ 1);
238 WMDeleteFromPLArray(value
, 1);
239 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
242 findCopyFile(themeDir
, WMGetFromPLString(file
));
244 } else if (strcasecmp(t
, "bitmap") == 0) {
250 file
= WMGetFromPLArray(value
, 1);
252 p
= strrchr(WMGetFromPLString(file
), '/');
254 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
256 newPath
= wstrdup(p
+ 1);
257 WMDeleteFromPLArray(value
, 1);
258 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
261 findCopyFile(themeDir
, WMGetFromPLString(file
));
264 file
= WMGetFromPLArray(value
, 2);
266 p
= strrchr(WMGetFromPLString(file
), '/');
268 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
270 newPath
= wstrdup(p
+ 1);
271 WMDeleteFromPLArray(value
, 2);
272 WMInsertInPLArray(value
, 2, WMCreatePLString(newPath
));
275 findCopyFile(themeDir
, WMGetFromPLString(file
));
282 int main(int argc
, char **argv
)
284 WMPropList
*prop
, *style
, *key
, *val
;
286 int i
, ch
, theme_too
= 0, make_pack
= 0;
287 char *style_file
= NULL
;
289 struct option longopts
[] = {
290 { "pack", no_argument
, NULL
, 'p' },
291 { "theme-options", no_argument
, NULL
, 't' },
292 { "version", no_argument
, NULL
, 'v' },
293 { "help", no_argument
, NULL
, 'h' },
297 while ((ch
= getopt_long(argc
, argv
, "ptvh", longopts
, NULL
)) != -1)
300 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
319 /* At most one non-option ARGV-element is accepted (the theme name) */
320 if (argc
- optind
> 1)
323 if (argc
- optind
== 1)
324 style_file
= argv
[argc
- 1];
326 if (make_pack
&& !style_file
) {
327 printf("%s: you must supply a name for the theme pack\n", __progname
);
331 WMPLSetCaseSensitive(False
);
333 path
= wdefaultspathfordomain("WindowMaker");
335 prop
= WMReadPropListFromFile(path
);
337 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname
, path
);
341 /* get global value */
342 path
= wglobaldefaultspathfordomain("WindowMaker");
344 val
= WMReadPropListFromFile(path
);
346 WMMergePLDictionaries(val
, prop
, True
);
347 WMReleasePropList(prop
);
351 style
= WMCreatePLDictionary(NULL
, NULL
);
353 for (i
= 0; options
[i
] != NULL
; i
++) {
354 key
= WMCreatePLString(options
[i
]);
356 val
= WMGetFromPLDictionary(prop
, key
);
358 WMRetainPropList(val
);
359 if (isFontOption(options
[i
])) {
360 char *newfont
, *oldfont
;
362 oldfont
= WMGetFromPLString(val
);
363 newfont
= convertFont(oldfont
, False
);
364 /* newfont is a reference to old if conversion is not needed */
365 if (newfont
!= oldfont
) {
366 WMReleasePropList(val
);
367 val
= WMCreatePLString(newfont
);
371 WMPutInPLDictionary(style
, key
, val
);
372 WMReleasePropList(val
);
374 WMReleasePropList(key
);
377 val
= WMGetFromPLDictionary(prop
, WMCreatePLString("PixmapPath"));
382 for (i
= 0; theme_options
[i
] != NULL
; i
++) {
383 key
= WMCreatePLString(theme_options
[i
]);
385 val
= WMGetFromPLDictionary(prop
, key
);
387 WMPutInPLDictionary(style
, key
, val
);
394 makeThemePack(style
, style_file
);
396 path
= wmalloc(strlen(ThemePath
) + 32);
397 strcpy(path
, ThemePath
);
398 strcat(path
, "/style");
399 WMWritePropListToFile(style
, path
);
403 WMWritePropListToFile(style
, style_file
);
405 puts(WMGetPropListDescription(style
, True
));