Commit a482d73d authored by Andrey Butirsky's avatar Andrey Butirsky
Browse files

feat: expose keyboard layout Short Name via DBus

Due space constraints, Short Name is the only name suitable for keyboard
layout indication on panels and systray. Usually it's just 2 symbols
corresponding to standard ISO country code.

libxkbcommon doesn't have this information, so we have to store it in
compositor for the exposing:

It's exposed by getLayoutDisplayName() DBus method now, as it should initially.
For Long Name, getCurrentLayoutLongName() method was added.

Relevant P-W commits:
Keyboard Layout plugin: passthrough Short Name from compositor to QML applet
fix: Keyboard Layout plugin: wrong property for passing Short Name
X11 part, P-D:
feat: expose keyboard layout Long Name via DBus

CCBUG: 390079
parent ba4dbab4
......@@ -314,6 +314,11 @@ QString KeyboardLayoutDBusInterface::getCurrentLayout()
return m_xkb->layoutName();
QString KeyboardLayoutDBusInterface::getCurrentLayoutLongName() const
return translatedLayout(m_xkb->layoutName());
QStringList KeyboardLayoutDBusInterface::getLayoutsList()
const auto layouts = m_xkb->layoutNames();
......@@ -326,7 +331,10 @@ QStringList KeyboardLayoutDBusInterface::getLayoutsList()
QString KeyboardLayoutDBusInterface::getLayoutDisplayName(const QString &layout)
return translatedLayout(layout);
// TODO: remove arguments from the DBus API methods
return m_xkb->layoutShortName();
......@@ -83,6 +83,7 @@ public:
public Q_SLOTS:
bool setLayout(const QString &layout);
QString getCurrentLayout();
QString getCurrentLayoutLongName() const;
QStringList getLayoutsList();
QString getLayoutDisplayName(const QString &layout);
......@@ -17,7 +17,6 @@
#include <QTemporaryFile>
#include <QKeyEvent>
// xkbcommon
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon-keysyms.h>
// system
......@@ -145,7 +144,7 @@ static bool stringIsEmptyOrNull(const char *str)
* As kwin_wayland may have the CAP_SET_NICE capability, it returns nullptr
* so we need to do it ourselves (see xkb_context_sanitize_rule_names).
static void applyEnvironmentRules(xkb_rule_names &ruleNames)
void Xkb::applyEnvironmentRules(xkb_rule_names &ruleNames)
if (stringIsEmptyOrNull(ruleNames.rules)) {
ruleNames.rules = getenv("XKB_DEFAULT_RULES");
......@@ -163,6 +162,8 @@ static void applyEnvironmentRules(xkb_rule_names &ruleNames)
if (ruleNames.options == nullptr) {
ruleNames.options = getenv("XKB_DEFAULT_OPTIONS");
m_layoutList = QString::fromLatin1(ruleNames.layout).split(QLatin1Char(','));
xkb_keymap *Xkb::loadKeymapFromConfig()
......@@ -385,6 +386,11 @@ QString Xkb::layoutName() const
return layoutName(m_currentLayout);
const QString &Xkb::layoutShortName() const
QString Xkb::layoutName(xkb_layout_index_t layout) const
if (!m_keymap) {
......@@ -9,6 +9,7 @@
#ifndef KWIN_XKB_H
#define KWIN_XKB_H
#include "input.h"
#include <xkbcommon/xkbcommon.h>
#include <kwin_export.h>
......@@ -90,6 +91,7 @@ public:
return m_currentLayout;
QString layoutName() const;
const QString &layoutShortName() const;
QMap<xkb_layout_index_t, QString> layoutNames() const;
quint32 numberOfLayouts() const;
......@@ -104,6 +106,7 @@ Q_SIGNALS:
void ledsChanged(const LEDs &leds);
void applyEnvironmentRules(xkb_rule_names &);
xkb_keymap *loadKeymapFromConfig();
xkb_keymap *loadDefaultKeymap();
void updateKeymap(xkb_keymap *keymap);
......@@ -113,6 +116,7 @@ private:
QString layoutName(xkb_layout_index_t layout) const;
xkb_context *m_context;
xkb_keymap *m_keymap;
QStringList m_layoutList;
xkb_state *m_state;
xkb_mod_index_t m_shiftModifier;
xkb_mod_index_t m_capsModifier;
Supports Markdown
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