Skip to content

Commit

Permalink
[terminal] Fix Terminal::keyPress() for non-ASCII chars (Fixes JB#28668)
Browse files Browse the repository at this point in the history
On some installations (e.g. tablet), Terminal::keyPress() messes
up the keycode by converting the keypress into a Latin1 character
and then appending this Latin1 character to a QString. For some
reason, we were lucky so far and it worked on the phone.

Behavior change: This now causes key combinations with Ctrl to be
ignored if the key isn't in the ASCII ranges 0x41-0x5f, 0x61-0x7f.
  • Loading branch information
thp committed Jun 2, 2015
1 parent 7224388 commit d82635a
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/terminal.cpp
Expand Up @@ -180,27 +180,36 @@ void Terminal::keyPress(int key, int modifiers)

resetBackBufferScrollPos();

if(c.isLetter() && (modifiers & Qt::ShiftModifier))
c = c.toUpper();
else if(c.isLetter())
c = c.toLower();
if (c.isLetter()) {
c = ((modifiers & Qt::ShiftModifier) != 0) ? c.toUpper() : c.toLower();
}

QString toWrite;

if( key <= 0xFF ) {
char asciiVal = c.toLatin1();

if(modifiers & Qt::AltModifier)
if (key <= 0xFF) {
if((modifiers & Qt::AltModifier) != 0) {
toWrite.append(ch_ESC);
}

if((modifiers & Qt::ControlModifier) && c.isLower())
asciiVal -= 0x60;
if((modifiers & Qt::ControlModifier) && c.isUpper())
asciiVal -= 0x40;
toWrite.append(asciiVal);
if ((modifiers & Qt::ControlModifier) != 0) {
char asciiVal = c.toLatin1();

if(iPtyIFace)
if (asciiVal >= 0x41 && asciiVal <= 0x5f) {
// Turn uppercase characters into their control code equivalent
toWrite.append(asciiVal - 0x40);
} else if (asciiVal >= 0x61 && asciiVal <= 0x7f) {
// Turn lowercase characters into their control code equivalent
toWrite.append(asciiVal - 0x60);
} else {
qWarning() << "Ctrl+" << c << " does not translate into a control code";
}
} else {
toWrite.append(c);
}

if (iPtyIFace) {
iPtyIFace->writeTerm(toWrite);
}
return;
}

Expand Down

0 comments on commit d82635a

Please sign in to comment.