Configure: Added proper check for Xmu library for WRaster
[wmaker-crm.git] / WPrefs.app / main.c
blob0d183dd877da50165498f2b849dc6eac5fcdc526
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "config.h"
23 #include "WPrefs.h"
25 #include <assert.h>
27 #include <X11/Xlocale.h>
28 #include <X11/XKBlib.h>
30 #include <sys/wait.h>
31 #include <unistd.h>
33 #ifdef HAVE_STDNORETURN
34 #include <stdnoreturn.h>
35 #endif
37 char *NOptionValueChanged = "NOptionValueChanged";
38 Bool xext_xkb_supported = False;
41 #define MAX_DEATHS 64
43 struct {
44 pid_t pid;
45 void *data;
46 void (*handler) (void *);
47 } DeadHandlers[MAX_DEATHS];
49 static pid_t DeadChildren[MAX_DEATHS];
50 static int DeadChildrenCount = 0;
52 static noreturn void wAbort(Bool foo)
54 /* Parameter not used, but tell the compiler that it is ok */
55 (void) foo;
57 exit(1);
60 static void print_help(const char *progname)
62 printf(_("usage: %s [options]\n"), progname);
63 puts(_("options:"));
64 puts(_(" -display <display> display to be used"));
65 puts(_(" --version print version number and exit"));
66 puts(_(" --help print this message and exit"));
69 #if 0
70 static RETSIGTYPE handleDeadChild(int sig)
72 pid_t pid;
73 int status;
75 pid = waitpid(-1, &status, WNOHANG);
76 if (pid > 0) {
77 DeadChildren[DeadChildrenCount++] = pid;
80 #endif
82 void 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);
97 int main(int argc, char **argv)
99 Display *dpy;
100 WMScreen *scr;
101 char *path;
102 int i;
103 char *display_name = "";
105 wsetabort(wAbort);
107 memset(DeadHandlers, 0, sizeof(DeadHandlers));
109 WMInitializeApplication("WPrefs", &argc, argv);
111 WMSetResourcePath(RESOURCE_PATH);
112 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
113 if (!path) {
114 /* maybe it is run directly from the source directory */
115 WMSetResourcePath(".");
116 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
117 if (!path) {
118 WMSetResourcePath("..");
121 if (path) {
122 wfree(path);
125 if (argc > 1) {
126 for (i = 1; i < argc; i++) {
127 if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
128 printf("WPrefs (Window Maker) %s\n", VERSION);
129 exit(0);
130 } else if (strcmp(argv[i], "-display") == 0) {
131 i++;
132 if (i >= argc) {
133 wwarning(_("too few arguments for %s"), argv[i - 1]);
134 exit(0);
136 display_name = argv[i];
137 } else {
138 print_help(argv[0]);
139 exit(0);
144 setlocale(LC_ALL, "");
146 #ifdef I18N
147 if (getenv("NLSPATH"))
148 bindtextdomain("WPrefs", getenv("NLSPATH"));
149 else
150 bindtextdomain("WPrefs", LOCALEDIR);
151 bind_textdomain_codeset("WPrefs", "UTF-8");
152 textdomain("WPrefs");
154 if (!XSupportsLocale()) {
155 wwarning(_("X server does not support locale"));
157 if (XSetLocaleModifiers("") == NULL) {
158 wwarning(_("cannot set locale modifiers"));
160 #endif
162 dpy = XOpenDisplay(display_name);
163 if (!dpy) {
164 wfatal(_("could not open display %s"), XDisplayName(display_name));
165 exit(0);
167 #if 0
168 XSynchronize(dpy, 1);
169 #endif
170 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
171 if (!scr) {
172 wfatal(_("could not initialize application"));
173 exit(0);
176 xext_xkb_supported = XkbQueryExtension(dpy, NULL, NULL, NULL, NULL, NULL);
178 WMPLSetCaseSensitive(False);
180 Initialize(scr);
182 while (1) {
183 XEvent event;
185 WMNextEvent(dpy, &event);
187 while (DeadChildrenCount-- > 0) {
188 int i;
190 for (i = 0; i < MAX_DEATHS; i++) {
191 if (DeadChildren[i] == DeadHandlers[i].pid) {
192 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
193 DeadHandlers[i].pid = 0;
198 WMHandleEvent(&event);