keyboard_layout.h 2.17 KB
Newer Older
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
1
2
3
/*
    KWin - the KDE window manager
    This file is part of the KDE project.
4

Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
5
    SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
6

Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
7
8
    SPDX-License-Identifier: GPL-2.0-or-later
*/
9
10
11
12
13
#ifndef KWIN_KEYBOARD_LAYOUT_H
#define KWIN_KEYBOARD_LAYOUT_H

#include "input_event_spy.h"
#include <QObject>
14
#include <QVector>
15
16

#include <KSharedConfig>
17
18
typedef uint32_t xkb_layout_index_t;

19
class KStatusNotifierItem;
20
class QAction;
21

22
23
24
namespace KWin
{
class Xkb;
25
class KeyboardLayoutDBusInterface;
26

27
28
29
30
31
namespace KeyboardLayoutSwitching
{
class Policy;
}

32
33
34
35
36
37
38
class KeyboardLayout : public QObject, public InputEventSpy
{
    Q_OBJECT
public:
    explicit KeyboardLayout(Xkb *xkb);
    ~KeyboardLayout() override;

39
40
41
42
    void setConfig(KSharedConfigPtr config) {
        m_config = config;
    }

43
44
45
46
    void init();

    void checkLayoutChange();
    void resetLayout();
47
    void updateNotifier();
48
49
50

    void keyEvent(KeyEvent *event) override;

51
52
53
54
Q_SIGNALS:
    void layoutChanged();
    void layoutsReconfigured();

55
56
57
58
private Q_SLOTS:
    void reconfigure();

private:
59
    void initDBusInterface();
60
    void notifyLayoutChange();
61
62
63
    void initNotifierItem();
    void switchToNextLayout();
    void switchToPreviousLayout();
64
    void switchToLayout(xkb_layout_index_t index);
65
    void reinitNotifierMenu();
66
    void loadShortcuts();
67
68
    Xkb *m_xkb;
    xkb_layout_index_t m_layout = 0;
69
70
    KStatusNotifierItem *m_notifierItem;
    KSharedConfigPtr m_config;
71
    QVector<QAction*> m_layoutShortcuts;
72
    KeyboardLayoutDBusInterface *m_dbusInterface = nullptr;
73
    KeyboardLayoutSwitching::Policy *m_policy = nullptr;
74
75
};

76
77
78
79
80
81
class KeyboardLayoutDBusInterface : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.KeyboardLayouts")

public:
82
    explicit KeyboardLayoutDBusInterface(Xkb *xkb, KeyboardLayout *parent);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
    ~KeyboardLayoutDBusInterface() override;

public Q_SLOTS:
    bool setLayout(const QString &layout);
    QString getCurrentLayout();
    QStringList getLayoutsList();
    QString getLayoutDisplayName(const QString &layout);

Q_SIGNALS:
    void currentLayoutChanged(QString layout);
    void layoutListChanged();

private:
    Xkb *m_xkb;
97
    KeyboardLayout *m_keyboardLayout;
98
99
};

100
101
102
}

#endif