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 "ruleswidget.h"
|
|
|
|
|
|
|
|
#include <klineedit.h>
|
|
|
|
#include <kcombobox.h>
|
2013-11-05 12:50:31 +00:00
|
|
|
#include <kcolorschememanager.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QCheckBox>
|
2013-11-05 12:50:31 +00:00
|
|
|
#include <QFileInfo>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QLabel>
|
2007-04-30 15:48:34 +00:00
|
|
|
#include <kwindowsystem.h>
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KLocalizedString>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QRegExp>
|
2013-04-08 15:42:41 +00:00
|
|
|
|
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2014-02-03 12:40:47 +00:00
|
|
|
#include <kactivities/consumer.h>
|
2013-04-08 15:42:41 +00:00
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <kmessagebox.h>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include "../../rules.h"
|
|
|
|
|
|
|
|
#include "detectwidget.h"
|
|
|
|
|
2018-02-12 20:40:05 +00:00
|
|
|
Q_DECLARE_METATYPE(NET::WindowType)
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
#define SETUP( var, type ) \
|
2011-08-17 21:51:55 +00:00
|
|
|
connect( enable_##var, SIGNAL(toggled(bool)), rule_##var, SLOT(setEnabled(bool))); \
|
|
|
|
connect( enable_##var, SIGNAL(toggled(bool)), this, SLOT(updateEnable##var())); \
|
|
|
|
connect( rule_##var, SIGNAL(activated(int)), this, SLOT(updateEnable##var())); \
|
2007-04-29 17:35:43 +00:00
|
|
|
enable_##var->setWhatsThis( enableDesc ); \
|
|
|
|
rule_##var->setWhatsThis( type##RuleDesc );
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
RulesWidget::RulesWidget(QWidget* parent)
|
2014-01-07 10:22:24 +00:00
|
|
|
: detect_dlg(nullptr)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
2014-01-30 09:39:40 +00:00
|
|
|
setupUi(this);
|
2014-03-25 21:17:02 +00:00
|
|
|
QRegularExpressionValidator* validator = new QRegularExpressionValidator(QRegularExpression("[0-9\\-+,xX:]*"), this);
|
2013-12-05 19:22:31 +00:00
|
|
|
maxsize->setValidator(validator);
|
|
|
|
minsize->setValidator(validator);
|
|
|
|
position->setValidator(validator);
|
|
|
|
Ui::RulesWidgetBase::size->setValidator(validator);
|
2008-02-03 04:37:34 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
QString enableDesc =
|
2011-01-30 14:34:42 +00:00
|
|
|
i18n("Enable this checkbox to alter this window property for the specified window(s).");
|
2007-04-29 17:35:43 +00:00
|
|
|
QString setRuleDesc =
|
2011-01-30 14:34:42 +00:00
|
|
|
i18n("Specify how the window property should be affected:<ul>"
|
|
|
|
"<li><em>Do Not Affect:</em> The window property will not be affected and therefore"
|
|
|
|
" the default handling for it will be used. Specifying this will block more generic"
|
|
|
|
" window settings from taking effect.</li>"
|
|
|
|
"<li><em>Apply Initially:</em> The window property will be only set to the given value"
|
|
|
|
" after the window is created. No further changes will be affected.</li>"
|
2011-12-08 09:00:14 +00:00
|
|
|
"<li><em>Remember:</em> The value of the window property will be remembered and every"
|
2011-01-30 14:34:42 +00:00
|
|
|
" time the window is created, the last remembered value will be applied.</li>"
|
|
|
|
"<li><em>Force:</em> The window property will be always forced to the given value.</li>"
|
|
|
|
"<li><em>Apply Now:</em> The window property will be set to the given value immediately"
|
|
|
|
" and will not be affected later (this action will be deleted afterwards).</li>"
|
|
|
|
"<li><em>Force temporarily:</em> The window property will be forced to the given value"
|
|
|
|
" until it is hidden (this action will be deleted after the window is hidden).</li>"
|
|
|
|
"</ul>");
|
2007-04-29 17:35:43 +00:00
|
|
|
QString forceRuleDesc =
|
2011-01-30 14:34:42 +00:00
|
|
|
i18n("Specify how the window property should be affected:<ul>"
|
|
|
|
"<li><em>Do Not Affect:</em> The window property will not be affected and therefore"
|
|
|
|
" the default handling for it will be used. Specifying this will block more generic"
|
|
|
|
" window settings from taking effect.</li>"
|
|
|
|
"<li><em>Force:</em> The window property will be always forced to the given value.</li>"
|
|
|
|
"<li><em>Force temporarily:</em> The window property will be forced to the given value"
|
|
|
|
" until it is hidden (this action will be deleted after the window is hidden).</li>"
|
|
|
|
"</ul>");
|
2007-04-29 17:35:43 +00:00
|
|
|
// window tabs have enable signals done in designer
|
|
|
|
// geometry tab
|
2011-01-30 14:34:42 +00:00
|
|
|
SETUP(position, set);
|
|
|
|
SETUP(size, set);
|
|
|
|
SETUP(desktop, set);
|
2012-08-24 16:48:50 +00:00
|
|
|
SETUP(screen, set);
|
2013-04-08 15:42:41 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2012-05-17 14:32:06 +00:00
|
|
|
SETUP(activity, set);
|
2013-04-08 15:42:41 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
SETUP(maximizehoriz, set);
|
|
|
|
SETUP(maximizevert, set);
|
|
|
|
SETUP(minimize, set);
|
|
|
|
SETUP(shade, set);
|
|
|
|
SETUP(fullscreen, set);
|
|
|
|
SETUP(placement, force);
|
2007-04-29 17:35:43 +00:00
|
|
|
// preferences tab
|
2011-01-30 14:34:42 +00:00
|
|
|
SETUP(above, set);
|
|
|
|
SETUP(below, set);
|
|
|
|
SETUP(noborder, set);
|
2013-11-05 12:50:31 +00:00
|
|
|
SETUP(decocolor, force);
|
2011-01-30 14:34:42 +00:00
|
|
|
SETUP(skiptaskbar, set);
|
|
|
|
SETUP(skippager, set);
|
|
|
|
SETUP(skipswitcher, set);
|
|
|
|
SETUP(acceptfocus, force);
|
|
|
|
SETUP(closeable, force);
|
|
|
|
SETUP(autogroup, force);
|
|
|
|
SETUP(autogroupfg, force);
|
|
|
|
SETUP(autogroupid, force);
|
|
|
|
SETUP(opacityactive, force);
|
|
|
|
SETUP(opacityinactive, force);
|
|
|
|
SETUP(shortcut, force);
|
2007-04-29 17:35:43 +00:00
|
|
|
// workarounds tab
|
2011-01-30 14:34:42 +00:00
|
|
|
SETUP(fsplevel, force);
|
2015-11-12 23:37:01 +00:00
|
|
|
SETUP(fpplevel, force);
|
2011-01-30 14:34:42 +00:00
|
|
|
SETUP(type, force);
|
2018-03-11 16:13:32 +00:00
|
|
|
SETUP(desktopfile, set);
|
2013-03-24 18:13:00 +00:00
|
|
|
SETUP(ignoregeometry, set);
|
2011-01-30 14:34:42 +00:00
|
|
|
SETUP(minsize, force);
|
|
|
|
SETUP(maxsize, force);
|
|
|
|
SETUP(strictgeometry, force);
|
|
|
|
SETUP(disableglobalshortcuts, force);
|
2011-03-20 14:42:05 +00:00
|
|
|
SETUP(blockcompositing, force);
|
2011-09-08 20:18:07 +00:00
|
|
|
|
2011-09-30 10:42:56 +00:00
|
|
|
connect (shortcut_edit, SIGNAL(clicked()), SLOT(shortcutEditClicked()));
|
|
|
|
|
|
|
|
edit_reg_wmclass->hide();
|
|
|
|
edit_reg_role->hide();
|
|
|
|
edit_reg_title->hide();
|
|
|
|
edit_reg_machine->hide();
|
2011-09-08 20:18:07 +00:00
|
|
|
|
2013-04-08 15:42:41 +00:00
|
|
|
#ifndef KWIN_BUILD_ACTIVITIES
|
|
|
|
rule_activity->hide();
|
|
|
|
enable_activity->hide();
|
|
|
|
activity->hide();
|
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
int i;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (i = 1;
|
|
|
|
i <= KWindowSystem::numberOfDesktops();
|
|
|
|
++i)
|
|
|
|
desktop->addItem(QString::number(i).rightJustified(2) + ':' + KWindowSystem::desktopName(i));
|
|
|
|
desktop->addItem(i18n("All Desktops"));
|
2012-05-17 14:32:06 +00:00
|
|
|
|
2013-04-08 15:42:41 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2015-06-02 18:04:23 +00:00
|
|
|
m_activities = new KActivities::Consumer(this);
|
|
|
|
connect(m_activities, &KActivities::Consumer::activitiesChanged,
|
|
|
|
this, [this] { updateActivitiesList(); });
|
|
|
|
connect(m_activities, &KActivities::Consumer::serviceStatusChanged,
|
|
|
|
this, [this] { updateActivitiesList(); });
|
|
|
|
updateActivitiesList();
|
2013-04-08 15:42:41 +00:00
|
|
|
#endif
|
2013-11-05 12:50:31 +00:00
|
|
|
|
|
|
|
KColorSchemeManager *schemes = new KColorSchemeManager(this);
|
|
|
|
decocolor->setModel(schemes->model());
|
2016-10-10 06:30:49 +00:00
|
|
|
|
|
|
|
// hide autogrouping as it's currently not supported
|
|
|
|
// BUG 370301
|
|
|
|
line_11->hide();
|
|
|
|
enable_autogroup->hide();
|
|
|
|
autogroup->hide();
|
|
|
|
rule_autogroup->hide();
|
|
|
|
enable_autogroupid->hide();
|
|
|
|
autogroupid->hide();
|
|
|
|
rule_autogroupid->hide();
|
|
|
|
enable_autogroupfg->hide();
|
|
|
|
autogroupfg->hide();
|
|
|
|
rule_autogroupfg->hide();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#undef SETUP
|
|
|
|
|
2011-08-17 21:51:55 +00:00
|
|
|
#define UPDATE_ENABLE_SLOT(var) \
|
2011-01-30 14:34:42 +00:00
|
|
|
void RulesWidget::updateEnable##var() \
|
2007-04-29 17:35:43 +00:00
|
|
|
{ \
|
2011-01-30 14:34:42 +00:00
|
|
|
/* leave the label readable label_##var->setEnabled( enable_##var->isChecked() && rule_##var->currentIndex() != 0 );*/ \
|
|
|
|
Ui::RulesWidgetBase::var->setEnabled( enable_##var->isChecked() && rule_##var->currentIndex() != 0 ); \
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// geometry tab
|
2011-01-30 14:34:42 +00:00
|
|
|
UPDATE_ENABLE_SLOT(position)
|
|
|
|
UPDATE_ENABLE_SLOT(size)
|
|
|
|
UPDATE_ENABLE_SLOT(desktop)
|
2012-08-24 16:48:50 +00:00
|
|
|
UPDATE_ENABLE_SLOT(screen)
|
2013-04-08 15:42:41 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2012-05-17 14:32:06 +00:00
|
|
|
UPDATE_ENABLE_SLOT(activity)
|
2013-04-08 15:42:41 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
UPDATE_ENABLE_SLOT(maximizehoriz)
|
|
|
|
UPDATE_ENABLE_SLOT(maximizevert)
|
|
|
|
UPDATE_ENABLE_SLOT(minimize)
|
|
|
|
UPDATE_ENABLE_SLOT(shade)
|
|
|
|
UPDATE_ENABLE_SLOT(fullscreen)
|
|
|
|
UPDATE_ENABLE_SLOT(placement)
|
2007-04-29 17:35:43 +00:00
|
|
|
// preferences tab
|
2011-01-30 14:34:42 +00:00
|
|
|
UPDATE_ENABLE_SLOT(above)
|
|
|
|
UPDATE_ENABLE_SLOT(below)
|
|
|
|
UPDATE_ENABLE_SLOT(noborder)
|
2013-11-05 12:50:31 +00:00
|
|
|
UPDATE_ENABLE_SLOT(decocolor)
|
2011-01-30 14:34:42 +00:00
|
|
|
UPDATE_ENABLE_SLOT(skiptaskbar)
|
|
|
|
UPDATE_ENABLE_SLOT(skippager)
|
|
|
|
UPDATE_ENABLE_SLOT(skipswitcher)
|
|
|
|
UPDATE_ENABLE_SLOT(acceptfocus)
|
|
|
|
UPDATE_ENABLE_SLOT(closeable)
|
|
|
|
UPDATE_ENABLE_SLOT(autogroup)
|
|
|
|
UPDATE_ENABLE_SLOT(autogroupfg)
|
|
|
|
UPDATE_ENABLE_SLOT(autogroupid)
|
|
|
|
UPDATE_ENABLE_SLOT(opacityactive)
|
|
|
|
UPDATE_ENABLE_SLOT(opacityinactive)
|
2007-04-29 17:35:43 +00:00
|
|
|
void RulesWidget::updateEnableshortcut()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
shortcut->setEnabled(enable_shortcut->isChecked() && rule_shortcut->currentIndex() != 0);
|
|
|
|
shortcut_edit->setEnabled(enable_shortcut->isChecked() && rule_shortcut->currentIndex() != 0);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
// workarounds tab
|
2011-01-30 14:34:42 +00:00
|
|
|
UPDATE_ENABLE_SLOT(fsplevel)
|
2015-11-12 23:37:01 +00:00
|
|
|
UPDATE_ENABLE_SLOT(fpplevel)
|
2011-01-30 14:34:42 +00:00
|
|
|
UPDATE_ENABLE_SLOT(type)
|
2013-03-24 18:13:00 +00:00
|
|
|
UPDATE_ENABLE_SLOT(ignoregeometry)
|
2011-01-30 14:34:42 +00:00
|
|
|
UPDATE_ENABLE_SLOT(minsize)
|
|
|
|
UPDATE_ENABLE_SLOT(maxsize)
|
|
|
|
UPDATE_ENABLE_SLOT(strictgeometry)
|
|
|
|
UPDATE_ENABLE_SLOT(disableglobalshortcuts)
|
2011-03-20 14:42:05 +00:00
|
|
|
UPDATE_ENABLE_SLOT(blockcompositing)
|
2018-03-11 16:13:32 +00:00
|
|
|
UPDATE_ENABLE_SLOT(desktopfile)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#undef UPDATE_ENABLE_SLOT
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const int set_rule_to_combo[] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
0, // Unused
|
|
|
|
0, // Don't Affect
|
|
|
|
3, // Force
|
|
|
|
1, // Apply
|
|
|
|
2, // Remember
|
|
|
|
4, // ApplyNow
|
|
|
|
5 // ForceTemporarily
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Rules::SetRule combo_to_set_rule[] = {
|
|
|
|
(Rules::SetRule)Rules::DontAffect,
|
|
|
|
(Rules::SetRule)Rules::Apply,
|
|
|
|
(Rules::SetRule)Rules::Remember,
|
|
|
|
(Rules::SetRule)Rules::Force,
|
|
|
|
(Rules::SetRule)Rules::ApplyNow,
|
|
|
|
(Rules::SetRule)Rules::ForceTemporarily
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int force_rule_to_combo[] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
0, // Unused
|
|
|
|
0, // Don't Affect
|
|
|
|
1, // Force
|
|
|
|
0, // Apply
|
|
|
|
0, // Remember
|
|
|
|
0, // ApplyNow
|
|
|
|
2 // ForceTemporarily
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const Rules::ForceRule combo_to_force_rule[] = {
|
|
|
|
(Rules::ForceRule)Rules::DontAffect,
|
|
|
|
(Rules::ForceRule)Rules::Force,
|
|
|
|
(Rules::ForceRule)Rules::ForceTemporarily
|
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static QString positionToStr(const QPoint& p)
|
|
|
|
{
|
|
|
|
if (p == invalidPoint)
|
2007-04-29 17:35:43 +00:00
|
|
|
return QString();
|
2011-01-30 14:34:42 +00:00
|
|
|
return QString::number(p.x()) + ',' + QString::number(p.y());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static QPoint strToPosition(const QString& str)
|
|
|
|
{
|
|
|
|
// two numbers, with + or -, separated by any of , x X :
|
|
|
|
QRegExp reg("\\s*([+-]?[0-9]*)\\s*[,xX:]\\s*([+-]?[0-9]*)\\s*");
|
|
|
|
if (!reg.exactMatch(str))
|
2007-04-29 17:35:43 +00:00
|
|
|
return invalidPoint;
|
2011-01-30 14:34:42 +00:00
|
|
|
return QPoint(reg.cap(1).toInt(), reg.cap(2).toInt());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static QString sizeToStr(const QSize& s)
|
|
|
|
{
|
|
|
|
if (!s.isValid())
|
2007-04-29 17:35:43 +00:00
|
|
|
return QString();
|
2011-01-30 14:34:42 +00:00
|
|
|
return QString::number(s.width()) + ',' + QString::number(s.height());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static QSize strToSize(const QString& str)
|
|
|
|
{
|
|
|
|
// two numbers, with + or -, separated by any of , x X :
|
|
|
|
QRegExp reg("\\s*([+-]?[0-9]*)\\s*[,xX:]\\s*([+-]?[0-9]*)\\s*");
|
|
|
|
if (!reg.exactMatch(str))
|
2007-04-29 17:35:43 +00:00
|
|
|
return QSize();
|
2011-01-30 14:34:42 +00:00
|
|
|
return QSize(reg.cap(1).toInt(), reg.cap(2).toInt());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int RulesWidget::desktopToCombo(int d) const
|
|
|
|
{
|
|
|
|
if (d >= 1 && d < desktop->count())
|
2007-04-29 17:35:43 +00:00
|
|
|
return d - 1;
|
|
|
|
return desktop->count() - 1; // on all desktops
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int RulesWidget::comboToDesktop(int val) const
|
|
|
|
{
|
|
|
|
if (val == desktop->count() - 1)
|
2007-04-29 17:35:43 +00:00
|
|
|
return NET::OnAllDesktops;
|
|
|
|
return val + 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2016-09-24 08:36:49 +00:00
|
|
|
|
2013-04-08 15:42:41 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2012-05-17 14:32:06 +00:00
|
|
|
int RulesWidget::activityToCombo(QString d) const
|
|
|
|
{
|
|
|
|
// TODO: ivan - do a multiselection list
|
|
|
|
for (int i = 0; i < activity->count(); i++) {
|
|
|
|
if (activity->itemData(i).toString() == d) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity->count() - 1; // on all activities
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RulesWidget::comboToActivity(int val) const
|
|
|
|
{
|
|
|
|
// TODO: ivan - do a multiselection list
|
|
|
|
if (val < 0 || val >= activity->count())
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
return activity->itemData(val).toString();
|
|
|
|
}
|
2015-06-02 18:04:23 +00:00
|
|
|
|
|
|
|
void RulesWidget::updateActivitiesList()
|
|
|
|
{
|
|
|
|
activity->clear();
|
|
|
|
|
|
|
|
// cloned from kactivities/src/lib/core/consumer.cpp
|
|
|
|
#define NULL_UUID "00000000-0000-0000-0000-000000000000"
|
|
|
|
activity->addItem(i18n("All Activities"), QString::fromLatin1(NULL_UUID));
|
|
|
|
#undef NULL_UUID
|
|
|
|
|
|
|
|
if (m_activities->serviceStatus() == KActivities::Consumer::Running) {
|
|
|
|
foreach (const QString & activityId, m_activities->activities(KActivities::Info::Running)) {
|
|
|
|
const KActivities::Info info(activityId);
|
|
|
|
activity->addItem(info.name(), activityId);
|
|
|
|
}
|
|
|
|
}
|
2016-09-24 08:36:49 +00:00
|
|
|
|
|
|
|
auto rules = this->rules();
|
|
|
|
if (rules->activityrule == Rules::UnusedSetRule) {
|
|
|
|
enable_activity->setChecked(false);
|
|
|
|
Ui::RulesWidgetBase::activity->setCurrentIndex(0);
|
|
|
|
} else {
|
|
|
|
enable_activity->setChecked(true);
|
|
|
|
Ui::RulesWidgetBase::activity->setCurrentIndex(activityToCombo(m_selectedActivityId));
|
|
|
|
}
|
|
|
|
updateEnableactivity();
|
2015-06-02 18:04:23 +00:00
|
|
|
}
|
2013-04-08 15:42:41 +00:00
|
|
|
#endif
|
2016-09-24 08:36:49 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static int placementToCombo(Placement::Policy placement)
|
|
|
|
{
|
|
|
|
static const int conv[] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
1, // NoPlacement
|
|
|
|
0, // Default
|
|
|
|
0, // Unknown
|
|
|
|
6, // Random
|
|
|
|
2, // Smart
|
|
|
|
4, // Cascade
|
|
|
|
5, // Centered
|
|
|
|
7, // ZeroCornered
|
|
|
|
8, // UnderMouse
|
|
|
|
9, // OnMainWindow
|
|
|
|
3 // Maximizing
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
return conv[ placement ];
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static Placement::Policy comboToPlacement(int val)
|
|
|
|
{
|
|
|
|
static const Placement::Policy conv[] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
Placement::Default,
|
|
|
|
Placement::NoPlacement,
|
|
|
|
Placement::Smart,
|
|
|
|
Placement::Maximizing,
|
|
|
|
Placement::Cascade,
|
|
|
|
Placement::Centered,
|
|
|
|
Placement::Random,
|
|
|
|
Placement::ZeroCornered,
|
|
|
|
Placement::UnderMouse,
|
|
|
|
Placement::OnMainWindow
|
|
|
|
// no Placement::Unknown
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
return conv[ val ];
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static int typeToCombo(NET::WindowType type)
|
|
|
|
{
|
2011-04-06 17:52:23 +00:00
|
|
|
if (type < NET::Normal || type > NET::Splash ||
|
|
|
|
type == NET::Override) // The user must NOT set a window to be unmanaged.
|
|
|
|
// This case is not handled in KWin and will lead to segfaults.
|
|
|
|
// Even iff it was supported, it would mean to allow the user to shoot himself
|
|
|
|
// since an unmanaged window has to manage itself, what is probably not the case when the hint is not set.
|
|
|
|
// Rule opportunity might be a relict from the Motif Hint window times of KDE1
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0; // Normal
|
2011-01-30 14:34:42 +00:00
|
|
|
static const int conv[] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
0, // Normal
|
|
|
|
7, // Desktop
|
2011-01-30 14:34:42 +00:00
|
|
|
3, // Dock
|
|
|
|
4, // Toolbar
|
|
|
|
5, // Menu
|
|
|
|
1, // Dialog
|
2011-04-06 17:52:23 +00:00
|
|
|
8, // Override - ignored.
|
2007-04-29 17:35:43 +00:00
|
|
|
9, // TopMenu
|
2011-01-30 14:34:42 +00:00
|
|
|
2, // Utility
|
|
|
|
6 // Splash
|
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
return conv[ type ];
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static NET::WindowType comboToType(int val)
|
|
|
|
{
|
|
|
|
static const NET::WindowType conv[] = {
|
2007-04-29 17:35:43 +00:00
|
|
|
NET::Normal,
|
|
|
|
NET::Dialog,
|
|
|
|
NET::Utility,
|
|
|
|
NET::Dock,
|
|
|
|
NET::Toolbar,
|
|
|
|
NET::Menu,
|
|
|
|
NET::Splash,
|
|
|
|
NET::Desktop,
|
|
|
|
NET::TopMenu
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
return conv[ val ];
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define GENERIC_RULE( var, func, Type, type, uimethod, uimethod0 ) \
|
2011-01-30 14:34:42 +00:00
|
|
|
if ( rules->var##rule == Rules::Unused##Type##Rule ) \
|
|
|
|
{ \
|
2007-04-29 17:35:43 +00:00
|
|
|
enable_##var->setChecked( false ); \
|
|
|
|
rule_##var->setCurrentIndex( 0 ); \
|
2008-02-03 04:37:34 +00:00
|
|
|
Ui::RulesWidgetBase::var->uimethod0; \
|
2007-04-29 17:35:43 +00:00
|
|
|
updateEnable##var(); \
|
2011-01-30 14:34:42 +00:00
|
|
|
} \
|
2007-04-29 17:35:43 +00:00
|
|
|
else \
|
2011-01-30 14:34:42 +00:00
|
|
|
{ \
|
2007-04-29 17:35:43 +00:00
|
|
|
enable_##var->setChecked( true ); \
|
|
|
|
rule_##var->setCurrentIndex( type##_rule_to_combo[ rules->var##rule ] ); \
|
2008-02-03 04:37:34 +00:00
|
|
|
Ui::RulesWidgetBase::var->uimethod( func( rules->var )); \
|
2007-04-29 17:35:43 +00:00
|
|
|
updateEnable##var(); \
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define CHECKBOX_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, setChecked, setChecked( false ))
|
2013-12-05 19:22:31 +00:00
|
|
|
#define LINEEDIT_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, setText, setText( QString() ))
|
2007-04-29 17:35:43 +00:00
|
|
|
#define COMBOBOX_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, setCurrentIndex, setCurrentIndex( 0 ))
|
2012-08-24 16:48:50 +00:00
|
|
|
#define SPINBOX_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, setValue, setValue(0))
|
2007-04-29 17:35:43 +00:00
|
|
|
#define CHECKBOX_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, setChecked, setChecked( false ))
|
2013-12-05 19:22:31 +00:00
|
|
|
#define LINEEDIT_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, setText, setText( QString() ))
|
2007-04-29 17:35:43 +00:00
|
|
|
#define COMBOBOX_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, setCurrentIndex, setCurrentIndex( 0 ))
|
2011-04-06 17:52:23 +00:00
|
|
|
#define SPINBOX_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, setValue, setValue(0))
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void RulesWidget::setRules(Rules* rules)
|
|
|
|
{
|
2011-09-29 14:19:47 +00:00
|
|
|
Rules tmp;
|
2014-01-07 10:22:24 +00:00
|
|
|
if (rules == nullptr)
|
2011-09-29 14:20:46 +00:00
|
|
|
rules = &tmp; // empty
|
2011-01-30 14:34:42 +00:00
|
|
|
description->setText(rules->description);
|
|
|
|
wmclass->setText(rules->wmclass);
|
|
|
|
whole_wmclass->setChecked(rules->wmclasscomplete);
|
|
|
|
wmclass_match->setCurrentIndex(rules->wmclassmatch);
|
2007-04-29 17:35:43 +00:00
|
|
|
wmclassMatchChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
role->setText(rules->windowrole);
|
|
|
|
role_match->setCurrentIndex(rules->windowrolematch);
|
2007-04-29 17:35:43 +00:00
|
|
|
roleMatchChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
types->item(0)->setSelected(rules->types & NET::NormalMask);
|
|
|
|
types->item(1)->setSelected(rules->types & NET::DialogMask);
|
|
|
|
types->item(2)->setSelected(rules->types & NET::UtilityMask);
|
|
|
|
types->item(3)->setSelected(rules->types & NET::DockMask);
|
|
|
|
types->item(4)->setSelected(rules->types & NET::ToolbarMask);
|
|
|
|
types->item(5)->setSelected(rules->types & NET::MenuMask);
|
|
|
|
types->item(6)->setSelected(rules->types & NET::SplashMask);
|
|
|
|
types->item(7)->setSelected(rules->types & NET::DesktopMask);
|
|
|
|
types->item(8)->setSelected(rules->types & NET::OverrideMask);
|
|
|
|
types->item(9)->setSelected(rules->types & NET::TopMenuMask);
|
|
|
|
title->setText(rules->title);
|
|
|
|
title_match->setCurrentIndex(rules->titlematch);
|
2007-04-29 17:35:43 +00:00
|
|
|
titleMatchChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
machine->setText(rules->clientmachine);
|
|
|
|
machine_match->setCurrentIndex(rules->clientmachinematch);
|
2007-04-29 17:35:43 +00:00
|
|
|
machineMatchChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
LINEEDIT_SET_RULE(position, positionToStr);
|
|
|
|
LINEEDIT_SET_RULE(size, sizeToStr);
|
|
|
|
COMBOBOX_SET_RULE(desktop, desktopToCombo);
|
2012-08-24 16:48:50 +00:00
|
|
|
SPINBOX_SET_RULE(screen, inc);
|
2013-04-08 15:42:41 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2016-09-24 08:36:49 +00:00
|
|
|
m_selectedActivityId = rules->activity;
|
2012-05-17 14:32:06 +00:00
|
|
|
COMBOBOX_SET_RULE(activity, activityToCombo);
|
2013-04-08 15:42:41 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
CHECKBOX_SET_RULE(maximizehoriz,);
|
|
|
|
CHECKBOX_SET_RULE(maximizevert,);
|
|
|
|
CHECKBOX_SET_RULE(minimize,);
|
|
|
|
CHECKBOX_SET_RULE(shade,);
|
|
|
|
CHECKBOX_SET_RULE(fullscreen,);
|
|
|
|
COMBOBOX_FORCE_RULE(placement, placementToCombo);
|
|
|
|
CHECKBOX_SET_RULE(above,);
|
|
|
|
CHECKBOX_SET_RULE(below,);
|
|
|
|
CHECKBOX_SET_RULE(noborder,);
|
2013-11-05 12:50:31 +00:00
|
|
|
auto decoColorToCombo = [this](const QString &value) {
|
|
|
|
for (int i = 0; i < decocolor->count(); ++i) {
|
|
|
|
if (decocolor->itemData(i).toString() == value) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 08:33:40 +00:00
|
|
|
// search for Breeze
|
2013-11-05 12:50:31 +00:00
|
|
|
for (int i = 0; i < decocolor->count(); ++i) {
|
2016-05-12 08:33:40 +00:00
|
|
|
if (QFileInfo(decocolor->itemData(i).toString()).baseName() == QStringLiteral("Breeze")) {
|
2013-11-05 12:50:31 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
COMBOBOX_FORCE_RULE(decocolor, decoColorToCombo);
|
2011-01-30 14:34:42 +00:00
|
|
|
CHECKBOX_SET_RULE(skiptaskbar,);
|
|
|
|
CHECKBOX_SET_RULE(skippager,);
|
|
|
|
CHECKBOX_SET_RULE(skipswitcher,);
|
|
|
|
CHECKBOX_FORCE_RULE(acceptfocus,);
|
|
|
|
CHECKBOX_FORCE_RULE(closeable,);
|
|
|
|
CHECKBOX_FORCE_RULE(autogroup,);
|
|
|
|
CHECKBOX_FORCE_RULE(autogroupfg,);
|
|
|
|
LINEEDIT_FORCE_RULE(autogroupid,);
|
2011-04-06 17:52:23 +00:00
|
|
|
SPINBOX_FORCE_RULE(opacityactive,);
|
|
|
|
SPINBOX_FORCE_RULE(opacityinactive,);
|
2011-01-30 14:34:42 +00:00
|
|
|
LINEEDIT_SET_RULE(shortcut,);
|
|
|
|
COMBOBOX_FORCE_RULE(fsplevel,);
|
2015-11-12 23:37:01 +00:00
|
|
|
COMBOBOX_FORCE_RULE(fpplevel,);
|
2011-01-30 14:34:42 +00:00
|
|
|
COMBOBOX_FORCE_RULE(type, typeToCombo);
|
2013-03-24 18:13:00 +00:00
|
|
|
CHECKBOX_SET_RULE(ignoregeometry,);
|
2011-01-30 14:34:42 +00:00
|
|
|
LINEEDIT_FORCE_RULE(minsize, sizeToStr);
|
|
|
|
LINEEDIT_FORCE_RULE(maxsize, sizeToStr);
|
|
|
|
CHECKBOX_FORCE_RULE(strictgeometry,);
|
|
|
|
CHECKBOX_FORCE_RULE(disableglobalshortcuts,);
|
2011-03-20 14:42:05 +00:00
|
|
|
CHECKBOX_FORCE_RULE(blockcompositing,);
|
2018-03-11 16:13:32 +00:00
|
|
|
LINEEDIT_SET_RULE(desktopfile,)
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#undef GENERIC_RULE
|
|
|
|
#undef CHECKBOX_SET_RULE
|
|
|
|
#undef LINEEDIT_SET_RULE
|
|
|
|
#undef COMBOBOX_SET_RULE
|
2012-08-24 16:48:50 +00:00
|
|
|
#undef SPINBOX_SET_RULE
|
2007-04-29 17:35:43 +00:00
|
|
|
#undef CHECKBOX_FORCE_RULE
|
|
|
|
#undef LINEEDIT_FORCE_RULE
|
|
|
|
#undef COMBOBOX_FORCE_RULE
|
2011-04-06 17:52:23 +00:00
|
|
|
#undef SPINBOX_FORCE_RULE
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define GENERIC_RULE( var, func, Type, type, uimethod ) \
|
2011-01-30 14:34:42 +00:00
|
|
|
if ( enable_##var->isChecked() && rule_##var->currentIndex() >= 0) \
|
|
|
|
{ \
|
2007-04-29 17:35:43 +00:00
|
|
|
rules->var##rule = combo_to_##type##_rule[ rule_##var->currentIndex() ]; \
|
2008-02-03 04:37:34 +00:00
|
|
|
rules->var = func( Ui::RulesWidgetBase::var->uimethod()); \
|
2011-01-30 14:34:42 +00:00
|
|
|
} \
|
2007-04-29 17:35:43 +00:00
|
|
|
else \
|
|
|
|
rules->var##rule = Rules::Unused##Type##Rule;
|
|
|
|
|
|
|
|
#define CHECKBOX_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, isChecked )
|
|
|
|
#define LINEEDIT_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, text )
|
|
|
|
#define COMBOBOX_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, currentIndex )
|
2012-08-24 16:48:50 +00:00
|
|
|
#define SPINBOX_SET_RULE( var, func ) GENERIC_RULE( var, func, Set, set, value)
|
2007-04-29 17:35:43 +00:00
|
|
|
#define CHECKBOX_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, isChecked )
|
|
|
|
#define LINEEDIT_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, text )
|
|
|
|
#define COMBOBOX_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, currentIndex )
|
2011-04-06 17:52:23 +00:00
|
|
|
#define SPINBOX_FORCE_RULE( var, func ) GENERIC_RULE( var, func, Force, force, value)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Rules* RulesWidget::rules() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
Rules* rules = new Rules();
|
|
|
|
rules->description = description->text();
|
|
|
|
rules->wmclass = wmclass->text().toUtf8();
|
|
|
|
rules->wmclasscomplete = whole_wmclass->isChecked();
|
2011-01-30 14:34:42 +00:00
|
|
|
rules->wmclassmatch = static_cast< Rules::StringMatch >(wmclass_match->currentIndex());
|
2007-04-29 17:35:43 +00:00
|
|
|
rules->windowrole = role->text().toUtf8();
|
2011-01-30 14:34:42 +00:00
|
|
|
rules->windowrolematch = static_cast< Rules::StringMatch >(role_match->currentIndex());
|
2007-04-29 17:35:43 +00:00
|
|
|
rules->types = 0;
|
|
|
|
bool all_types = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < types->count();
|
|
|
|
++i)
|
|
|
|
if (!types->item(i)->isSelected())
|
2007-04-29 17:35:43 +00:00
|
|
|
all_types = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (all_types) // if all types are selected, use AllTypesMask (for future expansion)
|
2007-04-29 17:35:43 +00:00
|
|
|
rules->types = NET::AllTypesMask;
|
2011-01-30 14:34:42 +00:00
|
|
|
else {
|
2014-02-03 08:37:08 +00:00
|
|
|
rules->types |= types->item(0)->isSelected() ? NET::NormalMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(1)->isSelected() ? NET::DialogMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(2)->isSelected() ? NET::UtilityMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(3)->isSelected() ? NET::DockMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(4)->isSelected() ? NET::ToolbarMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(5)->isSelected() ? NET::MenuMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(6)->isSelected() ? NET::SplashMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(7)->isSelected() ? NET::DesktopMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(8)->isSelected() ? NET::OverrideMask : NET::WindowTypeMask(0);
|
|
|
|
rules->types |= types->item(9)->isSelected() ? NET::TopMenuMask : NET::WindowTypeMask(0);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
rules->title = title->text();
|
2011-01-30 14:34:42 +00:00
|
|
|
rules->titlematch = static_cast< Rules::StringMatch >(title_match->currentIndex());
|
2007-04-29 17:35:43 +00:00
|
|
|
rules->clientmachine = machine->text().toUtf8();
|
2011-01-30 14:34:42 +00:00
|
|
|
rules->clientmachinematch = static_cast< Rules::StringMatch >(machine_match->currentIndex());
|
|
|
|
LINEEDIT_SET_RULE(position, strToPosition);
|
|
|
|
LINEEDIT_SET_RULE(size, strToSize);
|
|
|
|
COMBOBOX_SET_RULE(desktop, comboToDesktop);
|
2012-08-24 16:48:50 +00:00
|
|
|
SPINBOX_SET_RULE(screen, dec);
|
2013-04-08 15:42:41 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2012-05-17 14:32:06 +00:00
|
|
|
COMBOBOX_SET_RULE(activity, comboToActivity);
|
2013-04-08 15:42:41 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
CHECKBOX_SET_RULE(maximizehoriz,);
|
|
|
|
CHECKBOX_SET_RULE(maximizevert,);
|
|
|
|
CHECKBOX_SET_RULE(minimize,);
|
|
|
|
CHECKBOX_SET_RULE(shade,);
|
|
|
|
CHECKBOX_SET_RULE(fullscreen,);
|
|
|
|
COMBOBOX_FORCE_RULE(placement, comboToPlacement);
|
|
|
|
CHECKBOX_SET_RULE(above,);
|
|
|
|
CHECKBOX_SET_RULE(below,);
|
|
|
|
CHECKBOX_SET_RULE(noborder,);
|
2013-11-05 12:50:31 +00:00
|
|
|
auto comboToDecocolor = [this](int index) -> QString {
|
|
|
|
return QFileInfo(decocolor->itemData(index).toString()).baseName();
|
|
|
|
};
|
|
|
|
COMBOBOX_FORCE_RULE(decocolor, comboToDecocolor);
|
2011-01-30 14:34:42 +00:00
|
|
|
CHECKBOX_SET_RULE(skiptaskbar,);
|
|
|
|
CHECKBOX_SET_RULE(skippager,);
|
|
|
|
CHECKBOX_SET_RULE(skipswitcher,);
|
|
|
|
CHECKBOX_FORCE_RULE(acceptfocus,);
|
|
|
|
CHECKBOX_FORCE_RULE(closeable,);
|
|
|
|
CHECKBOX_FORCE_RULE(autogroup,);
|
|
|
|
CHECKBOX_FORCE_RULE(autogroupfg,);
|
|
|
|
LINEEDIT_FORCE_RULE(autogroupid,);
|
2011-04-06 17:52:23 +00:00
|
|
|
SPINBOX_FORCE_RULE(opacityactive,);
|
|
|
|
SPINBOX_FORCE_RULE(opacityinactive,);
|
2011-01-30 14:34:42 +00:00
|
|
|
LINEEDIT_SET_RULE(shortcut,);
|
|
|
|
COMBOBOX_FORCE_RULE(fsplevel,);
|
2015-11-12 23:37:01 +00:00
|
|
|
COMBOBOX_FORCE_RULE(fpplevel,);
|
2011-01-30 14:34:42 +00:00
|
|
|
COMBOBOX_FORCE_RULE(type, comboToType);
|
2013-03-24 18:13:00 +00:00
|
|
|
CHECKBOX_SET_RULE(ignoregeometry,);
|
2011-01-30 14:34:42 +00:00
|
|
|
LINEEDIT_FORCE_RULE(minsize, strToSize);
|
|
|
|
LINEEDIT_FORCE_RULE(maxsize, strToSize);
|
|
|
|
CHECKBOX_FORCE_RULE(strictgeometry,);
|
|
|
|
CHECKBOX_FORCE_RULE(disableglobalshortcuts,);
|
2011-03-20 14:42:05 +00:00
|
|
|
CHECKBOX_FORCE_RULE(blockcompositing,);
|
2018-03-11 16:13:32 +00:00
|
|
|
LINEEDIT_SET_RULE(desktopfile,);
|
2007-04-29 17:35:43 +00:00
|
|
|
return rules;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#undef GENERIC_RULE
|
|
|
|
#undef CHECKBOX_SET_RULE
|
|
|
|
#undef LINEEDIT_SET_RULE
|
|
|
|
#undef COMBOBOX_SET_RULE
|
2012-08-24 16:48:50 +00:00
|
|
|
#undef SPINBOX_SET_RULE
|
2007-04-29 17:35:43 +00:00
|
|
|
#undef CHECKBOX_FORCE_RULE
|
|
|
|
#undef LINEEDIT_FORCE_RULE
|
|
|
|
#undef COMBOBOX_FORCE_RULE
|
2011-04-06 17:52:23 +00:00
|
|
|
#undef SPINBOX_FORCE_RULE
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define STRING_MATCH_COMBO( type ) \
|
2011-01-30 14:34:42 +00:00
|
|
|
void RulesWidget::type##MatchChanged() \
|
2007-04-29 17:35:43 +00:00
|
|
|
{ \
|
2011-01-30 14:34:42 +00:00
|
|
|
edit_reg_##type->setEnabled( type##_match->currentIndex() == Rules::RegExpMatch ); \
|
|
|
|
type->setEnabled( type##_match->currentIndex() != Rules::UnimportantMatch ); \
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
STRING_MATCH_COMBO(wmclass)
|
|
|
|
STRING_MATCH_COMBO(role)
|
|
|
|
STRING_MATCH_COMBO(title)
|
|
|
|
STRING_MATCH_COMBO(machine)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#undef STRING_MATCH_COMBO
|
|
|
|
|
|
|
|
void RulesWidget::detectClicked()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-01-07 10:22:24 +00:00
|
|
|
assert(detect_dlg == nullptr);
|
2007-04-29 17:35:43 +00:00
|
|
|
detect_dlg = new DetectDialog;
|
2011-01-30 14:34:42 +00:00
|
|
|
connect(detect_dlg, SIGNAL(detectionDone(bool)), this, SLOT(detected(bool)));
|
2018-02-12 20:40:05 +00:00
|
|
|
detect_dlg->detect(Ui::RulesWidgetBase::detection_delay->value());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void RulesWidget::detected(bool ok)
|
|
|
|
{
|
|
|
|
if (ok) {
|
|
|
|
wmclass->setText(detect_dlg->selectedClass());
|
|
|
|
wmclass_match->setCurrentIndex(Rules::ExactMatch);
|
2007-04-29 17:35:43 +00:00
|
|
|
wmclassMatchChanged(); // grrr
|
2011-01-30 14:34:42 +00:00
|
|
|
whole_wmclass->setChecked(detect_dlg->selectedWholeClass());
|
|
|
|
role->setText(detect_dlg->selectedRole());
|
|
|
|
role_match->setCurrentIndex(detect_dlg->selectedRole().isEmpty()
|
|
|
|
? Rules::UnimportantMatch : Rules::ExactMatch);
|
2007-04-29 17:35:43 +00:00
|
|
|
roleMatchChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (detect_dlg->selectedWholeApp()) {
|
|
|
|
for (int i = 0;
|
|
|
|
i < types->count();
|
|
|
|
++i)
|
|
|
|
types->item(i)->setSelected(true);
|
|
|
|
} else {
|
2007-04-29 17:35:43 +00:00
|
|
|
NET::WindowType type = detect_dlg->selectedType();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < types->count();
|
|
|
|
++i)
|
|
|
|
types->item(i)->setSelected(false);
|
|
|
|
types->item(typeToCombo(type))->setSelected(true);
|
|
|
|
}
|
|
|
|
title->setText(detect_dlg->selectedTitle());
|
|
|
|
title_match->setCurrentIndex(detect_dlg->titleMatch());
|
2007-04-29 17:35:43 +00:00
|
|
|
titleMatchChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
machine->setText(detect_dlg->selectedMachine());
|
|
|
|
machine_match->setCurrentIndex(Rules::UnimportantMatch);
|
2007-04-29 17:35:43 +00:00
|
|
|
machineMatchChanged();
|
|
|
|
// prefill values from to window to settings which already set
|
2018-02-12 20:40:05 +00:00
|
|
|
prefillUnusedValues(detect_dlg->windowInfo());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
delete detect_dlg;
|
2014-01-07 10:22:24 +00:00
|
|
|
detect_dlg = nullptr;
|
2007-04-29 17:35:43 +00:00
|
|
|
detect_dlg_ok = ok;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define GENERIC_PREFILL( var, func, info, uimethod ) \
|
2011-01-30 14:34:42 +00:00
|
|
|
if ( !enable_##var->isChecked()) \
|
|
|
|
{ \
|
2008-02-03 04:37:34 +00:00
|
|
|
Ui::RulesWidgetBase::var->uimethod( func( info )); \
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define CHECKBOX_PREFILL( var, func, info ) GENERIC_PREFILL( var, func, info, setChecked )
|
|
|
|
#define LINEEDIT_PREFILL( var, func, info ) GENERIC_PREFILL( var, func, info, setText )
|
|
|
|
#define COMBOBOX_PREFILL( var, func, info ) GENERIC_PREFILL( var, func, info, setCurrentIndex )
|
2011-04-06 17:52:23 +00:00
|
|
|
#define SPINBOX_PREFILL( var, func, info ) GENERIC_PREFILL( var, func, info, setValue )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void RulesWidget::prefillUnusedValues(const KWindowInfo& info)
|
|
|
|
{
|
|
|
|
LINEEDIT_PREFILL(position, positionToStr, info.frameGeometry().topLeft());
|
|
|
|
LINEEDIT_PREFILL(size, sizeToStr, info.frameGeometry().size());
|
|
|
|
COMBOBOX_PREFILL(desktop, desktopToCombo, info.desktop());
|
2012-05-17 14:32:06 +00:00
|
|
|
// COMBOBOX_PREFILL(activity, activityToCombo, info.activity()); // TODO: ivan
|
2011-01-30 14:34:42 +00:00
|
|
|
CHECKBOX_PREFILL(maximizehoriz, , info.state() & NET::MaxHoriz);
|
|
|
|
CHECKBOX_PREFILL(maximizevert, , info.state() & NET::MaxVert);
|
|
|
|
CHECKBOX_PREFILL(minimize, , info.isMinimized());
|
|
|
|
CHECKBOX_PREFILL(shade, , info.state() & NET::Shaded);
|
|
|
|
CHECKBOX_PREFILL(fullscreen, , info.state() & NET::FullScreen);
|
2007-04-29 17:35:43 +00:00
|
|
|
//COMBOBOX_PREFILL( placement, placementToCombo );
|
2011-01-30 14:34:42 +00:00
|
|
|
CHECKBOX_PREFILL(above, , info.state() & NET::KeepAbove);
|
|
|
|
CHECKBOX_PREFILL(below, , info.state() & NET::KeepBelow);
|
2007-04-29 17:35:43 +00:00
|
|
|
// noborder is only internal KWin information, so let's guess
|
2011-01-30 14:34:42 +00:00
|
|
|
CHECKBOX_PREFILL(noborder, , info.frameGeometry() == info.geometry());
|
|
|
|
CHECKBOX_PREFILL(skiptaskbar, , info.state() & NET::SkipTaskbar);
|
|
|
|
CHECKBOX_PREFILL(skippager, , info.state() & NET::SkipPager);
|
2018-05-24 04:33:39 +00:00
|
|
|
CHECKBOX_PREFILL(skipswitcher, , info.state() & NET::SkipSwitcher);
|
2007-04-29 17:35:43 +00:00
|
|
|
//CHECKBOX_PREFILL( acceptfocus, );
|
|
|
|
//CHECKBOX_PREFILL( closeable, );
|
2009-11-16 11:26:37 +00:00
|
|
|
//CHECKBOX_PREFILL( autogroup, );
|
2009-11-17 10:41:32 +00:00
|
|
|
//CHECKBOX_PREFILL( autogroupfg, );
|
2009-11-16 13:31:02 +00:00
|
|
|
//LINEEDIT_PREFILL( autogroupid, );
|
2011-04-06 17:52:23 +00:00
|
|
|
SPINBOX_PREFILL(opacityactive, , 100 /*get the actual opacity somehow*/);
|
|
|
|
SPINBOX_PREFILL(opacityinactive, , 100 /*get the actual opacity somehow*/);
|
2007-04-29 17:35:43 +00:00
|
|
|
//LINEEDIT_PREFILL( shortcut, );
|
|
|
|
//COMBOBOX_PREFILL( fsplevel, );
|
2015-11-12 23:37:01 +00:00
|
|
|
//COMBOBOX_PREFILL( fpplevel, );
|
2011-01-30 14:34:42 +00:00
|
|
|
COMBOBOX_PREFILL(type, typeToCombo, info.windowType(SUPPORTED_MANAGED_WINDOW_TYPES_MASK));
|
2013-03-24 18:13:00 +00:00
|
|
|
//CHECKBOX_PREFILL( ignoregeometry, );
|
2011-01-30 14:34:42 +00:00
|
|
|
LINEEDIT_PREFILL(minsize, sizeToStr, info.frameGeometry().size());
|
|
|
|
LINEEDIT_PREFILL(maxsize, sizeToStr, info.frameGeometry().size());
|
2007-04-29 17:35:43 +00:00
|
|
|
//CHECKBOX_PREFILL( strictgeometry, );
|
|
|
|
//CHECKBOX_PREFILL( disableglobalshortcuts, );
|
2011-03-20 14:42:05 +00:00
|
|
|
//CHECKBOX_PREFILL( blockcompositing, );
|
2018-03-11 16:13:32 +00:00
|
|
|
LINEEDIT_PREFILL(desktopfile, , info.desktopFileName());
|
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 RulesWidget::prefillUnusedValues(const QVariantMap& info)
|
|
|
|
{
|
|
|
|
const QSize windowSize{info.value("width").toInt(), info.value("height").toInt()};
|
|
|
|
LINEEDIT_PREFILL(position, positionToStr, QPoint(info.value("x").toInt(), info.value("y").toInt()));
|
|
|
|
LINEEDIT_PREFILL(size, sizeToStr, windowSize);
|
|
|
|
COMBOBOX_PREFILL(desktop, desktopToCombo, info.value("x11DesktopNumber").toInt());
|
|
|
|
// COMBOBOX_PREFILL(activity, activityToCombo, info.activity()); // TODO: ivan
|
|
|
|
CHECKBOX_PREFILL(maximizehoriz, , info.value("maximizeHorizontal").toBool());
|
|
|
|
CHECKBOX_PREFILL(maximizevert, , info.value("maximizeVertical").toBool());
|
|
|
|
CHECKBOX_PREFILL(minimize, , info.value("minimized").toBool());
|
|
|
|
CHECKBOX_PREFILL(shade, , info.value("shaded").toBool());
|
|
|
|
CHECKBOX_PREFILL(fullscreen, , info.value("fullscreen").toBool());
|
|
|
|
//COMBOBOX_PREFILL( placement, placementToCombo );
|
|
|
|
CHECKBOX_PREFILL(above, , info.value("keepAbove").toBool());
|
|
|
|
CHECKBOX_PREFILL(below, , info.value("keepBelow").toBool());
|
|
|
|
CHECKBOX_PREFILL(noborder, , info.value("noBorder").toBool());
|
|
|
|
CHECKBOX_PREFILL(skiptaskbar, , info.value("skipTaskbar").toBool());
|
|
|
|
CHECKBOX_PREFILL(skippager, , info.value("skipPager").toBool());
|
|
|
|
CHECKBOX_PREFILL(skipswitcher, , info.value("skipSwitcher").toBool());
|
|
|
|
//CHECKBOX_PREFILL( acceptfocus, );
|
|
|
|
//CHECKBOX_PREFILL( closeable, );
|
|
|
|
//CHECKBOX_PREFILL( autogroup, );
|
|
|
|
//CHECKBOX_PREFILL( autogroupfg, );
|
|
|
|
//LINEEDIT_PREFILL( autogroupid, );
|
|
|
|
SPINBOX_PREFILL(opacityactive, , 100 /*get the actual opacity somehow*/);
|
|
|
|
SPINBOX_PREFILL(opacityinactive, , 100 /*get the actual opacity somehow*/);
|
|
|
|
//LINEEDIT_PREFILL( shortcut, );
|
|
|
|
//COMBOBOX_PREFILL( fsplevel, );
|
|
|
|
//COMBOBOX_PREFILL( fpplevel, );
|
|
|
|
COMBOBOX_PREFILL(type, typeToCombo, info.value("type").value<NET::WindowType>());
|
|
|
|
//CHECKBOX_PREFILL( ignoregeometry, );
|
|
|
|
LINEEDIT_PREFILL(minsize, sizeToStr, windowSize);
|
|
|
|
LINEEDIT_PREFILL(maxsize, sizeToStr, windowSize);
|
|
|
|
//CHECKBOX_PREFILL( strictgeometry, );
|
|
|
|
//CHECKBOX_PREFILL( disableglobalshortcuts, );
|
|
|
|
//CHECKBOX_PREFILL( blockcompositing, );
|
2018-03-11 16:13:32 +00:00
|
|
|
LINEEDIT_PREFILL(desktopfile, , info.value("desktopFile").toString());
|
2018-02-12 20:40:05 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#undef GENERIC_PREFILL
|
|
|
|
#undef CHECKBOX_PREFILL
|
|
|
|
#undef LINEEDIT_PREFILL
|
|
|
|
#undef COMBOBOX_PREFILL
|
2011-04-06 17:52:23 +00:00
|
|
|
#undef SPINBOX_PREFILL
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool RulesWidget::finalCheck()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (description->text().isEmpty()) {
|
|
|
|
if (!wmclass->text().isEmpty())
|
|
|
|
description->setText(i18n("Settings for %1", wmclass->text()));
|
2007-04-29 17:35:43 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
description->setText(i18n("Unnamed entry"));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
bool all_types = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < types->count();
|
|
|
|
++i)
|
|
|
|
if (!types->item(i)->isSelected())
|
2007-04-29 17:35:43 +00:00
|
|
|
all_types = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wmclass_match->currentIndex() == Rules::UnimportantMatch && all_types) {
|
|
|
|
if (KMessageBox::warningContinueCancel(window(),
|
|
|
|
i18n("You have specified the window class as unimportant.\n"
|
|
|
|
"This means the settings will possibly apply to windows from all applications. "
|
|
|
|
"If you really want to create a generic setting, it is recommended you at least "
|
|
|
|
"limit the window types to avoid special window types.")) != KMessageBox::Continue)
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void RulesWidget::prepareWindowSpecific(WId window)
|
|
|
|
{
|
2018-02-12 20:40:05 +00:00
|
|
|
// TODO: adjust for Wayland
|
2013-04-16 17:05:13 +00:00
|
|
|
tabs->setCurrentIndex(1); // geometry tab, skip tab for window identification
|
2014-02-03 08:37:08 +00:00
|
|
|
KWindowInfo info(window, NET::WMAllProperties, NET::WM2AllProperties); // read everything
|
2011-01-30 14:34:42 +00:00
|
|
|
prefillUnusedValues(info);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void RulesWidget::shortcutEditClicked()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
QPointer<EditShortcutDialog> dlg = new EditShortcutDialog(window());
|
|
|
|
dlg->setShortcut(shortcut->text());
|
|
|
|
if (dlg->exec() == QDialog::Accepted)
|
|
|
|
shortcut->setText(dlg->shortcut());
|
2009-12-17 21:04:32 +00:00
|
|
|
delete dlg;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
RulesDialog::RulesDialog(QWidget* parent, const char* name)
|
2013-12-05 19:22:31 +00:00
|
|
|
: QDialog(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
setModal(true);
|
2013-12-05 19:22:31 +00:00
|
|
|
setWindowTitle(i18n("Edit Window-Specific Settings"));
|
2013-09-30 06:44:57 +00:00
|
|
|
setWindowIcon(QIcon::fromTheme("preferences-system-windows-actions"));
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2013-12-05 19:22:31 +00:00
|
|
|
setLayout(new QVBoxLayout);
|
2011-01-30 14:34:42 +00:00
|
|
|
widget = new RulesWidget(this);
|
2013-12-05 19:22:31 +00:00
|
|
|
layout()->addWidget(widget);
|
|
|
|
|
|
|
|
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
|
|
|
connect(buttons, SIGNAL(accepted()), SLOT(accept()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), SLOT(reject()));
|
|
|
|
layout()->addWidget(buttons);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// window is set only for Alt+F3/Window-specific settings, because the dialog
|
|
|
|
// is then related to one specific window
|
2011-01-30 14:34:42 +00:00
|
|
|
Rules* RulesDialog::edit(Rules* r, WId window, bool show_hints)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
rules = r;
|
2011-01-30 14:34:42 +00:00
|
|
|
widget->setRules(rules);
|
|
|
|
if (window != 0)
|
|
|
|
widget->prepareWindowSpecific(window);
|
|
|
|
if (show_hints)
|
|
|
|
QTimer::singleShot(0, this, SLOT(displayHints()));
|
2007-04-29 17:35:43 +00:00
|
|
|
exec();
|
|
|
|
return rules;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void RulesDialog::displayHints()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
QString str = "<qt><p>";
|
2011-01-30 14:34:42 +00:00
|
|
|
str += i18n("This configuration dialog allows altering settings only for the selected window"
|
|
|
|
" or application. Find the setting you want to affect, enable the setting using the checkbox,"
|
|
|
|
" select in what way the setting should be affected and to which value.");
|
2007-04-29 17:35:43 +00:00
|
|
|
#if 0 // maybe later
|
2011-01-30 14:34:42 +00:00
|
|
|
str += "</p><p>" + i18n("Consult the documentation for more details.");
|
2007-04-29 17:35:43 +00:00
|
|
|
#endif
|
|
|
|
str += "</p></qt>";
|
2011-01-30 14:34:42 +00:00
|
|
|
KMessageBox::information(this, str, QString(), "displayhints");
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void RulesDialog::accept()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!widget->finalCheck())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
rules = widget->rules();
|
2013-12-05 19:22:31 +00:00
|
|
|
QDialog::accept();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
EditShortcut::EditShortcut(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void EditShortcut::editShortcut()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
QPointer< ShortcutDialog > dlg = new ShortcutDialog(QKeySequence(shortcut->text()), window());
|
|
|
|
if (dlg->exec() == QDialog::Accepted)
|
|
|
|
shortcut->setText(dlg->shortcut().toString());
|
2009-12-17 21:04:32 +00:00
|
|
|
delete dlg;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void EditShortcut::clearShortcut()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-12-05 19:22:31 +00:00
|
|
|
shortcut->clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
EditShortcutDialog::EditShortcutDialog(QWidget* parent, const char* name)
|
2013-12-05 19:22:31 +00:00
|
|
|
: QDialog(parent)
|
|
|
|
, widget(new EditShortcut(this))
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
setModal(true);
|
2013-12-05 19:22:31 +00:00
|
|
|
setWindowTitle(i18n("Edit Shortcut"));
|
|
|
|
|
|
|
|
setLayout(new QVBoxLayout);
|
|
|
|
|
|
|
|
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
|
|
|
connect(buttons, SIGNAL(accepted()), SLOT(accept()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), SLOT(reject()));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-12-05 19:22:31 +00:00
|
|
|
layout()->addWidget(widget);
|
2016-03-21 09:28:21 +00:00
|
|
|
layout()->addWidget(buttons);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void EditShortcutDialog::setShortcut(const QString& cut)
|
|
|
|
{
|
|
|
|
widget->shortcut->setText(cut);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QString EditShortcutDialog::shortcut() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return widget->shortcut->text();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
ShortcutDialog::ShortcutDialog(const QKeySequence& cut, QWidget* parent)
|
2013-12-05 19:22:31 +00:00
|
|
|
: QDialog(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
, widget(new KKeySequenceWidget(this))
|
|
|
|
{
|
|
|
|
widget->setKeySequence(cut);
|
2008-11-10 00:03:17 +00:00
|
|
|
// It's a global shortcut so don't allow multikey shortcuts
|
|
|
|
widget->setMultiKeyShortcutsAllowed(false);
|
2013-12-05 19:22:31 +00:00
|
|
|
|
2016-03-21 09:28:21 +00:00
|
|
|
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
2013-12-05 19:22:31 +00:00
|
|
|
connect(buttons, SIGNAL(accepted()), SLOT(accept()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), SLOT(reject()));
|
|
|
|
|
|
|
|
setLayout(new QVBoxLayout);
|
|
|
|
layout()->addWidget(widget);
|
|
|
|
layout()->addWidget(buttons);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void ShortcutDialog::accept()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-11-01 19:01:01 +00:00
|
|
|
QKeySequence seq = shortcut();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!seq.isEmpty()) {
|
|
|
|
if (seq[0] == Qt::Key_Escape) {
|
2007-04-29 17:35:43 +00:00
|
|
|
reject();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (seq[0] == Qt::Key_Space
|
|
|
|
|| (seq[0] & Qt::KeyboardModifierMask) == 0) {
|
|
|
|
// clear
|
2007-11-01 19:01:01 +00:00
|
|
|
widget->clearKeySequence();
|
2013-12-05 19:22:31 +00:00
|
|
|
QDialog::accept();
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-12-05 19:22:31 +00:00
|
|
|
QDialog::accept();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-11-01 18:51:01 +00:00
|
|
|
|
2007-11-01 19:01:01 +00:00
|
|
|
QKeySequence ShortcutDialog::shortcut() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-11-01 19:01:01 +00:00
|
|
|
return widget->keySequence();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-11-01 18:51:01 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|