Improve dockapp recognition
[wmaker-crm.git] / WPrefs.app / main.c
blob1add6dba733648b83c8d5033db244375fbc1c832
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"
24 #include <assert.h>
26 #include <X11/Xlocale.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
31 char *NOptionValueChanged = "NOptionValueChanged";
33 extern void Initialize(WMScreen * scr);
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 void wAbort(Bool foo)
48 exit(1);
51 static void print_help(char *progname)
53 printf(_("usage: %s [options]\n"), progname);
54 puts(_("options:"));
55 puts(_(" -display <display> display to be used"));
56 puts(_(" --version print version number and exit"));
57 puts(_(" --help print this message and exit"));
60 #if 0
61 static RETSIGTYPE handleDeadChild(int sig)
63 pid_t pid;
64 int status;
66 pid = waitpid(-1, &status, WNOHANG);
67 if (pid > 0) {
68 DeadChildren[DeadChildrenCount++] = pid;
71 #endif
73 void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
75 int i;
77 for (i = 0; i < MAX_DEATHS; i++) {
78 if (DeadHandlers[i].pid == 0) {
79 DeadHandlers[i].pid = pid;
80 DeadHandlers[i].handler = handler;
81 DeadHandlers[i].data = data;
82 break;
85 assert(i != MAX_DEATHS);
88 int main(int argc, char **argv)
90 Display *dpy;
91 WMScreen *scr;
92 char *locale, *path;
93 int i;
94 char *display_name = "";
96 wsetabort(wAbort);
98 memset(DeadHandlers, 0, sizeof(DeadHandlers));
100 WMInitializeApplication("WPrefs", &argc, argv);
102 WMSetResourcePath(RESOURCE_PATH);
103 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
104 if (!path) {
105 /* maybe it is run directly from the source directory */
106 WMSetResourcePath(".");
107 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
108 if (!path) {
109 WMSetResourcePath("..");
112 if (path) {
113 wfree(path);
116 if (argc > 1) {
117 for (i = 1; i < argc; i++) {
118 if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
119 printf("WPrefs (Window Maker) %s\n", VERSION);
120 exit(0);
121 } else if (strcmp(argv[i], "-display") == 0) {
122 i++;
123 if (i >= argc) {
124 wwarning(_("too few arguments for %s"), argv[i - 1]);
125 exit(0);
127 display_name = argv[i];
128 } else {
129 print_help(argv[0]);
130 exit(0);
135 locale = getenv("LANG");
136 setlocale(LC_ALL, "");
138 #ifdef I18N
139 if (getenv("NLSPATH"))
140 bindtextdomain("WPrefs", getenv("NLSPATH"));
141 else
142 bindtextdomain("WPrefs", LOCALEDIR);
143 bind_textdomain_codeset("WPrefs", "UTF-8");
144 textdomain("WPrefs");
146 if (!XSupportsLocale()) {
147 wwarning(_("X server does not support locale"));
149 if (XSetLocaleModifiers("") == NULL) {
150 wwarning(_("cannot set locale modifiers"));
152 #endif
154 dpy = XOpenDisplay(display_name);
155 if (!dpy) {
156 wfatal(_("could not open display %s"), XDisplayName(display_name));
157 exit(0);
159 #if 0
160 XSynchronize(dpy, 1);
161 #endif
162 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
163 if (!scr) {
164 wfatal(_("could not initialize application"));
165 exit(0);
168 WMPLSetCaseSensitive(False);
170 Initialize(scr);
172 while (1) {
173 XEvent event;
175 WMNextEvent(dpy, &event);
177 while (DeadChildrenCount-- > 0) {
178 int i;
180 for (i = 0; i < MAX_DEATHS; i++) {
181 if (DeadChildren[i] == DeadHandlers[i].pid) {
182 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
183 DeadHandlers[i].pid = 0;
188 WMHandleEvent(&event);