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",
91 "FrameSelectedBorderColor",
93 "WindowTitleExtendSpace",
94 "MenuTitleExtendSpace",
95 "MenuTextExtendSpace",
99 /* table of theme related options */
100 static char *theme_options
[] = {
106 "TopLeftResizeCursor",
107 "TopRightResizeCursor",
108 "BottomLeftResizeCursor",
109 "BottomRightResizeCursor",
110 "VerticalResizeCursor",
111 "HorizontalResizeCursor",
119 /* table of style related fonts */
121 static char *font_options
[] = {
132 extern char *__progname
;
134 WMPropList
*PixmapPath
= NULL
;
136 char *ThemePath
= NULL
;
138 extern char *convertFont(char *font
, Bool keepXLFD
);
140 void print_help(int print_usage
, int exitval
)
142 printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname
);
144 puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
146 puts(" -h, --help display this help and exit");
147 puts(" -v, --version output version information and exit");
148 puts(" -t, --theme-options output theme related options when producing a style file");
149 puts(" -p, --pack produce output as a theme pack");
154 static Bool
isFontOption(char *option
)
158 for (i
= 0; font_options
[i
] != NULL
; i
++) {
159 if (strcasecmp(option
, font_options
[i
]) == 0) {
167 void findCopyFile(char *dir
, char *file
)
171 fullPath
= wfindfileinarray(PixmapPath
, file
);
173 wwarning("Could not find file %s", file
);
175 (void)wrmdirhier(ThemePath
);
177 wcopy_file(dir
, fullPath
, fullPath
);
181 void makeThemePack(WMPropList
* style
, char *themeName
)
190 if ((t
= wusergnusteppath()) == NULL
)
192 themeNameLen
= strlen(t
) + strlen(themeName
) + 50;
193 themeDir
= wmalloc(themeNameLen
);
194 snprintf(themeDir
, themeNameLen
, "%s/Library/WindowMaker/Themes/%s.themed/", t
, themeName
);
195 ThemePath
= themeDir
;
197 if (!wmkdirhier(themeDir
)) {
198 wwarning("Could not make theme dir %s\n", themeDir
);
202 keys
= WMGetPLDictionaryKeys(style
);
204 for (i
= 0; i
< WMGetPropListItemCount(keys
); i
++) {
205 key
= WMGetFromPLArray(keys
, i
);
207 value
= WMGetFromPLDictionary(style
, key
);
208 if (value
&& WMIsPLArray(value
) && WMGetPropListItemCount(value
) > 2) {
212 type
= WMGetFromPLArray(value
, 0);
213 t
= WMGetFromPLString(type
);
217 if (strcasecmp(t
, "tpixmap") == 0 ||
218 strcasecmp(t
, "spixmap") == 0 ||
219 strcasecmp(t
, "cpixmap") == 0 ||
220 strcasecmp(t
, "mpixmap") == 0 ||
221 strcasecmp(t
, "tdgradient") == 0 ||
222 strcasecmp(t
, "tvgradient") == 0 ||
223 strcasecmp(t
, "thgradient") == 0) {
229 file
= WMGetFromPLArray(value
, 1);
231 p
= strrchr(WMGetFromPLString(file
), '/');
233 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
235 newPath
= wstrdup(p
+ 1);
236 WMDeleteFromPLArray(value
, 1);
237 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
240 findCopyFile(themeDir
, WMGetFromPLString(file
));
242 } else if (strcasecmp(t
, "bitmap") == 0) {
248 file
= WMGetFromPLArray(value
, 1);
250 p
= strrchr(WMGetFromPLString(file
), '/');
252 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
254 newPath
= wstrdup(p
+ 1);
255 WMDeleteFromPLArray(value
, 1);
256 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
259 findCopyFile(themeDir
, WMGetFromPLString(file
));
262 file
= WMGetFromPLArray(value
, 2);
264 p
= strrchr(WMGetFromPLString(file
), '/');
266 wcopy_file(themeDir
, WMGetFromPLString(file
), WMGetFromPLString(file
));
268 newPath
= wstrdup(p
+ 1);
269 WMDeleteFromPLArray(value
, 2);
270 WMInsertInPLArray(value
, 2, WMCreatePLString(newPath
));
273 findCopyFile(themeDir
, WMGetFromPLString(file
));
280 int main(int argc
, char **argv
)
282 WMPropList
*prop
, *style
, *key
, *val
;
284 int i
, ch
, theme_too
= 0, make_pack
= 0;
285 char *style_file
= NULL
;
287 struct option longopts
[] = {
288 { "pack", no_argument
, NULL
, 'p' },
289 { "theme-options", no_argument
, NULL
, 't' },
290 { "version", no_argument
, NULL
, 'v' },
291 { "help", no_argument
, NULL
, 'h' },
295 while ((ch
= getopt_long(argc
, argv
, "ptvh", longopts
, NULL
)) != -1)
298 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
317 /* At most one non-option ARGV-element is accepted (the theme name) */
318 if (argc
- optind
> 1)
321 if (argc
- optind
== 1)
322 style_file
= argv
[argc
- 1];
324 if (make_pack
&& !style_file
) {
325 printf("%s: you must supply a name for the theme pack\n", __progname
);
329 WMPLSetCaseSensitive(False
);
331 path
= wdefaultspathfordomain("WindowMaker");
333 prop
= WMReadPropListFromFile(path
);
335 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname
, path
);
339 /* get global value */
340 path
= wglobaldefaultspathfordomain("WindowMaker");
342 val
= WMReadPropListFromFile(path
);
344 WMMergePLDictionaries(val
, prop
, True
);
345 WMReleasePropList(prop
);
349 style
= WMCreatePLDictionary(NULL
, NULL
);
351 for (i
= 0; options
[i
] != NULL
; i
++) {
352 key
= WMCreatePLString(options
[i
]);
354 val
= WMGetFromPLDictionary(prop
, key
);
356 WMRetainPropList(val
);
357 if (isFontOption(options
[i
])) {
358 char *newfont
, *oldfont
;
360 oldfont
= WMGetFromPLString(val
);
361 newfont
= convertFont(oldfont
, False
);
362 /* newfont is a reference to old if conversion is not needed */
363 if (newfont
!= oldfont
) {
364 WMReleasePropList(val
);
365 val
= WMCreatePLString(newfont
);
369 WMPutInPLDictionary(style
, key
, val
);
370 WMReleasePropList(val
);
372 WMReleasePropList(key
);
375 val
= WMGetFromPLDictionary(prop
, WMCreatePLString("PixmapPath"));
380 for (i
= 0; theme_options
[i
] != NULL
; i
++) {
381 key
= WMCreatePLString(theme_options
[i
]);
383 val
= WMGetFromPLDictionary(prop
, key
);
385 WMPutInPLDictionary(style
, key
, val
);
392 makeThemePack(style
, style_file
);
394 path
= wmalloc(strlen(ThemePath
) + 32);
395 strcpy(path
, ThemePath
);
396 strcat(path
, "/style");
397 WMWritePropListToFile(style
, path
);
401 WMWritePropListToFile(style
, style_file
);
403 puts(WMGetPropListDescription(style
, True
));