move dock/icons size adjustments, to fix window placement
[wmaker-crm.git] / util / geticonset.c
blob3c9dea8fda265276e9f3c16bc334d06734bfe91d
1 /* geticonset.c - outputs icon configuration from WindowMaker to stdout
3 * Window Maker 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.
22 #ifdef __GLIBC__
23 #define _GNU_SOURCE /* getopt_long */
24 #endif
26 #include "config.h"
28 #include <getopt.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #ifdef HAVE_STDNORETURN
34 #include <stdnoreturn.h>
35 #endif
37 #include <WINGs/WUtil.h>
39 #include "../src/wconfig.h"
41 extern char *__progname;
43 static noreturn void print_help(int print_usage, int exitval)
45 printf("Usage: %s [-h] [-v] [file]\n", __progname);
46 if (print_usage) {
47 puts("Retrieves program icon configuration and output to FILE or to stdout");
48 puts("");
49 puts(" -h, --help display this help and exit");
50 puts(" -v, --version output version information and exit");
52 exit(exitval);
55 int main(int argc, char **argv)
57 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
58 WMPropList *all_windows, *iconset, *keylist;
59 char *path;
60 int i, ch;
62 struct option longopts[] = {
63 { "version", no_argument, NULL, 'v' },
64 { "help", no_argument, NULL, 'h' },
65 { NULL, 0, NULL, 0 }
68 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
69 switch(ch) {
70 case 'v':
71 printf("%s (Window Maker %s)\n", __progname, VERSION);
72 return 0;
73 /* NOTREACHED */
74 case 'h':
75 print_help(1, 0);
76 /* NOTREACHED */
77 case 0:
78 break;
79 default:
80 print_help(0, 1);
81 /* NOTREACHED */
84 argc -= optind;
85 argv += optind;
87 path = wdefaultspathfordomain("WMWindowAttributes");
89 all_windows = WMReadPropListFromFile(path);
90 if (!all_windows) {
91 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
92 return 1;
95 iconset = WMCreatePLDictionary(NULL, NULL);
97 keylist = WMGetPLDictionaryKeys(all_windows);
98 icon_key = WMCreatePLString("Icon");
100 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
101 WMPropList *icondic;
103 window_name = WMGetFromPLArray(keylist, i);
104 if (!WMIsPLString(window_name))
105 continue;
107 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
108 if (window_attrs && WMIsPLDictionary(window_attrs)) {
109 icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
110 if (icon_value) {
111 icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
112 WMPutInPLDictionary(iconset, window_name, icondic);
117 if (argc == 1) {
118 WMWritePropListToFile(iconset, argv[0]);
119 } else {
120 puts(WMGetPropListDescription(iconset, True));
122 return 0;