1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // epist.cc for Epistophy - 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
56 #include "../../src/XAtom.hh"
59 epist::epist(char **argv
, char *dpy_name
, char *rc_file
)
60 : BaseDisplay(argv
[0], dpy_name
) {
67 _rc_file
= expandTilde("~/.openbox/epistrc");
69 _xatom
= new XAtom(getXDisplay());
71 for (unsigned int i
= 0; i
< getNumberOfScreens(); ++i
) {
72 screen
*s
= new screen(this, i
);
74 _screens
.push_back(s
);
76 if (_screens
.empty()) {
77 cout
<< "No compatible window manager found on any screens. Aborting.\n";
81 _actions
.push_back(Action(Action::nextWorkspace
,
82 XKeysymToKeycode(getXDisplay(),
83 XStringToKeysym("Tab")),
85 _actions
.push_back(Action(Action::prevWorkspace
,
86 XKeysymToKeycode(getXDisplay(),
87 XStringToKeysym("Tab")),
88 ControlMask
| ShiftMask
));
89 _actions
.push_back(Action(Action::toggleshade
,
90 XKeysymToKeycode(getXDisplay(),
91 XStringToKeysym("F5")),
93 _actions
.push_back(Action(Action::close
,
94 XKeysymToKeycode(getXDisplay(),
95 XStringToKeysym("F4")),
97 _actions
.push_back(Action(Action::nextWindow
,
98 XKeysymToKeycode(getXDisplay(),
99 XStringToKeysym("Tab")),
101 _actions
.push_back(Action(Action::prevWindow
,
102 XKeysymToKeycode(getXDisplay(),
103 XStringToKeysym("Tab")),
104 Mod1Mask
| ShiftMask
));
105 _actions
.push_back(Action(Action::nextWindowOnAllWorkspaces
,
106 XKeysymToKeycode(getXDisplay(),
107 XStringToKeysym("Tab")),
108 Mod1Mask
| ControlMask
));
109 _actions
.push_back(Action(Action::prevWindowOnAllWorkspaces
,
110 XKeysymToKeycode(getXDisplay(),
111 XStringToKeysym("Tab")),
112 Mod1Mask
| ShiftMask
| ControlMask
));
113 _actions
.push_back(Action(Action::raise
,
114 XKeysymToKeycode(getXDisplay(),
115 XStringToKeysym("Up")),
117 _actions
.push_back(Action(Action::lower
,
118 XKeysymToKeycode(getXDisplay(),
119 XStringToKeysym("Down")),
121 _actions
.push_back(Action(Action::iconify
,
122 XKeysymToKeycode(getXDisplay(),
123 XStringToKeysym("I")),
124 Mod1Mask
| ControlMask
));
125 _actions
.push_back(Action(Action::toggleomnipresent
,
126 XKeysymToKeycode(getXDisplay(),
127 XStringToKeysym("O")),
128 Mod1Mask
| ControlMask
));
129 _actions
.push_back(Action(Action::changeWorkspace
,
130 XKeysymToKeycode(getXDisplay(),
131 XStringToKeysym("1")),
132 Mod1Mask
| ControlMask
, 0));
133 _actions
.push_back(Action(Action::changeWorkspace
,
134 XKeysymToKeycode(getXDisplay(),
135 XStringToKeysym("2")),
136 Mod1Mask
| ControlMask
, 1));
137 _actions
.push_back(Action(Action::changeWorkspace
,
138 XKeysymToKeycode(getXDisplay(),
139 XStringToKeysym("3")),
140 Mod1Mask
| ControlMask
, 2));
141 _actions
.push_back(Action(Action::changeWorkspace
,
142 XKeysymToKeycode(getXDisplay(),
143 XStringToKeysym("4")),
144 Mod1Mask
| ControlMask
, 3));
145 _actions
.push_back(Action(Action::sendToWorkspace
,
146 XKeysymToKeycode(getXDisplay(),
147 XStringToKeysym("1")),
148 Mod1Mask
| ControlMask
| ShiftMask
, 0));
149 _actions
.push_back(Action(Action::sendToWorkspace
,
150 XKeysymToKeycode(getXDisplay(),
151 XStringToKeysym("2")),
152 Mod1Mask
| ControlMask
| ShiftMask
, 1));
153 _actions
.push_back(Action(Action::sendToWorkspace
,
154 XKeysymToKeycode(getXDisplay(),
155 XStringToKeysym("3")),
156 Mod1Mask
| ControlMask
| ShiftMask
, 2));
157 _actions
.push_back(Action(Action::sendToWorkspace
,
158 XKeysymToKeycode(getXDisplay(),
159 XStringToKeysym("4")),
160 Mod1Mask
| ControlMask
| ShiftMask
, 3));
161 _actions
.push_back(Action(Action::execute
,
162 XKeysymToKeycode(getXDisplay(),
163 XStringToKeysym("F6")),
173 void epist::activateGrabs() {
175 ScreenList::const_iterator scrit
, scrend
= _screens
.end();
177 for (scrit
= _screens
.begin(); scrit
!= scrend
; ++scrit
) {
178 ActionList::const_iterator ait
, end
= _actions
.end();
180 for(ait
= _actions
.begin(); ait
!= end
; ++ait
) {
181 XGrabKey(getXDisplay(), ait
->keycode(), ait
->modifierMask(),
182 (*scrit
)->rootWindow(), False
, GrabModeAsync
, GrabModeAsync
);
188 bool epist::handleSignal(int sig
) {
191 cout
<< "epist: Restarting on request.\n";
192 execvp(_argv
[0], _argv
);
193 execvp(basename(_argv
[0]), _argv
);
194 return false; // this should be unreachable
207 void epist::process_event(XEvent
*e
) {
210 if (e
->xany
.type
== KeyPress
)
213 root
= e
->xany
.window
;
215 ScreenList::const_iterator it
, end
= _screens
.end();
216 for (it
= _screens
.begin(); it
!= end
; ++it
) {
217 if ((*it
)->rootWindow() == root
) {
218 (*it
)->processEvent(*e
);
223 // wasnt a root window, try for client windows
224 XWindow
*w
= findWindow(e
->xany
.window
);
225 if (w
) w
->processEvent(*e
);
229 void epist::addWindow(XWindow
*window
) {
230 _windows
.insert(WindowLookupPair(window
->window(), window
));
234 void epist::removeWindow(XWindow
*window
) {
235 _windows
.erase(window
->window());
239 XWindow
*epist::findWindow(Window window
) const {
240 WindowLookup::const_iterator it
= _windows
.find(window
);
241 if (it
!= _windows
.end())