KWin
Loading...
Searching...
No Matches
keyboard_layout.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10
11#include "input_event_spy.h"
12#include <QList>
13#include <QObject>
14#include <memory>
15#include <optional>
16
17#include <KConfigGroup>
18#include <KSharedConfig>
19typedef uint32_t xkb_layout_index_t;
20
21class QAction;
22class QDBusArgument;
23
24namespace KWin
25{
26class Xkb;
27class KeyboardLayoutDBusInterface;
28
29namespace KeyboardLayoutSwitching
30{
31class Policy;
32}
33
34class KeyboardLayout : public QObject, public InputEventSpy
35{
36 Q_OBJECT
37public:
38 explicit KeyboardLayout(Xkb *xkb, const KSharedConfigPtr &config);
39
40 ~KeyboardLayout() override;
41
42 void init();
43
44 void checkLayoutChange(uint previousLayout);
45 void switchToNextLayout();
48 void resetLayout();
49
50Q_SIGNALS:
51 void layoutChanged(uint index);
53
54private Q_SLOTS:
55 void reconfigure();
56
57private:
58 void initDBusInterface();
59 void notifyLayoutChange();
60 void switchToLayout(xkb_layout_index_t index);
61 void loadShortcuts();
62 Xkb *m_xkb;
63 xkb_layout_index_t m_layout = 0;
64 KConfigGroup m_configGroup;
65 QList<QAction *> m_layoutShortcuts;
66 KeyboardLayoutDBusInterface *m_dbusInterface = nullptr;
67 std::unique_ptr<KeyboardLayoutSwitching::Policy> m_policy;
68 std::optional<uint> m_lastUsedLayout;
69};
70
71class KeyboardLayoutDBusInterface : public QObject
72{
73 Q_OBJECT
74 Q_CLASSINFO("D-Bus Interface", "org.kde.KeyboardLayouts")
75
76public:
77 explicit KeyboardLayoutDBusInterface(Xkb *xkb, const KConfigGroup &configGroup, KeyboardLayout *parent);
79
81 {
82 QString shortName;
83 QString displayName;
84 QString longName;
85 };
86
87public Q_SLOTS:
88 void switchToNextLayout();
90 bool setLayout(uint index);
91 uint getLayout() const;
92 QList<LayoutNames> getLayoutsList() const;
93
94Q_SIGNALS:
95 void layoutChanged(uint index);
97
98private:
99 Xkb *m_xkb;
100 const KConfigGroup &m_configGroup;
101 KeyboardLayout *m_keyboardLayout;
102};
103
104QDBusArgument &operator<<(QDBusArgument &argument, const KeyboardLayoutDBusInterface::LayoutNames &layoutNames);
105const QDBusArgument &operator>>(const QDBusArgument &argument, KeyboardLayoutDBusInterface::LayoutNames &layoutNames);
106
107}
QList< LayoutNames > getLayoutsList() const
KeyboardLayoutDBusInterface(Xkb *xkb, const KConfigGroup &configGroup, KeyboardLayout *parent)
void layoutChanged(uint index)
void checkLayoutChange(uint previousLayout)
KeyboardLayout(Xkb *xkb, const KSharedConfigPtr &config)
~KeyboardLayout() override
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
uint32_t xkb_layout_index_t
uint32_t xkb_layout_index_t
QDebug & operator<<(QDebug &s, const KWin::DrmConnector *obj)
const QDBusArgument & operator>>(const QDBusArgument &argument, KeyboardLayoutDBusInterface::LayoutNames &layoutNames)