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_
15 #include "windowselector.h"
21 #include <kapplication.h>
23 #include <QDesktopWidget>
30 WindowSelector::WindowSelector( QObject
* receiver_P
, const char* slot_P
)
32 connect( this, SIGNAL( selected_signal( WId
)), receiver_P
, slot_P
);
35 void WindowSelector::select()
37 kapp
->desktop()->grabMouse( QCursor( Qt::CrossCursor
));
38 kapp
->installX11EventFilter( this );
41 bool WindowSelector::x11Event( XEvent
* e
)
43 if( e
->type
!= ButtonPress
)
45 kapp
->desktop()->releaseMouse();
46 if( e
->xbutton
.button
== Button1
)
48 WId window
= findRealWindow( e
->xbutton
.subwindow
);
50 selected_signal( window
);
56 WId
WindowSelector::findRealWindow( WId w
, int depth
)
60 static Atom wm_state
= XInternAtom( QX11Info::display(), "WM_STATE", False
);
63 unsigned long nitems
, after
;
65 if( XGetWindowProperty( QX11Info::display(), w
, wm_state
, 0, 0, False
, AnyPropertyType
,
66 &type
, &format
, &nitems
, &after
, &prop
) == Success
)
75 unsigned int nchildren
;
77 if( XQueryTree( QX11Info::display(), w
, &root
, &parent
, &children
, &nchildren
) != 0 )
79 for( unsigned int i
= 0;
80 i
< nchildren
&& ret
== None
;
82 ret
= findRealWindow( children
[ i
], depth
+ 1 );
83 if( children
!= NULL
)
90 } // namespace KHotKeys
92 #include "windowselector.moc"