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
57 #include "../../src/XAtom.hh"
60 epist::epist(char **argv, char *dpy_name, char *rc_file)
61 : BaseDisplay(argv[0], dpy_name) {
68 _rc_file = expandTilde("~/.openbox/epistrc");
70 _xatom = new XAtom(getXDisplay());
72 _active = _clients.end();
74 for (unsigned int i = 0; i < getNumberOfScreens(); ++i) {
75 screen *s = new screen(this, i);
77 _screens.push_back(s);
78 s->updateEverything();
81 if (_screens.empty()) {
82 cout << "No compatible window manager found on any screens. Aborting.\n";
86 addAction(Action::nextScreen, ControlMask, "Tab");
87 addAction(Action::prevScreen, ControlMask | ShiftMask, "Tab");
88 addAction(Action::nextWindow, Mod1Mask, "Tab");
89 addAction(Action::prevWindow, Mod1Mask | ShiftMask, "Tab");
90 addAction(Action::toggleshade, Mod1Mask, "F5");
91 addAction(Action::close, Mod1Mask, "F4");
92 addAction(Action::nextWindowOnAllWorkspaces, Mod1Mask | ControlMask, "Tab");
93 addAction(Action::prevWindowOnAllWorkspaces,
94 Mod1Mask | ShiftMask | ControlMask, "Tab");
95 addAction(Action::raise, Mod1Mask, "Up");
96 addAction(Action::lower, Mod1Mask, "Down");
97 addAction(Action::moveWindowUp, Mod1Mask | ControlMask, "Up", 1);
98 addAction(Action::moveWindowDown, Mod1Mask | ControlMask, "Down", 1);
99 addAction(Action::moveWindowLeft, Mod1Mask | ControlMask, "Left", 1);
100 addAction(Action::moveWindowRight, Mod1Mask | ControlMask, "Right", 1);
101 addAction(Action::resizeWindowHeight, ShiftMask | Mod1Mask | ControlMask,
103 addAction(Action::resizeWindowHeight, ShiftMask | Mod1Mask | ControlMask,
105 addAction(Action::resizeWindowWidth, ShiftMask | Mod1Mask | ControlMask,
107 addAction(Action::resizeWindowWidth, ShiftMask | Mod1Mask | ControlMask,
109 addAction(Action::iconify, Mod1Mask | ControlMask, "I");
110 addAction(Action::toggleomnipresent, Mod1Mask | ControlMask, "O");
111 addAction(Action::toggleMaximizeHorizontal, ShiftMask | Mod1Mask, "X");
112 addAction(Action::toggleMaximizeVertical, ShiftMask | ControlMask, "X");
113 addAction(Action::toggleMaximizeFull, Mod1Mask | ControlMask, "X");
114 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "1", 0);
115 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "2", 1);
116 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "3", 2);
117 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "4", 3);
118 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
120 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
122 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
124 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
126 addAction(Action::execute, Mod1Mask | ControlMask, "Escape",
127 "sleep 1 && xset dpms force off");
128 addAction(Action::execute, Mod1Mask, "space",
139 void epist::activateGrabs() {
141 ScreenList::const_iterator scrit, scrend = _screens.end();
143 for (scrit = _screens.begin(); scrit != scrend; ++scrit) {
144 ActionList::const_iterator ait, end = _actions.end();
146 for(ait = _actions.begin(); ait != end; ++ait) {
147 (*scrit)->grabKey(ait->keycode(), ait->modifierMask());
153 bool epist::handleSignal(int sig) {
156 cout << "epist: Restarting on request.\n";
157 execvp(_argv[0], _argv);
158 execvp(basename(_argv[0]), _argv);
159 return false; // this should be unreachable
172 void epist::process_event(XEvent *e) {
173 ScreenList::const_iterator it, end = _screens.end();
174 for (it = _screens.begin(); it != end; ++it) {
175 if ((*it)->rootWindow() == e->xany.window) {
176 (*it)->processEvent(*e);
181 // wasnt a root window, try for client windows
182 XWindow *w = findWindow(e->xany.window);
183 if (w) w->processEvent(*e);
187 void epist::addWindow(XWindow *window) {
188 _windows.insert(WindowLookupPair(window->window(), window));
192 void epist::removeWindow(XWindow *window) {
193 _windows.erase(window->window());
197 XWindow *epist::findWindow(Window window) const {
198 WindowLookup::const_iterator it = _windows.find(window);
199 if (it != _windows.end())
206 void epist::cycleScreen(int current, bool forward) const {
208 for (i = 0; i < _screens.size(); ++i)
209 if (_screens[i]->number() == current) {
213 assert(i < _screens.size()); // current is for an unmanaged screen
215 int dest = current + (forward ? 1 : -1);
217 if (dest < 0) dest = (signed)_screens.size() - 1;
218 else if (dest >= (signed)_screens.size()) dest = 0;
220 const XWindow *target = _screens[dest]->lastActiveWindow();
221 if (target) target->focus();
225 void epist::addAction(Action::ActionType act, unsigned int modifiers,
226 string key, int number) {
227 _actions.push_back(Action(act, XKeysymToKeycode(getXDisplay(),
228 XStringToKeysym(key.c_str())),
233 void epist::addAction(Action::ActionType act, unsigned int modifiers,
234 string key, string str) {
235 _actions.push_back(Action(act, XKeysymToKeycode(getXDisplay(),
236 XStringToKeysym(key.c_str())),