detectwidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "detectwidget.h"
00020
00021 #include <kapplication.h>
00022 #include <klocale.h>
00023 #include <kdebug.h>
00024 #include <kwin.h>
00025 #include <qlabel.h>
00026 #include <qradiobutton.h>
00027
00028 #include <X11/Xlib.h>
00029 #include <X11/Xatom.h>
00030 #include <X11/Xutil.h>
00031 #include <fixx11h.h>
00032
00033 namespace KWinInternal
00034 {
00035
00036 DetectWidget::DetectWidget( QWidget* parent, const char* name )
00037 : DetectWidgetBase( parent, name )
00038 {
00039 }
00040
00041 DetectDialog::DetectDialog( QWidget* parent, const char* name )
00042 : KDialogBase( parent, name, true, "", Ok | Cancel )
00043 , grabber( NULL )
00044 {
00045 widget = new DetectWidget( this );
00046 setMainWidget( widget );
00047 }
00048
00049 void DetectDialog::detect( WId window )
00050 {
00051 if( window == 0 )
00052 selectWindow();
00053 else
00054 readWindow( window );
00055 }
00056
00057 void DetectDialog::readWindow( WId w )
00058 {
00059 if( w == 0 )
00060 {
00061 emit detectionDone( false );
00062 return;
00063 }
00064 info = KWin::windowInfo( w, -1U, -1U );
00065 if( !info.valid())
00066 {
00067 emit detectionDone( false );
00068 return;
00069 }
00070 wmclass_class = info.windowClassClass();
00071 wmclass_name = info.windowClassName();
00072 role = info.windowRole();
00073 type = info.windowType( NET::NormalMask | NET::DesktopMask | NET::DockMask
00074 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask
00075 | NET::UtilityMask | NET::SplashMask );
00076 title = info.name();
00077 extrarole = "";
00078 machine = info.clientMachine();
00079 executeDialog();
00080 }
00081
00082 void DetectDialog::executeDialog()
00083 {
00084 static const char* const types[] =
00085 {
00086 I18N_NOOP( "Normal Window" ),
00087 I18N_NOOP( "Desktop" ),
00088 I18N_NOOP( "Dock (panel)" ),
00089 I18N_NOOP( "Toolbar" ),
00090 I18N_NOOP( "Torn-Off Menu" ),
00091 I18N_NOOP( "Dialog Window" ),
00092 I18N_NOOP( "Override Type" ),
00093 I18N_NOOP( "Standalone Menubar" ),
00094 I18N_NOOP( "Utility Window" ),
00095 I18N_NOOP( "Splash Screen" )
00096 };
00097 widget->class_label->setText( wmclass_class + " (" + wmclass_name + ' ' + wmclass_class + ")" );
00098 widget->role_label->setText( role );
00099 widget->use_role->setEnabled( !role.isEmpty());
00100 if( type == NET::Unknown )
00101 widget->type_label->setText( i18n( "Unknown - will be treated as Normal Window" ));
00102 else
00103 widget->type_label->setText( i18n( types[ type ] ));
00104 widget->title_label->setText( title );
00105 widget->extrarole_label->setText( extrarole );
00106 widget->machine_label->setText( machine );
00107 emit detectionDone( exec() == QDialog::Accepted );
00108 }
00109
00110 QCString DetectDialog::selectedClass() const
00111 {
00112 if( widget->use_class->isChecked() || widget->use_role->isChecked())
00113 return wmclass_class;
00114 return wmclass_name + ' ' + wmclass_class;
00115 }
00116
00117 bool DetectDialog::selectedWholeClass() const
00118 {
00119 return widget->use_whole_class->isChecked();
00120 }
00121
00122 QCString DetectDialog::selectedRole() const
00123 {
00124 if( widget->use_role->isChecked())
00125 return role;
00126 return "";
00127 }
00128
00129 QString DetectDialog::selectedTitle() const
00130 {
00131 return title;
00132 }
00133
00134 Rules::StringMatch DetectDialog::titleMatch() const
00135 {
00136 #if KDE_IS_VERSION( 3, 3, 90 )
00137 #warning Offer possibilities here
00138 #endif
00139 return Rules::UnimportantMatch;
00140 }
00141
00142 bool DetectDialog::selectedWholeApp() const
00143 {
00144 return widget->use_class->isChecked();
00145 }
00146
00147 NET::WindowType DetectDialog::selectedType() const
00148 {
00149 return type;
00150 }
00151
00152 QCString DetectDialog::selectedMachine() const
00153 {
00154 return machine;
00155 }
00156
00157 void DetectDialog::selectWindow()
00158 {
00159
00160
00161
00162 grabber = new QDialog( NULL, NULL, true, WX11BypassWM );
00163 grabber->move( -1000, -1000 );
00164 grabber->show();
00165 grabber->grabMouse( crossCursor );
00166 grabber->installEventFilter( this );
00167 }
00168
00169 bool DetectDialog::eventFilter( QObject* o, QEvent* e )
00170 {
00171 if( o != grabber )
00172 return false;
00173 if( e->type() != QEvent::MouseButtonRelease )
00174 return false;
00175 delete grabber;
00176 grabber = NULL;
00177 if( static_cast< QMouseEvent* >( e )->button() != LeftButton )
00178 {
00179 emit detectionDone( false );
00180 return true;
00181 }
00182 readWindow( findWindow());
00183 return true;
00184 }
00185
00186 WId DetectDialog::findWindow()
00187 {
00188 Window root;
00189 Window child;
00190 uint mask;
00191 int rootX, rootY, x, y;
00192 Window parent = qt_xrootwin();
00193 Atom wm_state = XInternAtom( qt_xdisplay(), "WM_STATE", False );
00194 for( int i = 0;
00195 i < 10;
00196 ++i )
00197 {
00198 XQueryPointer( qt_xdisplay(), parent, &root, &child,
00199 &rootX, &rootY, &x, &y, &mask );
00200 if( child == None )
00201 return 0;
00202 Atom type;
00203 int format;
00204 unsigned long nitems, after;
00205 unsigned char* prop;
00206 if( XGetWindowProperty( qt_xdisplay(), child, wm_state, 0, 0, False, AnyPropertyType,
00207 &type, &format, &nitems, &after, &prop ) == Success )
00208 {
00209 if( prop != NULL )
00210 XFree( prop );
00211 if( type != None )
00212 return child;
00213 }
00214 parent = child;
00215 }
00216 return 0;
00217 }
00218
00219 }
00220
00221 #include "detectwidget.moc"
This file is part of the documentation for kwin Library Version 3.3.0.