summaryrefslogtreecommitdiff
path: root/inputmethods/keyboard
authorharlekin <harlekin>2002-02-16 02:00:41 (UTC)
committer harlekin <harlekin>2002-02-16 02:00:41 (UTC)
commitf8744f9a9a59f7968ddbac66c927ba8da358f223 (patch) (unidiff)
tree8a9670929d1025bd1c610cd3350a6e2cb35ef6b8 /inputmethods/keyboard
parentc91dc39fb820f6f6b9805b96aea282f1deb4d576 (diff)
downloadopie-f8744f9a9a59f7968ddbac66c927ba8da358f223.zip
opie-f8744f9a9a59f7968ddbac66c927ba8da358f223.tar.gz
opie-f8744f9a9a59f7968ddbac66c927ba8da358f223.tar.bz2
Quick and dirty fix for the sticky keyboard problem on ipaq - just turn it off. Turned on on zaurus
Diffstat (limited to 'inputmethods/keyboard') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/keyboard/keyboard.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/inputmethods/keyboard/keyboard.cpp b/inputmethods/keyboard/keyboard.cpp
index 9dd24e4..233f08e 100644
--- a/inputmethods/keyboard/keyboard.cpp
+++ b/inputmethods/keyboard/keyboard.cpp
@@ -1,148 +1,162 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "keyboard.h" 21#include "keyboard.h"
22 22
23#include <qpe/global.h> 23#include <qpe/global.h>
24 24
25#include <qwindowsystem_qws.h> 25#include <qwindowsystem_qws.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qfontmetrics.h> 27#include <qfontmetrics.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <ctype.h> 29#include <ctype.h>
30 30
31#include <sys/utsname.h>
32
31 33
32#define USE_SMALL_BACKSPACE 34#define USE_SMALL_BACKSPACE
33 35
34Keyboard::Keyboard(QWidget* parent, const char* name, WFlags f) : 36Keyboard::Keyboard(QWidget* parent, const char* name, WFlags f) :
35 QFrame(parent, name, f), shift(FALSE), lock(FALSE), ctrl(FALSE), 37 QFrame(parent, name, f), shift(FALSE), lock(FALSE), ctrl(FALSE),
36 alt(FALSE), useLargeKeys(TRUE), useOptiKeys(0), pressedKey(-1), 38 alt(FALSE), useLargeKeys(TRUE), useOptiKeys(0), pressedKey(-1),
37 unicode(-1), qkeycode(0), modifiers(0) 39 unicode(-1), qkeycode(0), modifiers(0)
38{ 40{
39 // setPalette(QPalette(QColor(240,240,230))); // Beige! 41 // setPalette(QPalette(QColor(240,240,230))); // Beige!
40 // setFont( QFont( "Helvetica", 8 ) ); 42 // setFont( QFont( "Helvetica", 8 ) );
41// setPalette(QPalette(QColor(200,200,200))); // Gray 43// setPalette(QPalette(QColor(200,200,200))); // Gray
42 setPalette(QPalette(QColor(220,220,220))); // Gray 44 setPalette(QPalette(QColor(220,220,220))); // Gray
43 45
44 picks = new KeyboardPicks( this ); 46 picks = new KeyboardPicks( this );
45 picks->setFont( QFont( "smallsmooth", 9 ) ); 47 picks->setFont( QFont( "smallsmooth", 9 ) );
46 setFont( QFont( "smallsmooth", 9 ) ); 48 setFont( QFont( "smallsmooth", 9 ) );
47 picks->initialise(); 49 picks->initialise();
48 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 50 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
49 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 51 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
50 52
51 repeatTimer = new QTimer( this ); 53 repeatTimer = new QTimer( this );
52 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 54
55 // temporary quick and dirty fix for the "sticky keyboard bug"
56 // on ipaq.
57 struct utsname name;
58 if (uname(&name) != -1)
59 {
60 QString release=name.release;
61 qWarning("System release: %s\n", name.release);
62 if(release.find("embedix",0,TRUE) !=-1)
63 {
64 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
65 }
66 }
53} 67}
54 68
55void Keyboard::resizeEvent(QResizeEvent*) 69void Keyboard::resizeEvent(QResizeEvent*)
56{ 70{
57 int ph = picks->sizeHint().height(); 71 int ph = picks->sizeHint().height();
58 picks->setGeometry( 0, 0, width(), ph ); 72 picks->setGeometry( 0, 0, width(), ph );
59 keyHeight = (height()-ph)/5; 73 keyHeight = (height()-ph)/5;
60 int nk; 74 int nk;
61 if ( useOptiKeys ) { 75 if ( useOptiKeys ) {
62 nk = 15; 76 nk = 15;
63 } else if ( useLargeKeys ) { 77 } else if ( useLargeKeys ) {
64 nk = 15; 78 nk = 15;
65 } else { 79 } else {
66 nk = 19; 80 nk = 19;
67 } 81 }
68 defaultKeyWidth = width()/nk; 82 defaultKeyWidth = width()/nk;
69 xoffs = (width()-defaultKeyWidth*nk)/2; 83 xoffs = (width()-defaultKeyWidth*nk)/2;
70} 84}
71 85
72void KeyboardPicks::initialise() 86void KeyboardPicks::initialise()
73{ 87{
74 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 88 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
75 mode = 0; 89 mode = 0;
76 dc = new KeyboardConfig(this); 90 dc = new KeyboardConfig(this);
77 configs.append(dc); 91 configs.append(dc);
78} 92}
79 93
80QSize KeyboardPicks::sizeHint() const 94QSize KeyboardPicks::sizeHint() const
81{ 95{
82 return QSize(240,fontMetrics().lineSpacing()); 96 return QSize(240,fontMetrics().lineSpacing());
83} 97}
84 98
85 99
86void KeyboardConfig::generateText(const QString &s) 100void KeyboardConfig::generateText(const QString &s)
87{ 101{
88#if defined(Q_WS_QWS) || defined(_WS_QWS_) 102#if defined(Q_WS_QWS) || defined(_WS_QWS_)
89 for (int i=0; i<(int)backspaces; i++) { 103 for (int i=0; i<(int)backspaces; i++) {
90 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 104 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
91 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 105 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
92 } 106 }
93 for (int i=0; i<(int)s.length(); i++) { 107 for (int i=0; i<(int)s.length(); i++) {
94 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 108 parent->emitKey( s[i].unicode(), 0, 0, true, false );
95 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 109 parent->emitKey( s[i].unicode(), 0, 0, false, false );
96 } 110 }
97 parent->emitKey( 0, Qt::Key_Space, 0, true, false ); 111 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
98 parent->emitKey( 0, Qt::Key_Space, 0, false, false ); 112 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
99 backspaces = 0; 113 backspaces = 0;
100#endif 114#endif
101} 115}
102 116
103 117
104//PC keyboard layout and scancodes 118//PC keyboard layout and scancodes
105 119
106/* 120/*
107 Format: length, code, length, code, ..., 0 121 Format: length, code, length, code, ..., 0
108 122
109 length is measured in half the width of a standard key. 123 length is measured in half the width of a standard key.
110 If code < 0x80 we have length/2 consecutive standard keys, 124 If code < 0x80 we have length/2 consecutive standard keys,
111 starting with scancode code. 125 starting with scancode code.
112 126
113 Special keys are hardcoded, one at a time, with length of key 127 Special keys are hardcoded, one at a time, with length of key
114 and code >= 0x80, these are NOT standard PC scancodes, but are looked 128 and code >= 0x80, these are NOT standard PC scancodes, but are looked
115 up in specialM[]. (The special keys are not keymappable.) 129 up in specialM[]. (The special keys are not keymappable.)
116 130
117 */ 131 */
118 132
119static const uchar * const keyboard_opti[5] = { 133static const uchar * const keyboard_opti[5] = {
120 (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236", 134 (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236",
121 (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065", 135 (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065",
122 (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055", 136 (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055",
123 (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014", 137 (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014",
124 (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230" 138 (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230"
125}; 139};
126 140
127 141
128static const uchar * const keyboard_standard[5] = { 142static const uchar * const keyboard_standard[5] = {
129 143
130#ifdef USE_SMALL_BACKSPACE 144#ifdef USE_SMALL_BACKSPACE
131 (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217", 145 (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217",
132#else 146#else
133 (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217", 147 (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217",
134#endif 148#endif
135 //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP 149 //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP
136 150
137 (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222", 151 (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222",
138 //TAB + qwerty.. + backslash //+ DEL + END + PGDN 152 //TAB + qwerty.. + backslash //+ DEL + END + PGDN
139 153
140 (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203", 154 (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203",
141 //CAPS + asdf.. + RETURN 155 //CAPS + asdf.. + RETURN
142 156
143 (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211", 157 (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211",
144 //SHIFT + zxcv... //+ UP 158 //SHIFT + zxcv... //+ UP
145 159
146 (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214" 160 (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214"
147 //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT 161 //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT
148 162
@@ -668,127 +682,128 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
668 } 682 }
669 } else { 683 } else {
670#if defined(Q_WS_QWS) || defined(_WS_QWS_) 684#if defined(Q_WS_QWS) || defined(_WS_QWS_)
671/* 685/*
672 qk = QWSServer::keyMap()[k].key_code; 686 qk = QWSServer::keyMap()[k].key_code;
673 if ( qk != Key_unknown ) { 687 if ( qk != Key_unknown ) {
674 if ( ctrl ) 688 if ( ctrl )
675 u = QWSServer::keyMap()[k].ctrl_unicode; 689 u = QWSServer::keyMap()[k].ctrl_unicode;
676 else if ( shift^lock ) 690 else if ( shift^lock )
677 u = QWSServer::keyMap()[k].shift_unicode; 691 u = QWSServer::keyMap()[k].shift_unicode;
678 else 692 else
679 u = QWSServer::keyMap()[k].unicode; 693 u = QWSServer::keyMap()[k].unicode;
680 } 694 }
681*/ 695*/
682 char shifted = k; 696 char shifted = k;
683 if ( !isalpha( k ) ) { 697 if ( !isalpha( k ) ) {
684 // ### Fixme, bad code, needs improving, whole thing needs to 698 // ### Fixme, bad code, needs improving, whole thing needs to
685 // be re-coded to get rid of the way it did things with scancodes etc 699 // be re-coded to get rid of the way it did things with scancodes etc
686 for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ ) 700 for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ )
687 if ( shiftMap[i].normal == k ) 701 if ( shiftMap[i].normal == k )
688 shifted = shiftMap[i].shifted; 702 shifted = shiftMap[i].shifted;
689 } else { 703 } else {
690 shifted = toupper( k ); 704 shifted = toupper( k );
691 } 705 }
692 QChar tempChar( shift^lock ? shifted : k ); 706 QChar tempChar( shift^lock ? shifted : k );
693 unicode = tempChar.unicode(); 707 unicode = tempChar.unicode();
694#endif 708#endif
695 } 709 }
696 if ( unicode != -1 ) { 710 if ( unicode != -1 ) {
697 modifiers = (shift ? Qt::ShiftButton : 0) | (ctrl ? Qt::ControlButton : 0) | 711 modifiers = (shift ? Qt::ShiftButton : 0) | (ctrl ? Qt::ControlButton : 0) |
698 (alt ? Qt::AltButton : 0); 712 (alt ? Qt::AltButton : 0);
699#if defined(Q_WS_QWS) || defined(_WS_QWS_) 713#if defined(Q_WS_QWS) || defined(_WS_QWS_)
700 emit key( unicode, qkeycode, modifiers, true, false ); 714 emit key( unicode, qkeycode, modifiers, true, false );
701 repeatTimer->start( 500 ); 715 repeatTimer->start( 500 );
702#endif 716#endif
703 need_repaint = shift || alt || ctrl; 717 need_repaint = shift || alt || ctrl;
704 shift = alt = ctrl = FALSE; 718 shift = alt = ctrl = FALSE;
705 //qDebug( "pressed %d -> %04x ('%c')", k, u, u&0xffff < 256 ? u&0xff : 0 ); 719 //qDebug( "pressed %d -> %04x ('%c')", k, u, u&0xffff < 256 ? u&0xff : 0 );
706 720
707 KeyboardConfig *dc = picks->dc; 721 KeyboardConfig *dc = picks->dc;
708 722
709 if (dc) { 723 if (dc) {
710 if (qkeycode == Qt::Key_Backspace) { 724 if (qkeycode == Qt::Key_Backspace) {
711 dc->input.remove(dc->input.last()); // remove last input 725 dc->input.remove(dc->input.last()); // remove last input
712 dc->decBackspaces(); 726 dc->decBackspaces();
713 } else if ( k == 0226 || qkeycode == Qt::Key_Return || 727 } else if ( k == 0226 || qkeycode == Qt::Key_Return ||
714 qkeycode == Qt::Key_Space || 728 qkeycode == Qt::Key_Space ||
715 QChar(unicode).isPunct() ) { 729 QChar(unicode).isPunct() ) {
716 dc->input.clear(); 730 dc->input.clear();
717 dc->resetBackspaces(); 731 dc->resetBackspaces();
718 } else { 732 } else {
719 dc->add(QString(QChar(unicode))); 733 dc->add(QString(QChar(unicode)));
720 dc->incBackspaces(); 734 dc->incBackspaces();
721 } 735 }
722 } 736 }
723 737
724 picks->repaint(); 738 picks->repaint();
725 739
726 } 740 }
727 pressedKey = k; 741 pressedKey = k;
728 if ( need_repaint ) { 742 if ( need_repaint ) {
729 repaint( FALSE ); 743 repaint( FALSE );
730 } else { 744 } else {
731 QPainter p(this); 745 QPainter p(this);
732 drawKeyboard( p, pressedKey ); 746 drawKeyboard( p, pressedKey );
733 } 747 }
734 pressTid = startTimer(80); 748 pressTid = startTimer(80);
735 pressed = TRUE; 749 pressed = TRUE;
736} 750}
737 751
738 752
739void Keyboard::mouseReleaseEvent(QMouseEvent*) 753void Keyboard::mouseReleaseEvent(QMouseEvent*)
740{ 754{
741 if ( pressTid == 0 ) 755 if ( pressTid == 0 )
742 clearHighlight(); 756 clearHighlight();
743#if defined(Q_WS_QWS) || defined(_WS_QWS_) 757#if defined(Q_WS_QWS) || defined(_WS_QWS_)
744 if ( unicode != -1 ) { 758 if ( unicode != -1 ) {
745 emit key( unicode, qkeycode, modifiers, false, false ); 759 emit key( unicode, qkeycode, modifiers, false, false );
746 repeatTimer->stop(); 760 repeatTimer->stop();
747 } 761 }
748#endif 762#endif
749 pressed = FALSE; 763 pressed = FALSE;
750} 764}
751 765
752void Keyboard::timerEvent(QTimerEvent* e) 766void Keyboard::timerEvent(QTimerEvent* e)
753{ 767{
754 if ( e->timerId() == pressTid ) { 768 if ( e->timerId() == pressTid ) {
755 killTimer(pressTid); 769 killTimer(pressTid);
756 pressTid = 0; 770 pressTid = 0;
757 if ( !pressed ) 771 if ( !pressed )
758 clearHighlight(); 772 clearHighlight();
759 } 773 }
760} 774}
761 775
762void Keyboard::repeat() 776void Keyboard::repeat()
763{ 777{
764 repeatTimer->start( 150 ); 778
765 emit key( unicode, qkeycode, modifiers, true, true ); 779 repeatTimer->start( 200 );
780 emit key( unicode, qkeycode, modifiers, true, true );
766} 781}
767 782
768void Keyboard::clearHighlight() 783void Keyboard::clearHighlight()
769{ 784{
770 if ( pressedKey >= 0 ) { 785 if ( pressedKey >= 0 ) {
771 int tmp = pressedKey; 786 int tmp = pressedKey;
772 pressedKey = -1; 787 pressedKey = -1;
773 QPainter p(this); 788 QPainter p(this);
774 drawKeyboard( p, tmp ); 789 drawKeyboard( p, tmp );
775 } 790 }
776} 791}
777 792
778 793
779QSize Keyboard::sizeHint() const 794QSize Keyboard::sizeHint() const
780{ 795{
781 QFontMetrics fm=fontMetrics(); 796 QFontMetrics fm=fontMetrics();
782 int keyHeight = fm.lineSpacing()+2; 797 int keyHeight = fm.lineSpacing()+2;
783 798
784 if (useOptiKeys) 799 if (useOptiKeys)
785 keyHeight += 1; 800 keyHeight += 1;
786 801
787 return QSize( 320, keyHeight * 5 + picks->sizeHint().height() + 1 ); 802 return QSize( 320, keyHeight * 5 + picks->sizeHint().height() + 1 );
788} 803}
789 804
790 805
791void Keyboard::resetState() 806void Keyboard::resetState()
792{ 807{
793 picks->resetState(); 808 picks->resetState();
794} 809}