diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-03-13 21:39:00 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-03-13 21:40:38 +0900 |
commit | 18657676cc04c0d2d50edf5bf23d690b0915f27c (patch) | |
tree | 7a60b097af43e531b7f174a750e865adf3a55f4f | |
parent | fb507b7f3fce6a680ab0f5767f4ea58b62e40fba (diff) | |
download | kvkbd-18657676cc04c0d2d50edf5bf23d690b0915f27c.tar.gz kvkbd-18657676cc04c0d2d50edf5bf23d690b0915f27c.zip |
Fixed key text display when shift is used (caps is still broken) as well
as several improvements to the code.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 00e207e95d5aab6bbc37c8178bd189b0c0619be6)
-rw-r--r-- | src/MainWidget.cpp | 203 | ||||
-rw-r--r-- | src/MainWidget.h | 11 | ||||
-rw-r--r-- | src/VButton.cpp | 75 | ||||
-rw-r--r-- | src/VButton.h | 4 |
4 files changed, 132 insertions, 161 deletions
diff --git a/src/MainWidget.cpp b/src/MainWidget.cpp index 26c0f8f..8797085 100644 --- a/src/MainWidget.cpp +++ b/src/MainWidget.cpp @@ -132,7 +132,6 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const connect ( v,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( keyPress ( unsigned int ) ) ); btns.append ( v ); v->res(); - //caps_btns.append ( v ); } VButton *bksp = new VButton ( this,"" ); @@ -201,10 +200,9 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const caps->resize ( 63,30 ); caps->setText ( "Caps" ); caps->setToggleButton ( true ); - caps->res(); + connect ( caps,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift ( unsigned int ) ) ); other_keys.append(caps); - connect ( caps,TQT_SIGNAL ( clicked() ),this,TQT_SLOT ( toggleCaps() ) ); - connect ( caps,TQT_SIGNAL ( keyClick ( unsigned int ) ),this,TQT_SLOT ( keyPress ( unsigned int ) ) ); + caps->res(); for ( int a=0;a<R3LEN;a++ ) { @@ -245,15 +243,15 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const enter->res(); //ROW 4 - lshft = new VButton ( this,"" ); - lshft->setKeyCode ( 50 ); - lshft->move ( stx,sty+ ( 4*35 ) ); - lshft->resize ( 45,30 ); - lshft->setText ( "Shift" ); - lshft->setToggleButton ( true ); - connect ( lshft,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift() ) ); - mod_keys.append ( lshft ); - lshft->res(); + lshift = new VButton ( this,"" ); + lshift->setKeyCode ( 50 ); + lshift->move ( stx,sty+ ( 4*35 ) ); + lshift->resize ( 45,30 ); + lshift->setText ( "Shift" ); + lshift->setToggleButton ( true ); + connect ( lshift,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift( unsigned int ) ) ); + mod_keys.append ( lshift ); + lshift->res(); for ( int a=0;a<R4LEN;a++ ) { @@ -261,7 +259,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const v->setKeyCode ( kc4[a] ); //v->setText ( k4.mid ( a,1 ) ); //v->setShiftText ( k4s.mid ( a,1 ) ); - v->move ( stx+lshft->width() +5+ ( 35*a ),sty+ ( 4*35 ) ); + v->move ( stx+lshift->width() +5+ ( 35*a ),sty+ ( 4*35 ) ); btns.append ( v ); v->res(); connect ( v,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( keyPress ( unsigned int ) ) ); @@ -269,7 +267,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const VButton *sm = new VButton ( this,"" ); sm->setKeyCode ( 59 ); - sm->move ( stx+ ( R4LEN *35 ) +lshft->width() +5,sty+ ( 4*35 ) ); + sm->move ( stx+ ( R4LEN *35 ) +lshift->width() +5,sty+ ( 4*35 ) ); //sm->setText ( "," ); //sm->setShiftText ( "<" ); connect ( sm,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( keyPress ( unsigned int ) ) ); @@ -278,7 +276,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const VButton *gr = new VButton ( this,"" ); gr->setKeyCode ( 60 ); - gr->move ( stx+ ( ( R4LEN +1 ) *35 ) +lshft->width() +5,sty+ ( 4*35 ) ); + gr->move ( stx+ ( ( R4LEN +1 ) *35 ) +lshift->width() +5,sty+ ( 4*35 ) ); //gr->setText ( "." ); //gr->setShiftText ( ">" ); connect ( gr,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( keyPress ( unsigned int ) ) ); @@ -287,22 +285,22 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const VButton *sl = new VButton ( this,"" ); sl->setKeyCode ( 61 ); - sl->move ( stx+ ( ( R4LEN +2 ) *35 ) +lshft->width() +5,sty+ ( 4*35 ) ); + sl->move ( stx+ ( ( R4LEN +2 ) *35 ) +lshift->width() +5,sty+ ( 4*35 ) ); //sl->setText ( "/" ); //sl->setShiftText ( "?" ); connect ( sl,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( keyPress ( unsigned int ) ) ); btns.append ( sl ); sl->res(); - rshft = new VButton ( this,"" ); - rshft->setKeyCode ( 62 ); - rshft->move ( stx+ ( ( R4LEN +3 ) *35 ) +lshft->width() +5,sty+ ( 4*35 ) ); - rshft->resize ( 68,30 ); - rshft->setText ( "Shift" ); - rshft->setToggleButton ( true ); - connect ( rshft,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift() ) ); - mod_keys.append ( rshft ); - rshft->res(); + rshift = new VButton ( this,"" ); + rshift->setKeyCode ( 62 ); + rshift->move ( stx+ ( ( R4LEN +3 ) *35 ) +lshift->width() +5,sty+ ( 4*35 ) ); + rshift->resize ( 68,30 ); + rshift->setText ( "Shift" ); + rshift->setToggleButton ( true ); + connect ( rshift,TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleShift( unsigned int ) ) ); + mod_keys.append ( rshift ); + rshift->res(); //ROW 5 lctrl = new VButton ( this,"" ); @@ -378,8 +376,6 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const mod_keys.append ( rctrl ); rctrl->res(); - mappingNotify(NULL); - quit = new VButton ( this,"quit" ); quit->resize ( 20,30 ); quit->move ( 524,15 ); @@ -461,8 +457,7 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const numl->setText("Num\nLock"); numl->setToggleButton ( true ); other_keys.append(numl); - connect ( numl, TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( keyPress ( unsigned int ) ) ); - connect ( numl, TQT_SIGNAL ( clicked() ), this, TQT_SLOT ( toggleNumlock() ) ); + connect ( numl, TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( toggleNumlock() ) ); div = new VButton(this,"div"); @@ -508,6 +503,8 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const min->res(); connect ( min, TQT_SIGNAL ( keyClick ( unsigned int ) ), this, TQT_SLOT ( keyPress ( unsigned int ) ) ); + mappingNotify(NULL); + if (!stand_alone) { tray = new KbdTray ( this ); @@ -656,6 +653,7 @@ void MainWidget::restorePosition() } setGeometry(dflt_geom); } + void MainWidget::saveState() { TDEConfig *cfg = 0; @@ -831,6 +829,7 @@ void MainWidget::showDock() cfg->sync(); } + void MainWidget::toggleFontAutoRes() { bool c = tray->contextMenu()->isItemChecked( mnu_autores); @@ -839,64 +838,52 @@ void MainWidget::toggleFontAutoRes() cfg->writeEntry ("autoresfont", !c); cfg->sync(); } + void MainWidget::toggleNumlock() { - bool p=numl->isOn(); - for ( unsigned a=0;a<numl_keys.size();a++ ) { - NumpadVButton *v = numl_keys[a]; - v->numlockPressed(p); - } + send_key(numl->getKeyCode()); + updateNumlock(); } -void MainWidget::toggleCaps() + +void MainWidget::updateNumlock() { - bool p=caps->isOn(); - for ( unsigned a=0;a<btns.size();a++ ) { - VButton *v = btns[a]; - v->capsPressed(p); + bool state = numl->isOn(); + for (unsigned a = 0; a < numl_keys.size(); a++) + { + NumpadVButton *v = numl_keys[a]; + v->numlockPressed(state); } } -void MainWidget::toggleShift() +void MainWidget::toggleShift(unsigned int keycode) { - bool p=false; - if ( lshft->isOn() || rshft->isOn() ) p=true; + send_key(keycode); + updateShift(); +} - for ( unsigned a=0;a<btns.size();a++ ) { +void MainWidget::updateShift() +{ + bool state = caps->isOn() ^ (lshift->isOn() || rshift->isOn()); + for (unsigned a = 0; a < btns.size(); a++) + { VButton *v = btns[a]; - v->shiftPressed ( p ); + v->shiftPressed(state); } - } void MainWidget::keyPress ( unsigned int a ) { - send_key ( a,true,true ); - bool reverse = false; - if (lshft->isOn() || rshft->isOn()) - reverse=true; - - for ( unsigned a=0;a<mod_keys.size();a++ ) { - VButton *mod = ( VButton* ) mod_keys[a]; - mod->setOn ( false ); - } - - if (caps->isOn()) { - if (reverse) { - for (unsigned a=0;a<btns.size();a++) { - VButton *v = ( VButton* ) btns[a]; - v->capsPressed(true); - } - } - }else { - for (unsigned a=0;a<btns.size();a++) - { - VButton *v = ( VButton* ) btns[a]; - v->capsPressed(false); - } + send_key(a); + for (unsigned a = 0; a < mod_keys.size(); a++) + { + VButton *mod = mod_keys[a]; + mod->setOn(false); } - + // Make sure the key labels are correctly updated + updateShift(); } -void MainWidget::send_key ( unsigned int keycode, bool press, bool release ) + +void MainWidget::send_key(unsigned int keycode) { Window curr_focus; int revert_to; @@ -942,68 +929,52 @@ bool MainWidget::keyState ( int iKey ) void MainWidget::queryModState() { - //printf("Scroll: %d\n",keyState(XK_Scroll_Lock,pDisplay)); //printf("Caps : %d\n",keyState(XK_Caps_Lock,pDisplay)); //printf("Num : %d\n",keyState(XK_Num_Lock,pDisplay)); - bool caps_state = keyState ( XK_Caps_Lock); - bool numl_state = keyState ( XK_Num_Lock); - - if ( caps_state!=caps->isOn() ) { - caps->setOn ( caps_state ); - toggleCaps(); + bool caps_state = keyState(XK_Caps_Lock); + if (caps_state != caps->isOn()) + { + caps->setOn(caps_state); + updateShift(); } - if ( numl_state!= numl->isOn() ) { + + bool numl_state = keyState(XK_Num_Lock); + if (numl_state != numl->isOn()) + { numl->setOn(numl_state); - toggleNumlock(); + updateNumlock(); } } void MainWidget::setupText(VButton& v) { - KeyCode keycode=v.getKeyCode(); + // lowercase text KeySym keysym_l = XkbKeycodeToKeysym(display, keycode, 0, 0); - - KeySym keysym_u = XkbKeycodeToKeysym(display, keycode, 0, 1); - - long ret = keysym2ucs(keysym_l); - - TQString btn_text(TQChar((uint)ret)); - + TQString btn_text(TQChar((uint)keysym2ucs(keysym_l))); v.setText(btn_text); - TQString btn_upper(btn_text.upper()); - - if (btn_upper==btn_text) { - ret = keysym2ucs(keysym_u); - TQChar c((uint)ret); - if (c=='&') - v.setShiftText("&&"); - else - v.setShiftText(c); + // uppercase text + KeySym keysym_u = XkbKeycodeToKeysym(display, keycode, 0, 1); + TQChar c((uint)keysym2ucs(keysym_u)); + if (c == '&') + { + v.setShiftText("&&"); } - else { - v.setShiftText(btn_upper); + else + { + v.setShiftText(c); } } void MainWidget::mappingNotify(XMappingEvent *) { - //TQTimer::singleShot( 1000, this, TQT_SLOT(test()) ); - //if (e)XRefreshKeyboardMapping(e); - - //int index=0; - - for (unsigned a=0;a<btns.size();a++) { - VButton *v = (VButton *)btns[a]; + for (unsigned a = 0; a < btns.size(); a++) + { + VButton *v = btns[a]; setupText(*v); } -// for (int a=0;a<shft_btns.size();a++) -// { -// VButton *v = (VButton *)shft_btns[a]; -// setupText(*v); -// } } KbdDock::KbdDock ( MainWidget *m ) @@ -1914,13 +1885,3 @@ void KbdTray::mousePressEvent(TQMouseEvent *e) #include "MainWidget.moc" - - - - - - - - - - diff --git a/src/MainWidget.h b/src/MainWidget.h index f476c67..2c708cc 100644 --- a/src/MainWidget.h +++ b/src/MainWidget.h @@ -50,9 +50,8 @@ public: public slots: void keyPress(unsigned int keycode); - void toggleCaps(); void toggleNumlock(); - void toggleShift(); + void toggleShift(unsigned int keycode); void toggleNumericPad(); void toggleFontAutoRes(); void toggleLock(); @@ -73,6 +72,8 @@ protected: private: void updateFont(); + void updateNumlock(); + void updateShift(); bool nresize; @@ -82,8 +83,8 @@ private: VButton *caps; - VButton *lshft; - VButton *rshft; + VButton *lshift; + VButton *rshift; VButton *lctrl; VButton *rctrl; @@ -110,7 +111,7 @@ private: TQValueList<VButton *> other_keys; TQValueList<NumpadVButton *> numl_keys; - void send_key(unsigned int keycode, bool press, bool release); + void send_key(unsigned int keycode); Display *display; KbdTray *tray; diff --git a/src/VButton.cpp b/src/VButton.cpp index b4870f1..cabedd1 100644 --- a/src/VButton.cpp +++ b/src/VButton.cpp @@ -23,33 +23,12 @@ VButton::~VButton() void VButton::shiftPressed(bool press) { - if (press==true){ - TQString tu=l.upper(); - if (tu.compare(l)==0){ - //TQPushButton::setText(tu); - TQPushButton::setText(u); - } - else{ - TQPushButton::setText(tu); - } + if (press) + { + TQPushButton::setText(u); } - else{ - TQPushButton::setText(l); - } -} - -void VButton::capsPressed(bool press) -{ - if (press==true){ - TQString tu=l.upper(); - if (tu.compare(l)==0){ - TQPushButton::setText(tu); - } - else{ - TQPushButton::setText(u); - } - } - else{ + else + { TQPushButton::setText(l); } } @@ -107,34 +86,62 @@ void VButton::res() orig_size=geometry(); } -void VButton::mousePressEvent(TQMouseEvent * e) +void VButton::enterEvent(TQEvent *e) +{ + TQPushButton::enterEvent(e); + inside = true; +} + +void VButton::leaveEvent(TQEvent *e) +{ + TQPushButton::leaveEvent(e); + inside = false; +} + +void VButton::mousePressEvent(TQMouseEvent *e) { press=true; TQPushButton::mousePressEvent(e); - sendKey(); - startTimer(500); + if (!isToggleButton()) + { + // non toggle buttons need to send the key here + sendKey(); + startTimer(500); + } } -void VButton::mouseReleaseEvent(TQMouseEvent * e) +void VButton::mouseReleaseEvent(TQMouseEvent *e) { press=false; TQPushButton::mouseReleaseEvent(e); - TQT_TQOBJECT(this)->killTimers(); + if (hitButton(e->pos()) && isToggleButton()) + { + // toggle buttons need to send the key here because the underlying pushbutton state + // is only updated on mouse release + sendKey(); + } + killTimers(); inrpt=false; } void VButton::timerEvent(TQTimerEvent *) { - if (!press){ + if (!press) + { inrpt=false; return; } - if (press && !inrpt) { + if (press && !inrpt) + { inrpt=true; startTimer(120); return; } - sendKey(); + if (inside) + { + // Send key only if the mouse is still inside the button rectangle + sendKey(); + } } #include "VButton.moc" diff --git a/src/VButton.h b/src/VButton.h index 2f916ff..cab13cd 100644 --- a/src/VButton.h +++ b/src/VButton.h @@ -17,7 +17,6 @@ public: void setText(const TQString &text); void setShiftText(const TQString &text); void setColor(const TQColor &color); - void capsPressed(bool press); void reposition(int width, int height); void res(); @@ -28,6 +27,7 @@ public: private: bool press; bool inrpt; + bool inside; protected: unsigned int keycode; @@ -42,6 +42,8 @@ public slots: void shiftPressed(bool press); protected slots: + void enterEvent(TQEvent *e); + void leaveEvent(TQEvent *e); void mousePressEvent(TQMouseEvent *e); void mouseReleaseEvent(TQMouseEvent *e); |