diff --git a/sources/awesome-widget/plugin/awdataenginemapper.cpp b/sources/awesome-widget/plugin/awdataenginemapper.cpp index ed46924..faf76b8 100644 --- a/sources/awesome-widget/plugin/awdataenginemapper.cpp +++ b/sources/awesome-widget/plugin/awdataenginemapper.cpp @@ -43,6 +43,10 @@ AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_cus m_formatter["uptot"] = AWPluginFormatterMemoryMB::instance(); m_formatter["uptotkb"] = AWPluginFormatterMemory::instance(); m_formatter["upunits"] = AWPluginFormatterNetUnits::instance(); + // gpu memory + m_formatter["gpumem"] = AWPluginFormatterFloat::instance(); + m_formatter["gpufreemb"] = AWPluginFormatterMemoryMB::instance(); + m_formatter["gpufreegb"] = AWPluginFormatterMemoryGB::instance(); } @@ -109,4 +113,12 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy void AWDataEngineMapper::setDevices(const AWPluginMatcherSettings &_settings) { m_settings = _settings; + + // update formatters + // gpu memory per device + for (auto i = 0; i < m_settings.gpu.count(); ++i) { + m_formatter[QString("gpumem%1").arg(i)] = AWPluginFormatterFloat::instance(); + m_formatter[QString("gpufreemb%1").arg(i)] = AWPluginFormatterMemoryMB::instance(); + m_formatter[QString("gpufreegb%1").arg(i)] = AWPluginFormatterMemoryGB::instance(); + } } diff --git a/sources/awesome-widget/plugin/awkeycache.cpp b/sources/awesome-widget/plugin/awkeycache.cpp index 491928f..68e94f3 100644 --- a/sources/awesome-widget/plugin/awkeycache.cpp +++ b/sources/awesome-widget/plugin/awkeycache.cpp @@ -70,12 +70,12 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL qCDebug(LOG_AW) << "Looking for required keys in" << _keys << _bars << "using tooltip settings" << _tooltip; // initial copy - QSet used(_keys.cbegin(), _keys.cend()); + QSet used(_keys.cbegin(), _keys.cend()); used.unite(QSet(_bars.cbegin(), _bars.cend())); used.unite(QSet(_userKeys.cbegin(), _userKeys.cend())); // insert keys from tooltip for (auto [key, value] : _tooltip.asKeyValueRange()) { - if ((key.endsWith("Tooltip")) && value.toBool()) { + if (key.endsWith("Tooltip") && value.toBool()) { auto local = key; local.remove("Tooltip"); used << local; @@ -84,7 +84,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL // insert keys which depend on others, refer to AWKeys::calculateValues() // network keys - QStringList netKeys( + static QStringList netKeys( {"up", "upkb", "uptot", "uptotkb", "upunits", "down", "downkb", "downtot", "downtotkb", "downunits"}); for (auto &key : netKeys) { if (!used.contains(key)) @@ -96,11 +96,13 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL // netdev key if (std::any_of(netKeys.cbegin(), netKeys.cend(), [&used](auto &key) { return used.contains(key); })) used << "netdev"; - - // HACK append dummy if there are no other keys. This hack is required - // because empty list leads to the same behaviour as skip checking - if (used.isEmpty()) - used << "dummy"; + // gpu memory keys + static auto gpuMemoryCalculatedRegExp = QRegularExpression("^gpu(mem|freemb|freegb)"); + for (auto key : _keys.filter(gpuMemoryCalculatedRegExp)) { + auto index = key.remove(gpuMemoryCalculatedRegExp); + used << QString("gpuusedmb%1").arg(index) << QString("gputotmb%1").arg(index) + << QString("gpuusedgb%1").arg(index) << QString("gputotgb%1").arg(index); + } return used.values(); } diff --git a/sources/awesome-widget/plugin/awkeyoperations.cpp b/sources/awesome-widget/plugin/awkeyoperations.cpp index 33e34ac..574df55 100644 --- a/sources/awesome-widget/plugin/awkeyoperations.cpp +++ b/sources/awesome-widget/plugin/awkeyoperations.cpp @@ -85,6 +85,13 @@ QStringList AWKeyOperations::dictKeys() const // gpu for (auto i = 0; i < m_devices.gpu.count(); ++i) { allKeys.append(QString("gpu%1").arg(i)); + allKeys.append(QString("gpumem%1").arg(i)); + allKeys.append(QString("gpufreemb%1").arg(i)); + allKeys.append(QString("gpufreegb%1").arg(i)); + allKeys.append(QString("gputotmb%1").arg(i)); + allKeys.append(QString("gputotgb%1").arg(i)); + allKeys.append(QString("gpuusedmb%1").arg(i)); + allKeys.append(QString("gpuusedgb%1").arg(i)); allKeys.append(QString("gputemp%1").arg(i)); } // hdd diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 1729666..156f06c 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -248,6 +248,19 @@ void AWKeys::calculateValues() m_values["uptotkb"] = m_values[QString("uptotkb%1").arg(netIndex)]; m_values["upunits"] = m_values[QString("upunits%1").arg(netIndex)]; + // gpu memory keys + m_values["gpufreemb"] = m_values["gputotmb"].toLongLong() - m_values["gpuusedmb"].toLongLong(); + m_values["gpufreegb"] = m_values["gputotgb"].toDouble() - m_values["gpuusedgb"].toDouble(); + m_values["gpumem"] = 100.0 * m_values["gpuusedmb"].toDouble() / m_values["gputotmb"].toDouble(); + for (auto i = 0; i < devices.gpu.count(); ++i) { + m_values[QString("gpufreemb%1").arg(i)] = m_values[QString("gputotmb%1").arg(i)].toLongLong() + - m_values[QString("gpuusedmb%1").arg(i)].toLongLong(); + m_values[QString("gpufreegb%1").arg(i)] + = m_values[QString("gputotgb%1").arg(i)].toDouble() - m_values[QString("gpuusedgb%1").arg(i)].toDouble(); + m_values[QString("gpumem%1").arg(i)] = 100.0 * m_values[QString("gpuusedmb%1").arg(i)].toDouble() + / m_values[QString("gputotmb%1").arg(i)].toDouble(); + } + // user defined keys for (auto &key : m_keyOperator->userKeys()) m_values[key] = m_values[m_keyOperator->userKeySource(key)]; diff --git a/sources/awesome-widget/plugin/formatters/formatters.h b/sources/awesome-widget/plugin/formatters/formatters.h index 06153a5..745fb5c 100644 --- a/sources/awesome-widget/plugin/formatters/formatters.h +++ b/sources/awesome-widget/plugin/formatters/formatters.h @@ -15,6 +15,8 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ +#pragma once + #include "awpluginformatterac.h" #include "awpluginformattercustom.h" #include "awpluginformatterdouble.h" diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotal.cpp b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotal.cpp new file mode 100644 index 0000000..bdda42f --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotal.cpp @@ -0,0 +1,36 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginmatchergpumemorytotal.h" + +#include "formatters/formatters.h" + + +QHash AWPluginMatcherGPUMemoryTotal::keys(const QString &, const KSysGuard::Unit, + const AWPluginMatcherSettings &) const +{ + return { + {"gputotmb", AWPluginFormatterMemoryMB::instance()}, + {"gputotgb", AWPluginFormatterMemoryGB::instance()}, + }; +} + + +bool AWPluginMatcherGPUMemoryTotal::matches(const QString &_source) const +{ + return _source == "gpu/all/totalVram"; +} diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotal.h b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotal.h new file mode 100644 index 0000000..2d39be3 --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotal.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginmatcher.h" + + +class AWPluginMatcherGPUMemoryTotal : public AWPluginMatcher +{ +public: + [[nodiscard]] QHash keys(const QString &, KSysGuard::Unit, + const AWPluginMatcherSettings &) const override; + [[nodiscard]] bool matches(const QString &_source) const override; +}; diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotalcore.cpp b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotalcore.cpp new file mode 100644 index 0000000..94bdf02 --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotalcore.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginmatchergpumemorytotalcore.h" + +#include + +#include "formatters/formatters.h" + + +QHash +AWPluginMatcherGPUMemoryTotalCore::keys(const QString &_source, const KSysGuard::Unit, + const AWPluginMatcherSettings &_settings) const +{ + auto index = AWPluginMatcher::index(_source, _settings.gpu); + if (index == -1) + return {}; + + return { + {QString("gputotmb%1").arg(index), AWPluginFormatterMemoryMB::instance()}, + {QString("gputotgb%1").arg(index), AWPluginFormatterMemoryGB::instance()}, + }; +} + + +bool AWPluginMatcherGPUMemoryTotalCore::matches(const QString &_source) const +{ + static auto regexp = QRegularExpression("^gpu/gpu.*/totalVram$"); + return _source.contains(regexp); +} diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotalcore.h b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotalcore.h new file mode 100644 index 0000000..681eb51 --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemorytotalcore.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginmatcher.h" + + +class AWPluginMatcherGPUMemoryTotalCore : public AWPluginMatcher +{ +public: + [[nodiscard]] QHash + keys(const QString &_source, KSysGuard::Unit, const AWPluginMatcherSettings &_settings) const override; + [[nodiscard]] bool matches(const QString &_source) const override; +}; diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryused.cpp b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryused.cpp new file mode 100644 index 0000000..b2f6e20 --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryused.cpp @@ -0,0 +1,36 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginmatchergpumemoryused.h" + +#include "formatters/formatters.h" + + +QHash AWPluginMatcherGPUMemoryUsed::keys(const QString &, const KSysGuard::Unit, + const AWPluginMatcherSettings &) const +{ + return { + {"gpuusedmb", AWPluginFormatterMemoryMB::instance()}, + {"gpuusedgb", AWPluginFormatterMemoryGB::instance()}, + }; +} + + +bool AWPluginMatcherGPUMemoryUsed::matches(const QString &_source) const +{ + return _source == "gpu/all/usedVram"; +} diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryused.h b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryused.h new file mode 100644 index 0000000..0af2fcc --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryused.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginmatcher.h" + + +class AWPluginMatcherGPUMemoryUsed : public AWPluginMatcher +{ +public: + [[nodiscard]] QHash keys(const QString &, KSysGuard::Unit, + const AWPluginMatcherSettings &) const override; + [[nodiscard]] bool matches(const QString &_source) const override; +}; diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryusedcore.cpp b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryusedcore.cpp new file mode 100644 index 0000000..2584b06 --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryusedcore.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "awpluginmatchergpumemoryusedcore.h" + +#include + +#include "formatters/formatters.h" + + +QHash +AWPluginMatcherGPUMemoryUsedCore::keys(const QString &_source, const KSysGuard::Unit, + const AWPluginMatcherSettings &_settings) const +{ + auto index = AWPluginMatcher::index(_source, _settings.gpu); + if (index == -1) + return {}; + + return { + {QString("gpuusedmb%1").arg(index), AWPluginFormatterMemoryMB::instance()}, + {QString("gpuusedgb%1").arg(index), AWPluginFormatterMemoryGB::instance()}, + }; +} + + +bool AWPluginMatcherGPUMemoryUsedCore::matches(const QString &_source) const +{ + static auto regexp = QRegularExpression("^gpu/gpu.*/usedVram$"); + return _source.contains(regexp); +} diff --git a/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryusedcore.h b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryusedcore.h new file mode 100644 index 0000000..c3add30 --- /dev/null +++ b/sources/awesome-widget/plugin/matchers/awpluginmatchergpumemoryusedcore.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#pragma once + +#include "awpluginmatcher.h" + + +class AWPluginMatcherGPUMemoryUsedCore : public AWPluginMatcher +{ +public: + [[nodiscard]] QHash + keys(const QString &_source, KSysGuard::Unit, const AWPluginMatcherSettings &_settings) const override; + [[nodiscard]] bool matches(const QString &_source) const override; +}; diff --git a/sources/awesome-widget/plugin/matchers/matchers.h b/sources/awesome-widget/plugin/matchers/matchers.h index 4545cd3..d4bc8ba 100644 --- a/sources/awesome-widget/plugin/matchers/matchers.h +++ b/sources/awesome-widget/plugin/matchers/matchers.h @@ -15,6 +15,8 @@ * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ +#pragma once + #include "awpluginmatcherac.h" #include "awpluginmatcherbattery.h" #include "awpluginmatcherbrightness.h" @@ -28,6 +30,10 @@ #include "awpluginmatcherdesktopnumber.h" #include "awpluginmatchergpu.h" #include "awpluginmatchergpucore.h" +#include "awpluginmatchergpumemorytotal.h" +#include "awpluginmatchergpumemorytotalcore.h" +#include "awpluginmatchergpumemoryused.h" +#include "awpluginmatchergpumemoryusedcore.h" #include "awpluginmatchergputemperature.h" #include "awpluginmatcherhdd.h" #include "awpluginmatcherhddfree.h" @@ -80,6 +86,10 @@ static QList matchers = { AWPluginMatcherDesktopNumber::instance(), AWPluginMatcherGPU::instance(), AWPluginMatcherGPUCore::instance(), + AWPluginMatcherGPUMemoryTotal::instance(), + AWPluginMatcherGPUMemoryTotalCore::instance(), + AWPluginMatcherGPUMemoryUsed::instance(), + AWPluginMatcherGPUMemoryUsedCore::instance(), AWPluginMatcherGPUTemperature::instance(), AWPluginMatcherHDD::instance(), AWPluginMatcherHDDFree::instance(), diff --git a/sources/version.h.in b/sources/version.h.in index 9d834ac..005f5d5 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -70,6 +70,13 @@ static const char STATIC_KEYS[] = "time," "cpucl," "cpu," "gpu," + "gpumem," + "gpufreemb," + "gpufreegb," + "gputotmb," + "gputotgb," + "gpuusedmb," + "gpuusedgb," "memmb," "memgb," "memfreemb,"