~ubuntu-branches/ubuntu/hoary/psi/hoary

« back to all changes in this revision

Viewing changes to src/psiapplication.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * psiapplication.cpp - subclass of QApplication to do some workarounds
 
3
 * Copyright (C) 2003  Michail Pishchagin
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
#include "psiapplication.h"
 
22
 
 
23
#ifdef Q_WS_MAC
 
24
#include<Carbon/Carbon.h>
 
25
#endif
 
26
 
 
27
#ifdef Q_WS_X11
 
28
#include <time.h>
 
29
#include <sys/time.h>
 
30
 
 
31
#include <X11/Xlib.h>
 
32
#include <X11/Xutil.h>
 
33
#include <X11/Xatom.h>
 
34
#include <X11/SM/SMlib.h>
 
35
 
 
36
//static Atom atom_KdeNetUserTime;
 
37
static Atom kde_net_wm_user_time = 0;
 
38
 
 
39
//#if QT_VERSION > 0x030201
 
40
//#warning "Possibly, now it's time to clean up some 'focus stealing prevention' workaround code"
 
41
//#endif
 
42
 
 
43
Time   qt_x_last_input_time = CurrentTime;
 
44
//extern Time qt_x_time;
 
45
 
 
46
#ifdef KeyPress
 
47
#ifndef FIXX11H_KeyPress
 
48
#define FIXX11H_KeyPress
 
49
const int XKeyPress = KeyPress;
 
50
#undef KeyPress
 
51
const int KeyPress = XKeyPress;
 
52
#endif
 
53
#undef KeyPress
 
54
#endif
 
55
#endif
 
56
 
 
57
// mblsha:
 
58
// currently this file contains some Anti-"focus steling prevention" code by
 
59
// Lubos Lunak (l.lunak@kde.org)
 
60
//
 
61
// This should resolve all bugs with KWin3 and old Qt, but maybe it'll be useful for
 
62
// other window managers?
 
63
 
 
64
#ifdef Q_WS_X11
 
65
//#undef Q_WS_X11
 
66
#endif
 
67
 
 
68
//----------------------------------------------------------------------------
 
69
// PsiApplication
 
70
//----------------------------------------------------------------------------
 
71
 
 
72
PsiApplication::PsiApplication(int &argc, char **argv, bool GUIenabled)
 
73
: QApplication(argc, argv, GUIenabled)
 
74
{
 
75
        init(GUIenabled);
 
76
}
 
77
 
 
78
PsiApplication::~PsiApplication()
 
79
{
 
80
}
 
81
 
 
82
void PsiApplication::init(bool GUIenabled)
 
83
{
 
84
        Q_UNUSED(GUIenabled);
 
85
#ifdef Q_WS_X11
 
86
        if ( GUIenabled ) {
 
87
                const int max = 20;
 
88
                Atom* atoms[max];
 
89
                char* names[max];
 
90
                Atom atoms_return[max];
 
91
                int n = 0;
 
92
 
 
93
                //atoms[n] = &atom_KdeNetUserTime;
 
94
                //names[n++] = (char *) "_KDE_NET_USER_TIME";
 
95
 
 
96
                atoms[n] = &kde_net_wm_user_time;
 
97
                names[n++] = (char *) "_NET_WM_USER_TIME";
 
98
 
 
99
                XInternAtoms( qt_xdisplay(), names, n, false, atoms_return );
 
100
 
 
101
                for (int i = 0; i < n; i++ )
 
102
                        *atoms[i] = atoms_return[i];
 
103
        }
 
104
#endif
 
105
}
 
106
 
 
107
bool PsiApplication::notify(QObject *receiver, QEvent *event)
 
108
{
 
109
#ifdef Q_WS_X11
 
110
        if( event->type() == QEvent::Show && receiver->isWidgetType())
 
111
        {
 
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 );
 
116
        }
 
117
        if( event->type() == QEvent::Hide && receiver->isWidgetType())
 
118
        {
 
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 );
 
122
        }
 
123
#endif
 
124
        return QApplication::notify(receiver, event);
 
125
}
 
126
 
 
127
#ifdef Q_WS_X11
 
128
bool PsiApplication::x11EventFilter( XEvent *_event )
 
129
{
 
130
        switch ( _event->type ) {
 
131
                case ButtonPress:
 
132
                case XKeyPress:
 
133
                {
 
134
                        if( _event->type == ButtonPress )
 
135
                                qt_x_last_input_time = _event->xbutton.time;
 
136
                        else // KeyPress
 
137
                                qt_x_last_input_time = _event->xkey.time;
 
138
                        QWidget *w = activeWindow();
 
139
                        if( w ) {
 
140
                                XChangeProperty( qt_xdisplay(), w->winId(), kde_net_wm_user_time, XA_CARDINAL,
 
141
                                                 32, PropModeReplace, (unsigned char*)&qt_x_last_input_time, 1 );
 
142
                                /*timeval tv;
 
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);*/
 
148
                        }
 
149
                        break;
 
150
                }
 
151
 
 
152
                default:
 
153
                        break;
 
154
        }
 
155
 
 
156
        // process the event normally
 
157
        return false;
 
158
}
 
159
#endif
 
160
 
 
161
#ifdef Q_WS_MAC
 
162
bool PsiApplication::macEventFilter( EventHandlerCallRef, EventRef inEvent )
 
163
{
 
164
        UInt32 eclass = GetEventClass(inEvent);
 
165
        int etype = GetEventKind(inEvent);
 
166
        if(eclass == 'eppc' && etype == kEventAppleEvent) {
 
167
                dockActivated();
 
168
        }
 
169
        return false;
 
170
}
 
171
#endif
 
172