]> Dogcows Code - chaz/openbox/blob - util/epist/epist.cc
Added changeWorkspace() and a broken toggleShaded()
[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 "epist.hh"
54 #include "screen.hh"
55 #include "window.hh"
56 #include "../../src/XAtom.hh"
57
58
59 epist::epist(char **argv, char *dpy_name, char *rc_file)
60 : BaseDisplay(argv[0], dpy_name) {
61
62 _argv = argv;
63
64 if (rc_file)
65 _rc_file = rc_file;
66 else
67 _rc_file = expandTilde("~/.openbox/epistrc");
68
69 _xatom = new XAtom(getXDisplay());
70
71 screen *s = new screen(this, DefaultScreen(getXDisplay()));
72 if (s->managed())
73 _screens.push_back(s);
74 if (_screens.empty()) {
75 cout << "No compatible window manager found on any screens. Aborting.\n";
76 ::exit(1);
77 }
78
79 _actions.push_back(Action(Action::nextWorkspace,
80 XKeysymToKeycode(getXDisplay(),
81 XStringToKeysym("Tab")),
82 Mod1Mask));
83 _actions.push_back(Action(Action::prevWorkspace,
84 XKeysymToKeycode(getXDisplay(),
85 XStringToKeysym("Tab")),
86 ControlMask));
87 _actions.push_back(Action(Action::shade,
88 XKeysymToKeycode(getXDisplay(),
89 XStringToKeysym("F5")),
90 Mod1Mask));
91 activateGrabs();
92 }
93
94
95 epist::~epist() {
96 delete _xatom;
97 }
98
99 void epist::activateGrabs() {
100
101 ScreenList::const_iterator scrit, scrend = _screens.end();
102
103 for (scrit = _screens.begin(); scrit != scrend; ++scrit) {
104 ActionList::const_iterator ait, end = _actions.end();
105
106 for(ait = _actions.begin(); ait != end; ++ait) {
107 XGrabKey(getXDisplay(), ait->keycode(), ait->modifierMask(),
108 (*scrit)->rootWindow(), True, GrabModeAsync, GrabModeAsync);
109 }
110 }
111 }
112
113
114 bool epist::handleSignal(int sig) {
115 switch (sig) {
116 case SIGHUP:
117 cout << "epist: Restarting on request.\n";
118 execvp(_argv[0], _argv);
119 execvp(basename(_argv[0]), _argv);
120 return false; // this should be unreachable
121
122 case SIGTERM:
123 case SIGINT:
124 case SIGPIPE:
125 shutdown();
126 return true;
127 }
128
129 return false;
130 }
131
132
133 void epist::process_event(XEvent *e) {
134 Window root;
135
136 if (e->xany.type == KeyPress)
137 root = e->xkey.root;
138 else
139 root = e->xany.window;
140
141 ScreenList::const_iterator it, end = _screens.end();
142 for (it = _screens.begin(); it != end; ++it) {
143 if ((*it)->rootWindow() == root) {
144 (*it)->processEvent(*e);
145 return;
146 }
147 }
148
149 // wasnt a root window, try for client windows
150 XWindow *w = findWindow(e->xany.window);
151 if (w) w->processEvent(*e);
152 }
153
154
155 void epist::addWindow(XWindow *window) {
156 _windows.insert(WindowLookupPair(window->window(), window));
157 }
158
159
160 void epist::removeWindow(XWindow *window) {
161 _windows.erase(window->window());
162 }
163
164
165 XWindow *epist::findWindow(Window window) const {
166 WindowLookup::const_iterator it = _windows.find(window);
167 if (it != _windows.end())
168 return it->second;
169
170 return 0;
171 }
This page took 0.041201 seconds and 5 git commands to generate.