Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / workspace / khotkeys / kcontrol / windowselector.cpp
blob4710d294f41c42bf4337e524dc12f93c0bfca2e8
1 /****************************************************************************
3 KHotKeys
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"
17 #include <QCursor>
18 #include "voices.h"
20 #include <kdebug.h>
21 #include <kapplication.h>
22 #include <X11/Xlib.h>
23 #include <QDesktopWidget>
24 #include <QX11Info>
25 #include <fixx11h.h>
27 namespace KHotKeys
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 )
44 return false;
45 kapp->desktop()->releaseMouse();
46 if( e->xbutton.button == Button1 )
48 WId window = findRealWindow( e->xbutton.subwindow );
49 if( window )
50 selected_signal( window );
52 delete this;
53 return true;
56 WId WindowSelector::findRealWindow( WId w, int depth )
58 if( depth > 5 )
59 return None;
60 static Atom wm_state = XInternAtom( QX11Info::display(), "WM_STATE", False );
61 Atom type;
62 int format;
63 unsigned long nitems, after;
64 unsigned char* prop;
65 if( XGetWindowProperty( QX11Info::display(), w, wm_state, 0, 0, False, AnyPropertyType,
66 &type, &format, &nitems, &after, &prop ) == Success )
68 if( prop != NULL )
69 XFree( prop );
70 if( type != None )
71 return w;
73 Window root, parent;
74 Window* children;
75 unsigned int nchildren;
76 Window ret = None;
77 if( XQueryTree( QX11Info::display(), w, &root, &parent, &children, &nchildren ) != 0 )
79 for( unsigned int i = 0;
80 i < nchildren && ret == None;
81 ++i )
82 ret = findRealWindow( children[ i ], depth + 1 );
83 if( children != NULL )
84 XFree( children );
86 return ret;
90 } // namespace KHotKeys
92 #include "windowselector.moc"