Commit 73aa6fba authored by Andrey Butirsky's avatar Andrey Butirsky

refactor: pass layout in KeyboardLayout::layoutChanged() signal argument

On that signal, we asquare the new layout anyway all over the places.
Better just pass it along with the signal instead.

Also it's in-line with DBus API signal.
parent 260fa665
......@@ -72,11 +72,8 @@ void KeyboardLayout::initDBusInterface()
return;
}
m_dbusInterface = new KeyboardLayoutDBusInterface(m_xkb, m_configGroup, this);
connect(this, &KeyboardLayout::layoutChanged, m_dbusInterface,
[this] {
emit m_dbusInterface->layoutChanged(m_xkb->currentLayout());
}
);
connect(this, &KeyboardLayout::layoutChanged,
m_dbusInterface, &KeyboardLayoutDBusInterface::layoutChanged);
// TODO: the signal might be emitted even if the list didn't change
connect(this, &KeyboardLayout::layoutsReconfigured, m_dbusInterface, &KeyboardLayoutDBusInterface::layoutListChanged);
}
......@@ -150,17 +147,17 @@ void KeyboardLayout::loadShortcuts()
}
}
void KeyboardLayout::checkLayoutChange(quint32 previousLayout)
void KeyboardLayout::checkLayoutChange(uint previousLayout)
{
// Get here on key event or DBus call.
// m_layout - layout saved last time OSD occurred
// previousLayout - actual layout just before potential layout change
// We need OSD if current layout deviates from any of these
const auto layout = m_xkb->currentLayout();
if (m_layout != layout || previousLayout != layout) {
m_layout = layout;
const uint currentLayout = m_xkb->currentLayout();
if (m_layout != currentLayout || previousLayout != currentLayout) {
m_layout = currentLayout;
notifyLayoutChange();
emit layoutChanged();
emit layoutChanged(currentLayout);
}
}
......
......@@ -40,13 +40,13 @@ public:
void init();
void checkLayoutChange(quint32 previousLayout);
void checkLayoutChange(uint previousLayout);
void switchToNextLayout();
void switchToPreviousLayout();
void resetLayout();
Q_SIGNALS:
void layoutChanged();
void layoutChanged(uint index);
void layoutsReconfigured();
private Q_SLOTS:
......
......@@ -32,20 +32,16 @@ Policy::Policy(Xkb *xkb, KeyboardLayout *layout, const KConfigGroup &config)
Policy::~Policy() = default;
void Policy::setLayout(quint32 layout)
void Policy::setLayout(uint index)
{
const quint32 previousLayout = m_xkb->currentLayout();
m_xkb->switchToLayout(layout);
if (previousLayout != m_xkb->currentLayout()) {
emit m_layout->layoutChanged();
const uint previousLayout = m_xkb->currentLayout();
m_xkb->switchToLayout(index);
const uint currentLayout = m_xkb->currentLayout();
if (previousLayout != currentLayout) {
emit m_layout->layoutChanged(currentLayout);
}
}
quint32 Policy::layout() const
{
return m_xkb->currentLayout();
}
Policy *Policy::create(Xkb *xkb, KeyboardLayout *layout, const KConfigGroup &config, const QString &policy)
{
if (policy.toLower() == QStringLiteral("desktop")) {
......@@ -83,11 +79,11 @@ GlobalPolicy::GlobalPolicy(Xkb *xkb, KeyboardLayout *_layout, const KConfigGroup
: Policy(xkb, _layout, config)
{
connect(workspace()->sessionManager(), &SessionManager::prepareSessionSaveRequested, this,
[this] (const QString &name) {
[this, xkb] (const QString &name) {
Q_UNUSED(name)
clearLayouts();
if (layout()) {
m_config.writeEntry(defaultLayoutEntryKey(), layout());
if (const uint layout = xkb->currentLayout()) {
m_config.writeEntry(defaultLayoutEntryKey(), layout);
}
}
);
......@@ -179,26 +175,25 @@ void VirtualDesktopPolicy::desktopChanged()
setLayout(getLayout(m_layouts, d));
}
void VirtualDesktopPolicy::layoutChanged()
void VirtualDesktopPolicy::layoutChanged(uint index)
{
auto d = VirtualDesktopManager::self()->currentDesktop();
if (!d) {
return;
}
auto it = m_layouts.find(d);
const auto l = layout();
if (it == m_layouts.end()) {
m_layouts.insert(d, l);
m_layouts.insert(d, index);
connect(d, &VirtualDesktop::aboutToBeDestroyed, this,
[this, d] {
m_layouts.remove(d);
}
);
} else {
if (it.value() == l) {
if (it.value() == index) {
return;
}
it.value() = l;
it.value() = index;
}
}
......@@ -228,7 +223,7 @@ void WindowPolicy::clearCache()
m_layouts.clear();
}
void WindowPolicy::layoutChanged()
void WindowPolicy::layoutChanged(uint index)
{
auto c = workspace()->activeClient();
if (!c) {
......@@ -240,19 +235,18 @@ void WindowPolicy::layoutChanged()
}
auto it = m_layouts.find(c);
const auto l = layout();
if (it == m_layouts.end()) {
m_layouts.insert(c, l);
m_layouts.insert(c, index);
connect(c, &AbstractClient::windowClosed, this,
[this, c] {
m_layouts.remove(c);
}
);
} else {
if (it.value() == l) {
if (it.value() == index) {
return;
}
it.value() = l;
it.value() = index;
}
}
......@@ -316,14 +310,15 @@ void ApplicationPolicy::clientActivated(AbstractClient *c)
};
for (it = m_layouts.constBegin(); it != m_layouts.constEnd(); it++) {
if (AbstractClient::belongToSameApplication(c, it.key())) {
setLayout(it.value());
layoutChanged();
const uint layout = it.value();
setLayout(layout);
layoutChanged(layout);
return;
}
}
setLayout( m_layoutsRestored.take(c->desktopFileName()) );
if (layout()) {
layoutChanged();
if (const uint index = m_xkb->currentLayout()) {
layoutChanged(index);
}
}
......@@ -332,7 +327,7 @@ void ApplicationPolicy::clearCache()
m_layouts.clear();
}
void ApplicationPolicy::layoutChanged()
void ApplicationPolicy::layoutChanged(uint index)
{
auto c = workspace()->activeClient();
if (!c) {
......@@ -344,26 +339,24 @@ void ApplicationPolicy::layoutChanged()
}
auto it = m_layouts.find(c);
const auto l = layout();
if (it == m_layouts.end()) {
m_layouts.insert(c, l);
m_layouts.insert(c, index);
connect(c, &AbstractClient::windowClosed, this,
[this, c] {
m_layouts.remove(c);
}
);
} else {
if (it.value() == l) {
if (it.value() == index) {
return;
}
it.value() = l;
it.value() = index;
}
// update all layouts for the application
for (it = m_layouts.begin(); it != m_layouts.end(); it++) {
if (!AbstractClient::belongToSameApplication(it.key(), c)) {
continue;
if (AbstractClient::belongToSameApplication(it.key(), c)) {
it.value() = index;
}
it.value() = l;
}
}
......
......@@ -37,19 +37,18 @@ public:
protected:
explicit Policy(Xkb *xkb, KeyboardLayout *layout, const KConfigGroup &config = KConfigGroup());
virtual void clearCache() = 0;
virtual void layoutChanged() = 0;
virtual void layoutChanged(uint index) = 0;
void setLayout(quint32 layout);
quint32 layout() const;
void setLayout(uint index);
KConfigGroup m_config;
virtual const QString defaultLayoutEntryKey() const;
void clearLayouts();
static const char defaultLayoutEntryKeyPrefix[];
Xkb *m_xkb;
private:
Xkb *m_xkb;
KeyboardLayout *m_layout;
};
......@@ -66,7 +65,7 @@ public:
protected:
void clearCache() override {}
void layoutChanged() override {}
void layoutChanged(uint index) override {Q_UNUSED(index)}
private:
const QString defaultLayoutEntryKey() const override;
......@@ -85,7 +84,7 @@ public:
protected:
void clearCache() override;
void layoutChanged() override;
void layoutChanged(uint index) override;
private:
void desktopChanged();
......@@ -105,7 +104,7 @@ public:
protected:
void clearCache() override;
void layoutChanged() override;
void layoutChanged(uint index) override;
private:
QHash<AbstractClient*, quint32> m_layouts;
......@@ -124,7 +123,7 @@ public:
protected:
void clearCache() override;
void layoutChanged() override;
void layoutChanged(uint index) override;
private:
void clientActivated(AbstractClient *c);
......
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