summaryrefslogtreecommitdiff
path: root/noncore/apps/keyz-cfg/zkb.cpp
Unidiff
Diffstat (limited to 'noncore/apps/keyz-cfg/zkb.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/keyz-cfg/zkb.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp
index 58bde2a..c9e1dc5 100644
--- a/noncore/apps/keyz-cfg/zkb.cpp
+++ b/noncore/apps/keyz-cfg/zkb.cpp
@@ -1,25 +1,29 @@
1#include "zkb.h" 1#include "zkb.h"
2
3/* OPIE */
4#include <opie2/odebug.h>
5
2#include <stdio.h> 6#include <stdio.h>
3 7
4// Implementation of Action class 8// Implementation of Action class
5Action::Action():state(0), keycode(0), unicode(0), flags(0) { 9Action::Action():state(0), keycode(0), unicode(0), flags(0) {
6} 10}
7 11
8Action::Action(State* s, ushort kc, ushort uni, int f): 12Action::Action(State* s, ushort kc, ushort uni, int f):
9 state(s), keycode(kc), unicode(uni), flags(f) { 13 state(s), keycode(kc), unicode(uni), flags(f) {
10} 14}
11 15
12Action::~Action() { 16Action::~Action() {
13} 17}
14 18
15State* Action::getState() const { 19State* Action::getState() const {
16 return state; 20 return state;
17} 21}
18 22
19void Action::setState(State* s) { 23void Action::setState(State* s) {
20 state = s; 24 state = s;
21 setDefined(true); 25 setDefined(true);
22} 26}
23 27
24bool Action::hasEvent() const { 28bool Action::hasEvent() const {
25 return flags & Event; 29 return flags & Event;
@@ -231,75 +235,73 @@ int State::translateKeycode(int keycode) const {
231 return x2[keycode - 0x1000]; 235 return x2[keycode - 0x1000];
232 } 236 }
233 237
234 return -1; 238 return -1;
235} 239}
236 240
237// Implementation of Keymap class 241// Implementation of Keymap class
238Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { 242Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
239 repeatDelay=400; 243 repeatDelay=400;
240 repeatPeriod=80; 244 repeatPeriod=80;
241 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); 245 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
242} 246}
243 247
244Keymap::~Keymap() { 248Keymap::~Keymap() {
245 QMap<QString, State*>::Iterator it; 249 QMap<QString, State*>::Iterator it;
246 for(it = states.begin(); it != states.end(); ++it) { 250 for(it = states.begin(); it != states.end(); ++it) {
247 delete it.data(); 251 delete it.data();
248 } 252 }
249 states.clear(); 253 states.clear();
250} 254}
251 255
252bool Keymap::filter(int unicode, int keycode, int modifiers, 256bool Keymap::filter(int unicode, int keycode, int modifiers,
253 bool isPress, bool autoRepeat) { 257 bool isPress, bool autoRepeat) {
254 258
255 qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, " 259 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
256 "ispressed=%x\n", unicode, keycode, modifiers, isPress); 260 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
257 261
258 if (!enabled) { 262 if (!enabled) {
259 return false; 263 return false;
260 } 264 }
261 265
262 // the second check is workaround to make suspend work if 266 // the second check is workaround to make suspend work if
263 // the user pressed it right after he did resume. for some 267 // the user pressed it right after he did resume. for some
264 // reason the event sent by qt has autoRepeat true in this 268 // reason the event sent by qt has autoRepeat true in this
265 // case 269 // case
266 if (autoRepeat && keycode != 4177) { 270 if (autoRepeat && keycode != 4177) {
267 return true; 271 return true;
268 } 272 }
269 273
270 (void) unicode; (void) modifiers; 274 (void) unicode; (void) modifiers;
271 275
272 Action* action = currentState->get(keycode, isPress, true); 276 Action* action = currentState->get(keycode, isPress, true);
273 if (action==0 || !action->isDefined()) { 277 if (action==0 || !action->isDefined()) {
274 return true; 278 return true;
275 } 279 }
276 280
277 if (action->hasEvent()) { 281 if (action->hasEvent()) {
278 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 282 odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode()
279 "ispressed=%x\n", action->getUnicode(), 283 << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl;
280 action->getKeycode(), action->getModifiers(),
281 action->isPressed());
282 284
283 QWSServer::sendKeyEvent(action->getUnicode(), 285 QWSServer::sendKeyEvent(action->getUnicode(),
284 action->getKeycode(), action->getModifiers(), 286 action->getKeycode(), action->getModifiers(),
285 action->isPressed(), false); 287 action->isPressed(), false);
286 } 288 }
287 289
288 if (action->isAutorepeat()) { 290 if (action->isAutorepeat()) {
289 autoRepeatAction = action; 291 autoRepeatAction = action;
290 repeater.start(repeatDelay, TRUE); 292 repeater.start(repeatDelay, TRUE);
291 } else { 293 } else {
292 autoRepeatAction = 0; 294 autoRepeatAction = 0;
293 } 295 }
294 296
295 State* nstate = action->getState(); 297 State* nstate = action->getState();
296 if (nstate != 0) { 298 if (nstate != 0) {
297 setCurrentState(nstate); 299 setCurrentState(nstate);
298 QString lbl = getCurrentLabel(); 300 QString lbl = getCurrentLabel();
299 if (!lbl.isEmpty()) { 301 if (!lbl.isEmpty()) {
300 emit stateChanged(lbl); 302 emit stateChanged(lbl);
301 } 303 }
302 } 304 }
303 305
304 306
305 return true; 307 return true;
@@ -383,50 +385,49 @@ bool Keymap::addState(const QString& name, State* state) {
383 385
384 if (currentState == 0) { 386 if (currentState == 0) {
385 setCurrentState(state); 387 setCurrentState(state);
386 } 388 }
387 389
388 return true; 390 return true;
389} 391}
390 392
391State* Keymap::getCurrentState() const { 393State* Keymap::getCurrentState() const {
392 return currentState; 394 return currentState;
393} 395}
394 396
395QString Keymap::getCurrentLabel() { 397QString Keymap::getCurrentLabel() {
396 return currentLabel; 398 return currentLabel;
397} 399}
398 400
399bool Keymap::setCurrentState(State* state) { 401bool Keymap::setCurrentState(State* state) {
400 QMap<QString, State*>::Iterator it; 402 QMap<QString, State*>::Iterator it;
401 for(it = states.begin(); it != states.end(); ++it) { 403 for(it = states.begin(); it != states.end(); ++it) {
402 State* s = it.data(); 404 State* s = it.data();
403 if (s == state) { 405 if (s == state) {
404 currentState = s; 406 currentState = s;
405 currentStateName = it.key(); 407 currentStateName = it.key();
406 408
407 qDebug("state changed: %s\n", (const char*) 409 odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl;
408 currentStateName.utf8());
409 410
410 if (!lsmapInSync) { 411 if (!lsmapInSync) {
411 generateLabelStateMaps(); 412 generateLabelStateMaps();
412 } 413 }
413 414
414 QMap<State*, QString>::Iterator tit; 415 QMap<State*, QString>::Iterator tit;
415 tit = stateLabelMap.find(state); 416 tit = stateLabelMap.find(state);
416 if (tit != stateLabelMap.end()) { 417 if (tit != stateLabelMap.end()) {
417 currentLabel = tit.data(); 418 currentLabel = tit.data();
418 } else { 419 } else {
419 // odebug << "no label for: " + currentStateName + "\n" << oendl; 420 // odebug << "no label for: " + currentStateName + "\n" << oendl;
420 currentLabel = ""; 421 currentLabel = "";
421 } 422 }
422 423
423 return true; 424 return true;
424 } 425 }
425 } 426 }
426 427
427 return false; 428 return false;
428} 429}
429 430
430bool Keymap::removeState(const QString& name, bool force) { 431bool Keymap::removeState(const QString& name, bool force) {
431 QMap<QString, State*>::Iterator it = states.find(name); 432 QMap<QString, State*>::Iterator it = states.find(name);
432 433
@@ -442,53 +443,52 @@ bool Keymap::removeState(const QString& name, bool force) {
442 return false; 443 return false;
443 } else { 444 } else {
444 for(Action* a = acts.first(); a != 0; a = acts.next()) { 445 for(Action* a = acts.first(); a != 0; a = acts.next()) {
445 a->setState(0); 446 a->setState(0);
446 } 447 }
447 } 448 }
448 } 449 }
449 450
450 if (state == currentState) { 451 if (state == currentState) {
451 if (states.begin() != states.end()) { 452 if (states.begin() != states.end()) {
452 setCurrentState(states.begin().data()); 453 setCurrentState(states.begin().data());
453 } 454 }
454 } 455 }
455 456
456 states.remove(it); 457 states.remove(it);
457 delete state; 458 delete state;
458 459
459 lsmapInSync = false; 460 lsmapInSync = false;
460 461
461 return true; 462 return true;
462} 463}
463 464
464void Keymap::autoRepeat() { 465void Keymap::autoRepeat() {
465 if (autoRepeatAction != 0) { 466 if (autoRepeatAction != 0) {
466 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 467 odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode()
467 "ispressed=%x\n", autoRepeatAction->getUnicode(), 468 << ", keycode=" << autoRepeatAction->getKeycode()
468 autoRepeatAction->getKeycode(), 469 << ", modifiers=" << autoRepeatAction->getModifiers()
469 autoRepeatAction->getModifiers(), 470 << "ispressed=" << autoRepeatAction->isPressed() << oendl;
470 autoRepeatAction->isPressed());
471 471
472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), 472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(),
473 autoRepeatAction->getKeycode(), 473 autoRepeatAction->getKeycode(),
474 autoRepeatAction->getModifiers(), 474 autoRepeatAction->getModifiers(),
475 autoRepeatAction->isPressed(), true); 475 autoRepeatAction->isPressed(), true);
476 } 476 }
477 477
478 repeater.start(repeatPeriod, TRUE); 478 repeater.start(repeatPeriod, TRUE);
479} 479}
480 480
481bool Keymap::addLabel(const QString& label, const QString& state, int index) { 481bool Keymap::addLabel(const QString& label, const QString& state, int index) {
482 if (labels.find(label) != labels.end()) { 482 if (labels.find(label) != labels.end()) {
483 return false; 483 return false;
484 } 484 }
485 485
486 labels.insert(label, state); 486 labels.insert(label, state);
487 const QString& l = labels.find(label).key(); 487 const QString& l = labels.find(label).key();
488 if (index == -1) { 488 if (index == -1) {
489 labelList.append(l); 489 labelList.append(l);
490 } else { 490 } else {
491 labelList.insert(labelList.at(index), l); 491 labelList.insert(labelList.at(index), l);
492 } 492 }
493 493
494 lsmapInSync = false; 494 lsmapInSync = false;