Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/daemon/x11_helper.h
- This file was moved from kcms/keyboard/x11_helper.h.
Show All 22 Lines | |||||
23 | #include <QKeySequence> | 23 | #include <QKeySequence> | ||
24 | #include <QString> | 24 | #include <QString> | ||
25 | #include <QStringList> | 25 | #include <QStringList> | ||
26 | #include <QWidget> | 26 | #include <QWidget> | ||
27 | #include <QX11Info> | 27 | #include <QX11Info> | ||
28 | #include <QAbstractNativeEventFilter> | 28 | #include <QAbstractNativeEventFilter> | ||
29 | 29 | | |||
30 | #include <xcb/xcb.h> | 30 | #include <xcb/xcb.h> | ||
31 | | ||||
31 | //#include <xcb/xkb.h> | 32 | //#include <xcb/xkb.h> | ||
32 | 33 | | |||
33 | //union _xkb_event; | 34 | //union _xkb_event; | ||
34 | //class xcb_generic_event_t; | 35 | //class xcb_generic_event_t; | ||
35 | 36 | | |||
36 | // TODO: remove this when we can include xcb/xkb.h | 37 | // TODO: remove this when we can include xcb/xkb.h | ||
37 | namespace | 38 | namespace | ||
38 | { | 39 | { | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 107 | class XEventNotifier : public QObject, public QAbstractNativeEventFilter { | |||
107 | Q_OBJECT | 108 | Q_OBJECT | ||
108 | 109 | | |||
109 | Q_SIGNALS: | 110 | Q_SIGNALS: | ||
110 | void layoutChanged(); | 111 | void layoutChanged(); | ||
111 | void layoutMapChanged(); | 112 | void layoutMapChanged(); | ||
112 | 113 | | |||
113 | public: | 114 | public: | ||
114 | XEventNotifier(); | 115 | XEventNotifier(); | ||
115 | virtual ~XEventNotifier() {} | | |||
116 | 116 | | |||
117 | virtual void start(); | 117 | virtual void start(); | ||
118 | virtual void stop(); | 118 | virtual void stop(); | ||
119 | 119 | | |||
120 | protected: | 120 | protected: | ||
121 | // bool x11Event(XEvent * e); | 121 | // bool x11Event(XEvent * e); | ||
122 | virtual bool processOtherEvents(xcb_generic_event_t* e); | 122 | virtual bool processOtherEvents(xcb_generic_event_t* e); | ||
123 | virtual bool processXkbEvents(xcb_generic_event_t* e); | 123 | virtual bool processXkbEvents(xcb_generic_event_t* e); | ||
124 | bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override; | 124 | bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override; | ||
125 | 125 | | |||
126 | private: | 126 | private: | ||
127 | int registerForXkbEvents(Display* display); | 127 | int registerForXkbEvents(Display* display); | ||
128 | bool isXkbEvent(xcb_generic_event_t* event); | 128 | bool isXkbEvent(xcb_generic_event_t* event); | ||
129 | bool isGroupSwitchEvent(_xkb_event* event); | 129 | bool isGroupSwitchEvent(_xkb_event* event); | ||
130 | bool isLayoutSwitchEvent(_xkb_event* event); | 130 | bool isLayoutSwitchEvent(_xkb_event* event); | ||
131 | 131 | | |||
132 | int xkbOpcode; | 132 | int xkbOpcode; | ||
133 | }; | 133 | }; | ||
134 | 134 | | |||
135 | struct XkbConfig { | | |||
136 | QString keyboardModel; | | |||
137 | QStringList layouts; | | |||
138 | QStringList variants; | | |||
139 | QStringList options; | | |||
140 | | ||||
141 | bool isValid() { return ! layouts.empty(); } | | |||
142 | }; | | |||
143 | | ||||
144 | | ||||
145 | struct LayoutUnit { | | |||
146 | static const int MAX_LABEL_LENGTH; | | |||
147 | | ||||
148 | //TODO: move these to private? | | |||
149 | QString layout; | | |||
150 | QString variant; | | |||
151 | | ||||
152 | LayoutUnit() {} | | |||
153 | explicit LayoutUnit(const QString& fullLayoutName); | | |||
154 | LayoutUnit(const QString& layout_, const QString& variant_) { | | |||
155 | layout = layout_; | | |||
156 | variant = variant_; | | |||
157 | } | | |||
158 | /*explicit*/ LayoutUnit(const LayoutUnit& layoutUnit) { | | |||
159 | layout = layoutUnit.layout; | | |||
160 | variant = layoutUnit.variant; | | |||
161 | displayName = layoutUnit.displayName; | | |||
162 | shortcut = layoutUnit.shortcut; | | |||
163 | } | | |||
164 | | ||||
165 | QString getRawDisplayName() const { return displayName; } | | |||
166 | QString getDisplayName() const { return !displayName.isEmpty() ? displayName : layout; } | | |||
167 | void setDisplayName(const QString& name) { displayName = name; } | | |||
168 | | ||||
169 | void setShortcut(const QKeySequence& shortcut) { this->shortcut = shortcut; } | | |||
170 | QKeySequence getShortcut() const { return shortcut; } | | |||
171 | | ||||
172 | bool isEmpty() const { return layout.isEmpty(); } | | |||
173 | bool isValid() const { return ! isEmpty(); } | | |||
174 | bool operator==(const LayoutUnit& layoutItem) const { | | |||
175 | return layout==layoutItem.layout && variant==layoutItem.variant; | | |||
176 | } | | |||
177 | bool operator!=(const LayoutUnit& layoutItem) const { | | |||
178 | return ! (*this == layoutItem); | | |||
179 | } | | |||
180 | QString toString() const; | | |||
181 | | ||||
182 | private: | | |||
183 | QString displayName; | | |||
184 | QKeySequence shortcut; | | |||
185 | }; | | |||
186 | | ||||
187 | struct LayoutSet { | | |||
188 | QList<LayoutUnit> layouts; | | |||
189 | LayoutUnit currentLayout; | | |||
190 | | ||||
191 | LayoutSet() {} | | |||
192 | | ||||
193 | LayoutSet(const LayoutSet& currentLayouts) { | | |||
194 | this->layouts = currentLayouts.layouts; | | |||
195 | this->currentLayout = currentLayouts.currentLayout; | | |||
196 | } | | |||
197 | | ||||
198 | bool isValid() const { | | |||
199 | return currentLayout.isValid() && layouts.contains(currentLayout); | | |||
200 | } | | |||
201 | | ||||
202 | bool operator == (const LayoutSet& currentLayouts) const { | | |||
203 | return this->layouts == currentLayouts.layouts | | |||
204 | && this->currentLayout == currentLayouts.currentLayout; | | |||
205 | } | | |||
206 | | ||||
207 | LayoutSet& operator = (const LayoutSet& currentLayouts) { | | |||
208 | this->layouts = currentLayouts.layouts; | | |||
209 | this->currentLayout = currentLayouts.currentLayout; | | |||
210 | return *this; | | |||
211 | } | | |||
212 | | ||||
213 | QString toString() const { | | |||
214 | QString str(currentLayout.toString()); | | |||
215 | str += QLatin1String(": "); | | |||
216 | foreach(const LayoutUnit& layoutUnit, layouts) { | | |||
217 | str += layoutUnit.toString() + " "; | | |||
218 | } | | |||
219 | return str; | | |||
220 | } | | |||
221 | | ||||
222 | static QString toString(const QList<LayoutUnit>& layoutUnits) { | | |||
223 | QString str; | | |||
224 | foreach(const LayoutUnit& layoutUnit, layoutUnits) { | | |||
225 | str += layoutUnit.toString() + ","; | | |||
226 | } | | |||
227 | return str; | | |||
228 | } | | |||
229 | }; | | |||
230 | | ||||
231 | class X11Helper | 135 | class X11Helper | ||
232 | { | 136 | { | ||
233 | public: | 137 | public: | ||
234 | static const int MAX_GROUP_COUNT; | 138 | static const int MAX_GROUP_COUNT; | ||
235 | static const int ARTIFICIAL_GROUP_LIMIT_COUNT; | 139 | static const int ARTIFICIAL_GROUP_LIMIT_COUNT; | ||
236 | 140 | | |||
237 | static const char LEFT_VARIANT_STR[]; | 141 | static const char LEFT_VARIANT_STR[]; | ||
238 | static const char RIGHT_VARIANT_STR[]; | 142 | static const char RIGHT_VARIANT_STR[]; | ||
239 | 143 | | |||
240 | static bool xkbSupported(int* xkbOpcode); | 144 | static bool xkbSupported(int* xkbOpcode); | ||
241 | | ||||
242 | static void switchToNextLayout(); | | |||
243 | static void scrollLayouts(int delta); | | |||
244 | static bool isDefaultLayout(); | | |||
245 | static bool setDefaultLayout(); | | |||
246 | static bool setLayout(const LayoutUnit& layout); | | |||
247 | static LayoutUnit getCurrentLayout(); | | |||
248 | static LayoutSet getCurrentLayouts(); | | |||
249 | static QList<LayoutUnit> getLayoutsList(); | | |||
250 | static QStringList getLayoutsListAsString(const QList<LayoutUnit>& layoutsList); | | |||
251 | | ||||
252 | enum FetchType { ALL, LAYOUTS_ONLY, MODEL_ONLY }; | | |||
253 | static bool getGroupNames(Display* dpy, XkbConfig* xkbConfig, FetchType fetchType); | | |||
254 | | ||||
255 | private: | | |||
256 | static unsigned int getGroup(); | | |||
257 | static bool setGroup(unsigned int group); | | |||
258 | }; | 145 | }; | ||
259 | 146 | | |||
260 | #endif /* X11_HELPER_H_ */ | 147 | #endif /* X11_HELPER_H_ */ |