Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 83 lines (71 sloc) 1.934 kb
39be20d @kekekeks Initial commit for publishing at GitHub
authored
1 /*
2 focusguard.cpp
3 Author:
4 Nikita Tsukanov <keks9n@gmail.com>
5
6 Copyright (c) 2011 Nikita Tsukanov
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "focusguard.h"
22 #include <QEvent>
23 #include <QApplication>
24 #include <QChildEvent>
25 #include <QMouseEvent>
26 #include "x11.h"
27 #include <X11/Xlib.h>
28 namespace skypetab
29 {
30 FocusGuard::FocusGuard() :
31 QObject(0)
32 {
33 _initialized=false;
34 }
35
36 void FocusGuard::init()
37 {
38 if(!_initialized)
39 {
40 QApplication::instance()->installEventFilter(this);
41 _initialized=true;
42 }
43 }
44 FocusGuard FocusGuard::_instance;
2312893 @kekekeks Set focus on current time when activated
authored
45 time_t FocusGuard::lastManualFocusChangeTime=0;
39be20d @kekekeks Initial commit for publishing at GitHub
authored
46 bool FocusGuard::eventFilter(QObject *obj, QEvent *event)
47 {
0e9286c @kekekeks FocusGuard is more argressive now
authored
48 if(event->type()==QEvent::MouseButtonPress)
39be20d @kekekeks Initial commit for publishing at GitHub
authored
49 {
50 QWidget *w=qobject_cast<QWidget*>(obj);
51 QObject* parent=obj;
52 while(parent!=0)
53 {
54 if(_watched.contains(parent))
55 break;
56 parent=parent->parent();
57 }
58 if(parent==0)
59 return false;
60 w=qobject_cast<QWidget*>(parent);
2312893 @kekekeks Set focus on current time when activated
authored
61 lastManualFocusChangeTime=time(0);
39be20d @kekekeks Initial commit for publishing at GitHub
authored
62 XSetInputFocus(X11::XDisplay, w->winId(), RevertToNone, CurrentTime);
63
64 }
65 return false;
66 }
67
68 void FocusGuard::addGuardedWidget(QWidget *widget)
69 {
70 _instance.init();
71
72 _instance._watched.append(widget);
73 connect(widget,SIGNAL(destroyed(QObject*)), &_instance, SLOT(onDestroyed(QObject*)));
74 }
75
76 void FocusGuard::onDestroyed(QObject *obj)
77 {
78 _watched.removeAll(obj);
79 }
80
81
82 }
Something went wrong with that request. Please try again.