]>
Dogcows Code - chaz/openbox/blob - util/epist/epist.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // epist.cc for Epistrophy - 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
46 # include <sys/types.h>
48 #endif // HAVE_UNISTD_H
50 #ifdef HAVE_SYS_STAT_H
51 # include <sys/types.h>
52 # include <sys/stat.h>
53 #endif // HAVE_SYS_STAT_H
68 #include "../../src/xatom.hh"
71 epist::epist(char **argv
, char *dpy_name
, char *rc_file
)
72 : BaseDisplay(argv
[0], dpy_name
) {
79 _rc_file
= expandTilde("~/.openbox/epistrc");
82 if (0 != stat(_rc_file
.c_str(), &buf
) ||
83 !S_ISREG(buf
.st_mode
))
86 _xatom
= new XAtom(getXDisplay());
87 _active
= _clients
.end();
90 _ktree
= new keytree(getXDisplay(), this);
92 // set up the key tree
93 parser
p(_ktree
, _config
);
96 for (unsigned int i
= 0; i
< getNumberOfScreens(); ++i
) {
97 screen
*s
= new screen(this, i
);
99 _screens
.push_back(s
);
100 s
->updateEverything();
103 if (_screens
.empty()) {
104 cout
<< "No compatible window manager found on any screens. Aborting.\n";
116 void epist::activateGrabs() {
118 ScreenList::const_iterator scrit
, scrend
= _screens
.end();
120 for (scrit
= _screens
.begin(); scrit
!= scrend
; ++scrit
)
121 _ktree
->grabDefaults(*scrit
);
125 bool epist::handleSignal(int sig
) {
128 cout
<< "epist: Restarting on request.\n";
130 execvp(_argv
[0], _argv
);
132 string
base(basename(_argv
[0]));
133 execvp(base
.c_str(), _argv
);
135 return false; // this should be unreachable
149 void epist::process_event(XEvent
*e
) {
150 ScreenList::const_iterator it
, end
= _screens
.end();
151 for (it
= _screens
.begin(); it
!= end
; ++it
) {
152 if ((*it
)->rootWindow() == e
->xany
.window
) {
153 (*it
)->processEvent(*e
);
158 // wasnt a root window, try for client windows
159 XWindow
*w
= findWindow(e
->xany
.window
);
160 if (w
) w
->processEvent(*e
);
164 void epist::addWindow(XWindow
*window
) {
165 _windows
.insert(WindowLookupPair(window
->window(), window
));
169 void epist::removeWindow(XWindow
*window
) {
170 _windows
.erase(window
->window());
174 XWindow
*epist::findWindow(Window window
) const {
175 WindowLookup::const_iterator it
= _windows
.find(window
);
176 if (it
!= _windows
.end())
183 void epist::cycleScreen(int current
, bool forward
) const {
185 for (i
= 0; i
< _screens
.size(); ++i
)
186 if (_screens
[i
]->number() == current
) {
190 assert(i
< _screens
.size()); // current is for an unmanaged screen
192 int dest
= current
+ (forward
? 1 : -1);
194 if (dest
< 0) dest
= (signed)_screens
.size() - 1;
195 else if (dest
>= (signed)_screens
.size()) dest
= 0;
197 const XWindow
*target
= _screens
[dest
]->lastActiveWindow();
198 if (target
) target
->focus();
This page took 0.047835 seconds and 4 git commands to generate.