track kwinrc file only on changes

--instead of reading the kwin values all the time
when needed from user actions we now read them
only on startup and when the kwinrc file was
updated/changed

BUG:411657
FIXED-IN:0.9.3
pull/8/head
Michail Vourlakos 5 years ago
parent eb3639914b
commit 1a49238d57

@ -31,9 +31,6 @@
#include "../view/view.h"
#include "../../liblatte2/types.h"
// Qt
#include <QtDBus/QtDBus>
// KDE
#include <KConfigGroup>
#include <KActivities/Consumer>
@ -125,36 +122,20 @@ void CentralLayout::setDisableBordersForMaximizedWindows(bool disable)
bool CentralLayout::kwin_disabledMaximizedBorders() const
{
//! Identify Plasma Desktop version
QProcess process;
process.start("kreadconfig5 --file kwinrc --group Windows --key BorderlessMaximizedWindows");
process.waitForFinished();
QString output(process.readAllStandardOutput());
output = output.remove("\n");
if (!m_corona) {
return false;
}
return (output == "true");
return m_corona->universalSettings()->kwin_borderlessMaximizedWindowsEnabled();
}
void CentralLayout::kwin_setDisabledMaximizedBorders(bool disable)
{
if (kwin_disabledMaximizedBorders() == disable) {
if (!m_corona) {
return;
}
QString disableText = disable ? "true" : "false";
QProcess process;
QString commandStr = "kwriteconfig5 --file kwinrc --group Windows --key BorderlessMaximizedWindows --type bool " + disableText;
process.start(commandStr);
process.waitForFinished();
QDBusInterface iface("org.kde.KWin", "/KWin", "", QDBusConnection::sessionBus());
if (iface.isValid()) {
iface.call("reconfigure");
}
m_corona->universalSettings()->kwin_setDisabledMaximizedBorders(disable);
}
bool CentralLayout::showInMenu() const

@ -1064,7 +1064,7 @@ void SettingsDialog::loadSettings()
ui->autostartChkBox->setChecked(m_corona->universalSettings()->autostart());
ui->badges3DStyleChkBox->setChecked(m_corona->universalSettings()->badges3DStyle());
ui->infoWindowChkBox->setChecked(m_corona->universalSettings()->showInfoWindow());
ui->metaPressChkBox->setChecked(m_corona->universalSettings()->metaForwardedToLatte());
ui->metaPressChkBox->setChecked(m_corona->universalSettings()->kwin_metaForwardedToLatte());
ui->metaPressHoldChkBox->setChecked(m_corona->universalSettings()->metaPressAndHoldEnabled());
ui->noBordersForMaximizedChkBox->setChecked(m_corona->universalSettings()->canDisableBorders());
@ -1617,7 +1617,7 @@ bool SettingsDialog::saveAllChanges()
m_corona->universalSettings()->setMouseSensitivity(sensitivity);
m_corona->universalSettings()->setAutostart(autostart);
m_corona->universalSettings()->setBadges3DStyle(badges3DStyle);
m_corona->universalSettings()->forwardMetaToLatte(forwardMetaPress);
m_corona->universalSettings()->kwin_forwardMetaToLatte(forwardMetaPress);
m_corona->universalSettings()->setMetaPressAndHoldEnabled(metaPressAndHold);
m_corona->universalSettings()->setShowInfoWindow(showInfoWindow);
m_corona->universalSettings()->setCanDisableBorders(noBordersForMaximized);

@ -38,6 +38,7 @@
#define KWINMETAFORWARDTOPLASMASTRING "org.kde.plasmashell,/PlasmaShell,org.kde.PlasmaShell,activateLauncherMenu"
#define KWINCOLORSSCRIPT "kwin/scripts/lattewindowcolors"
#define KWINRC "/.config/kwinrc"
namespace Latte {
@ -98,8 +99,14 @@ void UniversalSettings::load()
KDirWatch::self()->addDir(path);
}
connect(KDirWatch::self(), &KDirWatch::created, this, &UniversalSettings::colorsScriptChanged);
connect(KDirWatch::self(), &KDirWatch::deleted, this, &UniversalSettings::colorsScriptChanged);
//! Track KWin rc options
const QString kwinrcFilePath = QDir::homePath() + KWINRC;
KDirWatch::self()->addFile(kwinrcFilePath);
recoverKWinOptions();
connect(KDirWatch::self(), &KDirWatch::created, this, &UniversalSettings::trackedFileChanged);
connect(KDirWatch::self(), &KDirWatch::deleted, this, &UniversalSettings::trackedFileChanged);
connect(KDirWatch::self(), &KDirWatch::dirty, this, &UniversalSettings::trackedFileChanged);
//! this is needed to inform globalshortcuts to update its modifiers tracking
emit metaPressAndHoldEnabledChanged();
@ -336,43 +343,35 @@ void UniversalSettings::setColorsScriptIsPresent(bool present)
void UniversalSettings::updateColorsScriptIsPresent()
{
qDebug() << "Updating Latte Colors Script presence...";
setColorsScriptIsPresent(!Layouts::Importer::standardPath(KWINCOLORSSCRIPT).isEmpty());
}
void UniversalSettings::colorsScriptChanged(const QString &file)
{
if (!file.endsWith(KWINCOLORSSCRIPT)) {
return;
void UniversalSettings::trackedFileChanged(const QString &file)
{
if (file.endsWith(KWINCOLORSSCRIPT)) {
updateColorsScriptIsPresent();
}
updateColorsScriptIsPresent();
}
bool UniversalSettings::metaForwardedToLatte() const
{
return kwin_metaForwardedToLatte();
if (file.endsWith(KWINRC)) {
recoverKWinOptions();
}
}
void UniversalSettings::forwardMetaToLatte(bool forward)
bool UniversalSettings::kwin_metaForwardedToLatte() const
{
kwin_forwardMetaToLatte(forward);
return m_kwinMetaForwardedToLatte;
}
bool UniversalSettings::kwin_metaForwardedToLatte() const
bool UniversalSettings::kwin_borderlessMaximizedWindowsEnabled() const
{
QProcess process;
process.start("kreadconfig5 --file kwinrc --group ModifierOnlyShortcuts --key Meta");
process.waitForFinished();
QString output(process.readAllStandardOutput());
output = output.remove("\n");
return (output == KWINMETAFORWARDTOLATTESTRING);
return m_kwinBorderlessMaximizedWindows;
}
void UniversalSettings::kwin_forwardMetaToLatte(bool forward)
{
if (kwin_metaForwardedToLatte() == forward) {
if (m_kwinMetaForwardedToLatte == forward) {
return;
}
@ -396,6 +395,48 @@ void UniversalSettings::kwin_forwardMetaToLatte(bool forward)
}
}
void UniversalSettings::kwin_setDisabledMaximizedBorders(bool disable)
{
if (m_kwinBorderlessMaximizedWindows == disable) {
return;
}
QString disableText = disable ? "true" : "false";
QProcess process;
QString commandStr = "kwriteconfig5 --file kwinrc --group Windows --key BorderlessMaximizedWindows --type bool " + disableText;
process.start(commandStr);
process.waitForFinished();
QDBusInterface iface("org.kde.KWin", "/KWin", "", QDBusConnection::sessionBus());
if (iface.isValid()) {
iface.call("reconfigure");
}
}
void UniversalSettings::recoverKWinOptions()
{
qDebug() << "kwinrc: recovering values...";
//! Meta forwarded to Latte option
QProcess process;
process.start("kreadconfig5 --file kwinrc --group ModifierOnlyShortcuts --key Meta");
process.waitForFinished();
QString output(process.readAllStandardOutput());
output = output.remove("\n");
m_kwinMetaForwardedToLatte = (output == KWINMETAFORWARDTOLATTESTRING);
//! BorderlessMaximizedWindows option
process.start("kreadconfig5 --file kwinrc --group Windows --key BorderlessMaximizedWindows");
process.waitForFinished();
output = process.readAllStandardOutput();
output = output.remove("\n");
m_kwinBorderlessMaximizedWindows = (output == "true");
}
bool UniversalSettings::metaPressAndHoldEnabled() const
{
return m_metaPressAndHoldEnabled;

@ -83,8 +83,11 @@ public:
bool colorsScriptIsPresent() const;
bool metaForwardedToLatte() const;
void forwardMetaToLatte(bool forward);
bool kwin_metaForwardedToLatte() const;
void kwin_forwardMetaToLatte(bool forward);
bool kwin_borderlessMaximizedWindowsEnabled() const;
void kwin_setDisabledMaximizedBorders(bool disable);
bool metaPressAndHoldEnabled() const;
void setMetaPressAndHoldEnabled(bool enabled);
@ -157,15 +160,13 @@ private slots:
void saveConfig();
void saveScalesConfig();
void recoverKWinOptions();
void updateColorsScriptIsPresent();
void colorsScriptChanged(const QString &file);
void trackedFileChanged(const QString &file);
private:
void cleanupSettings();
bool kwin_metaForwardedToLatte() const;
void kwin_forwardMetaToLatte(bool forward);
void setColorsScriptIsPresent(bool present);
Types::LayoutsMemoryUsage layoutsMemoryUsage() const;
@ -178,6 +179,10 @@ private:
bool m_metaPressAndHoldEnabled{true};
bool m_showInfoWindow{true};
//!kwinrc tracking
bool m_kwinMetaForwardedToLatte{false};
bool m_kwinBorderlessMaximizedWindows{false};
//when there isnt a version it is an old universal file
int m_version{1};

@ -337,7 +337,7 @@ bool GlobalShortcuts::activateLatteEntryAtContainment(const Latte::View *view, i
continue;
}
int appLauncher = m_corona->universalSettings()->metaForwardedToLatte() ?
int appLauncher = m_corona->universalSettings()->kwin_metaForwardedToLatte() ?
applicationLauncherId(view->containment()) : -1;
int showMethodIndex = -1;
@ -536,7 +536,7 @@ void GlobalShortcuts::showViews()
continue;
}
int appLauncher = m_corona->universalSettings()->metaForwardedToLatte() && showMeta ?
int appLauncher = m_corona->universalSettings()->kwin_metaForwardedToLatte() && showMeta ?
applicationLauncherId(c) : -1;
int showMethodIndex = -1;
@ -581,7 +581,7 @@ void GlobalShortcuts::showViews()
continue;
}
int appLauncher = m_corona->universalSettings()->metaForwardedToLatte() ?
int appLauncher = m_corona->universalSettings()->kwin_metaForwardedToLatte() ?
applicationLauncherId(c) : -1;
int showMethodIndex = -1;
@ -628,7 +628,7 @@ void GlobalShortcuts::showViews()
//! show Meta if it is not already shown for Tasks Latte View
if (!viewWithTasks || applicationLauncherId(viewWithTasks->containment()) == -1) {
for(const auto view : sortedViews) {
if (!viewWithMeta && m_corona->universalSettings()->metaForwardedToLatte() && applicationLauncherId(view->containment()) > -1) {
if (!viewWithMeta && m_corona->universalSettings()->kwin_metaForwardedToLatte() && applicationLauncherId(view->containment()) > -1) {
viewWithMeta = view;
break;
}

Loading…
Cancel
Save