Changeset View
Changeset View
Standalone View
Standalone View
keyboard_layout_switching.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2017 Martin Gräßlin <mgraesslin@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #ifndef KWIN_KEYBOARD_LAYOUT_SWITCHING_H | ||||
21 | #define KWIN_KEYBOARD_LAYOUT_SWITCHING_H | ||||
22 | | ||||
23 | #include <QObject> | ||||
24 | #include <QHash> | ||||
25 | | ||||
26 | namespace KWin | ||||
27 | { | ||||
28 | | ||||
29 | class KeyboardLayout; | ||||
30 | class Xkb; | ||||
31 | class VirtualDesktop; | ||||
32 | | ||||
33 | namespace KeyboardLayoutSwitching | ||||
34 | { | ||||
35 | | ||||
36 | class Policy : public QObject | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | public: | ||||
40 | virtual ~Policy(); | ||||
41 | | ||||
42 | virtual QString name() const = 0; | ||||
43 | | ||||
44 | static Policy *create(Xkb *xkb, KeyboardLayout *layout, const QString &policy); | ||||
45 | | ||||
46 | protected: | ||||
47 | explicit Policy(Xkb *xkb, KeyboardLayout *layout); | ||||
48 | virtual void clearCache() = 0; | ||||
49 | virtual void layoutChanged() = 0; | ||||
50 | | ||||
51 | void setLayout(quint32 layout); | ||||
52 | quint32 layout() const; | ||||
53 | | ||||
54 | private: | ||||
55 | Xkb *m_xkb; | ||||
56 | KeyboardLayout *m_layout; | ||||
57 | }; | ||||
58 | | ||||
59 | class GlobalPolicy : public Policy | ||||
60 | { | ||||
61 | Q_OBJECT | ||||
62 | public: | ||||
63 | explicit GlobalPolicy(Xkb *xkb, KeyboardLayout *layout); | ||||
64 | ~GlobalPolicy() override; | ||||
65 | | ||||
66 | QString name() const override { | ||||
67 | return QStringLiteral("Global"); | ||||
68 | } | ||||
69 | | ||||
70 | protected: | ||||
71 | void clearCache() override {} | ||||
72 | void layoutChanged() override {} | ||||
73 | }; | ||||
74 | | ||||
75 | class VirtualDesktopPolicy : public Policy | ||||
76 | { | ||||
77 | Q_OBJECT | ||||
78 | public: | ||||
79 | explicit VirtualDesktopPolicy(Xkb *xkb, KeyboardLayout *layout); | ||||
80 | ~VirtualDesktopPolicy() override; | ||||
81 | | ||||
82 | QString name() const override { | ||||
83 | return QStringLiteral("Desktop"); | ||||
84 | } | ||||
85 | | ||||
86 | protected: | ||||
87 | void clearCache() override; | ||||
88 | void layoutChanged() override; | ||||
89 | | ||||
90 | private: | ||||
91 | void desktopChanged(); | ||||
92 | QHash<VirtualDesktop *, quint32> m_layouts; | ||||
93 | }; | ||||
94 | | ||||
95 | } | ||||
96 | } | ||||
97 | | ||||
98 | #endif |