Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/daemon/xkb_helper.cpp
- This file was moved from kcms/keyboard/xkb_helper.cpp.
Show All 24 Lines | |||||
25 | #include <QStringList> | 25 | #include <QStringList> | ||
26 | #include <QTime> | 26 | #include <QTime> | ||
27 | #include <QX11Info> | 27 | #include <QX11Info> | ||
28 | #include <QStandardPaths> | 28 | #include <QStandardPaths> | ||
29 | #include <QDebug> | 29 | #include <QDebug> | ||
30 | 30 | | |||
31 | #include <kprocess.h> | 31 | #include <kprocess.h> | ||
32 | 32 | | |||
33 | #include "keyboard_config.h" | | |||
34 | | ||||
35 | | ||||
36 | static const char SETXKBMAP_EXEC[] = "setxkbmap"; | 33 | static const char SETXKBMAP_EXEC[] = "setxkbmap"; | ||
37 | static const char XMODMAP_EXEC[] = "xmodmap"; | 34 | static const char XMODMAP_EXEC[] = "xmodmap"; | ||
38 | 35 | | |||
39 | static bool setxkbmapNotFound = false; | 36 | static bool setxkbmapNotFound = false; | ||
40 | static QString setxkbmapExe; | 37 | static QString setxkbmapExe; | ||
41 | 38 | | |||
42 | static bool xmodmapNotFound = false; | 39 | static bool xmodmapNotFound = false; | ||
43 | static QString xmodmapExe; | 40 | static QString xmodmapExe; | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
92 | { | 89 | { | ||
93 | // TODO: is just home .Xmodmap enough or should system be involved too? | 90 | // TODO: is just home .Xmodmap enough or should system be involved too? | ||
94 | // QString configFileName = QDir("/etc/X11/xinit").filePath(".Xmodmap"); | 91 | // QString configFileName = QDir("/etc/X11/xinit").filePath(".Xmodmap"); | ||
95 | // executeXmodmap(configFileName); | 92 | // executeXmodmap(configFileName); | ||
96 | QString configFileName = QDir::home().filePath(QStringLiteral(".Xmodmap")); | 93 | QString configFileName = QDir::home().filePath(QStringLiteral(".Xmodmap")); | ||
97 | executeXmodmap(configFileName); | 94 | executeXmodmap(configFileName); | ||
98 | } | 95 | } | ||
99 | 96 | | |||
100 | //TODO: make private | | |||
101 | bool XkbHelper::runConfigLayoutCommand(const QStringList& setxkbmapCommandArguments) | 97 | bool XkbHelper::runConfigLayoutCommand(const QStringList& setxkbmapCommandArguments) | ||
102 | { | 98 | { | ||
103 | QTime timer; | 99 | QTime timer; | ||
104 | timer.start(); | 100 | timer.start(); | ||
105 | 101 | | |||
106 | KProcess setxkbmapProcess; | 102 | KProcess setxkbmapProcess; | ||
107 | setxkbmapProcess << getSetxkbmapExe() << setxkbmapCommandArguments; | 103 | setxkbmapProcess << getSetxkbmapExe() << setxkbmapCommandArguments; | ||
108 | int res = setxkbmapProcess.execute(); | 104 | int res = setxkbmapProcess.execute(); | ||
109 | 105 | | |||
110 | if( res == 0 ) { // restore Xmodmap mapping reset by setxkbmap | 106 | if( res == 0 ) { // restore Xmodmap mapping reset by setxkbmap | ||
111 | qCDebug(KCM_KEYBOARD) << "Executed successfully in " << timer.elapsed() << "ms" << setxkbmapProcess.program().join(QStringLiteral(" ")); | 107 | qCDebug(KCM_KEYBOARD) << "Executed successfully in " << timer.elapsed() << "ms" << setxkbmapProcess.program().join(QStringLiteral(" ")); | ||
112 | restoreXmodmap(); | 108 | restoreXmodmap(); | ||
113 | qCDebug(KCM_KEYBOARD) << "\t and with xmodmap" << timer.elapsed() << "ms"; | 109 | qCDebug(KCM_KEYBOARD) << "\t and with xmodmap" << timer.elapsed() << "ms"; | ||
114 | return true; | 110 | return true; | ||
115 | } | 111 | } | ||
116 | else { | 112 | else { | ||
117 | qCCritical(KCM_KEYBOARD) << "Failed to run" << setxkbmapProcess.program().join(QStringLiteral(" ")) << "return code:" << res; | 113 | qCCritical(KCM_KEYBOARD) << "Failed to run" << setxkbmapProcess.program().join(QStringLiteral(" ")) << "return code:" << res; | ||
118 | } | 114 | } | ||
119 | return false; | 115 | return false; | ||
120 | } | 116 | } | ||
121 | 117 | | |||
118 | /* | ||||
122 | bool XkbHelper::initializeKeyboardLayouts(const QList<LayoutUnit>& layoutUnits) | 119 | bool XkbHelper::initializeKeyboardLayouts(const QList<LayoutUnit>& layoutUnits) | ||
123 | { | 120 | { | ||
124 | QStringList layouts; | 121 | QStringList layouts; | ||
125 | QStringList variants; | 122 | QStringList variants; | ||
126 | foreach (const LayoutUnit& layoutUnit, layoutUnits) { | 123 | foreach (const LayoutUnit& layoutUnit, layoutUnits) { | ||
127 | layouts.append(layoutUnit.layout); | 124 | layouts.append(layoutUnit.layout); | ||
128 | variants.append(layoutUnit.variant); | 125 | variants.append(layoutUnit.variant); | ||
129 | } | 126 | } | ||
130 | 127 | | |||
131 | QStringList setxkbmapCommandArguments; | 128 | QStringList setxkbmapCommandArguments; | ||
132 | setxkbmapCommandArguments.append(QStringLiteral("-layout")); | 129 | setxkbmapCommandArguments.append(QStringLiteral("-layout")); | ||
133 | setxkbmapCommandArguments.append(layouts.join(COMMAND_OPTIONS_SEPARATOR)); | 130 | setxkbmapCommandArguments.append(layouts.join(COMMAND_OPTIONS_SEPARATOR)); | ||
134 | if( ! variants.join(QLatin1String("")).isEmpty() ) { | 131 | if( ! variants.join(QLatin1String("")).isEmpty() ) { | ||
135 | setxkbmapCommandArguments.append(QStringLiteral("-variant")); | 132 | setxkbmapCommandArguments.append(QStringLiteral("-variant")); | ||
136 | setxkbmapCommandArguments.append(variants.join(COMMAND_OPTIONS_SEPARATOR)); | 133 | setxkbmapCommandArguments.append(variants.join(COMMAND_OPTIONS_SEPARATOR)); | ||
137 | } | 134 | } | ||
138 | 135 | | |||
139 | return runConfigLayoutCommand(setxkbmapCommandArguments); | 136 | return runConfigLayoutCommand(setxkbmapCommandArguments); | ||
140 | } | 137 | } | ||
141 | 138 | */ | |||
142 | bool XkbHelper::initializeKeyboardLayouts(KeyboardConfig& config) | 139 | /* | ||
140 | bool XkbHelper::initializeKeyboardLayouts() | ||||
143 | { | 141 | { | ||
144 | QStringList setxkbmapCommandArguments; | 142 | QStringList setxkbmapCommandArguments; | ||
145 | if( ! config.keyboardModel.isEmpty() ) { | 143 | if( ! config.keyboardModel.isEmpty() ) { | ||
146 | XkbConfig xkbConfig; | 144 | XkbConfig xkbConfig; | ||
147 | X11Helper::getGroupNames(QX11Info::display(), &xkbConfig, X11Helper::MODEL_ONLY); | 145 | X11Helper::getGroupNames(QX11Info::display(), &xkbConfig, X11Helper::MODEL_ONLY); | ||
148 | if( xkbConfig.keyboardModel != config.keyboardModel ) { | 146 | if( xkbConfig.keyboardModel != config.keyboardModel ) { | ||
149 | setxkbmapCommandArguments.append(QStringLiteral("-model")); | 147 | setxkbmapCommandArguments.append(QStringLiteral("-model")); | ||
150 | setxkbmapCommandArguments.append(config.keyboardModel); | 148 | setxkbmapCommandArguments.append(config.keyboardModel); | ||
151 | } | 149 | } | ||
152 | } | 150 | } | ||
153 | if( config.configureLayouts ) { | 151 | if( config.configureLayouts ) { | ||
154 | QStringList layouts; | 152 | QStringList layouts; | ||
155 | QStringList variants; | 153 | QStringList variants; | ||
156 | QList<LayoutUnit> defaultLayouts = config.getDefaultLayouts(); | 154 | QList<LayoutUnit> defaultLayouts = config.getLayouts(); | ||
157 | foreach (const LayoutUnit& layoutUnit, defaultLayouts) { | 155 | foreach (const LayoutUnit& layoutUnit, defaultLayouts) { | ||
156 | if (layoutUnit.technology == "xkb") { | ||||
158 | layouts.append(layoutUnit.layout); | 157 | layouts.append(layoutUnit.layout); | ||
159 | variants.append(layoutUnit.variant); | 158 | variants.append(layoutUnit.variant); | ||
160 | } | 159 | } | ||
160 | } | ||||
161 | 161 | | |||
162 | setxkbmapCommandArguments.append(QStringLiteral("-layout")); | 162 | setxkbmapCommandArguments.append(QStringLiteral("-layout")); | ||
163 | setxkbmapCommandArguments.append(layouts.join(COMMAND_OPTIONS_SEPARATOR)); | 163 | setxkbmapCommandArguments.append(layouts.join(COMMAND_OPTIONS_SEPARATOR)); | ||
164 | if( ! variants.join(QLatin1String("")).isEmpty() ) { | 164 | if( ! variants.join(QLatin1String("")).isEmpty() ) { | ||
165 | setxkbmapCommandArguments.append(QStringLiteral("-variant")); | 165 | setxkbmapCommandArguments.append(QStringLiteral("-variant")); | ||
166 | setxkbmapCommandArguments.append(variants.join(COMMAND_OPTIONS_SEPARATOR)); | 166 | setxkbmapCommandArguments.append(variants.join(COMMAND_OPTIONS_SEPARATOR)); | ||
167 | } | 167 | } | ||
168 | } | 168 | } | ||
169 | if( config.resetOldXkbOptions ) { | 169 | if( config.resetOldXkbOptions ) { | ||
170 | setxkbmapCommandArguments.append(QStringLiteral("-option")); | 170 | setxkbmapCommandArguments.append(QStringLiteral("-option")); | ||
171 | } | 171 | } | ||
172 | if( ! config.xkbOptions.isEmpty() ) { | 172 | if( ! config.xkbOptions.isEmpty() ) { | ||
173 | setxkbmapCommandArguments.append(QStringLiteral("-option")); | 173 | setxkbmapCommandArguments.append(QStringLiteral("-option")); | ||
174 | setxkbmapCommandArguments.append(config.xkbOptions.join(COMMAND_OPTIONS_SEPARATOR)); | 174 | setxkbmapCommandArguments.append(config.xkbOptions.join(COMMAND_OPTIONS_SEPARATOR)); | ||
175 | } | 175 | } | ||
176 | 176 | | |||
177 | if( ! setxkbmapCommandArguments.isEmpty() ) { | 177 | if( ! setxkbmapCommandArguments.isEmpty() ) { | ||
178 | return runConfigLayoutCommand(setxkbmapCommandArguments); | 178 | return runConfigLayoutCommand(setxkbmapCommandArguments); | ||
179 | if( config.configureLayouts ) { | 179 | if( config.configureLayouts ) { | ||
180 | X11Helper::setDefaultLayout(); | 180 | X11Helper::setDefaultLayout(); | ||
181 | } | 181 | } | ||
182 | } | 182 | } | ||
183 | return false; | 183 | return false; | ||
184 | } | 184 | } | ||
185 | */ |