2
* psiapplication.cpp - subclass of QApplication to do some workarounds
3
* Copyright (C) 2003 Michail Pishchagin
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "psiapplication.h"
24
#include<Carbon/Carbon.h>
32
#include <X11/Xutil.h>
33
#include <X11/Xatom.h>
34
#include <X11/SM/SMlib.h>
36
//static Atom atom_KdeNetUserTime;
37
static Atom kde_net_wm_user_time = 0;
39
//#if QT_VERSION > 0x030201
40
//#warning "Possibly, now it's time to clean up some 'focus stealing prevention' workaround code"
43
Time qt_x_last_input_time = CurrentTime;
44
//extern Time qt_x_time;
47
#ifndef FIXX11H_KeyPress
48
#define FIXX11H_KeyPress
49
const int XKeyPress = KeyPress;
51
const int KeyPress = XKeyPress;
58
// currently this file contains some Anti-"focus steling prevention" code by
59
// Lubos Lunak (l.lunak@kde.org)
61
// This should resolve all bugs with KWin3 and old Qt, but maybe it'll be useful for
62
// other window managers?
68
//----------------------------------------------------------------------------
70
//----------------------------------------------------------------------------
72
PsiApplication::PsiApplication(int &argc, char **argv, bool GUIenabled)
73
: QApplication(argc, argv, GUIenabled)
78
PsiApplication::~PsiApplication()
82
void PsiApplication::init(bool GUIenabled)
90
Atom atoms_return[max];
93
//atoms[n] = &atom_KdeNetUserTime;
94
//names[n++] = (char *) "_KDE_NET_USER_TIME";
96
atoms[n] = &kde_net_wm_user_time;
97
names[n++] = (char *) "_NET_WM_USER_TIME";
99
XInternAtoms( qt_xdisplay(), names, n, false, atoms_return );
101
for (int i = 0; i < n; i++ )
102
*atoms[i] = atoms_return[i];
107
bool PsiApplication::notify(QObject *receiver, QEvent *event)
110
if( event->type() == QEvent::Show && receiver->isWidgetType())
112
QWidget* w = static_cast< QWidget* >( receiver );
113
if( w->isTopLevel() && qt_x_last_input_time != CurrentTime ) // CurrentTime means no input event yet
114
XChangeProperty( qt_xdisplay(), w->winId(), kde_net_wm_user_time, XA_CARDINAL,
115
32, PropModeReplace, (unsigned char*)&qt_x_last_input_time, 1 );
117
if( event->type() == QEvent::Hide && receiver->isWidgetType())
119
QWidget* w = static_cast< QWidget* >( receiver );
120
if( w->isTopLevel() && w->winId() != 0 )
121
XDeleteProperty( qt_xdisplay(), w->winId(), kde_net_wm_user_time );
124
return QApplication::notify(receiver, event);
128
bool PsiApplication::x11EventFilter( XEvent *_event )
130
switch ( _event->type ) {
134
if( _event->type == ButtonPress )
135
qt_x_last_input_time = _event->xbutton.time;
137
qt_x_last_input_time = _event->xkey.time;
138
QWidget *w = activeWindow();
140
XChangeProperty( qt_xdisplay(), w->winId(), kde_net_wm_user_time, XA_CARDINAL,
141
32, PropModeReplace, (unsigned char*)&qt_x_last_input_time, 1 );
143
gettimeofday( &tv, NULL );
144
unsigned long now = tv.tv_sec * 10 + tv.tv_usec / 100000;
145
XChangeProperty(qt_xdisplay(), w->winId(),
146
atom_KdeNetUserTime, XA_CARDINAL,
147
32, PropModeReplace, (unsigned char *)&now, 1);*/
156
// process the event normally
162
bool PsiApplication::macEventFilter( EventHandlerCallRef, EventRef inEvent )
164
UInt32 eclass = GetEventClass(inEvent);
165
int etype = GetEventKind(inEvent);
166
if(eclass == 'eppc' && etype == kEventAppleEvent) {