author | zecke <zecke> | 2004-03-02 21:04:44 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-02 21:04:44 (UTC) |
commit | dcf196abd97485cd9634d6ac135028a605c54fb5 (patch) (unidiff) | |
tree | a424872b45f52418e4c84148c7ed4cfcc0b1a681 /noncore | |
parent | 0a67659dce57ac1475841838369e924f2441e991 (diff) | |
download | opie-dcf196abd97485cd9634d6ac135028a605c54fb5.zip opie-dcf196abd97485cd9634d6ac135028a605c54fb5.tar.gz opie-dcf196abd97485cd9634d6ac135028a605c54fb5.tar.bz2 |
Fix key handling bug 1268
-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index 2c9ad71..db95154 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -200,25 +200,25 @@ void KRFBDecoder::gotServerInit() | |||
200 | currentState = AwaitingDesktopName; | 200 | currentState = AwaitingDesktopName; |
201 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 201 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
202 | con->waitForData( info->nameLength ); | 202 | con->waitForData( info->nameLength ); |
203 | } | 203 | } |
204 | 204 | ||
205 | void KRFBDecoder::gotDesktopName() | 205 | void KRFBDecoder::gotDesktopName() |
206 | { | 206 | { |
207 | assert( info ); | 207 | assert( info ); |
208 | assert( currentState == AwaitingDesktopName ); | 208 | assert( currentState == AwaitingDesktopName ); |
209 | 209 | ||
210 | qWarning( "Got desktop name" ); | 210 | qWarning( "Got desktop name" ); |
211 | 211 | ||
212 | disconnect( con, SIGNAL( gotEnoughData() ), | 212 | disconnect( con, SIGNAL( gotEnoughData() ), |
213 | this, SLOT( gotDesktopName() ) ); | 213 | this, SLOT( gotDesktopName() ) ); |
214 | 214 | ||
215 | char *buf = new char[ info->nameLength + 1 ]; | 215 | char *buf = new char[ info->nameLength + 1 ]; |
216 | CHECK_PTR( buf ); | 216 | CHECK_PTR( buf ); |
217 | 217 | ||
218 | con->read( buf, info->nameLength ); | 218 | con->read( buf, info->nameLength ); |
219 | buf[ info->nameLength ] = '\0'; | 219 | buf[ info->nameLength ] = '\0'; |
220 | info->name = buf; | 220 | info->name = buf; |
221 | 221 | ||
222 | qWarning( "Desktop: %s", info->name.latin1() ); | 222 | qWarning( "Desktop: %s", info->name.latin1() ); |
223 | 223 | ||
224 | delete buf; | 224 | delete buf; |
@@ -254,25 +254,25 @@ void KRFBDecoder::decidePixelFormat() | |||
254 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 254 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
255 | int chosenDepth; | 255 | int chosenDepth; |
256 | 256 | ||
257 | if ( con->options()->colors256 ) | 257 | if ( con->options()->colors256 ) |
258 | chosenDepth = 8; | 258 | chosenDepth = 8; |
259 | else | 259 | else |
260 | chosenDepth = bestDepth; | 260 | chosenDepth = bestDepth; |
261 | 261 | ||
262 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ | 262 | qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ |
263 | "eight bit %d, chosenDepth=%d", | 263 | "eight bit %d, chosenDepth=%d", |
264 | screenDepth, | 264 | screenDepth, |
265 | info->depth, | 265 | info->depth, |
266 | bestDepth, | 266 | bestDepth, |
267 | con->options()->colors256, chosenDepth ); | 267 | con->options()->colors256, chosenDepth ); |
268 | 268 | ||
269 | format->depth = chosenDepth; | 269 | format->depth = chosenDepth; |
270 | 270 | ||
271 | // If we're using the servers native depth | 271 | // If we're using the servers native depth |
272 | if ( chosenDepth == info->depth ) { | 272 | if ( chosenDepth == info->depth ) { |
273 | // Use the servers native format | 273 | // Use the servers native format |
274 | format->bpp = info->bpp; | 274 | format->bpp = info->bpp; |
275 | // format->bigEndian = info->bigEndian; | 275 | // format->bigEndian = info->bigEndian; |
276 | format->bigEndian = true; | 276 | format->bigEndian = true; |
277 | format->trueColor = info->trueColor; | 277 | format->trueColor = info->trueColor; |
278 | format->redMax = info->redMax; | 278 | format->redMax = info->redMax; |
@@ -364,88 +364,88 @@ void KRFBDecoder::sendUpdateRequest( bool incremental ) | |||
364 | // Now wait for the update | 364 | // Now wait for the update |
365 | currentState = AwaitingUpdate; | 365 | currentState = AwaitingUpdate; |
366 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 366 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
367 | con->waitForData( UpdateHeaderLength ); | 367 | con->waitForData( UpdateHeaderLength ); |
368 | } | 368 | } |
369 | 369 | ||
370 | void KRFBDecoder::gotUpdateHeader() | 370 | void KRFBDecoder::gotUpdateHeader() |
371 | { | 371 | { |
372 | assert( currentState == AwaitingUpdate ); | 372 | assert( currentState == AwaitingUpdate ); |
373 | 373 | ||
374 | // qWarning( "Got update header" ); | 374 | // qWarning( "Got update header" ); |
375 | 375 | ||
376 | disconnect( con, SIGNAL( gotEnoughData() ), | 376 | disconnect( con, SIGNAL( gotEnoughData() ), |
377 | this, SLOT( gotUpdateHeader() ) ); | 377 | this, SLOT( gotUpdateHeader() ) ); |
378 | 378 | ||
379 | CARD8 msgType; | 379 | CARD8 msgType; |
380 | con->read( &msgType, 1 ); | 380 | con->read( &msgType, 1 ); |
381 | 381 | ||
382 | if ( msgType != UpdateId ) { | 382 | if ( msgType != UpdateId ) { |
383 | // We might have a bell or server cut | 383 | // We might have a bell or server cut |
384 | if ( msgType == ServerCutId ) { | 384 | if ( msgType == ServerCutId ) { |
385 | oldState = currentState; | 385 | oldState = currentState; |
386 | gotServerCut(); | 386 | gotServerCut(); |
387 | } | 387 | } |
388 | else if ( msgType == BellId ) { | 388 | else if ( msgType == BellId ) { |
389 | oldState = currentState; | 389 | oldState = currentState; |
390 | gotBell(); | 390 | gotBell(); |
391 | } | 391 | } |
392 | else { | 392 | else { |
393 | int msg = msgType; | 393 | int msg = msgType; |
394 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 394 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
395 | "found when expecting an update " | 395 | "found when expecting an update " |
396 | "message." ).arg( msg ); | 396 | "message." ).arg( msg ); |
397 | currentState = Error; | 397 | currentState = Error; |
398 | emit error( protocolError ); | 398 | emit error( protocolError ); |
399 | } | 399 | } |
400 | return; | 400 | return; |
401 | } | 401 | } |
402 | 402 | ||
403 | CARD8 padding; | 403 | CARD8 padding; |
404 | con->read( &padding, 1 ); | 404 | con->read( &padding, 1 ); |
405 | 405 | ||
406 | con->read( &noRects, 2 ); | 406 | con->read( &noRects, 2 ); |
407 | noRects = Swap16IfLE( noRects ); | 407 | noRects = Swap16IfLE( noRects ); |
408 | 408 | ||
409 | // qWarning( "Expecting %d rects", noRects ); | 409 | // qWarning( "Expecting %d rects", noRects ); |
410 | 410 | ||
411 | // Now wait for the data | 411 | // Now wait for the data |
412 | currentState = AwaitingRectHeader; | 412 | currentState = AwaitingRectHeader; |
413 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 413 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
414 | con->waitForData( RectHeaderLength ); | 414 | con->waitForData( RectHeaderLength ); |
415 | } | 415 | } |
416 | 416 | ||
417 | void KRFBDecoder::gotRectHeader() | 417 | void KRFBDecoder::gotRectHeader() |
418 | { | 418 | { |
419 | assert( currentState == AwaitingRectHeader ); | 419 | assert( currentState == AwaitingRectHeader ); |
420 | 420 | ||
421 | // qWarning( "Got rect header" ); | 421 | // qWarning( "Got rect header" ); |
422 | 422 | ||
423 | disconnect( con, SIGNAL( gotEnoughData() ), | 423 | disconnect( con, SIGNAL( gotEnoughData() ), |
424 | this, SLOT( gotRectHeader() ) ); | 424 | this, SLOT( gotRectHeader() ) ); |
425 | 425 | ||
426 | con->read( &x, 2 ); | 426 | con->read( &x, 2 ); |
427 | x = Swap16IfLE( x ); | 427 | x = Swap16IfLE( x ); |
428 | con->read( &y, 2 ); | 428 | con->read( &y, 2 ); |
429 | y = Swap16IfLE( y ); | 429 | y = Swap16IfLE( y ); |
430 | 430 | ||
431 | con->read( &w, 2 ); | 431 | con->read( &w, 2 ); |
432 | w = Swap16IfLE( w ); | 432 | w = Swap16IfLE( w ); |
433 | con->read( &h, 2 ); | 433 | con->read( &h, 2 ); |
434 | h = Swap16IfLE( h ); | 434 | h = Swap16IfLE( h ); |
435 | 435 | ||
436 | con->read( &encoding, 4 ); | 436 | con->read( &encoding, 4 ); |
437 | 437 | ||
438 | // CARD32 encodingLocal = Swap32IfLE( encoding ); | 438 | // CARD32 encodingLocal = Swap32IfLE( encoding ); |
439 | // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", | 439 | // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", |
440 | // x, y, w, h, encodingLocal ); | 440 | // x, y, w, h, encodingLocal ); |
441 | 441 | ||
442 | // | 442 | // |
443 | // Each encoding needs to be handled differently. Some require | 443 | // Each encoding needs to be handled differently. Some require |
444 | // waiting for more data, but others like a copyrect do not. | 444 | // waiting for more data, but others like a copyrect do not. |
445 | // Our constants have already been byte swapped, so we use | 445 | // Our constants have already been byte swapped, so we use |
446 | // the remote value as is. | 446 | // the remote value as is. |
447 | // | 447 | // |
448 | if ( encoding == RawEncoding ) { | 448 | if ( encoding == RawEncoding ) { |
449 | // qWarning( "Raw encoding" ); | 449 | // qWarning( "Raw encoding" ); |
450 | handleRawRect(); | 450 | handleRawRect(); |
451 | } | 451 | } |
@@ -511,33 +511,33 @@ void KRFBDecoder::getRawRectChunk( int lines ) | |||
511 | // Wait for server init | 511 | // Wait for server init |
512 | // qWarning( "Waiting for raw rect chunk, %ld", count ); | 512 | // qWarning( "Waiting for raw rect chunk, %ld", count ); |
513 | 513 | ||
514 | currentState = AwaitingRawRectChunk; | 514 | currentState = AwaitingRawRectChunk; |
515 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); | 515 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); |
516 | con->waitForData( count ); | 516 | con->waitForData( count ); |
517 | } | 517 | } |
518 | 518 | ||
519 | void KRFBDecoder::gotRawRectChunk() | 519 | void KRFBDecoder::gotRawRectChunk() |
520 | { | 520 | { |
521 | assert( currentState == AwaitingRawRectChunk ); | 521 | assert( currentState == AwaitingRawRectChunk ); |
522 | 522 | ||
523 | disconnect( con, SIGNAL( gotEnoughData() ), | 523 | disconnect( con, SIGNAL( gotEnoughData() ), |
524 | this, SLOT( gotRawRectChunk() ) ); | 524 | this, SLOT( gotRawRectChunk() ) ); |
525 | 525 | ||
526 | // qWarning( "Got raw rect chunk" ); | 526 | // qWarning( "Got raw rect chunk" ); |
527 | 527 | ||
528 | // | 528 | // |
529 | // Read the rect data and copy it to the buffer. | 529 | // Read the rect data and copy it to the buffer. |
530 | // | 530 | // |
531 | 531 | ||
532 | // TODO: Replace this! | 532 | // TODO: Replace this! |
533 | int count = lines * w * format->bpp / 8; | 533 | int count = lines * w * format->bpp / 8; |
534 | char *hack = new char[ count ]; | 534 | char *hack = new char[ count ]; |
535 | con->read( hack, count ); | 535 | con->read( hack, count ); |
536 | buf->drawRawRectChunk( hack, x, y, w, lines ); | 536 | buf->drawRawRectChunk( hack, x, y, w, lines ); |
537 | delete hack; | 537 | delete hack; |
538 | // /TODO: | 538 | // /TODO: |
539 | 539 | ||
540 | h = h - lines; | 540 | h = h - lines; |
541 | y = y + lines; | 541 | y = y + lines; |
542 | 542 | ||
543 | if ( h > 0 ) { | 543 | if ( h > 0 ) { |
@@ -711,25 +711,25 @@ void KRFBDecoder::gotServerCutText() | |||
711 | // the remote server to use utf8 etc. but for now we have to assume they're the | 711 | // the remote server to use utf8 etc. but for now we have to assume they're the |
712 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 712 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
713 | // immediate plans to fix the issue. :-( (rich) | 713 | // immediate plans to fix the issue. :-( (rich) |
714 | // | 714 | // |
715 | 715 | ||
716 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 716 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
717 | CHECK_PTR( cutbuf ); | 717 | CHECK_PTR( cutbuf ); |
718 | 718 | ||
719 | con->read( cutbuf, serverCutTextLen ); | 719 | con->read( cutbuf, serverCutTextLen ); |
720 | cutbuf[ serverCutTextLen ] = '\0'; | 720 | cutbuf[ serverCutTextLen ] = '\0'; |
721 | 721 | ||
722 | /* For some reason QApplication::clipboard()->setText() segfaults when called | 722 | /* For some reason QApplication::clipboard()->setText() segfaults when called |
723 | * from within keypebble's mass of signals and slots | 723 | * from within keypebble's mass of signals and slots |
724 | qWarning( "Server cut: %s", cutbuf ); | 724 | qWarning( "Server cut: %s", cutbuf ); |
725 | 725 | ||
726 | QString cutText( cutbuf ); // DANGER!! | 726 | QString cutText( cutbuf ); // DANGER!! |
727 | qApp->clipboard()->setText( cutText ); | 727 | qApp->clipboard()->setText( cutText ); |
728 | */ | 728 | */ |
729 | 729 | ||
730 | delete cutbuf; | 730 | delete cutbuf; |
731 | // Now wait for the update (again) | 731 | // Now wait for the update (again) |
732 | if ( oldState == AwaitingUpdate ) { | 732 | if ( oldState == AwaitingUpdate ) { |
733 | currentState = AwaitingUpdate; | 733 | currentState = AwaitingUpdate; |
734 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 734 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
735 | con->waitForData( UpdateHeaderLength ); | 735 | con->waitForData( UpdateHeaderLength ); |
@@ -789,53 +789,42 @@ void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) | |||
789 | 789 | ||
790 | CARD8 mask = false; | 790 | CARD8 mask = false; |
791 | 791 | ||
792 | CARD16 padding = 0; | 792 | CARD16 padding = 0; |
793 | con->write( &KeyEventId, 1 ); | 793 | con->write( &KeyEventId, 1 ); |
794 | con->write( &mask, 1 ); | 794 | con->write( &mask, 1 ); |
795 | con->write( &padding, 2 ); | 795 | con->write( &padding, 2 ); |
796 | con->write( &key, 4 ); | 796 | con->write( &key, 4 ); |
797 | } | 797 | } |
798 | } | 798 | } |
799 | 799 | ||
800 | 800 | ||
801 | |||
802 | |||
803 | // | ||
804 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' | ||
805 | // is the same as the corresponding ASCII value.', but doesn't | ||
806 | // elaborate what the most ordinary keys are. The spec also lists | ||
807 | // a set (possibly subset, it's unspecified) of mappings for | ||
808 | // "other common keys" (backspace, tab, return, escape, etc). | ||
809 | // | ||
801 | int KRFBDecoder::toKeySym( QKeyEvent *k ) | 810 | int KRFBDecoder::toKeySym( QKeyEvent *k ) |
802 | { | 811 | { |
803 | int ke = 0; | ||
804 | |||
805 | ke = k->ascii(); | ||
806 | // Markus: Crappy hack. I dont know why lower case letters are | ||
807 | // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'. | ||
808 | // This sucks. :-( | ||
809 | |||
810 | if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd') | ||
811 | || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h') | ||
812 | || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l') | ||
813 | || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p') | ||
814 | || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't') | ||
815 | || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x') | ||
816 | || (ke == 'y') || (ke == 'z') ) { | ||
817 | ke = k->key(); | ||
818 | ke = ke + 0x20; | ||
819 | return ke; | ||
820 | } | ||
821 | 812 | ||
822 | // qkeydefs = xkeydefs! :-) | 813 | // |
823 | if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff ) | 814 | // Try and map these "other common keys" first. |
824 | return k->key(); | 815 | // |
825 | 816 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { | |
826 | if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) ) | 817 | for(int i = 0; keyMap[i].keycode != 0; i++) { |
827 | return k->key(); | 818 | if (k->key() == keyMap[i].keycode) { |
828 | 819 | return keyMap[i].keysym; | |
829 | // qkeydefs != xkeydefs! :-( | 820 | } |
830 | // This is gonna suck :-( | 821 | } |
831 | 822 | } | |
832 | int i = 0; | ||
833 | while ( keyMap[i].keycode ) { | ||
834 | if ( k->key() == keyMap[i].keycode ) | ||
835 | return keyMap[i].keysym; | ||
836 | i++; | ||
837 | } | ||
838 | 823 | ||
839 | return 0; | 824 | // |
825 | // If these keys aren't matched, return the ascii code and let the | ||
826 | // server figure it out. We don't return k->key(), as the data in | ||
827 | // key differs between input methods, and we don't want special cases. | ||
828 | // | ||
829 | return k->ascii(); | ||
840 | } | 830 | } |
841 | |||