wmaker: Created an array to hold the maximize menu entries
[wmaker-crm.git] / WPrefs.app / main.c
blob08dcb58a652d722c2c8ae508ed4874fa7ee82e7b
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 "WPrefs.h"
23 #include <assert.h>
25 #include <X11/Xlocale.h>
26 #include <X11/XKBlib.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
31 char *NOptionValueChanged = "NOptionValueChanged";
32 Bool xext_xkb_supported = False;
35 #define MAX_DEATHS 64
37 struct {
38 pid_t pid;
39 void *data;
40 void (*handler) (void *);
41 } DeadHandlers[MAX_DEATHS];
43 static pid_t DeadChildren[MAX_DEATHS];
44 static int DeadChildrenCount = 0;
46 static void wAbort(Bool foo)
48 /* Parameter not used, but tell the compiler that it is ok */
49 (void) foo;
51 exit(1);
54 static void print_help(const char *progname)
56 printf(_("usage: %s [options]\n"), progname);
57 puts(_("options:"));
58 puts(_(" -display <display> display to be used"));
59 puts(_(" --version print version number and exit"));
60 puts(_(" --help print this message and exit"));
63 #if 0
64 static RETSIGTYPE handleDeadChild(int sig)
66 pid_t pid;
67 int status;
69 pid = waitpid(-1, &status, WNOHANG);
70 if (pid > 0) {
71 DeadChildren[DeadChildrenCount++] = pid;
74 #endif
76 void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
78 int i;
80 for (i = 0; i < MAX_DEATHS; i++) {
81 if (DeadHandlers[i].pid == 0) {
82 DeadHandlers[i].pid = pid;
83 DeadHandlers[i].handler = handler;
84 DeadHandlers[i].data = data;
85 break;
88 assert(i != MAX_DEATHS);
91 int main(int argc, char **argv)
93 Display *dpy;
94 WMScreen *scr;
95 char *path;
96 int i;
97 char *display_name = "";
99 wsetabort(wAbort);
101 memset(DeadHandlers, 0, sizeof(DeadHandlers));
103 WMInitializeApplication("WPrefs", &argc, argv);
105 WMSetResourcePath(RESOURCE_PATH);
106 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
107 if (!path) {
108 /* maybe it is run directly from the source directory */
109 WMSetResourcePath(".");
110 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
111 if (!path) {
112 WMSetResourcePath("..");
115 if (path) {
116 wfree(path);
119 if (argc > 1) {
120 for (i = 1; i < argc; i++) {
121 if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
122 printf("WPrefs (Window Maker) %s\n", VERSION);
123 exit(0);
124 } else if (strcmp(argv[i], "-display") == 0) {
125 i++;
126 if (i >= argc) {
127 wwarning(_("too few arguments for %s"), argv[i - 1]);
128 exit(0);
130 display_name = argv[i];
131 } else {
132 print_help(argv[0]);
133 exit(0);
138 setlocale(LC_ALL, "");
140 #ifdef I18N
141 if (getenv("NLSPATH"))
142 bindtextdomain("WPrefs", getenv("NLSPATH"));
143 else
144 bindtextdomain("WPrefs", LOCALEDIR);
145 bind_textdomain_codeset("WPrefs", "UTF-8");
146 textdomain("WPrefs");
148 if (!XSupportsLocale()) {
149 wwarning(_("X server does not support locale"));
151 if (XSetLocaleModifiers("") == NULL) {
152 wwarning(_("cannot set locale modifiers"));
154 #endif
156 dpy = XOpenDisplay(display_name);
157 if (!dpy) {
158 wfatal(_("could not open display %s"), XDisplayName(display_name));
159 exit(0);
161 #if 0
162 XSynchronize(dpy, 1);
163 #endif
164 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
165 if (!scr) {
166 wfatal(_("could not initialize application"));
167 exit(0);
170 xext_xkb_supported = XkbQueryExtension(dpy, NULL, NULL, NULL, NULL, NULL);
172 WMPLSetCaseSensitive(False);
174 Initialize(scr);
176 while (1) {
177 XEvent event;
179 WMNextEvent(dpy, &event);
181 while (DeadChildrenCount-- > 0) {
182 int i;
184 for (i = 0; i < MAX_DEATHS; i++) {
185 if (DeadChildren[i] == DeadHandlers[i].pid) {
186 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
187 DeadHandlers[i].pid = 0;
192 WMHandleEvent(&event);