diff --git a/src_main/console/pikbdlistener.cpp b/src_main/console/pikbdlistener.cpp index 75a62bc0..39236416 100644 --- a/src_main/console/pikbdlistener.cpp +++ b/src_main/console/pikbdlistener.cpp @@ -117,6 +117,11 @@ const PIKbdListener::EscSeq PIKbdListener::esc_seq[] = { // End {0, 0, 0, 0, 0}, }; +void setupTerminal(bool on) { + printf("\e[?1000"); printf(on ? "h" : "l"); + printf("\e[?1002"); printf(on ? "h" : "l"); + fflush(0); +} #endif @@ -172,6 +177,7 @@ void PIKbdListener::begin() { term.c_lflag |= NOFLSH | IEXTEN; PRIVATE->tterm = term; tcsetattr(0, TCSANOW, &term); + setupTerminal(true); #endif } @@ -310,10 +316,10 @@ void PIKbdListener::readKeyboard() { #else tcsetattr(0, TCSANOW, &PRIVATE->tterm); PRIVATE->ret = read(0, rc, 8); - //piCout << "key" << PIString(rc).replaceAll("\e", "\\e"); - /*for (int i = 0; i < PRIVATE->ret; ++i) - cout << std::hex << int(((uchar * )&rc)[i]) << ' '; - cout << endl; + /*piCout << "key" << PIString(rc).replaceAll("\e", "\\e"); + for (int i = 0; i < PRIVATE->ret; ++i) + PICout(0) << PICoutManipulators::Hex << int(((uchar * )&rc)[i]) << ' '; + PICout(0) << "\n"; for (int i = 0; i < PRIVATE->ret; ++i) cout << "'" << (char)(rc[i]) << "' "; cout << endl;*/ @@ -337,14 +343,45 @@ void PIKbdListener::readKeyboard() { PRIVATE->ret--; } if (rc[1] == '[') { - for (int i = 2; i < 7; ++i) // search for modifier - if (rc[i] == ';') { - mod |= rc[i + 1] - '0' - 1; - for (int j = i; j < 6; ++j) rc[j] = rc[j + 2]; - rc[6] = rc[7] = 0; - PRIVATE->ret -= 2; - break; + if (rc[2] == 'M') { // mouse + if (PRIVATE->ret >= 5) { + me.x = uchar(rc[4] - '!'); + me.y = uchar(rc[5] - '!'); + int b = rc[3] & 0x7, a = rc[3] & 0x60; + if (a == 0x60) { + memcpy(&we, &me, sizeof(me)); + we.action = MouseWheel; + we.direction = (b == 0); + piCout << "wheel" << we.direction; + wheelEvent(we, kbddata_); + } else { + switch (b) { + case 0: me.buttons = MouseLeft; break; + case 1: me.buttons = MouseMiddle; break; + case 2: me.buttons = MouseRight; break; + } + if (a == 0x20) { + if (b == 3) me.action = MouseButtonRelease; + else me.action = MouseButtonPress; + } + if (a == 0x40) me.action = MouseMove; + PIString _s[] = {"press", "release", "move"}; + piCoutObj << _s[me.action] << me.buttons << ":" << me.x << me.y; + mouseEvent(me, kbddata_); + } + //piCout << me.x << me.y << PICoutManipulators::Hex << b << a; } + return; + } else { + for (int i = 2; i < 7; ++i) // search for modifier + if (rc[i] == ';') { + mod |= rc[i + 1] - '0' - 1; + for (int j = i; j < 6; ++j) rc[j] = rc[j + 2]; + rc[6] = rc[7] = 0; + PRIVATE->ret -= 2; + break; + } + } } if (PRIVATE->ret >= 3 && rc[1] == 'O') { // search for modifier (F1-F4) if (rc[2] >= '1' && rc[2] <= '8') { @@ -397,6 +434,7 @@ void PIKbdListener::end() { SetConsoleMode(PRIVATE->hIn, PRIVATE->smode); #else tcsetattr(0, TCSANOW, &PRIVATE->sterm); + setupTerminal(false); #endif } @@ -408,12 +446,14 @@ void PIKbdListener::setActive(bool yes) { SetConsoleMode(PRIVATE->hIn, PRIVATE->tmode); #else tcsetattr(0, TCSANOW, &PRIVATE->tterm); + setupTerminal(true); #endif } else { #ifdef WINDOWS SetConsoleMode(PRIVATE->hIn, PRIVATE->smode); #else tcsetattr(0, TCSANOW, &PRIVATE->sterm); + setupTerminal(false); #endif } }