Do not switch workspace to follow new windows in others
[wmaker-crm.git] / util / seticons.c
blob568e0b13fa453ca77be69ccfcf1ee51e03671442
1 /* seticons.c - sets icon configuration in WindowMaker
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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #define PROG_VERSION "seticons (Window Maker) 0.1"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <WINGs/WUtil.h>
30 #include "../src/wconfig.h"
32 char *ProgName;
34 char *defaultsPathForDomain(char *domain)
36 static char path[1024];
37 char *gspath;
39 gspath = getenv("GNUSTEP_USER_ROOT");
40 if (gspath) {
41 strcpy(path, gspath);
42 strcat(path, "/");
43 } else {
44 char *home;
46 home = getenv("HOME");
47 if (!home) {
48 printf("%s:could not get HOME environment variable!\n", ProgName);
49 exit(0);
52 strcpy(path, home);
53 strcat(path, "/GNUstep/");
55 strcat(path, DEFAULTS_DIR);
56 strcat(path, "/");
57 strcat(path, domain);
59 return path;
62 void print_help()
64 printf("Usage: %s [OPTIONS] FILE\n", ProgName);
65 puts("Reads icon configuration from FILE and updates Window Maker.");
66 puts("");
67 puts(" --help display this help and exit");
68 puts(" --version output version information and exit");
71 int main(int argc, char **argv)
73 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
74 WMPropList *all_windows, *iconset, *keylist;
75 int i;
76 char *path = NULL;
78 ProgName = argv[0];
80 if (argc < 2) {
81 printf("%s: missing argument\n", ProgName);
82 printf("Try '%s --help' for more information\n", ProgName);
85 for (i = 1; i < argc; i++) {
86 if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
87 print_help();
88 exit(0);
89 } else if (strcmp(argv[i], "--version") == 0) {
90 puts(PROG_VERSION);
91 exit(0);
92 } else {
93 if (path) {
94 printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
95 printf("Try '%s --help' for more information\n", ProgName);
96 exit(1);
98 path = argv[i];
102 path = defaultsPathForDomain("WMWindowAttributes");
104 all_windows = WMReadPropListFromFile(path);
105 if (!all_windows) {
106 printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path);
107 exit(1);
110 iconset = WMReadPropListFromFile(argv[1]);
111 if (!iconset) {
112 printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
113 exit(1);
116 keylist = WMGetPLDictionaryKeys(iconset);
117 icon_key = WMCreatePLString("Icon");
119 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
120 window_name = WMGetFromPLArray(keylist, i);
121 if (!WMIsPLString(window_name))
122 continue;
124 icon_value = WMGetFromPLDictionary(iconset, window_name);
125 if (!icon_value || !WMIsPLDictionary(icon_value))
126 continue;
128 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
129 if (window_attrs) {
130 if (WMIsPLDictionary(window_attrs)) {
131 WMMergePLDictionaries(window_attrs, icon_value, True);
133 } else {
134 WMPutInPLDictionary(all_windows, window_name, icon_value);
138 WMWritePropListToFile(all_windows, path, True);
140 exit(0);