2
* Copyright (C) 2010 Andriy Rysin (rysin@kde.org)
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include <QtGui/QKeySequence>
24
#include <QtCore/QString>
25
#include <QtCore/QStringList>
26
#include <QtGui/QWidget>
29
class XEventNotifier : public QWidget {
34
void layoutMapChanged();
37
XEventNotifier(QWidget* parent=NULL);
38
virtual ~XEventNotifier() {}
44
bool x11Event(XEvent * e);
45
virtual bool processOtherEvents(XEvent* e);
46
virtual bool processXkbEvents(XEvent* e);
49
int registerForXkbEvents(Display* display);
50
bool isXkbEvent(XEvent* event);
51
bool isGroupSwitchEvent(XEvent* event);
52
bool isLayoutSwitchEvent(XEvent* event);
58
QString keyboardModel;
63
bool isValid() { return ! layouts.empty(); }
68
static const int MAX_LABEL_LENGTH;
70
//TODO: move these to private?
75
explicit LayoutUnit(const QString& fullLayoutName);
76
LayoutUnit(const QString& layout_, const QString& variant_) {
80
/*explicit*/ LayoutUnit(const LayoutUnit& layoutUnit) {
81
layout = layoutUnit.layout;
82
variant = layoutUnit.variant;
83
displayName = layoutUnit.displayName;
84
shortcut = layoutUnit.shortcut;
87
QString getRawDisplayName() const { return displayName; }
88
QString getDisplayName() const { return !displayName.isEmpty() ? displayName : layout; }
89
void setDisplayName(const QString& name) { displayName = name; }
91
void setShortcut(const QKeySequence& shortcut) { this->shortcut = shortcut; }
92
QKeySequence getShortcut() const { return shortcut; }
94
bool isEmpty() const { return layout.isEmpty(); }
95
bool isValid() const { return ! isEmpty(); }
96
bool operator==(const LayoutUnit& layoutItem) const {
97
return layout==layoutItem.layout && variant==layoutItem.variant;
99
bool operator!=(const LayoutUnit& layoutItem) const {
100
return ! (*this == layoutItem);
102
QString toString() const;
106
QKeySequence shortcut;
110
QList<LayoutUnit> layouts;
111
LayoutUnit currentLayout;
115
LayoutSet(const LayoutSet& currentLayouts) {
116
this->layouts = currentLayouts.layouts;
117
this->currentLayout = currentLayouts.currentLayout;
120
bool isValid() const {
121
return currentLayout.isValid() && layouts.contains(currentLayout);
124
bool operator == (const LayoutSet& currentLayouts) const {
125
return this->layouts == currentLayouts.layouts
126
&& this->currentLayout == currentLayouts.currentLayout;
129
LayoutSet& operator = (const LayoutSet& currentLayouts) {
130
this->layouts = currentLayouts.layouts;
131
this->currentLayout = currentLayouts.currentLayout;
135
QString toString() const {
136
QString str(currentLayout.toString());
138
foreach(const LayoutUnit& layoutUnit, layouts) {
139
str += layoutUnit.toString() + " ";
144
static QString toString(const QList<LayoutUnit>& layoutUnits) {
146
foreach(const LayoutUnit& layoutUnit, layoutUnits) {
147
str += layoutUnit.toString() + ",";
156
static int MAX_GROUP_COUNT;
157
static const char* LEFT_VARIANT_STR;
158
static const char* RIGHT_VARIANT_STR;
160
static bool xkbSupported(int* xkbOpcode);
162
static void switchToNextLayout();
163
static void scrollLayouts(int delta);
164
static bool isDefaultLayout();
165
static bool setDefaultLayout();
166
static bool setLayout(const LayoutUnit& layout);
167
static LayoutUnit getCurrentLayout();
168
static LayoutSet getCurrentLayouts();
169
static QList<LayoutUnit> getLayoutsList();
170
static QStringList getLayoutsListAsString(const QList<LayoutUnit>& layoutsList);
172
enum FetchType { ALL, LAYOUTS_ONLY, MODEL_ONLY };
173
static bool getGroupNames(Display* dpy, XkbConfig* xkbConfig, FetchType fetchType);
176
static unsigned int getGroup();
177
static bool setGroup(unsigned int group);
180
#endif /* X11_HELPER_H_ */