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 #define THEME_SUBPATH "/" PACKAGE_TARNAME "/Themes/"
59 #define THEME_EXTDIR ".themed/"
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 static const char *prog_name
;
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", prog_name
);
143 puts("Retrieves style/theme configuration and outputs to "
144 "~/" GSUSER_SUBDIR
"/" USERDATA_SUBDIR THEME_SUBPATH
"file" THEME_EXTDIR
"style"
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
);
179 wcopy_file(dir
, fullPath
, file
);
183 static void makeThemePack(WMPropList
* style
, const char *themeName
)
191 const char *user_library
;
193 user_library
= wuserdatapath();
194 if (user_library
== NULL
)
196 themeNameLen
= strlen(user_library
) + 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_library
, 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 newPath
= wstrdup(p
+ 1);
241 wcopy_file(themeDir
, WMGetFromPLString(file
), newPath
);
243 WMDeleteFromPLArray(value
, 1);
244 WMInsertInPLArray(value
, 1, WMCreatePLString(newPath
));
247 findCopyFile(themeDir
, WMGetFromPLString(file
));
249 } else if (strcasecmp(t
, "bitmap") == 0) {
255 file
= WMGetFromPLArray(value
, 1);
257 p
= strrchr(WMGetFromPLString(file
), '/');
259 newPath
= wstrdup(p
+ 1);
261 wcopy_file(themeDir
, WMGetFromPLString(file
), newPath
);
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 newPath
= wstrdup(p
+ 1);
276 wcopy_file(themeDir
, WMGetFromPLString(file
), newPath
);
278 WMDeleteFromPLArray(value
, 2);
279 WMInsertInPLArray(value
, 2, WMCreatePLString(newPath
));
282 findCopyFile(themeDir
, WMGetFromPLString(file
));
287 WMReleasePropList(keys
);
290 int main(int argc
, char **argv
)
292 WMPropList
*prop
, *style
, *key
, *val
;
294 int i
, ch
, theme_too
= 0, make_pack
= 0;
295 char *style_file
= NULL
;
297 struct option longopts
[] = {
298 { "pack", no_argument
, NULL
, 'p' },
299 { "theme-options", no_argument
, NULL
, 't' },
300 { "version", no_argument
, NULL
, 'v' },
301 { "help", no_argument
, NULL
, 'h' },
306 while ((ch
= getopt_long(argc
, argv
, "ptvh", longopts
, NULL
)) != -1)
309 printf("%s (Window Maker %s)\n", prog_name
, VERSION
);
328 /* At most one non-option ARGV-element is accepted (the theme name) */
329 if (argc
- optind
> 1)
332 if (argc
- optind
== 1)
333 style_file
= argv
[argc
- 1];
335 if (make_pack
&& !style_file
) {
336 printf("%s: you must supply a name for the theme pack\n", prog_name
);
340 WMPLSetCaseSensitive(False
);
342 path
= wdefaultspathfordomain("WindowMaker");
344 prop
= WMReadPropListFromFile(path
);
346 printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name
, path
);
350 /* get global value */
351 path
= wglobaldefaultspathfordomain("WindowMaker");
353 val
= WMReadPropListFromFile(path
);
355 WMMergePLDictionaries(val
, prop
, True
);
356 WMReleasePropList(prop
);
360 style
= WMCreatePLDictionary(NULL
, NULL
);
362 for (i
= 0; options
[i
] != NULL
; i
++) {
363 key
= WMCreatePLString(options
[i
]);
365 val
= WMGetFromPLDictionary(prop
, key
);
367 WMRetainPropList(val
);
368 if (isFontOption(options
[i
])) {
369 char *newfont
, *oldfont
;
371 oldfont
= WMGetFromPLString(val
);
372 newfont
= convertFont(oldfont
, False
);
373 /* newfont is a reference to old if conversion is not needed */
374 if (newfont
!= oldfont
) {
375 WMReleasePropList(val
);
376 val
= WMCreatePLString(newfont
);
380 WMPutInPLDictionary(style
, key
, val
);
381 WMReleasePropList(val
);
383 WMReleasePropList(key
);
386 val
= WMGetFromPLDictionary(prop
, WMCreatePLString("PixmapPath"));
391 for (i
= 0; theme_options
[i
] != NULL
; i
++) {
392 key
= WMCreatePLString(theme_options
[i
]);
394 val
= WMGetFromPLDictionary(prop
, key
);
396 WMPutInPLDictionary(style
, key
, val
);
403 makeThemePack(style
, style_file
);
405 path
= wmalloc(strlen(ThemePath
) + 32);
406 strcpy(path
, ThemePath
);
407 strcat(path
, "/style");
408 WMWritePropListToFile(style
, path
);
412 WMWritePropListToFile(style
, style_file
);
414 puts(WMGetPropListDescription(style
, True
));