~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/randr/krandrpassivepopup.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "krandrpassivepopup.h"
 
20
 
 
21
#include <kapplication.h>
 
22
#include <QX11Info>
 
23
//Added by qt3to4:
 
24
#include <QPixmap>
 
25
#include <QEvent>
 
26
 
 
27
// this class is just like KPassivePopup, but it keeps track of the widget
 
28
// it's supposed to be positioned next to, and adjust its position if that
 
29
// widgets moves (needed because after a resolution switch Kicker will
 
30
// reposition itself, causing normal KPassivePopup to stay at weird places)
 
31
 
 
32
KRandrPassivePopup::KRandrPassivePopup( QWidget *parent, Qt::WFlags f )
 
33
    : KPassivePopup( parent, f )
 
34
    {
 
35
    update_timer.setSingleShot( true );
 
36
    connect( &update_timer, SIGNAL( timeout()), SLOT( slotPositionSelf()));
 
37
    }
 
38
    
 
39
KRandrPassivePopup* KRandrPassivePopup::message( const QString &caption, const QString &text,
 
40
    const QPixmap &icon, QWidget *parent, int timeout )
 
41
    {
 
42
    KRandrPassivePopup *pop = new KRandrPassivePopup( parent );
 
43
    pop->setAutoDelete( true );
 
44
    pop->setView( caption, text, icon );
 
45
    pop->setTimeout( timeout );
 
46
    pop->show();
 
47
    pop->startWatchingWidget( parent );
 
48
    return pop;
 
49
    }
 
50
 
 
51
void KRandrPassivePopup::startWatchingWidget( QWidget* widget_P )
 
52
    {
 
53
    static Atom wm_state = XInternAtom( QX11Info::display() , "WM_STATE", False );
 
54
    Window win = widget_P->winId();
 
55
    bool x11_events = false;
 
56
    for(;;)
 
57
        {
 
58
        Window root, parent;
 
59
        Window* children;
 
60
        unsigned int nchildren;
 
61
        XQueryTree( QX11Info::display(), win, &root, &parent, &children, &nchildren );
 
62
        if( children != NULL )
 
63
            XFree( children );
 
64
        if( win == root ) // huh?
 
65
            break;
 
66
        win = parent;
 
67
        
 
68
        QWidget* widget = QWidget::find( win );
 
69
        if( widget != NULL )
 
70
            {
 
71
            widget->installEventFilter( this );
 
72
            watched_widgets.append( widget );
 
73
            }
 
74
        else
 
75
            {
 
76
            XWindowAttributes attrs;
 
77
            XGetWindowAttributes( QX11Info::display(), win, &attrs );
 
78
            XSelectInput( QX11Info::display(), win, attrs.your_event_mask | StructureNotifyMask );
 
79
            watched_windows.append( win );
 
80
            x11_events = true;
 
81
            }
 
82
        Atom type;
 
83
        int format;
 
84
        unsigned long nitems, after;
 
85
        unsigned char* data;
 
86
        if( XGetWindowProperty( QX11Info::display(), win, wm_state, 0, 0, False, AnyPropertyType,
 
87
            &type, &format, &nitems, &after, &data ) == Success )
 
88
            {
 
89
            if( data != NULL )
 
90
                XFree( data );
 
91
            if( type != None ) // toplevel window
 
92
                break;
 
93
            }
 
94
        }
 
95
    if( x11_events )
 
96
        kapp->installX11EventFilter( this );
 
97
    }
 
98
        
 
99
bool KRandrPassivePopup::eventFilter( QObject* o, QEvent* e )
 
100
    {
 
101
    if( e->type() == QEvent::Move && o->isWidgetType()
 
102
        && watched_widgets.contains( static_cast< QWidget* >( o )))
 
103
        QTimer::singleShot( 0, this, SLOT( slotPositionSelf()));
 
104
    return false;
 
105
    }
 
106
 
 
107
bool KRandrPassivePopup::x11Event( XEvent* e )
 
108
    {
 
109
    if( e->type == ConfigureNotify && watched_windows.contains( e->xconfigure.window ) )
 
110
        {
 
111
        if( !update_timer.isActive() )
 
112
            update_timer.start( 10 );
 
113
        return false;
 
114
        }
 
115
    return KPassivePopup::x11Event( e );
 
116
    }
 
117
        
 
118
void KRandrPassivePopup::slotPositionSelf()
 
119
    {
 
120
    positionSelf();
 
121
    }
 
122
    
 
123
#include "krandrpassivepopup.moc"