Use inotify to check for changes to the defaults database. Workaround for
[wmaker-crm.git] / WPrefs.app / main.c
blob151729c7921526e939fd741705c45787e213975f
1 /*
2 * WPrefs - Window Maker Preferences Program
4 * Copyright (c) 1998-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #include "WPrefs.h"
25 #include <assert.h>
27 #include <X11/Xlocale.h>
29 #include <sys/wait.h>
30 #include <unistd.h>
33 char *NOptionValueChanged = "NOptionValueChanged";
35 extern void Initialize(WMScreen *scr);
37 #define MAX_DEATHS 64
39 struct {
40 pid_t pid;
41 void *data;
42 void (*handler)(void*);
43 } DeadHandlers[MAX_DEATHS];
46 static pid_t DeadChildren[MAX_DEATHS];
47 static int DeadChildrenCount = 0;
49 void
50 wAbort(Bool foo)
52 exit(1);
56 static void
57 print_help(char *progname)
59 printf(_("usage: %s [options]\n"), progname);
60 puts(_("options:"));
61 puts(_(" -display <display> display to be used"));
62 puts(_(" --version print version number and exit"));
63 puts(_(" --help print this message and exit"));
67 #if 0
68 static RETSIGTYPE
69 handleDeadChild(int sig)
71 pid_t pid;
72 int status;
74 pid = waitpid(-1, &status, WNOHANG);
75 if (pid > 0) {
76 DeadChildren[DeadChildrenCount++] = pid;
79 #endif
81 void
82 AddDeadChildHandler(pid_t pid, void (*handler)(void*), void *data)
84 int i;
86 for (i = 0; i < MAX_DEATHS; i++) {
87 if (DeadHandlers[i].pid == 0) {
88 DeadHandlers[i].pid = pid;
89 DeadHandlers[i].handler = handler;
90 DeadHandlers[i].data = data;
91 break;
94 assert(i!=MAX_DEATHS);
98 int
99 main(int argc, char **argv)
101 Display *dpy;
102 WMScreen *scr;
103 char *locale, *path;
104 int i;
105 char *display_name="";
107 wsetabort(wAbort);
109 memset(DeadHandlers, 0, sizeof(DeadHandlers));
111 WMInitializeApplication("WPrefs", &argc, argv);
113 WMSetResourcePath(RESOURCE_PATH);
114 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
115 if (!path) {
116 /* maybe it is run directly from the source directory */
117 WMSetResourcePath(".");
118 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
119 if (!path) {
120 WMSetResourcePath("..");
123 if (path) {
124 wfree(path);
127 if (argc>1) {
128 for (i=1; i<argc; i++) {
129 if (strcmp(argv[i], "-version")==0
130 || strcmp(argv[i], "--version")==0) {
131 printf("WPrefs (Window Maker) %s\n", VERSION);
132 exit(0);
133 } else if (strcmp(argv[i], "-display")==0) {
134 i++;
135 if (i>=argc) {
136 wwarning(_("too few arguments for %s"), argv[i-1]);
137 exit(0);
139 display_name = argv[i];
140 } else {
141 print_help(argv[0]);
142 exit(0);
147 locale = getenv("LANG");
148 setlocale(LC_ALL, "");
150 #ifdef I18N
151 if (getenv("NLSPATH"))
152 bindtextdomain("WPrefs", getenv("NLSPATH"));
153 else
154 bindtextdomain("WPrefs", LOCALEDIR);
155 bind_textdomain_codeset("WPrefs", "UTF-8");
156 textdomain("WPrefs");
158 if (!XSupportsLocale()) {
159 wwarning(_("X server does not support locale"));
161 if (XSetLocaleModifiers("") == NULL) {
162 wwarning(_("cannot set locale modifiers"));
164 #endif
166 dpy = XOpenDisplay(display_name);
167 if (!dpy) {
168 wfatal(_("could not open display %s"), XDisplayName(display_name));
169 exit(0);
171 #if 0
172 XSynchronize(dpy, 1);
173 #endif
174 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
175 if (!scr) {
176 wfatal(_("could not initialize application"));
177 exit(0);
180 WMPLSetCaseSensitive(False);
182 Initialize(scr);
184 while (1) {
185 XEvent event;
187 WMNextEvent(dpy, &event);
189 while (DeadChildrenCount-- > 0) {
190 int i;
192 for (i=0; i<MAX_DEATHS; i++) {
193 if (DeadChildren[i] == DeadHandlers[i].pid) {
194 (*DeadHandlers[i].handler)(DeadHandlers[i].data);
195 DeadHandlers[i].pid = 0;
200 WMHandleEvent(&event);