mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
Avoiding an extra key press event if the repeat function kicks in when controlling VDR via the PC keyboard
This commit is contained in:
54
remote.c
54
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 2.6 2013/01/13 12:01:52 kls Exp $
|
||||
* $Id: remote.c 2.7 2013/02/02 12:44:33 kls Exp $
|
||||
*/
|
||||
|
||||
#include "remote.h"
|
||||
@@ -295,6 +295,14 @@ int cKbdRemote::MapCodeToFunc(uint64_t Code)
|
||||
return kfNone;
|
||||
}
|
||||
|
||||
void cKbdRemote::PutKey(uint64_t Code, bool Repeat, bool Release)
|
||||
{
|
||||
if (rawMode || !Put(Code, Repeat, Release)) {
|
||||
if (int func = MapCodeToFunc(Code))
|
||||
Put(KBDKEY(func), Repeat, Release);
|
||||
}
|
||||
}
|
||||
|
||||
int cKbdRemote::ReadKey(void)
|
||||
{
|
||||
cPoller Poller(STDIN_FILENO);
|
||||
@@ -356,24 +364,46 @@ uint64_t cKbdRemote::ReadKeySequence(void)
|
||||
|
||||
void cKbdRemote::Action(void)
|
||||
{
|
||||
uint64_t FirstCommand = 0;
|
||||
uint64_t LastCommand = 0;
|
||||
bool Delayed = false;
|
||||
bool Repeat = false;
|
||||
|
||||
while (Running()) {
|
||||
uint64_t Command = ReadKeySequence();
|
||||
if (LastCommand && Command != LastCommand && Repeat) {
|
||||
if (!rawMode)
|
||||
Put(LastCommand, false, true);
|
||||
if (Command) {
|
||||
if (Command == LastCommand) {
|
||||
// If two keyboard events with the same command come in without an intermediate
|
||||
// timeout, this is a long key press that caused the repeat function to kick in:
|
||||
Delayed = false;
|
||||
FirstCommand = 0;
|
||||
PutKey(Command, true);
|
||||
Repeat = true;
|
||||
}
|
||||
else if (Command == FirstCommand) {
|
||||
// If the same command comes in twice with an intermediate timeout, we
|
||||
// need to delay the second command to see whether it is going to be
|
||||
// a repeat function or a separate key press:
|
||||
Delayed = true;
|
||||
}
|
||||
else {
|
||||
// This is a totally new key press, so we accept it immediately:
|
||||
PutKey(Command);
|
||||
Delayed = false;
|
||||
FirstCommand = Command;
|
||||
}
|
||||
}
|
||||
else if (Repeat) {
|
||||
// Timeout after a repeat function, so we generate a 'release':
|
||||
PutKey(LastCommand, false, true);
|
||||
Repeat = false;
|
||||
}
|
||||
if (Command) {
|
||||
if (Command == LastCommand)
|
||||
Repeat = true;
|
||||
if (rawMode || !Put(Command, Repeat)) {
|
||||
int func = MapCodeToFunc(Command);
|
||||
if (func)
|
||||
Put(KBDKEY(func));
|
||||
}
|
||||
else if (Delayed && FirstCommand) {
|
||||
// Timeout after two normal key presses of the same key, so accept the
|
||||
// delayed key:
|
||||
PutKey(FirstCommand);
|
||||
Delayed = false;
|
||||
FirstCommand = 0;
|
||||
}
|
||||
LastCommand = Command;
|
||||
}
|
||||
|
Reference in New Issue
Block a user