Undim switchpanel icons when selecting windows directly.
[wmaker-crm.git] / WPrefs.app / main.c
blob561113fab56881d6f82beb9be6ff95f4a3ec2793
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>
27 #include <sys/wait.h>
28 #include <unistd.h>
30 char *NOptionValueChanged = "NOptionValueChanged";
33 #define MAX_DEATHS 64
35 struct {
36 pid_t pid;
37 void *data;
38 void (*handler) (void *);
39 } DeadHandlers[MAX_DEATHS];
41 static pid_t DeadChildren[MAX_DEATHS];
42 static int DeadChildrenCount = 0;
44 static void wAbort(Bool foo)
46 exit(1);
49 static void print_help(const char *progname)
51 printf(_("usage: %s [options]\n"), progname);
52 puts(_("options:"));
53 puts(_(" -display <display> display to be used"));
54 puts(_(" --version print version number and exit"));
55 puts(_(" --help print this message and exit"));
58 #if 0
59 static RETSIGTYPE handleDeadChild(int sig)
61 pid_t pid;
62 int status;
64 pid = waitpid(-1, &status, WNOHANG);
65 if (pid > 0) {
66 DeadChildren[DeadChildrenCount++] = pid;
69 #endif
71 void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
73 int i;
75 for (i = 0; i < MAX_DEATHS; i++) {
76 if (DeadHandlers[i].pid == 0) {
77 DeadHandlers[i].pid = pid;
78 DeadHandlers[i].handler = handler;
79 DeadHandlers[i].data = data;
80 break;
83 assert(i != MAX_DEATHS);
86 int main(int argc, char **argv)
88 Display *dpy;
89 WMScreen *scr;
90 char *path;
91 int i;
92 char *display_name = "";
94 wsetabort(wAbort);
96 memset(DeadHandlers, 0, sizeof(DeadHandlers));
98 WMInitializeApplication("WPrefs", &argc, argv);
100 WMSetResourcePath(RESOURCE_PATH);
101 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
102 if (!path) {
103 /* maybe it is run directly from the source directory */
104 WMSetResourcePath(".");
105 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
106 if (!path) {
107 WMSetResourcePath("..");
110 if (path) {
111 wfree(path);
114 if (argc > 1) {
115 for (i = 1; i < argc; i++) {
116 if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
117 printf("WPrefs (Window Maker) %s\n", VERSION);
118 exit(0);
119 } else if (strcmp(argv[i], "-display") == 0) {
120 i++;
121 if (i >= argc) {
122 wwarning(_("too few arguments for %s"), argv[i - 1]);
123 exit(0);
125 display_name = argv[i];
126 } else {
127 print_help(argv[0]);
128 exit(0);
133 setlocale(LC_ALL, "");
135 #ifdef I18N
136 if (getenv("NLSPATH"))
137 bindtextdomain("WPrefs", getenv("NLSPATH"));
138 else
139 bindtextdomain("WPrefs", LOCALEDIR);
140 bind_textdomain_codeset("WPrefs", "UTF-8");
141 textdomain("WPrefs");
143 if (!XSupportsLocale()) {
144 wwarning(_("X server does not support locale"));
146 if (XSetLocaleModifiers("") == NULL) {
147 wwarning(_("cannot set locale modifiers"));
149 #endif
151 dpy = XOpenDisplay(display_name);
152 if (!dpy) {
153 wfatal(_("could not open display %s"), XDisplayName(display_name));
154 exit(0);
156 #if 0
157 XSynchronize(dpy, 1);
158 #endif
159 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
160 if (!scr) {
161 wfatal(_("could not initialize application"));
162 exit(0);
165 WMPLSetCaseSensitive(False);
167 Initialize(scr);
169 while (1) {
170 XEvent event;
172 WMNextEvent(dpy, &event);
174 while (DeadChildrenCount-- > 0) {
175 int i;
177 for (i = 0; i < MAX_DEATHS; i++) {
178 if (DeadChildren[i] == DeadHandlers[i].pid) {
179 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
180 DeadHandlers[i].pid = 0;
185 WMHandleEvent(&event);