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:
parent
06b2245bcd
commit
26cb900ddf
@ -1582,3 +1582,7 @@ Bob Withers <bwit@pobox.com>
|
||||
Javier Fernández-Sanguino Peña <jfs@computer.org>
|
||||
for reporting a security hole in the way the SVDRP command GRAB writes the
|
||||
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
|
||||
|
2
HISTORY
2
HISTORY
@ -4053,3 +4053,5 @@ Video Disk Recorder Revision History
|
||||
(suggested by Andreas Brugger).
|
||||
- The DVB devices now retune (and, if applicable, resend the DiSEqC data) if
|
||||
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).
|
||||
|
87
remote.c
87
remote.c
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* 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"
|
||||
@ -262,29 +262,66 @@ int cKbdRemote::MapCodeToFunc(uint64 Code)
|
||||
return (Code <= 0xFF) ? Code : kfNone;
|
||||
}
|
||||
|
||||
void cKbdRemote::Action(void)
|
||||
int cKbdRemote::ReadKey(void)
|
||||
{
|
||||
cPoller Poller(STDIN_FILENO);
|
||||
while (Running()) {
|
||||
if (Poller.Poll(100)) {
|
||||
uint64 Command = 0;
|
||||
uint i = 0;
|
||||
while (Running() && i < sizeof(Command)) {
|
||||
uchar ch;
|
||||
int r = read(STDIN_FILENO, &ch, 1);
|
||||
if (r == 1) {
|
||||
Command <<= 8;
|
||||
Command |= ch;
|
||||
i++;
|
||||
if (Poller.Poll(50)) {
|
||||
uchar ch = 0;
|
||||
int r = safe_read(STDIN_FILENO, &ch, 1);
|
||||
if (r == 1)
|
||||
return ch;
|
||||
if (r < 0)
|
||||
LOG_ERROR_STR("cKbdRemote");
|
||||
}
|
||||
else if (r == 0) {
|
||||
// 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
|
||||
// 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):
|
||||
if (Command == 0x1B && Poller.Poll(100))
|
||||
continue;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64 cKbdRemote::ReadKeySequence(void)
|
||||
{
|
||||
uint64 k = 0;
|
||||
int key1;
|
||||
|
||||
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 (rawMode || !Put(Command)) {
|
||||
int func = MapCodeToFunc(Command);
|
||||
@ -292,13 +329,5 @@ void cKbdRemote::Action(void)
|
||||
Put(KBDKEY(func));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
LOG_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
remote.h
4
remote.h
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* 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
|
||||
@ -89,6 +89,8 @@ private:
|
||||
static bool rawMode;
|
||||
struct termios savedTm;
|
||||
virtual void Action(void);
|
||||
int ReadKey(void);
|
||||
uint64 ReadKeySequence(void);
|
||||
int MapCodeToFunc(uint64 Code);
|
||||
public:
|
||||
cKbdRemote(void);
|
||||
|
Loading…
Reference in New Issue
Block a user