]>
Dogcows Code - chaz/openbox/blob - util/epist/epist.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // epist.cc for Epistory - a key handler for NETWM/EWMH window managers.
3 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
24 # include "../../config.h"
25 #endif // HAVE_CONFIG_H
29 # include <sys/types.h>
31 #endif // HAVE_UNISTD_H
35 #endif // HAVE_STDLIB_H
39 #endif // HAVE_SIGNAL_H
43 #endif // HAVE_LIBGEN_H
55 #include "../../src/XAtom.hh"
57 bool _shutdown
= false;
59 char *_display_name
= 0;
60 Display
*_display
= 0;
66 static void signalhandler(int sig
)
67 #else // HAVE_SIGACTION
68 static RETSIGTYPE
signalhandler(int sig
)
69 #endif // HAVE_SIGACTION
73 cout
<< "epist: Segmentation fault. Aborting and dumping core.\n";
76 cout
<< "epist: Restarting on request.\n";
77 execvp(_argv
[0], _argv
);
78 execvp(basename(_argv
[0]), _argv
);
82 #ifndef HAVE_SIGACTION
83 // assume broken, braindead sysv signal semantics
84 signal(sig
, (RETSIGTYPE (*)(int)) signalhandler
);
85 #endif // HAVE_SIGACTION
89 void parseCommandLine(int argc
, char **argv
) {
92 for (int i
= 1; i
< argc
; ++i
) {
93 if (string(argv
[i
]) == "-display") {
95 cout
<< "error:: '-display' requires an argument\n";
98 _display_name
= argv
[i
];
100 string dtmp
= (string
)"DISPLAY=" + _display_name
;
101 if (putenv(const_cast<char*>(dtmp
.c_str()))) {
102 cout
<< "warning: couldn't set environment variable 'DISPLAY'\n";
110 bool findSupportingWM() {
112 if (! _xatom
->getValue(_root
, XAtom::net_supporting_wm_check
, XAtom::window
,
113 support_win
) || support_win
== None
)
117 _xatom
->getValue(support_win
, XAtom::net_wm_name
, XAtom::utf8
, title
);
118 cout
<< "Found compatible window manager: " << title
<< endl
;
123 int main(int argc
, char **argv
) {
124 #ifdef HAVE_SIGACTION
125 struct sigaction action
;
127 action
.sa_handler
= signalhandler
;
128 action
.sa_mask
= sigset_t();
129 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
131 sigaction(SIGPIPE
, &action
, NULL
);
132 sigaction(SIGSEGV
, &action
, NULL
);
133 sigaction(SIGFPE
, &action
, NULL
);
134 sigaction(SIGTERM
, &action
, NULL
);
135 sigaction(SIGINT
, &action
, NULL
);
136 sigaction(SIGHUP
, &action
, NULL
);
137 #else // !HAVE_SIGACTION
138 signal(SIGPIPE
, (RETSIGTYPE (*)(int)) signalhandler
);
139 signal(SIGSEGV
, (RETSIGTYPE (*)(int)) signalhandler
);
140 signal(SIGFPE
, (RETSIGTYPE (*)(int)) signalhandler
);
141 signal(SIGTERM
, (RETSIGTYPE (*)(int)) signalhandler
);
142 signal(SIGINT
, (RETSIGTYPE (*)(int)) signalhandler
);
143 signal(SIGHUP
, (RETSIGTYPE (*)(int)) signalhandler
);
144 #endif // HAVE_SIGACTION
146 parseCommandLine(argc
, argv
);
148 _display
= XOpenDisplay(_display_name
);
150 cout
<< "Connection to X server '" << _display_name
<< "' failed.\n";
153 _root
= RootWindow(_display
, DefaultScreen(_display
));
154 _xatom
= new XAtom(_display
);
156 XSelectInput(_display
, _root
, PropertyChangeMask
);
158 // find a window manager supporting NETWM, waiting for it to load if we must
159 while (! (_shutdown
|| findSupportingWM()));
163 updateActiveWindow();
166 while (! _shutdown
) {
167 if (XPending(_display
)) {
169 XNextEvent(_display
, &e
);
177 XCloseDisplay(_display
);
This page took 0.041457 seconds and 5 git commands to generate.