version 4.5.0
PIThread::stopAndWait now returns bool PIKbdListener on Linux now use piwaitevent_p and can immediately stop new base method piZeroMemory, also migrate all "memset 0" to piZeroMemory
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "piliterals.h"
|
||||
#include "piwaitevent_p.h"
|
||||
#ifndef WINDOWS
|
||||
# include <termios.h>
|
||||
#else
|
||||
@@ -144,6 +145,7 @@ PRIVATE_DEFINITION_START(PIKbdListener)
|
||||
int
|
||||
#endif
|
||||
ret;
|
||||
PIWaitEvent event;
|
||||
PRIVATE_DEFINITION_END(PIKbdListener)
|
||||
|
||||
|
||||
@@ -157,11 +159,11 @@ PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread()
|
||||
#else
|
||||
tcgetattr(0, &PRIVATE->sterm);
|
||||
#endif
|
||||
is_active = true;
|
||||
ret_func = slot;
|
||||
kbddata_ = _d;
|
||||
dbl_interval = 400;
|
||||
PIKbdListener::exiting = exit_enabled = false;
|
||||
ret_func = slot;
|
||||
kbddata_ = _d;
|
||||
dbl_interval = 400;
|
||||
PRIVATE->event.create();
|
||||
PIKbdListener::exiting = false;
|
||||
if (startNow) start();
|
||||
}
|
||||
|
||||
@@ -169,7 +171,7 @@ PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread()
|
||||
PIKbdListener::~PIKbdListener() {
|
||||
stop();
|
||||
if (!waitForFinish(100_ms)) terminate();
|
||||
end();
|
||||
PRIVATE->event.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +218,8 @@ PIKbdListener::MouseButtons getButtons(DWORD v) {
|
||||
void PIKbdListener::readKeyboard() {
|
||||
ke.key = 0;
|
||||
ke.modifiers = 0;
|
||||
memset(rc, 0, 8);
|
||||
char rc[8];
|
||||
piZeroMemory(rc, 8);
|
||||
#ifdef WINDOWS
|
||||
INPUT_RECORD ir;
|
||||
ReadConsoleInput(PRIVATE->hIn, &ir, 1, &(PRIVATE->ret));
|
||||
@@ -403,6 +406,7 @@ void PIKbdListener::readKeyboard() {
|
||||
}
|
||||
#else
|
||||
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
|
||||
if (!PRIVATE->event.wait(0)) return;
|
||||
PRIVATE->ret = read(0, rc, 8);
|
||||
/*piCout << "key" << PIString(rc).replaceAll("\e", "\\e");
|
||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||
@@ -542,6 +546,13 @@ void PIKbdListener::readKeyboard() {
|
||||
|
||||
void PIKbdListener::stop() {
|
||||
PIThread::stop();
|
||||
PRIVATE->event.interrupt();
|
||||
}
|
||||
|
||||
|
||||
bool PIKbdListener::stopAndWait(PISystemTime timeout) {
|
||||
stop();
|
||||
return waitForFinish(timeout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,15 +29,11 @@
|
||||
#include "pithread.h"
|
||||
#include "pitime.h"
|
||||
|
||||
#define WAIT_FOR_EXIT \
|
||||
while (!PIKbdListener::exiting) \
|
||||
piMSleep(PIP_MIN_MSLEEP * 5); \
|
||||
if (PIKbdListener::instance()) { \
|
||||
PIKbdListener::instance()->stop(); \
|
||||
if (!PIKbdListener::instance()->waitForFinish(PISystemTime::fromMilliseconds(100))) { \
|
||||
PIKbdListener::instance()->setDebug(false); \
|
||||
PIKbdListener::instance()->terminate(); \
|
||||
} \
|
||||
#define WAIT_FOR_EXIT \
|
||||
while (!PIKbdListener::exiting) \
|
||||
piMSleep(PIP_MIN_MSLEEP * 5); \
|
||||
if (PIKbdListener::instance()) { \
|
||||
if (!PIKbdListener::instance()->stopAndWait(PISystemTime::fromSeconds(1))) PIKbdListener::instance()->terminate(); \
|
||||
}
|
||||
|
||||
|
||||
@@ -188,6 +184,8 @@ public:
|
||||
|
||||
void stop();
|
||||
|
||||
bool stopAndWait(PISystemTime timeout = {});
|
||||
|
||||
//! Returns if keyboard listening is active (not running!)
|
||||
bool isActive() { return is_active; }
|
||||
|
||||
@@ -258,9 +256,8 @@ private:
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
KBFunc ret_func;
|
||||
int exit_key;
|
||||
bool exit_enabled, is_active;
|
||||
bool exit_enabled = false, is_active = true;
|
||||
void * kbddata_;
|
||||
char rc[8];
|
||||
double dbl_interval;
|
||||
PITimeMeasurer tm_dbl;
|
||||
KeyEvent ke;
|
||||
|
||||
Reference in New Issue
Block a user