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