1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Fixed handling multi byte key sequences in cKbdRemote

This commit is contained in:
Klaus Schmidinger 2006-01-01 14:28:47 +01:00
parent 06b2245bcd
commit 26cb900ddf
4 changed files with 73 additions and 36 deletions

View File

@ -1582,3 +1582,7 @@ Bob Withers <bwit@pobox.com>
Javier Fernández-Sanguino Peña <jfs@computer.org> Javier Fernández-Sanguino Peña <jfs@computer.org>
for reporting a security hole in the way the SVDRP command GRAB writes the for reporting a security hole in the way the SVDRP command GRAB writes the
image file image file
Jürgen Schneider <ivory7@gmx.de>
for a patch that was used as a base to fix handling multi byte key sequences
in cKbdRemote

View File

@ -4053,3 +4053,5 @@ Video Disk Recorder Revision History
(suggested by Andreas Brugger). (suggested by Andreas Brugger).
- The DVB devices now retune (and, if applicable, resend the DiSEqC data) if - The DVB devices now retune (and, if applicable, resend the DiSEqC data) if
the lock is lost (based on a patch from Reinhard Nissl). the lock is lost (based on a patch from Reinhard Nissl).
- Fixed handling multi byte key sequences in cKbdRemote (based on a patch from
Jürgen Schneider).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: remote.c 1.45 2005/09/03 12:29:48 kls Exp $ * $Id: remote.c 1.46 2006/01/01 14:21:07 kls Exp $
*/ */
#include "remote.h" #include "remote.h"
@ -262,29 +262,66 @@ int cKbdRemote::MapCodeToFunc(uint64 Code)
return (Code <= 0xFF) ? Code : kfNone; return (Code <= 0xFF) ? Code : kfNone;
} }
void cKbdRemote::Action(void) int cKbdRemote::ReadKey(void)
{ {
cPoller Poller(STDIN_FILENO); cPoller Poller(STDIN_FILENO);
while (Running()) { if (Poller.Poll(50)) {
if (Poller.Poll(100)) { uchar ch = 0;
uint64 Command = 0; int r = safe_read(STDIN_FILENO, &ch, 1);
uint i = 0; if (r == 1)
while (Running() && i < sizeof(Command)) { return ch;
uchar ch; if (r < 0)
int r = read(STDIN_FILENO, &ch, 1); LOG_ERROR_STR("cKbdRemote");
if (r == 1) {
Command <<= 8;
Command |= ch;
i++;
} }
else if (r == 0) { return -1;
// don't know why, but sometimes special keys that start with }
// 0x1B ('ESC') cause a short gap between the 0x1B and the rest
// of their codes, so we'll need to wait some 100ms to see if uint64 cKbdRemote::ReadKeySequence(void)
// there is more coming up - or whether this really is the 'ESC' {
// key (if somebody knows how to clean this up, please let me know): uint64 k = 0;
if (Command == 0x1B && Poller.Poll(100)) int key1;
continue;
if ((key1 = ReadKey()) >= 0) {
k = key1;
if (key1 == 0x1B) {
// Start of escape sequence
if ((key1 = ReadKey()) >= 0) {
k <<= 8;
k |= key1 & 0xFF;
switch (key1) {
case 0x4F: // 3-byte sequence
if ((key1 = ReadKey()) >= 0) {
k <<= 8;
k |= key1 & 0xFF;
}
break;
case 0x5B: // 3- or more-byte sequence
if ((key1 = ReadKey()) >= 0) {
k <<= 8;
k |= key1 & 0xFF;
switch (key1) {
case 0x31 ... 0x3F: // more-byte sequence
while (key1 != 0x7E) {
k <<= 8;
k |= key1 & 0xFF;
if ((key1 = ReadKey()) < 0)
break; // Sequence ends here
}
break;
}
}
break;
}
}
}
}
return k;
}
void cKbdRemote::Action(void)
{
while (Running()) {
uint64 Command = ReadKeySequence();
if (Command) { if (Command) {
if (rawMode || !Put(Command)) { if (rawMode || !Put(Command)) {
int func = MapCodeToFunc(Command); int func = MapCodeToFunc(Command);
@ -292,13 +329,5 @@ void cKbdRemote::Action(void)
Put(KBDKEY(func)); Put(KBDKEY(func));
} }
} }
break;
}
else {
LOG_ERROR;
break;
}
}
}
} }
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: remote.h 1.31 2005/09/03 12:28:42 kls Exp $ * $Id: remote.h 1.32 2006/01/01 14:00:50 kls Exp $
*/ */
#ifndef __REMOTE_H #ifndef __REMOTE_H
@ -89,6 +89,8 @@ private:
static bool rawMode; static bool rawMode;
struct termios savedTm; struct termios savedTm;
virtual void Action(void); virtual void Action(void);
int ReadKey(void);
uint64 ReadKeySequence(void);
int MapCodeToFunc(uint64 Code); int MapCodeToFunc(uint64 Code);
public: public:
cKbdRemote(void); cKbdRemote(void);