Actually block CannedInput actions while display is shown

This commit is contained in:
Jonathan Bennett 2025-06-05 23:19:29 -05:00
parent 97eb03cb35
commit ae96221292

View File

@ -14,8 +14,8 @@
#include "detect/ScanI2C.h" #include "detect/ScanI2C.h"
#include "graphics/Screen.h" #include "graphics/Screen.h"
#include "graphics/SharedUIDisplay.h" #include "graphics/SharedUIDisplay.h"
#include "graphics/images.h"
#include "graphics/emotes.h" #include "graphics/emotes.h"
#include "graphics/images.h"
#include "input/ScanAndSelect.h" #include "input/ScanAndSelect.h"
#include "main.h" // for cardkb_found #include "main.h" // for cardkb_found
#include "mesh/generated/meshtastic/cannedmessages.pb.h" #include "mesh/generated/meshtastic/cannedmessages.pb.h"
@ -257,6 +257,10 @@ bool CannedMessageModule::isCharInputAllowed() const
*/ */
int CannedMessageModule::handleInputEvent(const InputEvent *event) int CannedMessageModule::handleInputEvent(const InputEvent *event)
{ {
// Block ALL input if an alert banner is active
if (screen && screen->isOverlayBannerShowing()) {
return 0;
}
// Allow input only from configured source (hardware/software filter) // Allow input only from configured source (hardware/software filter)
if (!isInputSourceAllowed(event)) if (!isInputSourceAllowed(event))
return 0; return 0;
@ -772,11 +776,6 @@ bool CannedMessageModule::handleSystemCommandInput(const InputEvent *event)
if (event->inputEvent != static_cast<char>(ANYKEY)) if (event->inputEvent != static_cast<char>(ANYKEY))
return false; return false;
// Block ALL input if an alert banner is active // TODO: Make an accessor function
if (screen && screen->isOverlayBannerShowing()) {
return true;
}
// System commands (all others fall through to return false) // System commands (all others fall through to return false)
switch (event->kbchar) { switch (event->kbchar) {
// Fn key symbols // Fn key symbols
@ -1071,8 +1070,8 @@ int32_t CannedMessageModule::runOnce()
if (this->cursor == this->freetext.length()) { if (this->cursor == this->freetext.length()) {
this->freetext += (char)this->payload; this->freetext += (char)this->payload;
} else { } else {
this->freetext = this->freetext = this->freetext.substring(0, this->cursor) + (char)this->payload +
this->freetext.substring(0, this->cursor) + (char)this->payload + this->freetext.substring(this->cursor); this->freetext.substring(this->cursor);
} }
this->cursor++; this->cursor++;
uint16_t maxChars = meshtastic_Constants_DATA_PAYLOAD_LEN - (moduleConfig.canned_message.send_bell ? 1 : 0); uint16_t maxChars = meshtastic_Constants_DATA_PAYLOAD_LEN - (moduleConfig.canned_message.send_bell ? 1 : 0);
@ -1520,13 +1519,17 @@ void CannedMessageModule::drawEmotePickerScreen(OLEDDisplay *display, OLEDDispla
int numEmotes = graphics::numEmotes; int numEmotes = graphics::numEmotes;
// Clamp highlight index // Clamp highlight index
if (emotePickerIndex < 0) emotePickerIndex = 0; if (emotePickerIndex < 0)
if (emotePickerIndex >= numEmotes) emotePickerIndex = numEmotes - 1; emotePickerIndex = 0;
if (emotePickerIndex >= numEmotes)
emotePickerIndex = numEmotes - 1;
// Determine which emote is at the top // Determine which emote is at the top
int topIndex = emotePickerIndex - visibleRows / 2; int topIndex = emotePickerIndex - visibleRows / 2;
if (topIndex < 0) topIndex = 0; if (topIndex < 0)
if (topIndex > numEmotes - visibleRows) topIndex = std::max(0, numEmotes - visibleRows); topIndex = 0;
if (topIndex > numEmotes - visibleRows)
topIndex = std::max(0, numEmotes - visibleRows);
// Draw header/title // Draw header/title
display->setFont(FONT_SMALL); display->setFont(FONT_SMALL);
@ -1538,7 +1541,8 @@ void CannedMessageModule::drawEmotePickerScreen(OLEDDisplay *display, OLEDDispla
for (int vis = 0; vis < visibleRows; ++vis) { for (int vis = 0; vis < visibleRows; ++vis) {
int emoteIdx = topIndex + vis; int emoteIdx = topIndex + vis;
if (emoteIdx >= numEmotes) break; if (emoteIdx >= numEmotes)
break;
const graphics::Emote &emote = graphics::emotes[emoteIdx]; const graphics::Emote &emote = graphics::emotes[emoteIdx];
int rowY = listTop + vis * rowHeight; int rowY = listTop + vis * rowHeight;
@ -1714,7 +1718,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
for (int j = 0; j < graphics::numEmotes; j++) { for (int j = 0; j < graphics::numEmotes; j++) {
const char *label = graphics::emotes[j].label; const char *label = graphics::emotes[j].label;
int labelLen = strlen(label); int labelLen = strlen(label);
if (labelLen == 0) continue; if (labelLen == 0)
continue;
if (strncmp(msg + pos, label, labelLen) == 0) { if (strncmp(msg + pos, label, labelLen) == 0) {
if (!foundEmote || labelLen > foundLen) { if (!foundEmote || labelLen > foundLen) {
foundEmote = &graphics::emotes[j]; foundEmote = &graphics::emotes[j];
@ -1730,7 +1735,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
int nextEmote = msgLen; int nextEmote = msgLen;
for (int j = 0; j < graphics::numEmotes; j++) { for (int j = 0; j < graphics::numEmotes; j++) {
const char *label = graphics::emotes[j].label; const char *label = graphics::emotes[j].label;
if (!label || !*label) continue; if (!label || !*label)
continue;
char *found = strstr(msg + pos, label); char *found = strstr(msg + pos, label);
if (found && (found - msg) < nextEmote) { if (found && (found - msg) < nextEmote) {
nextEmote = found - msg; nextEmote = found - msg;
@ -1807,7 +1813,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
} }
} }
} }
if (!currentLine.empty()) lines.push_back(currentLine); if (!currentLine.empty())
lines.push_back(currentLine);
// Draw lines with emotes // Draw lines with emotes
int rowHeight = FONT_HEIGHT_SMALL; int rowHeight = FONT_HEIGHT_SMALL;
@ -1870,10 +1877,12 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
int maxEmoteHeight = 0; int maxEmoteHeight = 0;
for (int j = 0; j < graphics::numEmotes; j++) { for (int j = 0; j < graphics::numEmotes; j++) {
const char *label = graphics::emotes[j].label; const char *label = graphics::emotes[j].label;
if (!label || !*label) continue; if (!label || !*label)
continue;
const char *search = msg; const char *search = msg;
while ((search = strstr(search, label))) { while ((search = strstr(search, label))) {
if (graphics::emotes[j].height > maxEmoteHeight) maxEmoteHeight = graphics::emotes[j].height; if (graphics::emotes[j].height > maxEmoteHeight)
maxEmoteHeight = graphics::emotes[j].height;
search += strlen(label); // Advance past this emote search += strlen(label); // Advance past this emote
} }
} }
@ -1901,7 +1910,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
for (int j = 0; j < graphics::numEmotes; j++) { for (int j = 0; j < graphics::numEmotes; j++) {
const char *label = graphics::emotes[j].label; const char *label = graphics::emotes[j].label;
int labelLen = strlen(label); int labelLen = strlen(label);
if (labelLen == 0) continue; if (labelLen == 0)
continue;
if (strncmp(msg + pos, label, labelLen) == 0) { if (strncmp(msg + pos, label, labelLen) == 0) {
if (!foundEmote || labelLen > foundLen) { if (!foundEmote || labelLen > foundLen) {
foundEmote = &graphics::emotes[j]; foundEmote = &graphics::emotes[j];
@ -1917,7 +1927,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
int nextEmote = msgLen; int nextEmote = msgLen;
for (int j = 0; j < graphics::numEmotes; j++) { for (int j = 0; j < graphics::numEmotes; j++) {
const char *label = graphics::emotes[j].label; const char *label = graphics::emotes[j].label;
if (label[0] == 0) continue; if (label[0] == 0)
continue;
char *found = strstr(msg + pos, label); char *found = strstr(msg + pos, label);
if (found && (found - msg) < nextEmote) { if (found && (found - msg) < nextEmote) {
nextEmote = found - msg; nextEmote = found - msg;
@ -1939,7 +1950,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
#ifdef USE_EINK #ifdef USE_EINK
int nextX = x + (highlight ? 12 : 0); int nextX = x + (highlight ? 12 : 0);
if (highlight) display->drawString(x + 0, lineY + textYOffset, ">"); if (highlight)
display->drawString(x + 0, lineY + textYOffset, ">");
#else #else
int scrollPadding = 8; int scrollPadding = 8;
if (highlight) { if (highlight) {
@ -1972,7 +1984,8 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
} }
} }
#ifndef USE_EINK #ifndef USE_EINK
if (highlight) display->setColor(WHITE); if (highlight)
display->setColor(WHITE);
#endif #endif
yCursor += rowHeight; yCursor += rowHeight;