summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/zkbapplet/keyzcfg/zkb.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkb.cpp b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp
index a357b88..3cc3669 100644
--- a/noncore/applets/zkbapplet/keyzcfg/zkb.cpp
+++ b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp
@@ -134,276 +134,277 @@ void Action::setAutorepeat(bool p) {
134const short State::x1[] = { /* from 0x20 to 0x5f */ 134const short State::x1[] = { /* from 0x20 to 0x5f */
135 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ 135 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */
136 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ 136 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */
137 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ 137 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */
138 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ 138 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */
139 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ 139 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */
140 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ 140 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */
141 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ 141 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */
142 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ 142 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */
143 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ 143 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */
144 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ 144 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */
145 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ 145 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */
146 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ 146 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */
147}; 147};
148 148
149const short State::x2[] = { /* from 0x1000 to 0x1057*/ 149const short State::x2[] = { /* from 0x1000 to 0x1057*/
150 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ 150 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */
151 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ 151 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */
152 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ 152 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */
153 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ 153 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */
154 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ 154 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */
155 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ 155 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */
156 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ 156 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */
157 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ 157 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */
158 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ 158 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */
159 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ 159 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */
160 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ 160 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */
161}; 161};
162 162
163State::State(State* p):parent(p), keys(0) { 163State::State(State* p):parent(p), keys(0) {
164 keys = new Action[Key_Max * 2 + 1]; 164 keys = new Action[Key_Max * 2 + 1];
165} 165}
166 166
167State::State(const State& s) { 167State::State(const State& s) {
168 parent = s.parent; 168 parent = s.parent;
169 keys = new Action[Key_Max * 2 + 1]; 169 keys = new Action[Key_Max * 2 + 1];
170 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); 170 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
171} 171}
172 172
173State::~State() { 173State::~State() {
174 if (keys!=0) { 174 if (keys!=0) {
175 delete [] keys; 175 delete [] keys;
176 } 176 }
177} 177}
178 178
179Action* State::get(int keycode, bool pressed, bool follow) const { 179Action* State::get(int keycode, bool pressed, bool follow) const {
180 Action* ret = 0; 180 Action* ret = 0;
181 int n = translateKeycode(keycode); 181 int n = translateKeycode(keycode);
182 182
183 if (n != -1 && keys != 0) { 183 if (n != -1 && keys != 0) {
184 if (pressed) { 184 if (pressed) {
185 n += Key_Max; 185 n += Key_Max;
186 } 186 }
187 ret = &keys[n]; 187 ret = &keys[n];
188 } 188 }
189 189
190 if (ret==0 || !ret->isDefined()) { 190 if (ret==0 || !ret->isDefined()) {
191 if (follow && parent!=0) { 191 if (follow && parent!=0) {
192 ret = parent->get(keycode, pressed, follow); 192 ret = parent->get(keycode, pressed, follow);
193 } 193 }
194 } 194 }
195 195
196 return ret; 196 return ret;
197} 197}
198 198
199bool State::set(int keycode, bool pressed, Action& action) { 199bool State::set(int keycode, bool pressed, Action& action) {
200 int n = translateKeycode(keycode); 200 int n = translateKeycode(keycode);
201 201
202 if (n==-1 || keys==0) { 202 if (n==-1 || keys==0) {
203 return false; 203 return false;
204 } 204 }
205 205
206 if (pressed) { 206 if (pressed) {
207 n += Key_Max + 1; 207 n += Key_Max + 1;
208 } 208 }
209 209
210 keys[n] = action; 210 keys[n] = action;
211 return true; 211 return true;
212} 212}
213 213
214State* State::getParent() const { 214State* State::getParent() const {
215 return parent; 215 return parent;
216} 216}
217 217
218void State::setParent(State* s) { 218void State::setParent(State* s) {
219 parent = s; 219 parent = s;
220} 220}
221 221
222int State::translateKeycode(int keycode) const { 222int State::translateKeycode(int keycode) const {
223 if (keycode < 0x20) { 223 if (keycode < 0x20) {
224 return -1; 224 return -1;
225 } 225 }
226 226
227 if (keycode < 0x80) { 227 if (keycode < 0x80) {
228 return x1[keycode - 0x20]; 228 return x1[keycode - 0x20];
229 } 229 }
230 230
231 if (keycode < 0x1000) { 231 if (keycode < 0x1000) {
232 return -1; 232 return -1;
233 } 233 }
234 234
235 if (keycode < 0x1057) { 235 if (keycode < 0x1057) {
236 return x2[keycode - 0x1000]; 236 return x2[keycode - 0x1000];
237 } 237 }
238 238
239 return -1; 239 return -1;
240} 240}
241 241
242// Implementation of Keymap class 242// Implementation of Keymap class
243Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { 243Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
244 repeatDelay=400; 244 repeatDelay=400;
245 repeatPeriod=80; 245 repeatPeriod=80;
246 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); 246 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
247} 247}
248 248
249Keymap::~Keymap() { 249Keymap::~Keymap() {
250 odebug << "removing keyboard filter for zkb"<<oendl; 250 odebug << "removing keyboard filter for zkb"<<oendl;
251 Opie::Core::OKeyFilter::inst()->remHandler(this); 251 Opie::Core::OKeyFilter::inst()->remHandler(this);
252 QMap<QString, State*>::Iterator it; 252 QMap<QString, State*>::Iterator it;
253 for(it = states.begin(); it != states.end(); ++it) { 253 for(it = states.begin(); it != states.end(); ++it) {
254 delete it.data(); 254 delete it.data();
255 } 255 }
256 states.clear(); 256 states.clear();
257} 257}
258 258
259bool Keymap::filter(int unicode, int keycode, int modifiers, 259bool Keymap::filter(int unicode, int keycode, int modifiers,
260 bool isPress, bool autoRepeat) { 260 bool isPress, bool autoRepeat) {
261 261
262 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
263 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
264
265 if (!enabled) { 262 if (!enabled) {
266 return false; 263 return false;
267 } 264 }
268 265
266 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
267 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
268
269 // the second check is workaround to make suspend work if 269 // the second check is workaround to make suspend work if
270 // the user pressed it right after he did resume. for some 270 // the user pressed it right after he did resume. for some
271 // reason the event sent by qt has autoRepeat true in this 271 // reason the event sent by qt has autoRepeat true in this
272 // case 272 // case
273 if (autoRepeat && keycode != 4177) { 273 if (autoRepeat && keycode != 4177) {
274 return true; 274 return true;
275 } 275 }
276 276
277 (void) unicode; (void) modifiers; 277 (void) unicode; (void) modifiers;
278 278
279 Action* action = currentState->get(keycode, isPress, true); 279 Action* action = currentState->get(keycode, isPress, true);
280 if (action==0 || !action->isDefined()) { 280 if (action==0 || !action->isDefined()) {
281 return true; 281 odebug << "no action defined for that"<<oendl;
282 return false;
282 } 283 }
283 284
284 if (action->hasEvent()) { 285 if (action->hasEvent()) {
285 odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode() 286 odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode()
286 << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl; 287 << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl;
287 288
288 QWSServer::sendKeyEvent(action->getUnicode(), 289 QWSServer::sendKeyEvent(action->getUnicode(),
289 action->getKeycode(), action->getModifiers(), 290 action->getKeycode(), action->getModifiers(),
290 action->isPressed(), false); 291 action->isPressed(), false);
291 } 292 }
292 293
293 if (action->isAutorepeat()) { 294 if (action->isAutorepeat()) {
294 autoRepeatAction = action; 295 autoRepeatAction = action;
295 repeater.start(repeatDelay, TRUE); 296 repeater.start(repeatDelay, TRUE);
296 } else { 297 } else {
297 autoRepeatAction = 0; 298 autoRepeatAction = 0;
298 } 299 }
299 300
300 State* nstate = action->getState(); 301 State* nstate = action->getState();
301 if (nstate != 0) { 302 if (nstate != 0) {
302 setCurrentState(nstate); 303 setCurrentState(nstate);
303 QString lbl = getCurrentLabel(); 304 QString lbl = getCurrentLabel();
304 if (!lbl.isEmpty()) { 305 if (!lbl.isEmpty()) {
305 emit stateChanged(lbl); 306 emit stateChanged(lbl);
306 } 307 }
307 } 308 }
308 309
309 310
310 return true; 311 return true;
311} 312}
312 313
313void Keymap::enable() { 314void Keymap::enable() {
314 enabled = true; 315 enabled = true;
315} 316}
316 317
317void Keymap::disable() { 318void Keymap::disable() {
318 enabled = false; 319 enabled = false;
319} 320}
320 321
321QStringList Keymap::listStates() { 322QStringList Keymap::listStates() {
322 QStringList ret; 323 QStringList ret;
323 324
324 QMap<QString, State*>::Iterator it; 325 QMap<QString, State*>::Iterator it;
325 for(it = states.begin(); it != states.end(); ++it) { 326 for(it = states.begin(); it != states.end(); ++it) {
326 ret.append(it.key()); 327 ret.append(it.key());
327 } 328 }
328 329
329 return ret; 330 return ret;
330} 331}
331 332
332State* Keymap::getStateByName(const QString& name) { 333State* Keymap::getStateByName(const QString& name) {
333 QMap<QString, State*>::Iterator it = states.find(name); 334 QMap<QString, State*>::Iterator it = states.find(name);
334 335
335 if (it == states.end()) { 336 if (it == states.end()) {
336 return 0; 337 return 0;
337 } 338 }
338 339
339 return it.data(); 340 return it.data();
340} 341}
341 342
342QStringList Keymap::listLabels() { 343QStringList Keymap::listLabels() {
343 QStringList ret; 344 QStringList ret;
344 345
345 for(uint i = 0; i < labelList.count(); i++) { 346 for(uint i = 0; i < labelList.count(); i++) {
346 ret.append(*labelList.at(i)); 347 ret.append(*labelList.at(i));
347 } 348 }
348 349
349 return ret; 350 return ret;
350} 351}
351 352
352State* Keymap::getStateByLabel(const QString& label) { 353State* Keymap::getStateByLabel(const QString& label) {
353 QMap<QString, QString>::Iterator lit = labels.find(label); 354 QMap<QString, QString>::Iterator lit = labels.find(label);
354 State* state = 0; 355 State* state = 0;
355 356
356 if (lit == labels.end()) { 357 if (lit == labels.end()) {
357 return 0; 358 return 0;
358 } 359 }
359 360
360 QString name = lit.data(); 361 QString name = lit.data();
361 362
362 int n = name.find(":*"); 363 int n = name.find(":*");
363 if (n>=0 && n==(int)(name.length()-2)) { 364 if (n>=0 && n==(int)(name.length()-2)) {
364 name=name.left(name.length() - 1); 365 name=name.left(name.length() - 1);
365 366
366 n = currentStateName.findRev(":"); 367 n = currentStateName.findRev(":");
367 if (n >= 0) { 368 if (n >= 0) {
368 name += currentStateName.mid(n+1); 369 name += currentStateName.mid(n+1);
369 } 370 }
370 } 371 }
371 372
372// odebug << "look for: " << name.utf8() << "\n" << oendl; 373// odebug << "look for: " << name.utf8() << "\n" << oendl;
373 QMap<QString, State*>::Iterator sit = states.find(name); 374 QMap<QString, State*>::Iterator sit = states.find(name);
374 if (sit != states.end()) { 375 if (sit != states.end()) {
375 state = sit.data(); 376 state = sit.data();
376 } 377 }
377 378
378 return state; 379 return state;
379} 380}
380 381
381bool Keymap::addState(const QString& name, State* state) { 382bool Keymap::addState(const QString& name, State* state) {
382 if (states.find(name) != states.end()) { 383 if (states.find(name) != states.end()) {
383 return false; 384 return false;
384 } 385 }
385 386
386 states.insert(name, state); 387 states.insert(name, state);
387 lsmapInSync = false; 388 lsmapInSync = false;
388 389
389 if (currentState == 0) { 390 if (currentState == 0) {
390 setCurrentState(state); 391 setCurrentState(state);
391 } 392 }
392 393
393 return true; 394 return true;
394} 395}
395 396
396State* Keymap::getCurrentState() const { 397State* Keymap::getCurrentState() const {
397 return currentState; 398 return currentState;
398} 399}
399 400
400QString Keymap::getCurrentLabel() { 401QString Keymap::getCurrentLabel() {
401 return currentLabel; 402 return currentLabel;
402} 403}
403 404
404bool Keymap::setCurrentState(State* state) { 405bool Keymap::setCurrentState(State* state) {
405 QMap<QString, State*>::Iterator it; 406 QMap<QString, State*>::Iterator it;
406 for(it = states.begin(); it != states.end(); ++it) { 407 for(it = states.begin(); it != states.end(); ++it) {
407 State* s = it.data(); 408 State* s = it.data();
408 if (s == state) { 409 if (s == state) {
409 currentState = s; 410 currentState = s;