pip micro disable piintrospection piwaitevent

PIP_NO_SOCET
This commit is contained in:
2025-10-18 11:20:18 +03:00
parent 4885623492
commit cf89d77981
14 changed files with 506 additions and 459 deletions

View File

@@ -18,9 +18,11 @@
*/
#include "pikbdlistener.h"
#include "piincludes_p.h"
#include "piliterals.h"
#include "piwaitevent_p.h"
#ifndef MICRO_PIP
# include "piincludes_p.h"
# include "piliterals.h"
# include "piwaitevent_p.h"
// clang-format off
#ifndef WINDOWS
# include <termios.h>
@@ -49,7 +51,7 @@ bool PIKbdListener::exiting;
PIKbdListener * PIKbdListener::_object = 0;
#ifndef WINDOWS
# ifndef WINDOWS
// unix
const PIKbdListener::EscSeq PIKbdListener::esc_seq[] = {
{"OA", PIKbdListener::UpArrow, 0, 0, 1},
@@ -130,22 +132,22 @@ void setupTerminal(bool on) {
printf(on ? "h" : "l");
fflush(0);
}
#endif
# endif
PRIVATE_DEFINITION_START(PIKbdListener)
#ifdef WINDOWS
# ifdef WINDOWS
void *hIn, *hOut;
DWORD smode, tmode;
CONSOLE_SCREEN_BUFFER_INFO sbi;
#else
# else
struct termios sterm, tterm;
#endif
#ifdef WINDOWS
# endif
# ifdef WINDOWS
DWORD
#else
# else
int
#endif
# endif
ret;
PIWaitEvent event;
PRIVATE_DEFINITION_END(PIKbdListener)
@@ -154,13 +156,13 @@ PRIVATE_DEFINITION_END(PIKbdListener)
PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread() {
setName("keyboard_listener"_a);
_object = this;
#ifdef WINDOWS
# ifdef WINDOWS
PRIVATE->hIn = GetStdHandle(STD_INPUT_HANDLE);
PRIVATE->hOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode(PRIVATE->hIn, &PRIVATE->smode);
#else
# else
tcgetattr(0, &PRIVATE->sterm);
#endif
# endif
ret_func = slot;
kbddata_ = _d;
dbl_interval = 400;
@@ -178,10 +180,10 @@ PIKbdListener::~PIKbdListener() {
void PIKbdListener::begin() {
#ifdef WINDOWS
# ifdef WINDOWS
GetConsoleMode(PRIVATE->hIn, &PRIVATE->tmode);
SetConsoleMode(PRIVATE->hIn, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS);
#else
# else
struct termios term;
tcgetattr(0, &term);
term.c_lflag &= ~(ECHO | ICANON);
@@ -189,11 +191,11 @@ void PIKbdListener::begin() {
PRIVATE->tterm = term;
tcsetattr(0, TCSANOW, &term);
setupTerminal(true);
#endif
# endif
}
#ifdef WINDOWS
# ifdef WINDOWS
PIKbdListener::KeyModifiers getModifiers(DWORD v, bool * shift = 0) {
PIKbdListener::KeyModifiers ret;
bool ctrl = v & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED);
@@ -214,7 +216,7 @@ PIKbdListener::MouseButtons getButtons(DWORD v) {
if (v & FROM_LEFT_2ND_BUTTON_PRESSED) ret |= PIKbdListener::MouseMiddle;
return ret;
}
#endif
# endif
void PIKbdListener::readKeyboard() {
@@ -222,7 +224,7 @@ void PIKbdListener::readKeyboard() {
ke.modifiers = 0;
char rc[8];
piZeroMemory(rc, 8);
#ifdef WINDOWS
# ifdef WINDOWS
INPUT_RECORD ir;
ReadConsoleInput(PRIVATE->hIn, &ir, 1, &(PRIVATE->ret));
switch (ir.EventType) {
@@ -406,7 +408,7 @@ void PIKbdListener::readKeyboard() {
} break;
default: piMSleep(10); return;
}
#else
# else
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
if (!PRIVATE->event.wait(0)) return;
PRIVATE->ret = read(0, rc, 8);
@@ -533,7 +535,7 @@ void PIKbdListener::readKeyboard() {
cout << endl;*/
}
if (ke.key == 0 && PRIVATE->ret > 1) ke.key = PIChar::fromSystem(rc).unicode16Code();
#endif
# endif
if ((rc[0] == '\n' || rc[0] == '\r') && PRIVATE->ret == 1) ke.key = Return;
if (exit_enabled && ke.key == exit_key) {
PIKbdListener::exiting = true;
@@ -560,30 +562,32 @@ bool PIKbdListener::stopAndWait(PISystemTime timeout) {
void PIKbdListener::end() {
// cout << "list end" << endl;
#ifdef WINDOWS
# ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->smode);
#else
# else
tcsetattr(0, TCSANOW, &PRIVATE->sterm);
setupTerminal(false);
#endif
# endif
}
void PIKbdListener::setActive(bool yes) {
is_active = yes;
if (is_active) {
#ifdef WINDOWS
# ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->tmode);
#else
# else
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
setupTerminal(true);
#endif
# endif
} else {
#ifdef WINDOWS
# ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->smode);
#else
# else
tcsetattr(0, TCSANOW, &PRIVATE->sterm);
setupTerminal(false);
#endif
# endif
}
}
#endif // MICRO_PIP

View File

@@ -26,15 +26,19 @@
#ifndef PIKBDLISTENER_H
#define PIKBDLISTENER_H
#include "pithread.h"
#include "pitime.h"
#include "pibase.h"
#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(); \
}
#ifndef MICRO_PIP
# include "pithread.h"
# include "pitime.h"
# 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(); \
}
class PIP_EXPORT PIKbdListener: public PIThread {
@@ -231,7 +235,7 @@ private:
void run() override { readKeyboard(); }
void end() override;
#ifndef WINDOWS
# ifndef WINDOWS
struct PIP_EXPORT EscSeq {
const char * seq;
int key;
@@ -251,7 +255,7 @@ private:
};
static const EscSeq esc_seq[];
#endif
# endif
PRIVATE_DECLARATION(PIP_EXPORT)
KBFunc ret_func;
@@ -305,4 +309,5 @@ REGISTER_PIVARIANTSIMPLE(PIKbdListener::KeyEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::MouseEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::WheelEvent)
#endif // MICRO_PIP
#endif // PIKBDLISTENER_H