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"
57 #ifndef GLOBAL_DEFAULTS_SUBDIR
58 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
61 /* table of style related options */
62 static char *options
[] = {
91 "FrameFocusedBorderColor",
92 "FrameSelectedBorderColor",
94 "WindowTitleExtendSpace",
95 "MenuTitleExtendSpace",
96 "MenuTextExtendSpace",
100 /* table of theme related options */
101 static char *theme_options
[] = {
107 "TopLeftResizeCursor",
108 "TopRightResizeCursor",
109 "BottomLeftResizeCursor",
110 "BottomRightResizeCursor",
111 "VerticalResizeCursor",
112 "HorizontalResizeCursor",
120 /* table of style related fonts */
122 static char *font_options
[] = {
132 extern char *__progname
;
134 WMPropList
*PixmapPath
= NULL
;
136 char *ThemePath
= NULL
;
139 static noreturn
void print_help(int print_usage
, int exitval
)
141 printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname
);
143 puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
145 puts(" -h, --help display this help and exit");
146 puts(" -v, --version output version information and exit");
147 puts(" -t, --theme-options output theme related options when producing a style file");
148 puts(" -p, --pack produce output as a theme pack");
153 static Bool
isFontOption(const char *option
)
157 for (i
= 0; font_options
[i
] != NULL
; i
++) {
158 if (strcasecmp(option
, font_options
[i
]) == 0) {
166 static void findCopyFile(const char *dir
, const char *file
)
170 fullPath
= wfindfileinarray(PixmapPath
, file
);
172 wwarning("Could not find file %s", file
);
174 (void)wrmdirhier(ThemePath
);
176 wcopy_file(dir
, fullPath
, fullPath
);
180 #define THEME_SUBPATH "/Library/WindowMaker/Themes/"
181 #define THEME_EXTDIR ".themed/"
183 static void makeThemePack(WMPropList
* style
, const char *themeName
)
191 const char *user_base
;
193 user_base
= wusergnusteppath();
194 if (user_base
== NULL
)
196 themeNameLen
= strlen(user_base
) + sizeof(THEME_SUBPATH
) + strlen(themeName
) + sizeof(THEME_EXTDIR
) + 1;
197 themeDir
= wmalloc(themeNameLen
);
198 snprintf(themeDir
, themeNameLen
,
199 "%s" THEME_SUBPATH
"%s" THEME_EXTDIR
,
200 user_base
, themeName
);
201 ThemePath
= themeDir
;
203 if (!wmkdirhier(themeDir
)) {
204 wwarning("Could not make theme dir %s\n", themeDir
);
208 keys
= WMGetPLDictionaryKeys(style
);
210 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
211 key
= WMGetFromPLArray(keys
, i
);
213 value
= WMGetFromPLDictionary(style
, key
);
214 if (value
&& WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
218 type
= WMGetFromPLArray(value
, 0);
219 t
= WMGetFromPLString(type
);
223 if (strcasecmp(t
, "tpixmap") == 0 ||
224 strcasecmp(t
, "spixmap") == 0 ||
225 strcasecmp(t
, "cpixmap") == 0 ||
226 strcasecmp(t
, "mpixmap") == 0 ||
227 strcasecmp(t
, "tdgradient") == 0 ||
228 strcasecmp(t
, "tvgradient") == 0 ||
229 strcasecmp(t
, "thgradient") == 0) {
235 file
= WMGetFromPLArray(value
, 1);
237 p
= strrchr(WMGetFromPLString(file
), '/');
239 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
241 newPath
= wstrdup(p
+ 1);
242 WMDeleteFromPLArray(value
, 1);
243 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
246 findCopyFile(themeDir
, WMGetFromPLString(file
));
248 } else if (strcasecmp(t
, "bitmap") == 0) {
254 file
= WMGetFromPLArray(value
, 1);
256 p
= strrchr(WMGetFromPLString(file
), '/');
258 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
260 newPath
= wstrdup(p
+ 1);
261 WMDeleteFromPLArray(value
, 1);
262 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
265 findCopyFile(themeDir
, WMGetFromPLString(file
));
268 file
= WMGetFromPLArray(value
, 2);
270 p
= strrchr(WMGetFromPLString(file
), '/');
272 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
274 newPath
= wstrdup(p
+ 1);
275 WMDeleteFromPLArray(value
, 2);
276 WMInsertInPLArray(value
, 2, WMCreatePLString(newPath
));
279 findCopyFile(themeDir
, WMGetFromPLString(file
));
284 WMReleasePropList(keys
);
287 int main(int argc
, char **argv
)
289 WMPropList
*prop
, *style
, *key
, *val
;
291 int i
, ch
, theme_too
= 0, make_pack
= 0;
292 char *style_file
= NULL
;
294 struct option longopts
[] = {
295 { "pack", no_argument
, NULL
, 'p' },
296 { "theme-options", no_argument
, NULL
, 't' },
297 { "version", no_argument
, NULL
, 'v' },
298 { "help", no_argument
, NULL
, 'h' },
302 while ((ch
= getopt_long(argc
, argv
, "ptvh", longopts
, NULL
)) != -1)
305 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
324 /* At most one non-option ARGV-element is accepted (the theme name) */
325 if (argc
- optind
> 1)
328 if (argc
- optind
== 1)
329 style_file
= argv
[argc
- 1];
331 if (make_pack
&& !style_file
) {
332 printf("%s: you must supply a name for the theme pack\n", __progname
);
336 WMPLSetCaseSensitive(False
);
338 path
= wdefaultspathfordomain("WindowMaker");
340 prop
= WMReadPropListFromFile(path
);
342 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname
, path
);
346 /* get global value */
347 path
= wglobaldefaultspathfordomain("WindowMaker");
349 val
= WMReadPropListFromFile(path
);
351 WMMergePLDictionaries(val
, prop
, True
);
352 WMReleasePropList(prop
);
356 style
= WMCreatePLDictionary(NULL
, NULL
);
358 for (i
= 0; options
[i
] != NULL
; i
++) {
359 key
= WMCreatePLString(options
[i
]);
361 val
= WMGetFromPLDictionary(prop
, key
);
363 WMRetainPropList(val
);
364 if (isFontOption(options
[i
])) {
365 char *newfont
, *oldfont
;
367 oldfont
= WMGetFromPLString(val
);
368 newfont
= convertFont(oldfont
, False
);
369 /* newfont is a reference to old if conversion is not needed */
370 if (newfont
!= oldfont
) {
371 WMReleasePropList(val
);
372 val
= WMCreatePLString(newfont
);
376 WMPutInPLDictionary(style
, key
, val
);
377 WMReleasePropList(val
);
379 WMReleasePropList(key
);
382 val
= WMGetFromPLDictionary(prop
, WMCreatePLString("PixmapPath"));
387 for (i
= 0; theme_options
[i
] != NULL
; i
++) {
388 key
= WMCreatePLString(theme_options
[i
]);
390 val
= WMGetFromPLDictionary(prop
, key
);
392 WMPutInPLDictionary(style
, key
, val
);
399 makeThemePack(style
, style_file
);
401 path
= wmalloc(strlen(ThemePath
) + 32);
402 strcpy(path
, ThemePath
);
403 strcat(path
, "/style");
404 WMWritePropListToFile(style
, path
);
408 WMWritePropListToFile(style
, style_file
);
410 puts(WMGetPropListDescription(style
, True
));