diff options
author | Michele Calgaro <[email protected]> | 2021-03-13 21:39:00 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2021-03-13 21:39:00 +0900 |
commit | 00e207e95d5aab6bbc37c8178bd189b0c0619be6 (patch) | |
tree | d7ce4d55e87a33ec2bb9e20ed209fedae90e4096 /src/MainWidget.cpp | |
parent | fb22ce0a5666025d9964522561f83d9b6008e4ad (diff) | |
download | kvkbd-00e207e95d5aab6bbc37c8178bd189b0c0619be6.tar.gz kvkbd-00e207e95d5aab6bbc37c8178bd189b0c0619be6.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 <[email protected]>
Diffstat (limited to 'src/MainWidget.cpp')
-rw-r--r-- | src/MainWidget.cpp | 203 |
1 files changed, 82 insertions, 121 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" - - - - - - - - - - |