]> Dogcows Code - chaz/openbox/blob - util/epist/screen.cc
Epist now supports stacked cycling. :D/-< :D\-<
[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 #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->getBoolValue(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 &e) {
373 // we're not interested in non-modifiers
374 if (!isModifier(e.xkey.keycode))
375 return;
376
377 // the only keyrelease event we care about (for now) is when we do stacked
378 // cycling and the modifier is released
379 if (_stacked_cycling && _cycling && nothingIsPressed()) {
380 XWindow *w = *_active;
381
382 // all modifiers have been released. ungrab the keyboard, move the
383 // focused window to the top of the Z-order and raise it
384 ungrabModifiers();
385
386 _clients.remove(w);
387 _clients.push_front(w);
388 w->raise();
389
390 _cycling = false;
391 }
392 }
393
394
395 // do we want to add this window to our list?
396 bool screen::doAddWindow(Window window) const {
397 assert(_managed);
398
399 Atom type;
400 if (! _xatom->getValue(window, XAtom::net_wm_window_type, XAtom::atom,
401 type))
402 return True;
403
404 if (type == _xatom->getAtom(XAtom::net_wm_window_type_dock) ||
405 type == _xatom->getAtom(XAtom::net_wm_window_type_menu))
406 return False;
407
408 return True;
409 }
410
411
412 void screen::updateEverything() {
413 updateNumDesktops();
414 updateActiveDesktop();
415 updateClientList();
416 updateActiveWindow();
417 }
418
419
420 void screen::updateNumDesktops() {
421 assert(_managed);
422
423 if (! _xatom->getValue(_root, XAtom::net_number_of_desktops, XAtom::cardinal,
424 (unsigned long)_num_desktops))
425 _num_desktops = 1; // assume that there is at least 1 desktop!
426 }
427
428
429 void screen::updateActiveDesktop() {
430 assert(_managed);
431
432 if (! _xatom->getValue(_root, XAtom::net_current_desktop, XAtom::cardinal,
433 (unsigned long)_active_desktop))
434 _active_desktop = 0; // there must be at least one desktop, and it must
435 // be the current one
436 }
437
438
439 void screen::updateClientList() {
440 assert(_managed);
441
442 WindowList::iterator insert_point = _active;
443 if (insert_point != _clients.end())
444 ++insert_point; // get to the item client the focused client
445
446 // get the client list from the root window
447 Window *rootclients = 0;
448 unsigned long num = (unsigned) -1;
449 if (! _xatom->getValue(_root, XAtom::net_client_list, XAtom::window, num,
450 &rootclients))
451 num = 0;
452
453 WindowList::iterator it;
454 const WindowList::iterator end = _clients.end();
455 unsigned long i;
456
457 // insert new clients after the active window
458 for (i = 0; i < num; ++i) {
459 for (it = _clients.begin(); it != end; ++it)
460 if (**it == rootclients[i])
461 break;
462 if (it == end) { // didn't already exist
463 if (doAddWindow(rootclients[i])) {
464 // cout << "Added window: 0x" << hex << rootclients[i] << dec << endl;
465 _clients.insert(insert_point, new XWindow(_epist, this,
466 rootclients[i]));
467 }
468 }
469 }
470
471 // remove clients that no longer exist (that belong to this screen)
472 for (it = _clients.begin(); it != end;) {
473 WindowList::iterator it2 = it;
474 ++it;
475
476 // is on another screen?
477 if ((*it2)->getScreen() != this)
478 continue;
479
480 for (i = 0; i < num; ++i)
481 if (**it2 == rootclients[i])
482 break;
483 if (i == num) { // no longer exists
484 // cout << "Removed window: 0x" << hex << (*it2)->window() << dec << endl;
485 // watch for the active and last-active window
486 if (it2 == _active)
487 _active = _clients.end();
488 if (it2 == _last_active)
489 _last_active = _clients.end();
490 delete *it2;
491 _clients.erase(it2);
492 }
493 }
494
495 if (rootclients) delete [] rootclients;
496 }
497
498
499 const XWindow *screen::lastActiveWindow() const {
500 if (_last_active != _clients.end())
501 return *_last_active;
502
503 // find a window if one exists
504 WindowList::const_iterator it, end = _clients.end();
505 for (it = _clients.begin(); it != end; ++it)
506 if ((*it)->getScreen() == this && ! (*it)->iconic() &&
507 ((*it)->desktop() == 0xffffffff || (*it)->desktop() == _active_desktop))
508 return *it;
509
510 // no windows on this screen
511 return 0;
512 }
513
514
515 void screen::updateActiveWindow() {
516 assert(_managed);
517
518 Window a = None;
519 _xatom->getValue(_root, XAtom::net_active_window, XAtom::window, a);
520
521 WindowList::iterator it, end = _clients.end();
522 for (it = _clients.begin(); it != end; ++it) {
523 if (**it == a) {
524 if ((*it)->getScreen() != this)
525 return;
526 break;
527 }
528 }
529 _active = it;
530 if (it != end)
531 _last_active = it;
532
533 /* cout << "Active window is now: ";
534 if (_active == _clients.end()) cout << "None\n";
535 else cout << "0x" << hex << (*_active)->window() << dec << endl;
536 */
537 }
538
539
540 void screen::execCommand(const string &cmd) const {
541 pid_t pid;
542 if ((pid = fork()) == 0) {
543 // make the command run on the correct screen
544 if (putenv(const_cast<char*>(_info->displayString().c_str()))) {
545 cout << "warning: couldn't set environment variable 'DISPLAY'\n";
546 perror("putenv()");
547 }
548 execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL);
549 exit(-1);
550 } else if (pid == -1) {
551 cout << _epist->getApplicationName() <<
552 ": Could not fork a process for executing a command\n";
553 }
554 }
555
556
557 void screen::cycleWindow(unsigned int state, const bool forward,
558 const int increment, const bool allscreens,
559 const bool alldesktops, const bool sameclass,
560 const string &cn)
561 {
562 assert(_managed);
563 assert(increment > 0);
564
565 if (_clients.empty()) return;
566
567 string classname(cn);
568 if (sameclass && classname.empty() && _active != _clients.end())
569 classname = (*_active)->appClass();
570
571 WindowList::const_iterator target = _active,
572 begin = _clients.begin(),
573 end = _clients.end();
574
575 XWindow *t = 0;
576
577 for (int x = 0; x < increment; ++x) {
578 while (1) {
579 if (forward) {
580 if (target == end) {
581 target = begin;
582 } else {
583 ++target;
584 }
585 } else {
586 if (target == begin)
587 target = end;
588 --target;
589 }
590
591 // must be no window to focus
592 if (target == _active)
593 return;
594
595 // start back at the beginning of the loop
596 if (target == end)
597 continue;
598
599 // determine if this window is invalid for cycling to
600 t = *target;
601 if (t->iconic()) continue;
602 if (! allscreens && t->getScreen() != this) continue;
603 if (! alldesktops && ! (t->desktop() == _active_desktop ||
604 t->desktop() == 0xffffffff)) continue;
605 if (sameclass && ! classname.empty() &&
606 t->appClass() != classname) continue;
607 if (! t->canFocus()) continue;
608
609 // found a good window so break out of the while, and perhaps continue
610 // with the for loop
611 break;
612 }
613 }
614
615 // phew. we found the window, so focus it.
616 if (_stacked_cycling && state) {
617 if (!_cycling) {
618 // grab modifiers so we can intercept KeyReleases from them
619 grabModifiers();
620 _cycling = true;
621 }
622
623 // if the window is on another desktop, we can't use XSetInputFocus, since
624 // it doesn't imply a woskpace change.
625 if (t->desktop() == _active_desktop)
626 t->focus(false); // focus, but don't raise
627 else
628 t->focus(); // change workspace and focus
629 }
630 else {
631 t->focus();
632 }
633 }
634
635
636 void screen::cycleWorkspace(const bool forward, const int increment,
637 const bool loop) const {
638 assert(_managed);
639 assert(increment > 0);
640
641 unsigned int destination = _active_desktop;
642
643 for (int x = 0; x < increment; ++x) {
644 if (forward) {
645 if (destination < _num_desktops - 1)
646 ++destination;
647 else if (loop)
648 destination = 0;
649 } else {
650 if (destination > 0)
651 --destination;
652 else if (loop)
653 destination = _num_desktops - 1;
654 }
655 }
656
657 if (destination != _active_desktop)
658 changeWorkspace(destination);
659 }
660
661
662 void screen::changeWorkspace(const int num) const {
663 assert(_managed);
664
665 _xatom->sendClientMessage(_root, XAtom::net_current_desktop, _root, num);
666 }
667
668 void screen::changeWorkspaceVert(const int num) const {
669 assert(_managed);
670 int width = 0;
671 int num_desktops = (signed)_num_desktops;
672 int active_desktop = (signed)_active_desktop;
673 int wnum = 0;
674
675 _config->getNumberValue(Config::workspaceColumns, width);
676
677 if (width > num_desktops || width <= 0)
678 return;
679
680 // a cookie to the person that makes this pretty
681 if (num < 0) {
682 wnum = active_desktop - width;
683 if (wnum < 0) {
684 wnum = num_desktops/width * width + active_desktop;
685 if (wnum >= num_desktops)
686 wnum = num_desktops - 1;
687 }
688 }
689 else {
690 wnum = active_desktop + width;
691 if (wnum >= num_desktops) {
692 wnum = (active_desktop + width) % num_desktops - 1;
693 if (wnum < 0)
694 wnum = 0;
695 }
696 }
697 changeWorkspace(wnum);
698 }
699
700 void screen::changeWorkspaceHorz(const int num) const {
701 assert(_managed);
702 int width = 0;
703 int num_desktops = (signed)_num_desktops;
704 int active_desktop = (signed)_active_desktop;
705 int wnum = 0;
706
707 _config->getNumberValue(Config::workspaceColumns, width);
708
709 if (width > num_desktops || width <= 0)
710 return;
711
712 if (num < 0) {
713 if (active_desktop % width != 0)
714 changeWorkspace(active_desktop - 1);
715 else {
716 wnum = active_desktop + width - 1;
717 if (wnum >= num_desktops)
718 wnum = num_desktops - 1;
719 }
720 }
721 else {
722 if (active_desktop % width != width - 1) {
723 wnum = active_desktop + 1;
724 if (wnum >= num_desktops)
725 wnum = num_desktops / width * width;
726 }
727 else
728 wnum = active_desktop - width + 1;
729 }
730 changeWorkspace(wnum);
731 }
732
733 void screen::grabKey(const KeyCode keyCode, const int modifierMask) const {
734
735 Display *display = _epist->getXDisplay();
736 int numlockMask, scrolllockMask;
737
738 _epist->getLockModifiers(numlockMask, scrolllockMask);
739
740 XGrabKey(display, keyCode, modifierMask,
741 _root, True, GrabModeAsync, GrabModeAsync);
742 XGrabKey(display, keyCode,
743 modifierMask|LockMask,
744 _root, True, GrabModeAsync, GrabModeAsync);
745 XGrabKey(display, keyCode,
746 modifierMask|scrolllockMask,
747 _root, True, GrabModeAsync, GrabModeAsync);
748 XGrabKey(display, keyCode,
749 modifierMask|numlockMask,
750 _root, True, GrabModeAsync, GrabModeAsync);
751
752 XGrabKey(display, keyCode,
753 modifierMask|LockMask|scrolllockMask,
754 _root, True, GrabModeAsync, GrabModeAsync);
755 XGrabKey(display, keyCode,
756 modifierMask|scrolllockMask|numlockMask,
757 _root, True, GrabModeAsync, GrabModeAsync);
758 XGrabKey(display, keyCode,
759 modifierMask|numlockMask|LockMask,
760 _root, True, GrabModeAsync, GrabModeAsync);
761
762 XGrabKey(display, keyCode,
763 modifierMask|numlockMask|LockMask|scrolllockMask,
764 _root, True, GrabModeAsync, GrabModeAsync);
765 }
766
767 void screen::ungrabKey(const KeyCode keyCode, const int modifierMask) const {
768
769 Display *display = _epist->getXDisplay();
770 int numlockMask, scrolllockMask;
771
772 _epist->getLockModifiers(numlockMask, scrolllockMask);
773
774 XUngrabKey(display, keyCode, modifierMask, _root);
775 XUngrabKey(display, keyCode, modifierMask|LockMask, _root);
776 XUngrabKey(display, keyCode, modifierMask|scrolllockMask, _root);
777 XUngrabKey(display, keyCode, modifierMask|numlockMask, _root);
778 XUngrabKey(display, keyCode, modifierMask|LockMask|scrolllockMask, _root);
779 XUngrabKey(display, keyCode, modifierMask|scrolllockMask|numlockMask, _root);
780 XUngrabKey(display, keyCode, modifierMask|numlockMask|LockMask, _root);
781 XUngrabKey(display, keyCode, modifierMask|numlockMask|LockMask|
782 scrolllockMask, _root);
783 }
784
785
786 void screen::grabModifiers() const {
787 Display *display = _epist->getXDisplay();
788
789 XGrabKeyboard(display, rootWindow(), True, GrabModeAsync,
790 GrabModeAsync, CurrentTime);
791 }
792
793
794 void screen::ungrabModifiers() const {
795 Display *display = _epist->getXDisplay();
796
797 XUngrabKeyboard(display, CurrentTime);
798 }
799
800
801 bool screen::isModifier(const KeyCode kc) const {
802 KeySym ks = XKeycodeToKeysym(_epist->getXDisplay(), kc, 0);
803
804 if (ks == XK_Shift_L || ks == XK_Shift_R ||
805 ks == XK_Control_L || ks == XK_Control_R ||
806 ks == XK_Meta_L || ks == XK_Meta_R ||
807 ks == XK_Alt_L || ks == XK_Alt_R ||
808 ks == XK_Super_L || ks == XK_Super_R ||
809 ks == XK_Hyper_L || ks == XK_Hyper_R)
810 return true;
811 else
812 return false;
813 }
814
815
816 bool screen::nothingIsPressed(void) const
817 {
818 char keys[32];
819 XQueryKeymap(_epist->getXDisplay(), keys);
820
821 for (int i = 0; i < 32; ++i) {
822 if (keys[i] != 0)
823 return false;
824 }
825
826 return true;
827 }
This page took 0.070871 seconds and 5 git commands to generate.