2004-06-22 16:31:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "detectwidget.h"
|
|
|
|
|
|
|
|
#include <kapplication.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kwin.h>
|
|
|
|
#include <qlabel.h>
|
2004-06-22 18:10:21 +00:00
|
|
|
#include <qradiobutton.h>
|
2004-06-22 16:31:57 +00:00
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xutil.h>
|
2004-06-22 18:10:21 +00:00
|
|
|
#include <fixx11h.h>
|
2004-06-22 16:31:57 +00:00
|
|
|
|
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
DetectWidget::DetectWidget( QWidget* parent, const char* name )
|
|
|
|
: DetectWidgetBase( parent, name )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DetectDialog::DetectDialog( QWidget* parent, const char* name )
|
2004-06-22 18:10:21 +00:00
|
|
|
: KDialogBase( parent, name, true, "", Ok | Cancel )
|
2004-06-22 16:31:57 +00:00
|
|
|
, grabber( NULL )
|
|
|
|
{
|
|
|
|
widget = new DetectWidget( this );
|
|
|
|
setMainWidget( widget );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DetectDialog::detect( WId window )
|
|
|
|
{
|
|
|
|
if( window == 0 )
|
|
|
|
selectWindow();
|
|
|
|
else
|
|
|
|
readWindow( window );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DetectDialog::readWindow( WId w )
|
|
|
|
{
|
|
|
|
if( w == 0 )
|
|
|
|
{
|
|
|
|
emit detectionDone( false );
|
|
|
|
return;
|
|
|
|
}
|
2004-08-04 11:00:40 +00:00
|
|
|
info = KWin::windowInfo( w, -1U, -1U ); // read everything
|
2004-06-22 16:31:57 +00:00
|
|
|
if( !info.valid())
|
|
|
|
{
|
|
|
|
emit detectionDone( false );
|
|
|
|
return;
|
|
|
|
}
|
2004-07-28 15:49:54 +00:00
|
|
|
wmclass_class = info.windowClassClass();
|
|
|
|
wmclass_name = info.windowClassName();
|
|
|
|
role = info.windowRole();
|
2004-06-22 16:31:57 +00:00
|
|
|
type = info.windowType( NET::NormalMask | NET::DesktopMask | NET::DockMask
|
|
|
|
| NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask
|
|
|
|
| NET::UtilityMask | NET::SplashMask );
|
|
|
|
title = info.name();
|
|
|
|
extrarole = ""; // TODO
|
2004-07-28 15:49:54 +00:00
|
|
|
machine = info.clientMachine();
|
2004-06-22 16:31:57 +00:00
|
|
|
executeDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DetectDialog::executeDialog()
|
|
|
|
{
|
|
|
|
static const char* const types[] =
|
|
|
|
{
|
|
|
|
I18N_NOOP( "Normal Window" ),
|
|
|
|
I18N_NOOP( "Desktop" ),
|
|
|
|
I18N_NOOP( "Dock (panel)" ),
|
|
|
|
I18N_NOOP( "Toolbar" ),
|
2004-07-06 12:38:33 +00:00
|
|
|
I18N_NOOP( "Torn-Off Menu" ),
|
2004-06-22 16:31:57 +00:00
|
|
|
I18N_NOOP( "Dialog Window" ),
|
|
|
|
I18N_NOOP( "Override Type" ),
|
|
|
|
I18N_NOOP( "Standalone Menubar" ),
|
|
|
|
I18N_NOOP( "Utility Window" ),
|
2004-06-27 16:18:56 +00:00
|
|
|
I18N_NOOP( "Splash Screen" )
|
2004-06-22 16:31:57 +00:00
|
|
|
};
|
|
|
|
widget->class_label->setText( wmclass_class + " (" + wmclass_name + ' ' + wmclass_class + ")" );
|
|
|
|
widget->role_label->setText( role );
|
2004-07-30 13:38:02 +00:00
|
|
|
widget->use_role->setEnabled( !role.isEmpty());
|
2004-08-24 08:35:47 +00:00
|
|
|
if( widget->use_role->isEnabled())
|
|
|
|
widget->use_role->setChecked( true );
|
|
|
|
else
|
|
|
|
widget->use_whole_class->setChecked( true );
|
2004-06-22 16:31:57 +00:00
|
|
|
if( type == NET::Unknown )
|
|
|
|
widget->type_label->setText( i18n( "Unknown - will be treated as Normal Window" ));
|
|
|
|
else
|
|
|
|
widget->type_label->setText( i18n( types[ type ] ));
|
|
|
|
widget->title_label->setText( title );
|
|
|
|
widget->extrarole_label->setText( extrarole );
|
|
|
|
widget->machine_label->setText( machine );
|
|
|
|
emit detectionDone( exec() == QDialog::Accepted );
|
|
|
|
}
|
|
|
|
|
2004-06-22 18:10:21 +00:00
|
|
|
QCString DetectDialog::selectedClass() const
|
|
|
|
{
|
|
|
|
if( widget->use_class->isChecked() || widget->use_role->isChecked())
|
|
|
|
return wmclass_class;
|
|
|
|
return wmclass_name + ' ' + wmclass_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DetectDialog::selectedWholeClass() const
|
|
|
|
{
|
|
|
|
return widget->use_whole_class->isChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
QCString DetectDialog::selectedRole() const
|
|
|
|
{
|
|
|
|
if( widget->use_role->isChecked())
|
|
|
|
return role;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2004-07-30 13:35:55 +00:00
|
|
|
QString DetectDialog::selectedTitle() const
|
|
|
|
{
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rules::StringMatch DetectDialog::titleMatch() const
|
|
|
|
{
|
|
|
|
#if KDE_IS_VERSION( 3, 3, 90 )
|
|
|
|
#warning Offer possibilities here
|
|
|
|
#endif
|
|
|
|
return Rules::UnimportantMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DetectDialog::selectedWholeApp() const
|
|
|
|
{
|
|
|
|
return widget->use_class->isChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
NET::WindowType DetectDialog::selectedType() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCString DetectDialog::selectedMachine() const
|
|
|
|
{
|
|
|
|
return machine;
|
|
|
|
}
|
2004-06-22 18:10:21 +00:00
|
|
|
|
2004-06-22 16:31:57 +00:00
|
|
|
void DetectDialog::selectWindow()
|
|
|
|
{
|
|
|
|
// use a dialog, so that all user input is blocked
|
|
|
|
// use WX11BypassWM and moving away so that it's not actually visible
|
|
|
|
// grab only mouse, so that keyboard can be used e.g. for switching windows
|
|
|
|
grabber = new QDialog( NULL, NULL, true, WX11BypassWM );
|
|
|
|
grabber->move( -1000, -1000 );
|
|
|
|
grabber->show();
|
|
|
|
grabber->grabMouse( crossCursor );
|
|
|
|
grabber->installEventFilter( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DetectDialog::eventFilter( QObject* o, QEvent* e )
|
|
|
|
{
|
|
|
|
if( o != grabber )
|
|
|
|
return false;
|
|
|
|
if( e->type() != QEvent::MouseButtonRelease )
|
|
|
|
return false;
|
|
|
|
delete grabber;
|
|
|
|
grabber = NULL;
|
2004-06-22 18:10:21 +00:00
|
|
|
if( static_cast< QMouseEvent* >( e )->button() != LeftButton )
|
|
|
|
{
|
|
|
|
emit detectionDone( false );
|
|
|
|
return true;
|
|
|
|
}
|
2004-06-22 16:31:57 +00:00
|
|
|
readWindow( findWindow());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
WId DetectDialog::findWindow()
|
|
|
|
{
|
|
|
|
Window root;
|
|
|
|
Window child;
|
|
|
|
uint mask;
|
|
|
|
int rootX, rootY, x, y;
|
|
|
|
Window parent = qt_xrootwin();
|
|
|
|
Atom wm_state = XInternAtom( qt_xdisplay(), "WM_STATE", False );
|
|
|
|
for( int i = 0;
|
|
|
|
i < 10;
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
XQueryPointer( qt_xdisplay(), parent, &root, &child,
|
|
|
|
&rootX, &rootY, &x, &y, &mask );
|
|
|
|
if( child == None )
|
|
|
|
return 0;
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, after;
|
|
|
|
unsigned char* prop;
|
|
|
|
if( XGetWindowProperty( qt_xdisplay(), child, wm_state, 0, 0, False, AnyPropertyType,
|
|
|
|
&type, &format, &nitems, &after, &prop ) == Success )
|
|
|
|
{
|
|
|
|
if( prop != NULL )
|
|
|
|
XFree( prop );
|
|
|
|
if( type != None )
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
parent = child;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "detectwidget.moc"
|