2 * Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
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.
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.
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.
19 #include "krandrpassivepopup.h"
21 #include <kapplication.h>
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)
32 KRandrPassivePopup::KRandrPassivePopup( QWidget
*parent
, Qt::WFlags f
)
33 : KPassivePopup( parent
, f
)
35 update_timer
.setSingleShot( true );
36 connect( &update_timer
, SIGNAL( timeout()), SLOT( slotPositionSelf()));
39 KRandrPassivePopup
* KRandrPassivePopup::message( const QString
&caption
, const QString
&text
,
40 const QPixmap
&icon
, QWidget
*parent
, int timeout
)
42 KRandrPassivePopup
*pop
= new KRandrPassivePopup( parent
);
43 pop
->setAutoDelete( true );
44 pop
->setView( caption
, text
, icon
);
45 pop
->setTimeout( timeout
);
47 pop
->startWatchingWidget( parent
);
51 void KRandrPassivePopup::startWatchingWidget( QWidget
* widget_P
)
53 static Atom wm_state
= XInternAtom( QX11Info::display() , "WM_STATE", False
);
54 Window win
= widget_P
->winId();
55 bool x11_events
= false;
60 unsigned int nchildren
;
61 XQueryTree( QX11Info::display(), win
, &root
, &parent
, &children
, &nchildren
);
62 if( children
!= NULL
)
64 if( win
== root
) // huh?
68 QWidget
* widget
= QWidget::find( win
);
71 widget
->installEventFilter( this );
72 watched_widgets
.append( widget
);
76 XWindowAttributes attrs
;
77 XGetWindowAttributes( QX11Info::display(), win
, &attrs
);
78 XSelectInput( QX11Info::display(), win
, attrs
.your_event_mask
| StructureNotifyMask
);
79 watched_windows
.append( win
);
84 unsigned long nitems
, after
;
86 if( XGetWindowProperty( QX11Info::display(), win
, wm_state
, 0, 0, False
, AnyPropertyType
,
87 &type
, &format
, &nitems
, &after
, &data
) == Success
)
91 if( type
!= None
) // toplevel window
96 kapp
->installX11EventFilter( this );
99 bool KRandrPassivePopup::eventFilter( QObject
* o
, QEvent
* e
)
101 if( e
->type() == QEvent::Move
&& o
->isWidgetType()
102 && watched_widgets
.contains( static_cast< QWidget
* >( o
)))
103 QTimer::singleShot( 0, this, SLOT( slotPositionSelf()));
107 bool KRandrPassivePopup::x11Event( XEvent
* e
)
109 if( e
->type
== ConfigureNotify
&& watched_windows
.contains( e
->xconfigure
.window
) )
111 if( !update_timer
.isActive() )
112 update_timer
.start( 10 );
115 return KPassivePopup::x11Event( e
);
118 void KRandrPassivePopup::slotPositionSelf()
123 #include "krandrpassivepopup.moc"