]> Dogcows Code - chaz/openbox/blob - util/epist/epist.cc
add default workspace change bindings
[chaz/openbox] / util / epist / epist.cc
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>
4 //
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:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
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.
22
23 #ifdef HAVE_CONFIG_H
24 # include "../../config.h"
25 #endif // HAVE_CONFIG_H
26
27 extern "C" {
28 #ifdef HAVE_UNISTD_H
29 # include <sys/types.h>
30 # include <unistd.h>
31 #endif // HAVE_UNISTD_H
32
33 #ifdef HAVE_STDLIB_H
34 # include <stdlib.h>
35 #endif // HAVE_STDLIB_H
36
37 #ifdef HAVE_SIGNAL_H
38 # include <signal.h>
39 #endif // HAVE_SIGNAL_H
40
41 #ifdef HAVE_LIBGEN_H
42 # include <libgen.h>
43 #endif // HAVE_LIBGEN_H
44 }
45
46 #include <iostream>
47 #include <string>
48
49 using std::cout;
50 using std::endl;
51 using std::string;
52
53 #include "actions.hh"
54 #include "epist.hh"
55 #include "screen.hh"
56 #include "window.hh"
57 #include "../../src/XAtom.hh"
58
59
60 epist::epist(char **argv, char *dpy_name, char *rc_file)
61 : BaseDisplay(argv[0], dpy_name) {
62
63 _argv = argv;
64
65 if (rc_file)
66 _rc_file = rc_file;
67 else
68 _rc_file = expandTilde("~/.openbox/epistrc");
69
70 _xatom = new XAtom(getXDisplay());
71
72 _active = _clients.end();
73
74 for (unsigned int i = 0; i < getNumberOfScreens(); ++i) {
75 screen *s = new screen(this, i);
76 if (s->managed()) {
77 _screens.push_back(s);
78 s->updateEverything();
79 }
80 }
81 if (_screens.empty()) {
82 cout << "No compatible window manager found on any screens. Aborting.\n";
83 ::exit(1);
84 }
85
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::prevWorkspace, Mod1Mask, "Left");
96 addAction(Action::nextWorkspace, Mod1Mask, "Right");
97 addAction(Action::raise, Mod1Mask, "Up");
98 addAction(Action::lower, Mod1Mask, "Down");
99 addAction(Action::moveWindowUp, Mod1Mask | ControlMask, "Up", 1);
100 addAction(Action::moveWindowDown, Mod1Mask | ControlMask, "Down", 1);
101 addAction(Action::moveWindowLeft, Mod1Mask | ControlMask, "Left", 1);
102 addAction(Action::moveWindowRight, Mod1Mask | ControlMask, "Right", 1);
103 addAction(Action::resizeWindowHeight, ShiftMask | Mod1Mask | ControlMask,
104 "Up", -1);
105 addAction(Action::resizeWindowHeight, ShiftMask | Mod1Mask | ControlMask,
106 "Down", 1);
107 addAction(Action::resizeWindowWidth, ShiftMask | Mod1Mask | ControlMask,
108 "Left", -1);
109 addAction(Action::resizeWindowWidth, ShiftMask | Mod1Mask | ControlMask,
110 "Right", 1);
111 addAction(Action::iconify, Mod1Mask | ControlMask, "I");
112 addAction(Action::toggleomnipresent, Mod1Mask | ControlMask, "O");
113 addAction(Action::toggleMaximizeHorizontal, ShiftMask | Mod1Mask, "X");
114 addAction(Action::toggleMaximizeVertical, ShiftMask | ControlMask, "X");
115 addAction(Action::toggleMaximizeFull, Mod1Mask | ControlMask, "X");
116 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "1", 0);
117 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "2", 1);
118 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "3", 2);
119 addAction(Action::changeWorkspace, Mod1Mask | ControlMask, "4", 3);
120 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
121 "1", 0);
122 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
123 "2", 1);
124 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
125 "3", 2);
126 addAction(Action::sendToWorkspace, Mod1Mask | ControlMask | ShiftMask,
127 "4", 3);
128 addAction(Action::execute, Mod1Mask | ControlMask, "Escape",
129 "sleep 1 && xset dpms force off");
130 addAction(Action::execute, Mod1Mask, "space",
131 "rxvt");
132
133 activateGrabs();
134 }
135
136
137 epist::~epist() {
138 delete _xatom;
139 }
140
141 void epist::activateGrabs() {
142
143 ScreenList::const_iterator scrit, scrend = _screens.end();
144
145 for (scrit = _screens.begin(); scrit != scrend; ++scrit) {
146 ActionList::const_iterator ait, end = _actions.end();
147
148 for(ait = _actions.begin(); ait != end; ++ait) {
149 (*scrit)->grabKey(ait->keycode(), ait->modifierMask());
150 }
151 }
152 }
153
154
155 bool epist::handleSignal(int sig) {
156 switch (sig) {
157 case SIGHUP:
158 cout << "epist: Restarting on request.\n";
159 execvp(_argv[0], _argv);
160 execvp(basename(_argv[0]), _argv);
161 return false; // this should be unreachable
162
163 case SIGTERM:
164 case SIGINT:
165 case SIGPIPE:
166 shutdown();
167 return true;
168 }
169
170 return false;
171 }
172
173
174 void epist::process_event(XEvent *e) {
175 ScreenList::const_iterator it, end = _screens.end();
176 for (it = _screens.begin(); it != end; ++it) {
177 if ((*it)->rootWindow() == e->xany.window) {
178 (*it)->processEvent(*e);
179 return;
180 }
181 }
182
183 // wasnt a root window, try for client windows
184 XWindow *w = findWindow(e->xany.window);
185 if (w) w->processEvent(*e);
186 }
187
188
189 void epist::addWindow(XWindow *window) {
190 _windows.insert(WindowLookupPair(window->window(), window));
191 }
192
193
194 void epist::removeWindow(XWindow *window) {
195 _windows.erase(window->window());
196 }
197
198
199 XWindow *epist::findWindow(Window window) const {
200 WindowLookup::const_iterator it = _windows.find(window);
201 if (it != _windows.end())
202 return it->second;
203
204 return 0;
205 }
206
207
208 void epist::cycleScreen(int current, bool forward) const {
209 unsigned int i;
210 for (i = 0; i < _screens.size(); ++i)
211 if (_screens[i]->number() == current) {
212 current = i;
213 break;
214 }
215 assert(i < _screens.size()); // current is for an unmanaged screen
216
217 int dest = current + (forward ? 1 : -1);
218
219 if (dest < 0) dest = (signed)_screens.size() - 1;
220 else if (dest >= (signed)_screens.size()) dest = 0;
221
222 const XWindow *target = _screens[dest]->lastActiveWindow();
223 if (target) target->focus();
224 }
225
226
227 void epist::addAction(Action::ActionType act, unsigned int modifiers,
228 string key, int number) {
229 _actions.push_back(Action(act, XKeysymToKeycode(getXDisplay(),
230 XStringToKeysym(key.c_str())),
231 modifiers, number));
232 }
233
234
235 void epist::addAction(Action::ActionType act, unsigned int modifiers,
236 string key, string str) {
237 _actions.push_back(Action(act, XKeysymToKeycode(getXDisplay(),
238 XStringToKeysym(key.c_str())),
239 modifiers, str));
240 }
This page took 0.042654 seconds and 4 git commands to generate.