Commit 128eb13c authored by Cyril Rossi's avatar Cyril Rossi

KCM KWinScreenEdges port to KConfigXT

Summary: Following D27862 port KWinScreenEdges to KConfigXT, handle isSaveNeeded and isDefault KCModule state.

Reviewers: #kwin, ervin, bport, meven, zzag

Reviewed By: #kwin, ervin, zzag

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D28475
parent 01314f8e
......@@ -6,11 +6,13 @@ set(kcm_screenedges_SRCS
monitor.cpp
screenpreviewwidget.cpp
kwinscreenedge.cpp
kwinscreenedgeconfigform.cpp
)
qt5_add_dbus_interface(kcm_screenedges_SRCS ${KWin_SOURCE_DIR}/org.kde.kwin.Effects.xml kwin_effects_interface)
set(kcm_kwinscreenedges_PART_SRCS main.cpp ${kcm_screenedges_SRCS})
ki18n_wrap_ui(kcm_kwinscreenedges_PART_SRCS main.ui)
kconfig_add_kcfg_files(kcm_kwinscreenedges_PART_SRCS kwinscreenedgesettings.kcfgc kwinscreenedgescriptsettings.kcfgc)
add_library(kcm_kwinscreenedges MODULE ${kcm_kwinscreenedges_PART_SRCS})
set(kcm_screenedges_LIBS
Qt5::DBus
......
......@@ -193,17 +193,17 @@ ElectricBorder KWinScreenEdge::monitorEdgeToElectricBorder(int edge)
void KWinScreenEdge::onChanged()
{
bool needSave = false;
bool needSave = isSaveNeeded();
for (auto it = m_reference.begin(); it != m_reference.cend(); ++it) {
needSave |= it.value() != monitor()->selectedEdgeItem(KWinScreenEdge::electricBorderToMonitorEdge(it.key()));
}
emit saveNeededChanged(needSave);
bool isDefault = true;
bool defaults = isDefault();
for (auto it = m_default.begin(); it != m_default.cend(); ++it) {
isDefault &= it.value() == monitor()->selectedEdgeItem(KWinScreenEdge::electricBorderToMonitorEdge(it.key()));
defaults &= it.value() == monitor()->selectedEdgeItem(KWinScreenEdge::electricBorderToMonitorEdge(it.key()));
}
emit defaultChanged(isDefault);
emit defaultChanged(defaults);
}
void KWinScreenEdge::createConnection()
......@@ -214,4 +214,14 @@ void KWinScreenEdge::createConnection()
&KWinScreenEdge::onChanged);
}
bool KWinScreenEdge::isSaveNeeded() const
{
return false;
}
bool KWinScreenEdge::isDefault() const
{
return true;
}
} // namespace
......@@ -54,9 +54,9 @@ public:
void monitorChangeDefaultEdge(const QList<int> &borderList, int index);
// revert to reference settings and assess for saveNeeded and default changed
void reload();
virtual void reload();
// reset to default settings and assess for saveNeeded and default changed
void setDefaults();
virtual void setDefaults();
private Q_SLOTS:
void onChanged();
......@@ -68,6 +68,8 @@ Q_SIGNALS:
private:
virtual Monitor *monitor() const = 0;
virtual bool isSaveNeeded() const;
virtual bool isDefault() const;
// internal use, assert if border equals ELECTRIC_COUNT or ElectricNone
static int electricBorderToMonitorEdge(ElectricBorder border);
......
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
Copyright (C) 2020 Cyril Rossi <cyril.rossi@enioka.com>
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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kwinscreenedgeconfigform.h"
#include "ui_main.h"
namespace KWin
{
KWinScreenEdgesConfigForm::KWinScreenEdgesConfigForm(QWidget *parent)
: KWinScreenEdge(parent)
, ui(new Ui::KWinScreenEdgesConfigUI)
{
ui->setupUi(this);
connect(ui->kcfg_ElectricBorderDelay, SIGNAL(valueChanged(int)), this, SLOT(sanitizeCooldown()));
// Visual feedback of action group conflicts
connect(ui->kcfg_ElectricBorders, SIGNAL(currentIndexChanged(int)), this, SLOT(groupChanged()));
connect(ui->kcfg_ElectricBorderMaximize, SIGNAL(stateChanged(int)), this, SLOT(groupChanged()));
connect(ui->kcfg_ElectricBorderTiling, SIGNAL(stateChanged(int)), this, SLOT(groupChanged()));
connect(ui->electricBorderCornerRatioSpin, SIGNAL(valueChanged(int)), this, SLOT(onChanged()));
}
KWinScreenEdgesConfigForm::~KWinScreenEdgesConfigForm()
{
delete ui;
}
void KWinScreenEdgesConfigForm::setElectricBorderCornerRatio(double value)
{
m_referenceCornerRatio = value;
ui->electricBorderCornerRatioSpin->setValue(m_referenceCornerRatio * 100.);
}
void KWinScreenEdgesConfigForm::setDefaultElectricBorderCornerRatio(double value)
{
m_defaultCornerRatio = value;
}
double KWinScreenEdgesConfigForm::electricBorderCornerRatio() const
{
return ui->electricBorderCornerRatioSpin->value() / 100.;
}
void KWinScreenEdgesConfigForm::reload()
{
ui->electricBorderCornerRatioSpin->setValue(m_referenceCornerRatio * 100.);
KWinScreenEdge::reload();
}
void KWinScreenEdgesConfigForm::setDefaults()
{
ui->electricBorderCornerRatioSpin->setValue(m_defaultCornerRatio * 100.);
KWinScreenEdge::setDefaults();
}
Monitor *KWinScreenEdgesConfigForm::monitor() const
{
return ui->monitor;
}
bool KWinScreenEdgesConfigForm::isSaveNeeded() const
{
return m_referenceCornerRatio != electricBorderCornerRatio();
}
bool KWinScreenEdgesConfigForm::isDefault() const
{
return m_defaultCornerRatio == electricBorderCornerRatio();
}
void KWinScreenEdgesConfigForm::sanitizeCooldown()
{
ui->kcfg_ElectricBorderCooldown->setMinimum(ui->kcfg_ElectricBorderDelay->value() + 50);
}
void KWinScreenEdgesConfigForm::groupChanged()
{
// Monitor conflicts
bool hide = false;
if (ui->kcfg_ElectricBorders->currentIndex() == 2) {
hide = true;
}
monitorHideEdge(ElectricTop, hide);
monitorHideEdge(ElectricRight, hide);
monitorHideEdge(ElectricBottom, hide);
monitorHideEdge(ElectricLeft, hide);
}
} // namespace
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
Copyright (C) 2020 Cyril Rossi <cyril.rossi@enioka.com>
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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef __KWINSCREENEDGECONFIGFORM_H__
#define __KWINSCREENEDGECONFIGFORM_H__
#include "kwinscreenedge.h"
namespace Ui
{
class KWinScreenEdgesConfigUI;
}
namespace KWin
{
class KWinScreenEdgesConfigForm : public KWinScreenEdge
{
Q_OBJECT
public:
KWinScreenEdgesConfigForm(QWidget *parent = nullptr);
~KWinScreenEdgesConfigForm() override;
// value is between 0. and 1.
void setElectricBorderCornerRatio(double value);
void setDefaultElectricBorderCornerRatio(double value);
// return value between 0. and 1.
double electricBorderCornerRatio() const;
void reload() override;
void setDefaults() override;
protected:
Monitor *monitor() const override;
bool isSaveNeeded() const override;
bool isDefault() const override;
private Q_SLOTS:
void sanitizeCooldown();
void groupChanged();
private:
// electricBorderCornerRatio value between 0. and 1.
double m_referenceCornerRatio = 0.;
double m_defaultCornerRatio = 0.;
Ui::KWinScreenEdgesConfigUI *ui;
};
} // namespace
#endif
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc">
<parameter name="ScriptName"/>
</kcfgfile>
<group name="Script-$(ScriptName)">
<entry key="BorderActivate" type="IntList">
<default>ElectricNone</default>
</entry>
</group>
</kcfg>
File=kwinscreenedgescriptsettings.kcfg
NameSpace=KWin
ClassName=KWinScreenEdgeScriptSettings
IncludeFiles=kwinglobals.h
Mutators=true
DefaultValueGetters=true
ParentInConstructor=true
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc"/>
<group name="Windows">
<entry key="ElectricBorders" type="Int">
<default>0</default>
</entry>
<entry key="ElectricBorderDelay" type="Int">
<default>150</default>
</entry>
<entry key="ElectricBorderCooldown" type="Int">
<default>350</default>
</entry>
<entry key="ElectricBorderMaximize" type="Bool">
<default>true</default>
</entry>
<entry key="ElectricBorderTiling" type="Bool">
<default>true</default>
</entry>
<entry key="ElectricBorderCornerRatio" type="Double">
<default>0.25</default>
</entry>
</group>
<group name="ElectricBorders">
<entry key="Top" type="String">
<default>None</default>
</entry>
<entry key="TopRight" type="String">
<default>None</default>
</entry>
<entry key="Right" type="String">
<default>None</default>
</entry>
<entry key="BottomRight" type="String">
<default>None</default>
</entry>
<entry key="Bottom" type="String">
<default>None</default>
</entry>
<entry key="BottomLeft" type="String">
<default>None</default>
</entry>
<entry key="Left" type="String">
<default>None</default>
</entry>
<entry key="TopLeft" type="String">
<default>PresentWindowsAll</default>
</entry>
</group>
<group name="Effect-PresentWindows">
<entry key="BorderActivateAll" type="IntList">
<default>ElectricTopLeft</default>
</entry>
<entry name="BorderActivatePresentWindows" key="BorderActivate" type="IntList">
<default>ElectricNone</default>
</entry>
<entry key="BorderActivateClass" type="IntList">
<default>ElectricNone</default>
</entry>
</group>
<group name="Effect-DesktopGrid">
<entry name="BorderActivateDesktopGrid" key="BorderActivate" type="IntList">
<default>ElectricNone</default>
</entry>
</group>
<group name="Effect-Cube">
<entry name="BorderActivateCube" key="BorderActivate" type="IntList">
<default>ElectricNone</default>
</entry>
<entry key="BorderActivateCylinder" type="IntList">
<default>ElectricNone</default>
</entry>
<entry key="BorderActivateSphere" type="IntList">
<default>ElectricNone</default>
</entry>
</group>
<group name="TabBox">
<entry name="BorderActivateTabBox" key="BorderActivate" type="IntList">
<default>ElectricLeft</default>
</entry>
<entry key="BorderAlternativeActivate" type="IntList">
<default>ElectricNone</default>
</entry>
</group>
</kcfg>
File=kwinscreenedgesettings.kcfg
NameSpace=KWin
ClassName=KWinScreenEdgeSettings
IncludeFiles=kwinglobals.h
Mutators=true
DefaultValueGetters=true
ParentInConstructor=true
This diff is collapsed.
......@@ -3,6 +3,7 @@
This file is part of the KDE project.
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
Copyright (C) 2020 Cyril Rossi <cyril.rossi@enioka.com>
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
......@@ -26,43 +27,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kwinglobals.h"
#include "ui_main.h"
class QShowEvent;
namespace KWin
{
class KWinScreenEdgesConfigForm;
class KWinScreenEdgeSettings;
class KWinScreenEdgeScriptSettings;
enum class BuiltInEffect;
class KWinScreenEdgesConfigForm : public QWidget, public Ui::KWinScreenEdgesConfigForm
{
Q_OBJECT
public:
explicit KWinScreenEdgesConfigForm(QWidget* parent);
};
class KWinScreenEdgesConfig : public KCModule
{
Q_OBJECT
public:
explicit KWinScreenEdgesConfig(QWidget* parent, const QVariantList& args);
explicit KWinScreenEdgesConfig(QWidget *parent, const QVariantList &args);
~KWinScreenEdgesConfig() override;
public Q_SLOTS:
virtual void groupChanged();
void save() override;
void load() override;
void defaults() override;
protected:
void showEvent(QShowEvent* e) override;
private Q_SLOTS:
void sanitizeCooldown();
void showEvent(QShowEvent *e) override;
private:
KWinScreenEdgesConfigForm* m_ui;
KWinScreenEdgesConfigForm *m_form;
KSharedConfigPtr m_config;
QStringList m_scripts; //list of script IDs ordered in the list they are presented in the menu
QHash<QString, KWinScreenEdgeScriptSettings*> m_scriptSettings;
KWinScreenEdgeSettings *m_settings;
enum EffectActions {
PresentWindowsAll = ELECTRIC_ACTION_COUNT, // Start at the end of built in actions
......@@ -77,20 +72,16 @@ private:
EffectCount
};
bool effectEnabled(const BuiltInEffect& effect, const KConfigGroup& cfg) const;
bool effectEnabled(const BuiltInEffect &effect, const KConfigGroup &cfg) const;
void monitorAddItem(const QString& item);
void monitorItemSetEnabled(int index, bool enabled);
void monitorInit();
void monitorLoadAction(ElectricBorder edge, const QString& configName);
void monitorLoad();
void monitorSaveAction(int edge, const QString& configName);
void monitorSave();
void monitorDefaults();
void monitorLoadSettings();
void monitorLoadDefaultSettings();
void monitorSaveSettings();
void monitorShowEvent();
void monitorChangeEdge(ElectricBorder border, int index);
void monitorHideEdge(ElectricBorder border, bool hidden);
QList<int> monitorCheckEffectHasEdge(int index) const;
static ElectricBorderAction electricBorderActionFromString(const QString &string);
static QString electricBorderActionToString(int action);
};
} // namespace
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KWinScreenEdgesConfigForm</class>
<widget class="QWidget" name="KWinScreenEdgesConfigForm">
<class>KWinScreenEdgesConfigUI</class>
<widget class="QWidget" name="KWinScreenEdgesConfigUI">
<property name="geometry">
<rect>
<x>0</x>
......@@ -67,12 +67,12 @@
<string>&amp;Maximize:</string>
</property>
<property name="buddy">
<cstring>quickMaximizeBox</cstring>
<cstring>kcfg_ElectricBorderMaximize</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="quickMaximizeBox">
<widget class="QCheckBox" name="kcfg_ElectricBorderMaximize">
<property name="text">
<string>Windows dragged to top edge</string>
</property>
......@@ -89,7 +89,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="quickTileBox">
<widget class="QCheckBox" name="kcfg_ElectricBorderTiling">
<property name="text">
<string>Windows dragged to left or right edge</string>
</property>
......@@ -147,12 +147,12 @@
<string>&amp;Switch desktop on edge:</string>
</property>
<property name="buddy">
<cstring>desktopSwitchCombo</cstring>
<cstring>kcfg_ElectricBorders</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="KComboBox" name="desktopSwitchCombo">
<widget class="KComboBox" name="kcfg_ElectricBorders">
<item>
<property name="text">
<string comment="Switch desktop on edge">Disabled</string>
......@@ -179,12 +179,12 @@
<string>Activation &amp;delay:</string>
</property>
<property name="buddy">
<cstring>activationDelaySpin</cstring>
<cstring>kcfg_ElectricBorderDelay</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="activationDelaySpin">
<widget class="QSpinBox" name="kcfg_ElectricBorderDelay">
<property name="suffix">
<string> ms</string>
</property>
......@@ -211,12 +211,12 @@
<string>&amp;Reactivation delay:</string>
</property>
<property name="buddy">
<cstring>triggerCooldownSpin</cstring>
<cstring>kcfg_ElectricBorderCooldown</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="triggerCooldownSpin">
<widget class="QSpinBox" name="kcfg_ElectricBorderCooldown">
<property name="enabled">
<bool>true</bool>
</property>
......@@ -280,7 +280,7 @@
<resources/>
<connections>
<connection>
<sender>quickTileBox</sender>
<sender>kcfg_ElectricBorderTiling</sender>
<signal>toggled(bool)</signal>
<receiver>label_1</receiver>
<slot>setEnabled(bool)</slot>
......@@ -296,7 +296,7 @@
</hints>
</connection>
<connection>
<sender>quickTileBox</sender>
<sender>kcfg_ElectricBorderTiling</sender>
<signal>toggled(bool)</signal>
<receiver>electricBorderCornerRatioSpin</receiver>
<slot>setEnabled(bool)</slot>
......@@ -312,7 +312,7 @@
</hints>
</connection>
<connection>
<sender>quickTileBox</sender>
<sender>kcfg_ElectricBorderTiling</sender>
<signal>toggled(bool)</signal>
<receiver>electricBorderCornerRatioLabel</receiver>
<slot>setEnabled(bool)</slot>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment