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>
55 #include "../src/wconfig.h"
58 /* table of style related options */
59 static char *options
[] = {
88 "FrameFocusedBorderColor",
89 "FrameSelectedBorderColor",
91 "WindowTitleExtendSpace",
92 "MenuTitleExtendSpace",
93 "MenuTextExtendSpace",
97 /* table of theme related options */
98 static char *theme_options
[] = {
104 "TopLeftResizeCursor",
105 "TopRightResizeCursor",
106 "BottomLeftResizeCursor",
107 "BottomRightResizeCursor",
108 "VerticalResizeCursor",
109 "HorizontalResizeCursor",
117 /* table of style related fonts */
119 static char *font_options
[] = {
129 static const char *prog_name
;
131 WMPropList
*PixmapPath
= NULL
;
133 char *ThemePath
= NULL
;
136 static noreturn
void print_help(int print_usage
, int exitval
)
138 printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", prog_name
);
140 puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
142 puts(" -h, --help display this help and exit");
143 puts(" -v, --version output version information and exit");
144 puts(" -t, --theme-options output theme related options when producing a style file");
145 puts(" -p, --pack produce output as a theme pack");
150 static Bool
isFontOption(const char *option
)
154 for (i
= 0; font_options
[i
] != NULL
; i
++) {
155 if (strcasecmp(option
, font_options
[i
]) == 0) {
163 static void findCopyFile(const char *dir
, const char *file
)
167 fullPath
= wfindfileinarray(PixmapPath
, file
);
169 wwarning("Could not find file %s", file
);
171 (void)wrmdirhier(ThemePath
);
174 wcopy_file(dir
, fullPath
, fullPath
);
178 #define THEME_SUBPATH "/Library/WindowMaker/Themes/"
179 #define THEME_EXTDIR ".themed/"
181 static void makeThemePack(WMPropList
* style
, const char *themeName
)
189 const char *user_base
;
191 user_base
= wusergnusteppath();
192 if (user_base
== NULL
)
194 themeNameLen
= strlen(user_base
) + sizeof(THEME_SUBPATH
) + strlen(themeName
) + sizeof(THEME_EXTDIR
) + 1;
195 themeDir
= wmalloc(themeNameLen
);
196 snprintf(themeDir
, themeNameLen
,
197 "%s" THEME_SUBPATH
"%s" THEME_EXTDIR
,
198 user_base
, themeName
);
199 ThemePath
= themeDir
;
201 if (!wmkdirhier(themeDir
)) {
202 wwarning("Could not make theme dir %s\n", themeDir
);
206 keys
= WMGetPLDictionaryKeys(style
);
208 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
209 key
= WMGetFromPLArray(keys
, i
);
211 value
= WMGetFromPLDictionary(style
, key
);
212 if (value
&& WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
216 type
= WMGetFromPLArray(value
, 0);
217 t
= WMGetFromPLString(type
);
221 if (strcasecmp(t
, "tpixmap") == 0 ||
222 strcasecmp(t
, "spixmap") == 0 ||
223 strcasecmp(t
, "cpixmap") == 0 ||
224 strcasecmp(t
, "mpixmap") == 0 ||
225 strcasecmp(t
, "tdgradient") == 0 ||
226 strcasecmp(t
, "tvgradient") == 0 ||
227 strcasecmp(t
, "thgradient") == 0) {
233 file
= WMGetFromPLArray(value
, 1);
235 p
= strrchr(WMGetFromPLString(file
), '/');
237 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
239 newPath
= wstrdup(p
+ 1);
240 WMDeleteFromPLArray(value
, 1);
241 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
244 findCopyFile(themeDir
, WMGetFromPLString(file
));
246 } else if (strcasecmp(t
, "bitmap") == 0) {
252 file
= WMGetFromPLArray(value
, 1);
254 p
= strrchr(WMGetFromPLString(file
), '/');
256 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
258 newPath
= wstrdup(p
+ 1);
259 WMDeleteFromPLArray(value
, 1);
260 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
263 findCopyFile(themeDir
, WMGetFromPLString(file
));
266 file
= WMGetFromPLArray(value
, 2);
268 p
= strrchr(WMGetFromPLString(file
), '/');
270 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
272 newPath
= wstrdup(p
+ 1);
273 WMDeleteFromPLArray(value
, 2);
274 WMInsertInPLArray(value
, 2, WMCreatePLString(newPath
));
277 findCopyFile(themeDir
, WMGetFromPLString(file
));
282 WMReleasePropList(keys
);
285 int main(int argc
, char **argv
)
287 WMPropList
*prop
, *style
, *key
, *val
;
289 int i
, ch
, theme_too
= 0, make_pack
= 0;
290 char *style_file
= NULL
;
292 struct option longopts
[] = {
293 { "pack", no_argument
, NULL
, 'p' },
294 { "theme-options", no_argument
, NULL
, 't' },
295 { "version", no_argument
, NULL
, 'v' },
296 { "help", no_argument
, NULL
, 'h' },
301 while ((ch
= getopt_long(argc
, argv
, "ptvh", longopts
, NULL
)) != -1)
304 printf("%s (Window Maker %s)\n", prog_name
, VERSION
);
323 /* At most one non-option ARGV-element is accepted (the theme name) */
324 if (argc
- optind
> 1)
327 if (argc
- optind
== 1)
328 style_file
= argv
[argc
- 1];
330 if (make_pack
&& !style_file
) {
331 printf("%s: you must supply a name for the theme pack\n", prog_name
);
335 WMPLSetCaseSensitive(False
);
337 path
= wdefaultspathfordomain("WindowMaker");
339 prop
= WMReadPropListFromFile(path
);
341 printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name
, path
);
345 /* get global value */
346 path
= wglobaldefaultspathfordomain("WindowMaker");
348 val
= WMReadPropListFromFile(path
);
350 WMMergePLDictionaries(val
, prop
, True
);
351 WMReleasePropList(prop
);
355 style
= WMCreatePLDictionary(NULL
, NULL
);
357 for (i
= 0; options
[i
] != NULL
; i
++) {
358 key
= WMCreatePLString(options
[i
]);
360 val
= WMGetFromPLDictionary(prop
, key
);
362 WMRetainPropList(val
);
363 if (isFontOption(options
[i
])) {
364 char *newfont
, *oldfont
;
366 oldfont
= WMGetFromPLString(val
);
367 newfont
= convertFont(oldfont
, False
);
368 /* newfont is a reference to old if conversion is not needed */
369 if (newfont
!= oldfont
) {
370 WMReleasePropList(val
);
371 val
= WMCreatePLString(newfont
);
375 WMPutInPLDictionary(style
, key
, val
);
376 WMReleasePropList(val
);
378 WMReleasePropList(key
);
381 val
= WMGetFromPLDictionary(prop
, WMCreatePLString("PixmapPath"));
386 for (i
= 0; theme_options
[i
] != NULL
; i
++) {
387 key
= WMCreatePLString(theme_options
[i
]);
389 val
= WMGetFromPLDictionary(prop
, key
);
391 WMPutInPLDictionary(style
, key
, val
);
398 makeThemePack(style
, style_file
);
400 path
= wmalloc(strlen(ThemePath
) + 32);
401 strcpy(path
, ThemePath
);
402 strcat(path
, "/style");
403 WMWritePropListToFile(style
, path
);
407 WMWritePropListToFile(style
, style_file
);
409 puts(WMGetPropListDescription(style
, True
));