You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.7 KiB
119 lines
3.7 KiB
15 years ago
|
/*
|
||
|
* Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include "tderandrpassivepopup.h"
|
||
15 years ago
|
|
||
|
#include <kapplication.h>
|
||
|
|
||
|
// this class is just like KPassivePopup, but it keeps track of the widget
|
||
|
// it's supposed to be positioned next to, and adjust its position if that
|
||
|
// widgets moves (needed because after a resolution switch Kicker will
|
||
|
// reposition itself, causing normal KPassivePopup to stay at weird places)
|
||
|
|
||
14 years ago
|
KRandrPassivePopup::KRandrPassivePopup( TQWidget *parent, const char *name, WFlags f )
|
||
15 years ago
|
: KPassivePopup( parent, name, f )
|
||
|
{
|
||
14 years ago
|
connect( &update_timer, TQT_SIGNAL( timeout()), TQT_SLOT( slotPositionSelf()));
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
KRandrPassivePopup* KRandrPassivePopup::message( const TQString &caption, const TQString &text,
|
||
|
const TQPixmap &icon, TQWidget *parent, const char *name, int timeout )
|
||
15 years ago
|
{
|
||
|
KRandrPassivePopup *pop = new KRandrPassivePopup( parent, name );
|
||
|
pop->setAutoDelete( true );
|
||
|
pop->setView( caption, text, icon );
|
||
|
pop->setTimeout( timeout );
|
||
|
pop->show();
|
||
|
pop->startWatchingWidget( parent );
|
||
|
return pop;
|
||
|
}
|
||
|
|
||
14 years ago
|
void KRandrPassivePopup::startWatchingWidget( TQWidget* widget_P )
|
||
15 years ago
|
{
|
||
13 years ago
|
static Atom wm_state = XInternAtom( tqt_xdisplay() , "WM_STATE", False );
|
||
15 years ago
|
Window win = widget_P->winId();
|
||
|
bool x11_events = false;
|
||
|
for(;;)
|
||
|
{
|
||
|
Window root, parent;
|
||
|
Window* children;
|
||
|
unsigned int nchildren;
|
||
13 years ago
|
XQueryTree( tqt_xdisplay(), win, &root, &parent, &children, &nchildren );
|
||
15 years ago
|
if( children != NULL )
|
||
|
XFree( children );
|
||
|
if( win == root ) // huh?
|
||
|
break;
|
||
|
win = parent;
|
||
|
|
||
13 years ago
|
TQWidget* widget = TQWidget::find( win );
|
||
15 years ago
|
if( widget != NULL )
|
||
|
{
|
||
|
widget->installEventFilter( this );
|
||
|
watched_widgets.append( widget );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
XWindowAttributes attrs;
|
||
13 years ago
|
XGetWindowAttributes( tqt_xdisplay(), win, &attrs );
|
||
|
XSelectInput( tqt_xdisplay(), win, attrs.your_event_mask | StructureNotifyMask );
|
||
15 years ago
|
watched_windows.append( win );
|
||
|
x11_events = true;
|
||
|
}
|
||
|
Atom type;
|
||
|
int format;
|
||
|
unsigned long nitems, after;
|
||
|
unsigned char* data;
|
||
13 years ago
|
if( XGetWindowProperty( tqt_xdisplay(), win, wm_state, 0, 0, False, AnyPropertyType,
|
||
15 years ago
|
&type, &format, &nitems, &after, &data ) == Success )
|
||
|
{
|
||
|
if( data != NULL )
|
||
|
XFree( data );
|
||
|
if( type != None ) // toplevel window
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if( x11_events )
|
||
|
kapp->installX11EventFilter( this );
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KRandrPassivePopup::eventFilter( TQObject* o, TQEvent* e )
|
||
15 years ago
|
{
|
||
14 years ago
|
if( e->type() == TQEvent::Move && o->isWidgetType()
|
||
13 years ago
|
&& watched_widgets.contains( TQT_TQWIDGET( o )))
|
||
14 years ago
|
TQTimer::singleShot( 0, this, TQT_SLOT( slotPositionSelf()));
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
|
||
|
bool KRandrPassivePopup::x11Event( XEvent* e )
|
||
|
{
|
||
13 years ago
|
if( e->type == ConfigureNotify && watched_windows.contains( e->xconfigure.window ))
|
||
15 years ago
|
{
|
||
|
if( !update_timer.isActive())
|
||
|
update_timer.start( 10, true );
|
||
|
return false;
|
||
|
}
|
||
|
return KPassivePopup::x11Event( e );
|
||
|
}
|
||
|
|
||
|
void KRandrPassivePopup::slotPositionSelf()
|
||
|
{
|
||
|
positionSelf();
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tderandrpassivepopup.moc"
|