]> icculus.org git repositories - dana/openbox.git/blob - util/epist/screen.cc
Fixed a boob mistake which was causing KeyRelease events to not be handled properly...
[dana/openbox.git] / util / epist / screen.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // screen.cc for Epistrophy - 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_STDIO_H
29 #  include <stdio.h>
30 #endif // HAVE_STDIO_H
31
32 #ifdef    HAVE_UNISTD_H
33 #  include <sys/types.h>
34 #  include <unistd.h>
35 #endif // HAVE_UNISTD_H
36
37 #include <X11/keysym.h>
38 }
39
40 #include <iostream>
41 #include <string>
42
43 using std::cout;
44 using std::endl;
45 using std::hex;
46 using std::dec;
47 using std::string;
48
49 #include "../../src/BaseDisplay.hh"
50 #include "../../src/XAtom.hh"
51 #include "screen.hh"
52 #include "epist.hh"
53 #include "config.hh"
54
55 screen::screen(epist *epist, int number) 
56   : _clients(epist->clientsList()), _active(epist->activeWindow()),
57     _config(epist->getConfig()), _grabbed(true), _cycling(false),
58     _stacked_cycling(false)
59 {
60   _epist = epist;
61   _xatom = _epist->xatom();
62   _last_active = _clients.end();
63   _number = number;
64   _info = _epist->getScreenInfo(_number);
65   _root = _info->getRootWindow();
66
67   _config->getValue(Config::stackedCycling, _stacked_cycling);
68
69   // find a window manager supporting NETWM, waiting for it to load if we must
70   int count = 20;  // try for 20 seconds
71   _managed = false;
72   while (! (_epist->doShutdown() || _managed || count <= 0)) {
73     if (! (_managed = findSupportingWM()))
74       sleep(1);
75     --count;
76   }
77   if (_managed)
78     cout << "Found compatible window manager '" << _wm_name << "' for screen "
79          << _number << ".\n";
80   else {
81     cout << "Unable to find a compatible window manager for screen " <<
82       _number << ".\n";
83     return;
84   }
85  
86   XSelectInput(_epist->getXDisplay(), _root, PropertyChangeMask);
87 }
88
89 screen::~screen() {
90   if (_managed)
91     XSelectInput(_epist->getXDisplay(), _root, None);
92 }
93
94
95 bool screen::findSupportingWM() {
96   Window support_win;
97   if (! _xatom->getValue(_root, XAtom::net_supporting_wm_check, XAtom::window,
98                          support_win) || support_win == None)
99     return false;
100
101   string title;
102   _xatom->getValue(support_win, XAtom::net_wm_name, XAtom::utf8, title);
103   _wm_name = title;
104   return true;
105 }
106
107
108 XWindow *screen::findWindow(const XEvent &e) const {
109   assert(_managed);
110
111   WindowList::const_iterator it, end = _clients.end();
112   for (it = _clients.begin(); it != end; ++it)
113     if (**it == e.xany.window)
114       break;
115   if(it == end)
116     return 0;
117   return *it;
118 }
119
120
121 void screen::processEvent(const XEvent &e) {
122   assert(_managed);
123   assert(e.xany.window == _root);
124
125   switch (e.type) {
126   case PropertyNotify:
127     // root window
128     if (e.xproperty.atom == _xatom->getAtom(XAtom::net_number_of_desktops))
129       updateNumDesktops();
130     else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_current_desktop))
131       updateActiveDesktop();
132     else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_active_window))
133       updateActiveWindow();
134     else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_client_list)) {
135       // catch any window unmaps first
136       XEvent ev;
137       if (XCheckTypedWindowEvent(_epist->getXDisplay(), e.xany.window,
138                                  DestroyNotify, &ev) ||
139           XCheckTypedWindowEvent(_epist->getXDisplay(), e.xany.window,
140                                  UnmapNotify, &ev)) {
141         processEvent(ev);
142       }
143
144       updateClientList();
145     }
146     break;
147   case KeyPress:
148     handleKeypress(e);
149     break;
150
151   case KeyRelease:
152     handleKeyrelease(e);
153     break;
154
155   default:
156     break;
157   }
158 }
159
160 void screen::handleKeypress(const XEvent &e) {
161   int scrolllockMask, numlockMask;
162   _epist->getLockModifiers(numlockMask, scrolllockMask);
163   
164   // Mask out the lock modifiers. We want our keys to always work
165   // This should be made an option
166   unsigned int state = e.xkey.state & ~(LockMask|scrolllockMask|numlockMask);
167   keytree &ktree = _epist->getKeyTree();
168   const Action *it = ktree.getAction(e, state, this);
169
170   if (!it)
171     return;
172
173   switch (it->type()) {
174   case Action::nextScreen:
175     _epist->cycleScreen(_number, true);
176     return;
177
178   case Action::prevScreen:
179     _epist->cycleScreen(_number, false);
180     return;
181
182   case Action::nextWorkspace:
183     cycleWorkspace(true, it->number() != 0 ? it->number(): 1);
184     return;
185
186   case Action::prevWorkspace:
187     cycleWorkspace(false, it->number() != 0 ? it->number(): 1);
188     return;
189
190   case Action::nextWindow:
191     
192     cycleWindow(state, true, it->number() != 0 ? it->number(): 1);
193     return;
194
195   case Action::prevWindow:
196     cycleWindow(state, false, it->number() != 0 ? it->number(): 1);
197     return;
198
199   case Action::nextWindowOnAllWorkspaces:
200     cycleWindow(state, true, it->number() != 0 ? it->number(): 1,  false, true);
201     return;
202
203   case Action::prevWindowOnAllWorkspaces:
204     cycleWindow(state, false, it->number() != 0 ? it->number(): 1, false, true);
205     return;
206
207   case Action::nextWindowOnAllScreens:
208     cycleWindow(state, true, it->number() != 0 ? it->number(): 1, true);
209     return;
210
211   case Action::prevWindowOnAllScreens:
212     cycleWindow(state, false, it->number() != 0 ? it->number(): 1, true);
213     return;
214
215   case Action::nextWindowOfClass:
216     cycleWindow(state, true, it->number() != 0 ? it->number(): 1,
217                 false, false, true, it->string());
218     return;
219
220   case Action::prevWindowOfClass:
221     cycleWindow(state, false, it->number() != 0 ? it->number(): 1,
222                 false, false, true, it->string());
223     return;
224       
225   case Action::nextWindowOfClassOnAllWorkspaces:
226     cycleWindow(state, true, it->number() != 0 ? it->number(): 1,
227                 false, true, true, it->string());
228     return;
229       
230   case Action::prevWindowOfClassOnAllWorkspaces:
231     cycleWindow(state, false, it->number() != 0 ? it->number(): 1,
232                 false, true, true, it->string());
233     return;
234
235   case Action::changeWorkspace:
236     changeWorkspace(it->number());
237     return;
238
239   case Action::upWorkspace:
240     changeWorkspaceVert(-1);
241     return;
242
243   case Action::downWorkspace:
244     changeWorkspaceVert(1);
245     return;
246
247   case Action::leftWorkspace:
248     changeWorkspaceHorz(-1);
249     return;
250
251   case Action::rightWorkspace:
252     changeWorkspaceHorz(1);
253     return;
254
255   case Action::execute:
256     execCommand(it->string());
257     return;
258
259   case Action::showRootMenu:
260     _xatom->sendClientMessage(rootWindow(), XAtom::openbox_show_root_menu,
261                               None);
262     return;
263
264   case Action::showWorkspaceMenu:
265     _xatom->sendClientMessage(rootWindow(), XAtom::openbox_show_workspace_menu,
266                               None);
267     return;
268
269   case Action::toggleGrabs: {
270     if (_grabbed) {
271       ktree.ungrabDefaults(this);
272       _grabbed = false;
273     } else {
274       ktree.grabDefaults(this);
275       _grabbed = true;
276     }
277     return;
278   }
279
280   default:
281     break;
282   }
283
284   // these actions require an active window
285   if (_active != _clients.end()) {
286     XWindow *window = *_active;
287       
288     switch (it->type()) {
289     case Action::iconify:
290       window->iconify();
291       return;
292
293     case Action::close:
294       window->close();
295       return;
296
297     case Action::raise:
298       window->raise();
299       return;
300
301     case Action::lower:
302       window->lower();
303       return;
304
305     case Action::sendToWorkspace:
306       window->sendTo(it->number());
307       return;
308
309     case Action::toggleOmnipresent:
310       if (window->desktop() == 0xffffffff)
311         window->sendTo(_active_desktop);
312       else
313         window->sendTo(0xffffffff);
314       return;
315
316     case Action::moveWindowUp:
317       window->move(window->x(), window->y() -
318                    (it->number() != 0 ? it->number(): 1));
319       return;
320       
321     case Action::moveWindowDown:
322       window->move(window->x(), window->y() +
323                    (it->number() != 0 ? it->number(): 1));
324       return;
325       
326     case Action::moveWindowLeft:
327       window->move(window->x() - (it->number() != 0 ? it->number(): 1),
328                    window->y());
329       return;
330       
331     case Action::moveWindowRight:
332       window->move(window->x() + (it->number() != 0 ? it->number(): 1),
333                    window->y());
334       return;
335       
336     case Action::resizeWindowWidth:
337       window->resizeRel(it->number(), 0);
338       return;
339       
340     case Action::resizeWindowHeight:
341       window->resizeRel(0, it->number());
342       return;
343       
344     case Action::toggleShade:
345       window->shade(! window->shaded());
346       return;
347       
348     case Action::toggleMaximizeHorizontal:
349       window->toggleMaximize(XWindow::Max_Horz);
350       return;
351       
352     case Action::toggleMaximizeVertical:
353       window->toggleMaximize(XWindow::Max_Vert);
354       return;
355       
356     case Action::toggleMaximizeFull:
357       window->toggleMaximize(XWindow::Max_Full);
358       return;
359
360     case Action::toggleDecorations:
361       window->decorate(! window->decorated());
362       return;
363       
364     default:
365       assert(false);  // unhandled action type!
366       break;
367     }
368   }
369 }
370
371
372 void screen::handleKeyrelease(const XEvent &) {
373   // the only keyrelease event we care about (for now) is when we do stacked
374   // cycling and the modifier is released
375   if (_stacked_cycling && _cycling && nothingIsPressed()) {
376     XWindow *w = *_active;
377
378     // all modifiers have been released. ungrab the keyboard, move the
379     // focused window to the top of the Z-order and raise it
380     ungrabModifiers();
381
382     _clients.remove(w);
383     _clients.push_front(w);
384     w->raise();
385
386     _cycling = false;
387   }
388 }
389
390
391 // do we want to add this window to our list?
392 bool screen::doAddWindow(Window window) const {
393   assert(_managed);
394
395   Atom type;
396   if (! _xatom->getValue(window, XAtom::net_wm_window_type, XAtom::atom,
397                          type))
398     return True;
399
400   if (type == _xatom->getAtom(XAtom::net_wm_window_type_dock) ||
401       type == _xatom->getAtom(XAtom::net_wm_window_type_menu))
402     return False;
403
404   return True;
405 }
406
407
408 void screen::updateEverything() {
409   updateNumDesktops();
410   updateActiveDesktop();
411   updateClientList();
412   updateActiveWindow();
413 }
414
415
416 void screen::updateNumDesktops() {
417   assert(_managed);
418
419   if (! _xatom->getValue(_root, XAtom::net_number_of_desktops, XAtom::cardinal,
420                          (unsigned long)_num_desktops))
421     _num_desktops = 1;  // assume that there is at least 1 desktop!
422 }
423
424
425 void screen::updateActiveDesktop() {
426   assert(_managed);
427
428   if (! _xatom->getValue(_root, XAtom::net_current_desktop, XAtom::cardinal,
429                          (unsigned long)_active_desktop))
430     _active_desktop = 0;  // there must be at least one desktop, and it must
431                           // be the current one
432 }
433
434
435 void screen::updateClientList() {
436   assert(_managed);
437
438   WindowList::iterator insert_point = _active;
439   if (insert_point != _clients.end())
440     ++insert_point; // get to the item client the focused client
441   
442   // get the client list from the root window
443   Window *rootclients = 0;
444   unsigned long num = (unsigned) -1;
445   if (! _xatom->getValue(_root, XAtom::net_client_list, XAtom::window, num,
446                          &rootclients))
447     num = 0;
448
449   WindowList::iterator it;
450   const WindowList::iterator end = _clients.end();
451   unsigned long i;
452   
453   // insert new clients after the active window
454   for (i = 0; i < num; ++i) {
455     for (it = _clients.begin(); it != end; ++it)
456       if (**it == rootclients[i])
457         break;
458     if (it == end) {  // didn't already exist
459       if (doAddWindow(rootclients[i])) {
460         //        cout << "Added window: 0x" << hex << rootclients[i] << dec << endl;
461         _clients.insert(insert_point, new XWindow(_epist, this,
462                                                   rootclients[i]));
463       }
464     }
465   }
466
467   // remove clients that no longer exist (that belong to this screen)
468   for (it = _clients.begin(); it != end;) {
469     WindowList::iterator it2 = it;
470     ++it;
471
472     // is on another screen?
473     if ((*it2)->getScreen() != this)
474       continue;
475
476     for (i = 0; i < num; ++i)
477       if (**it2 == rootclients[i])
478         break;
479     if (i == num)  { // no longer exists
480       //      cout << "Removed window: 0x" << hex << (*it2)->window() << dec << endl;
481       // watch for the active and last-active window
482       if (it2 == _active)
483         _active = _clients.end();
484       if (it2 == _last_active)
485         _last_active = _clients.end();
486       delete *it2;
487       _clients.erase(it2);
488     }
489   }
490
491   if (rootclients) delete [] rootclients;
492 }
493
494
495 const XWindow *screen::lastActiveWindow() const {
496   if (_last_active != _clients.end())
497     return *_last_active;
498
499   // find a window if one exists
500   WindowList::const_iterator it, end = _clients.end();
501   for (it = _clients.begin(); it != end; ++it)
502     if ((*it)->getScreen() == this && ! (*it)->iconic() &&
503         ((*it)->desktop() == 0xffffffff || (*it)->desktop() == _active_desktop))
504       return *it;
505
506   // no windows on this screen
507   return 0;
508 }
509
510
511 void screen::updateActiveWindow() {
512   assert(_managed);
513
514   Window a = None;
515   _xatom->getValue(_root, XAtom::net_active_window, XAtom::window, a);
516   
517   WindowList::iterator it, end = _clients.end();
518   for (it = _clients.begin(); it != end; ++it) {
519     if (**it == a) {
520       if ((*it)->getScreen() != this)
521         return;
522       break;
523     }
524   }
525   _active = it;
526   if (it != end)
527     _last_active = it;
528
529   /*  cout << "Active window is now: ";
530       if (_active == _clients.end()) cout << "None\n";
531       else cout << "0x" << hex << (*_active)->window() << dec << endl;
532   */
533 }
534
535
536 void screen::execCommand(const string &cmd) const {
537   pid_t pid;
538   if ((pid = fork()) == 0) {
539     // make the command run on the correct screen
540     if (putenv(const_cast<char*>(_info->displayString().c_str()))) {
541       cout << "warning: couldn't set environment variable 'DISPLAY'\n";
542       perror("putenv()");
543     }
544     execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL);
545     exit(-1);
546   } else if (pid == -1) {
547     cout << _epist->getApplicationName() <<
548       ": Could not fork a process for executing a command\n";
549   }
550 }
551
552
553 void screen::cycleWindow(unsigned int state, const bool forward,
554                          const int increment, const bool allscreens,
555                          const bool alldesktops, const bool sameclass,
556                          const string &cn)
557 {
558   assert(_managed);
559   assert(increment > 0);
560
561   if (_clients.empty()) return;
562
563   string classname(cn);
564   if (sameclass && classname.empty() && _active != _clients.end())
565     classname = (*_active)->appClass();
566
567   WindowList::const_iterator target = _active,
568     begin = _clients.begin(),
569     end = _clients.end();
570
571   XWindow *t = 0;
572   
573   for (int x = 0; x < increment; ++x) {
574     while (1) {
575       if (forward) {
576         if (target == end) {
577           target = begin;
578         } else {
579           ++target;
580         }
581       } else {
582         if (target == begin)
583           target = end;
584         --target;
585       }
586
587       // must be no window to focus
588       if (target == _active)
589         return;
590
591       // start back at the beginning of the loop
592       if (target == end)
593         continue;
594
595       // determine if this window is invalid for cycling to
596       t = *target;
597       if (t->iconic()) continue;
598       if (! allscreens && t->getScreen() != this) continue;
599       if (! alldesktops && ! (t->desktop() == _active_desktop ||
600                               t->desktop() == 0xffffffff)) continue;
601       if (sameclass && ! classname.empty() &&
602           t->appClass() != classname) continue;
603       if (! t->canFocus()) continue;
604
605       // found a good window so break out of the while, and perhaps continue
606       // with the for loop
607       break;
608     }
609   }
610
611   // phew. we found the window, so focus it.
612   if (_stacked_cycling && state) {
613     if (!_cycling) {
614       // grab modifiers so we can intercept KeyReleases from them
615       grabModifiers();
616       _cycling = true;
617     }
618
619     // if the window is on another desktop, we can't use XSetInputFocus, since
620     // it doesn't imply a woskpace change.
621     if (t->desktop() == _active_desktop)
622       t->focus(false); // focus, but don't raise
623     else
624       t->focus(); // change workspace and focus
625   }  
626   else {
627     t->focus();
628   }
629 }
630
631
632 void screen::cycleWorkspace(const bool forward, const int increment,
633                             const bool loop) const {
634   assert(_managed);
635   assert(increment > 0);
636
637   unsigned int destination = _active_desktop;
638
639   for (int x = 0; x < increment; ++x) {
640     if (forward) {
641       if (destination < _num_desktops - 1)
642         ++destination;
643       else if (loop)
644         destination = 0;
645     } else {
646       if (destination > 0)
647         --destination;
648       else if (loop)
649         destination = _num_desktops - 1;
650     }
651   }
652
653   if (destination != _active_desktop) 
654     changeWorkspace(destination);
655 }
656
657
658 void screen::changeWorkspace(const int num) const {
659   assert(_managed);
660
661   _xatom->sendClientMessage(_root, XAtom::net_current_desktop, _root, num);
662 }
663
664 void screen::changeWorkspaceVert(const int num) const {
665   assert(_managed);
666   int width = 0;
667   int num_desktops = (signed)_num_desktops;
668   int active_desktop = (signed)_active_desktop;
669   int wnum = 0;
670
671   _config->getValue(Config::workspaceColumns, width);
672
673   if (width > num_desktops || width <= 0)
674     return;
675
676   // a cookie to the person that makes this pretty
677   if (num < 0) {
678     wnum = active_desktop - width;
679     if (wnum < 0) {
680       wnum = num_desktops/width * width + active_desktop;
681       if (wnum >= num_desktops)
682         wnum = num_desktops - 1;
683     }
684   }
685   else {
686     wnum = active_desktop + width;
687     if (wnum >= num_desktops) {
688       wnum = (active_desktop + width) % num_desktops - 1;
689       if (wnum < 0)
690         wnum = 0;
691     }
692   }
693   changeWorkspace(wnum);
694 }
695
696 void screen::changeWorkspaceHorz(const int num) const {
697   assert(_managed);
698   int width = 0;
699   int num_desktops = (signed)_num_desktops;
700   int active_desktop = (signed)_active_desktop;
701   int wnum = 0;
702
703   _config->getValue(Config::workspaceColumns, width);
704
705   if (width > num_desktops || width <= 0)
706     return;
707
708   if (num < 0) {
709     if (active_desktop % width != 0)
710       changeWorkspace(active_desktop - 1);
711     else {
712       wnum = active_desktop + width - 1;
713       if (wnum >= num_desktops)
714         wnum = num_desktops - 1;
715     }
716   }
717   else {
718     if (active_desktop % width != width - 1) {
719       wnum = active_desktop + 1;
720       if (wnum >= num_desktops)
721         wnum = num_desktops / width * width;
722     }
723     else
724       wnum = active_desktop - width + 1;
725   }
726   changeWorkspace(wnum);
727 }
728
729 void screen::grabKey(const KeyCode keyCode, const int modifierMask) const {
730
731   Display *display = _epist->getXDisplay();
732   int numlockMask, scrolllockMask;
733
734   _epist->getLockModifiers(numlockMask, scrolllockMask);
735
736   XGrabKey(display, keyCode, modifierMask,
737            _root, True, GrabModeAsync, GrabModeAsync);
738   XGrabKey(display, keyCode, 
739            modifierMask|LockMask,
740            _root, True, GrabModeAsync, GrabModeAsync);
741   XGrabKey(display, keyCode, 
742            modifierMask|scrolllockMask,
743            _root, True, GrabModeAsync, GrabModeAsync);
744   XGrabKey(display, keyCode, 
745            modifierMask|numlockMask,
746            _root, True, GrabModeAsync, GrabModeAsync);
747     
748   XGrabKey(display, keyCode, 
749            modifierMask|LockMask|scrolllockMask,
750            _root, True, GrabModeAsync, GrabModeAsync);
751   XGrabKey(display, keyCode, 
752            modifierMask|scrolllockMask|numlockMask,
753            _root, True, GrabModeAsync, GrabModeAsync);
754   XGrabKey(display, keyCode, 
755            modifierMask|numlockMask|LockMask,
756            _root, True, GrabModeAsync, GrabModeAsync);
757     
758   XGrabKey(display, keyCode, 
759            modifierMask|numlockMask|LockMask|scrolllockMask,
760            _root, True, GrabModeAsync, GrabModeAsync);
761 }
762
763 void screen::ungrabKey(const KeyCode keyCode, const int modifierMask) const {
764
765   Display *display = _epist->getXDisplay();
766   int numlockMask, scrolllockMask;
767
768   _epist->getLockModifiers(numlockMask, scrolllockMask);
769
770   XUngrabKey(display, keyCode, modifierMask, _root);
771   XUngrabKey(display, keyCode, modifierMask|LockMask, _root);
772   XUngrabKey(display, keyCode, modifierMask|scrolllockMask, _root);
773   XUngrabKey(display, keyCode, modifierMask|numlockMask, _root);
774   XUngrabKey(display, keyCode, modifierMask|LockMask|scrolllockMask, _root);
775   XUngrabKey(display, keyCode, modifierMask|scrolllockMask|numlockMask, _root);
776   XUngrabKey(display, keyCode, modifierMask|numlockMask|LockMask, _root);
777   XUngrabKey(display, keyCode, modifierMask|numlockMask|LockMask|
778              scrolllockMask, _root);
779 }
780
781
782 void screen::grabModifiers() const {
783   Display *display = _epist->getXDisplay();
784
785   XGrabKeyboard(display, rootWindow(), True, GrabModeAsync,
786                 GrabModeAsync, CurrentTime);
787 }
788
789
790 void screen::ungrabModifiers() const {
791   Display *display = _epist->getXDisplay();
792
793   XUngrabKeyboard(display, CurrentTime);
794 }
795
796
797 bool screen::nothingIsPressed(void) const
798 {
799   char keys[32];
800   XQueryKeymap(_epist->getXDisplay(), keys);
801
802   for (int i = 0; i < 32; ++i) {
803     if (keys[i] != 0)
804       return false;
805   }
806
807   return true;
808 }