1
/****************************************************************************
5
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
7
Distributed under the terms of the GNU General Public License version 2.
9
****************************************************************************/
11
#define WINDOWSELECTOR_CPP
13
#include "helper_widgets/window_selector.h"
16
#include <kapplication.h>
18
#include <QtGui/QDesktopWidget>
27
WindowSelector::WindowSelector( QObject* receiver_P, const char* slot_P )
29
connect( this, SIGNAL( selected_signal( WId )), receiver_P, slot_P );
32
void WindowSelector::select()
34
kapp->desktop()->grabMouse( QCursor( Qt::CrossCursor ));
35
kapp->installX11EventFilter( this );
38
bool WindowSelector::x11Event( XEvent* e )
40
if( e->type != ButtonPress )
42
kapp->desktop()->releaseMouse();
43
if( e->xbutton.button == Button1 )
45
WId window = findRealWindow( e->xbutton.subwindow );
47
selected_signal( window );
53
WId WindowSelector::findRealWindow( WId w, int depth )
57
static Atom wm_state = XInternAtom( QX11Info::display(), "WM_STATE", False );
60
unsigned long nitems, after;
62
if( XGetWindowProperty( QX11Info::display(), w, wm_state, 0, 0, False, AnyPropertyType,
63
&type, &format, &nitems, &after, &prop ) == Success )
72
unsigned int nchildren;
74
if( XQueryTree( QX11Info::display(), w, &root, &parent, &children, &nchildren ) != 0 )
76
for( unsigned int i = 0;
77
i < nchildren && ret == None;
79
ret = findRealWindow( children[ i ], depth + 1 );
80
if( children != NULL )
87
} // namespace KHotKeys
89
#include "window_selector.moc"