Load settings for KDecoration2 based plugins
* library to load * decoration buttons (based on old KDecoration1 implementation)
This commit is contained in:
parent
a019fa259c
commit
24a4a87bac
3 changed files with 82 additions and 12 deletions
|
@ -63,12 +63,12 @@ DecorationBridge *DecorationBridge::self()
|
|||
|
||||
void DecorationBridge::init()
|
||||
{
|
||||
KConfigGroup config = KSharedConfig::openConfig(KWIN_CONFIG)->group(s_pluginName);
|
||||
KDecoration2::DecorationSettings::self(this);
|
||||
|
||||
// TODO: configurable plugin
|
||||
const auto offers = KPluginTrader::self()->query(s_pluginName,
|
||||
s_pluginName,
|
||||
QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(QStringLiteral("org.kde.breeze")));
|
||||
QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(config.readEntry("library", "org.kde.breeze")));
|
||||
if (offers.isEmpty()) {
|
||||
qWarning() << "Could not locate decoration plugin";
|
||||
return;
|
||||
|
|
|
@ -22,8 +22,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "composite.h"
|
||||
#include "virtualdesktops.h"
|
||||
|
||||
#include <config-kwin.h>
|
||||
|
||||
#include <KDecoration2/DecorationSettings>
|
||||
|
||||
#include <KConfigGroup>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
namespace Decoration
|
||||
|
@ -32,6 +36,8 @@ SettingsImpl::SettingsImpl(KDecoration2::DecorationSettings *parent)
|
|||
: QObject()
|
||||
, DecorationSettingsPrivate(parent)
|
||||
{
|
||||
readSettings();
|
||||
|
||||
connect(Compositor::self(), &Compositor::compositingToggled,
|
||||
parent, &KDecoration2::DecorationSettings::alphaChannelSupportedChanged);
|
||||
connect(VirtualDesktopManager::self(), &VirtualDesktopManager::countChanged, this,
|
||||
|
@ -56,21 +62,71 @@ bool SettingsImpl::isOnAllDesktopsAvailable() const
|
|||
return VirtualDesktopManager::self()->count() > 1;
|
||||
}
|
||||
|
||||
QList< KDecoration2::DecorationButtonType > SettingsImpl::decorationButtonsLeft() const
|
||||
static QHash<KDecoration2::DecorationButtonType, QChar> s_buttonNames;
|
||||
static void initButtons()
|
||||
{
|
||||
return QList<KDecoration2::DecorationButtonType >({
|
||||
KDecoration2::DecorationButtonType::Menu,
|
||||
KDecoration2::DecorationButtonType::OnAllDesktops
|
||||
});
|
||||
if (!s_buttonNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::Menu] = QChar('M');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::ApplicationMenu] = QChar('N');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::OnAllDesktops] = QChar('S');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::QuickHelp] = QChar('H');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::Minimize] = QChar('I');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::Maximize] = QChar('A');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::Close] = QChar('X');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::KeepAbove] = QChar('F');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::KeepBelow] = QChar('B');
|
||||
s_buttonNames[KDecoration2::DecorationButtonType::Shade] = QChar('L');
|
||||
}
|
||||
|
||||
QList< KDecoration2::DecorationButtonType > SettingsImpl::decorationButtonsRight() const
|
||||
static QString buttonsToString(const QList<KDecoration2::DecorationButtonType> &buttons)
|
||||
{
|
||||
return QList<KDecoration2::DecorationButtonType >({
|
||||
auto buttonToString = [](KDecoration2::DecorationButtonType button) -> QChar {
|
||||
const auto it = s_buttonNames.constFind(button);
|
||||
if (it != s_buttonNames.constEnd()) {
|
||||
return it.value();
|
||||
}
|
||||
return QChar();
|
||||
};
|
||||
QString ret;
|
||||
for (auto button : buttons) {
|
||||
ret.append(buttonToString(button));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList< KDecoration2::DecorationButtonType > SettingsImpl::readDecorationButtons(const KConfigGroup &config,
|
||||
const char *key,
|
||||
const QList< KDecoration2::DecorationButtonType > &defaultValue) const
|
||||
{
|
||||
initButtons();
|
||||
auto buttonsFromString = [](const QString &buttons) -> QList<KDecoration2::DecorationButtonType> {
|
||||
QList<KDecoration2::DecorationButtonType> ret;
|
||||
for (auto it = buttons.begin(); it != buttons.end(); ++it) {
|
||||
for (auto it2 = s_buttonNames.constBegin(); it2 != s_buttonNames.constEnd(); ++it2) {
|
||||
if (it2.value() == (*it)) {
|
||||
ret << it2.key();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
return buttonsFromString(config.readEntry(key, buttonsToString(defaultValue)));
|
||||
}
|
||||
|
||||
void SettingsImpl::readSettings()
|
||||
{
|
||||
KConfigGroup config = KSharedConfig::openConfig(KWIN_CONFIG)->group(QStringLiteral("org.kde.kdecoration2"));
|
||||
m_leftButtons = readDecorationButtons(config, "ButtonsOnLeft", QList<KDecoration2::DecorationButtonType >({
|
||||
KDecoration2::DecorationButtonType::Menu,
|
||||
KDecoration2::DecorationButtonType::OnAllDesktops
|
||||
}));
|
||||
m_rightButtons = readDecorationButtons(config, "ButtonsOnRight", QList<KDecoration2::DecorationButtonType >({
|
||||
KDecoration2::DecorationButtonType::Minimize,
|
||||
KDecoration2::DecorationButtonType::Maximize,
|
||||
KDecoration2::DecorationButtonType::Close
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <QObject>
|
||||
|
||||
class KConfigGroup;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
namespace Decoration
|
||||
|
@ -37,8 +39,20 @@ public:
|
|||
virtual ~SettingsImpl();
|
||||
bool isAlphaChannelSupported() const override;
|
||||
bool isOnAllDesktopsAvailable() const override;
|
||||
QList< KDecoration2::DecorationButtonType > decorationButtonsLeft() const override;
|
||||
QList< KDecoration2::DecorationButtonType > decorationButtonsRight() const override;
|
||||
QList< KDecoration2::DecorationButtonType > decorationButtonsLeft() const override {
|
||||
return m_leftButtons;
|
||||
}
|
||||
QList< KDecoration2::DecorationButtonType > decorationButtonsRight() const override {
|
||||
return m_rightButtons;
|
||||
}
|
||||
|
||||
private:
|
||||
void readSettings();
|
||||
QList< KDecoration2::DecorationButtonType > readDecorationButtons(const KConfigGroup &config,
|
||||
const char *key,
|
||||
const QList< KDecoration2::DecorationButtonType > &defaultValue) const;
|
||||
QList< KDecoration2::DecorationButtonType > m_leftButtons;
|
||||
QList< KDecoration2::DecorationButtonType > m_rightButtons;
|
||||
};
|
||||
} // Decoration
|
||||
} // KWin
|
||||
|
|
Loading…
Reference in a new issue