2007-04-29 17:35:43 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "detectwidget.h"
|
2016-08-16 13:31:14 +00:00
|
|
|
#include "../../plugins/platforms/x11/standalone/x11cursor.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KLocalizedString>
|
2013-11-01 11:29:05 +00:00
|
|
|
#include <QDebug>
|
2007-04-30 15:48:34 +00:00
|
|
|
#include <kwindowsystem.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QCheckBox>
|
2013-12-05 19:22:31 +00:00
|
|
|
#include <QDialogButtonBox>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QByteArray>
|
2011-04-06 17:52:23 +00:00
|
|
|
#include <QTimer>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2018-02-12 20:40:05 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingCallWatcher>
|
|
|
|
#include <QDBusPendingReply>
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(NET::WindowType)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
DetectWidget::DetectWidget(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
DetectDialog::DetectDialog(QWidget* parent, const char* name)
|
2018-02-12 20:40:05 +00:00
|
|
|
: QDialog(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
setModal(true);
|
2013-12-05 19:22:31 +00:00
|
|
|
setLayout(new QVBoxLayout);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
widget = new DetectWidget(this);
|
2013-12-05 19:22:31 +00:00
|
|
|
layout()->addWidget(widget);
|
|
|
|
|
|
|
|
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this);
|
|
|
|
layout()->addWidget(buttons);
|
|
|
|
|
|
|
|
connect(buttons, SIGNAL(accepted()), SLOT(accept()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), SLOT(reject()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2018-02-12 20:40:05 +00:00
|
|
|
void DetectDialog::detect(int secs)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-02-12 20:40:05 +00:00
|
|
|
QTimer::singleShot(secs*1000, this, SLOT(selectWindow()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void DetectDialog::executeDialog()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
static const char* const types[] = {
|
|
|
|
I18N_NOOP("Normal Window"),
|
|
|
|
I18N_NOOP("Desktop"),
|
|
|
|
I18N_NOOP("Dock (panel)"),
|
|
|
|
I18N_NOOP("Toolbar"),
|
|
|
|
I18N_NOOP("Torn-Off Menu"),
|
|
|
|
I18N_NOOP("Dialog Window"),
|
|
|
|
I18N_NOOP("Override Type"),
|
|
|
|
I18N_NOOP("Standalone Menubar"),
|
|
|
|
I18N_NOOP("Utility Window"),
|
|
|
|
I18N_NOOP("Splash Screen")
|
|
|
|
};
|
2015-11-05 14:14:06 +00:00
|
|
|
widget->class_label->setText(wmclass_class + QLatin1String(" (") + wmclass_name + ' ' + wmclass_class + ')');
|
2011-01-30 14:34:42 +00:00
|
|
|
widget->role_label->setText(role);
|
2011-11-09 20:23:14 +00:00
|
|
|
widget->match_role->setEnabled(!role.isEmpty());
|
2011-01-30 14:34:42 +00:00
|
|
|
if (type == NET::Unknown)
|
|
|
|
widget->type_label->setText(i18n("Unknown - will be treated as Normal Window"));
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
widget->type_label->setText(i18n(types[ type ]));
|
|
|
|
widget->title_label->setText(title);
|
|
|
|
widget->machine_label->setText(machine);
|
2011-04-06 17:52:23 +00:00
|
|
|
widget->adjustSize();
|
|
|
|
adjustSize();
|
|
|
|
if (width() < 4*height()/3)
|
|
|
|
resize(4*height()/3, height());
|
2013-12-05 19:22:31 +00:00
|
|
|
emit detectionDone(exec() == QDialog::Accepted);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QByteArray DetectDialog::selectedClass() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-11-09 20:23:14 +00:00
|
|
|
if (widget->match_whole_class->isChecked())
|
|
|
|
return wmclass_name + ' ' + wmclass_class;
|
|
|
|
return wmclass_class;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool DetectDialog::selectedWholeClass() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-11-09 20:23:14 +00:00
|
|
|
return widget->match_whole_class->isChecked();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QByteArray DetectDialog::selectedRole() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-11-09 20:23:14 +00:00
|
|
|
if (widget->match_role->isChecked())
|
2007-04-29 17:35:43 +00:00
|
|
|
return role;
|
|
|
|
return "";
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QString DetectDialog::selectedTitle() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return title;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Rules::StringMatch DetectDialog::titleMatch() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return widget->match_title->isChecked() ? Rules::ExactMatch : Rules::UnimportantMatch;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool DetectDialog::selectedWholeApp() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-11-09 20:23:14 +00:00
|
|
|
return !widget->match_type->isChecked();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
NET::WindowType DetectDialog::selectedType() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return type;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QByteArray DetectDialog::selectedMachine() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return machine;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void DetectDialog::selectWindow()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-02-12 20:40:05 +00:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"),
|
|
|
|
QStringLiteral("/KWin"),
|
|
|
|
QStringLiteral("org.kde.KWin"),
|
|
|
|
QStringLiteral("queryWindowInfo"));
|
|
|
|
QDBusPendingReply<QVariantMap> async = QDBusConnection::sessionBus().asyncCall(message);
|
|
|
|
|
|
|
|
QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(async, this);
|
|
|
|
connect(callWatcher, &QDBusPendingCallWatcher::finished, this,
|
|
|
|
[this](QDBusPendingCallWatcher *self) {
|
|
|
|
QDBusPendingReply<QVariantMap> reply = *self;
|
|
|
|
self->deleteLater();
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
emit detectionDone(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_windowInfo = reply.value();
|
|
|
|
wmclass_class = m_windowInfo.value("resourceClass").toByteArray();
|
|
|
|
wmclass_name = m_windowInfo.value("resourceName").toByteArray();
|
|
|
|
role = m_windowInfo.value("role").toByteArray();
|
|
|
|
type = m_windowInfo.value("type").value<NET::WindowType>();
|
|
|
|
title = m_windowInfo.value("caption").toString();
|
|
|
|
machine = m_windowInfo.value("clientMachine").toByteArray();
|
|
|
|
executeDialog();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2018-02-12 20:40:05 +00:00
|
|
|
);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|