Skip to content

Commit 5d66c2b

Browse files
committed
Guard IME under U8G2 flag and restore font/limits
1 parent 3faeb91 commit 5d66c2b

File tree

2 files changed

+25
-49
lines changed

2 files changed

+25
-49
lines changed

src/modules/CannedMessageModule.cpp

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ extern MessageStore messageStore;
4444
#endif
4545
#endif
4646

47-
#if defined(USE_TEXT_INPUT_IME) || defined(USE_U8G2_EINK_TEXT)
48-
#define MESHTASTIC_HAS_IME 1
49-
#endif
50-
5147
#ifndef INPUTBROKER_MATRIX_TYPE
5248
#define INPUTBROKER_MATRIX_TYPE 0
5349
#endif
@@ -124,7 +120,7 @@ static void renderEmote(OLEDDisplay *display, int &nextX, int lineY, int rowHeig
124120
}
125121
}
126122

127-
#if defined(MESHTASTIC_HAS_IME)
123+
#if defined(USE_U8G2_EINK_TEXT)
128124
static bool isChineseImeAllowed()
129125
{
130126
return config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_CN;
@@ -232,18 +228,6 @@ void CannedMessageModule::cycleImeMode()
232228
imeSelectedOffset = 0;
233229
}
234230

235-
void CannedMessageModule::resetImeState()
236-
{
237-
imeMode = ImeMode::EN;
238-
ime.setEnabled(false);
239-
ime.reset();
240-
imePage = 0;
241-
imePageSize = 0;
242-
imeSelectedOffset = 0;
243-
imeCandidateHitCount = 0;
244-
}
245-
#endif // MESHTASTIC_HAS_IME
246-
247231
static U8G2_FOR_ADAFRUIT_GFX *getU8g2Fonts(OLEDDisplay *display)
248232
{
249233
#if defined(USE_EINK)
@@ -924,7 +908,6 @@ bool CannedMessageModule::handleMessageSelectorInput(const InputEvent *event, bo
924908
cursor = 0;
925909
payload = 0;
926910
currentMessageIndex = -1;
927-
resetImeState();
928911

929912
// Notify UI that we want to redraw/close this screen
930913
UIFrameEvent e;
@@ -962,7 +945,6 @@ bool CannedMessageModule::handleMessageSelectorInput(const InputEvent *event, bo
962945
// Set runState to inactive so we return to main UI
963946
runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
964947
currentMessageIndex = -1;
965-
resetImeState();
966948

967949
// Notify UI to regenerate frame set and redraw
968950
UIFrameEvent e;
@@ -1014,7 +996,6 @@ bool CannedMessageModule::handleMessageSelectorInput(const InputEvent *event, bo
1014996

1015997
// Return to inactive state
1016998
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1017-
resetImeState();
1018999
this->currentMessageIndex = -1;
10191000
this->freetext = "";
10201001
this->cursor = 0;
@@ -1160,7 +1141,6 @@ bool CannedMessageModule::handleFreeTextInput(const InputEvent *event)
11601141
cursor = 0;
11611142
payload = 0;
11621143
currentMessageIndex = -1;
1163-
resetImeState();
11641144

11651145
// Notify UI that we want to redraw/close this screen
11661146
UIFrameEvent e;
@@ -1670,7 +1650,14 @@ int32_t CannedMessageModule::runOnce()
16701650

16711651
// Normal module disable/idle handling
16721652
if ((this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED) || (this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE)) {
1673-
resetImeState();
1653+
#if defined(USE_U8G2_EINK_TEXT)
1654+
imeMode = ImeMode::EN;
1655+
ime.setEnabled(false);
1656+
ime.reset();
1657+
imePage = 0;
1658+
imeSelectedOffset = 0;
1659+
imeCandidateHitCount = 0;
1660+
#endif
16741661
// Clean up virtual keyboard if needed when going inactive
16751662
if (graphics::NotificationRenderer::virtualKeyboard && graphics::NotificationRenderer::textInputCallback == nullptr) {
16761663
LOG_INFO("Performing delayed virtual keyboard cleanup");
@@ -1720,7 +1707,6 @@ int32_t CannedMessageModule::runOnce()
17201707
(this->runState == CANNED_MESSAGE_RUN_STATE_MESSAGE_SELECTION)) {
17211708
LOG_DEBUG("[CANNED] sending/ack/message selection -> inactive (payload=%d)", this->payload);
17221709
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1723-
resetImeState();
17241710
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET;
17251711
this->currentMessageIndex = -1;
17261712
this->freetext = "";
@@ -1731,7 +1717,6 @@ int32_t CannedMessageModule::runOnce()
17311717
else if (this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE && this->payload == 0) {
17321718
LOG_DEBUG("[CANNED] sending active -> inactive (payload=0)");
17331719
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1734-
resetImeState();
17351720
this->currentMessageIndex = -1;
17361721
this->freetext = "";
17371722
this->cursor = 0;
@@ -1745,7 +1730,6 @@ int32_t CannedMessageModule::runOnce()
17451730
this->freetext = "";
17461731
this->cursor = 0;
17471732
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1748-
resetImeState();
17491733

17501734
// Clean up virtual keyboard if it exists during timeout
17511735
if (graphics::NotificationRenderer::virtualKeyboard) {
@@ -1778,15 +1762,11 @@ int32_t CannedMessageModule::runOnce()
17781762
// Now deactivate this module
17791763
LOG_DEBUG("[CANNED] freetext sent -> inactive");
17801764
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1781-
#if defined(USE_U8G2_EINK_TEXT)
1782-
resetImeState();
1783-
#endif
17841765

17851766
return INT32_MAX; // don’t fall back into canned list
17861767
} else {
17871768
LOG_DEBUG("[CANNED] freetext empty -> inactive");
17881769
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1789-
resetImeState();
17901770
}
17911771
} else {
17921772
if (strcmp(this->messages[this->currentMessageIndex], "[Select Destination]") == 0) {
@@ -1812,14 +1792,12 @@ int32_t CannedMessageModule::runOnce()
18121792
// Now deactivate this module
18131793
LOG_DEBUG("[CANNED] canned message sent -> inactive");
18141794
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1815-
resetImeState();
18161795

18171796
return INT32_MAX; // don’t fall back into canned list
18181797
}
18191798
} else {
18201799
LOG_DEBUG("[CANNED] action select invalid index -> inactive");
18211800
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
1822-
resetImeState();
18231801
}
18241802
}
18251803
// fallback clean-up if nothing above returned
@@ -1887,19 +1865,19 @@ int32_t CannedMessageModule::runOnce()
18871865
case INPUT_BROKER_MSG_TAB: // Tab key: handled by input handler
18881866
return 0;
18891867
case INPUT_BROKER_LEFT:
1890-
case INPUT_BROKER_RIGHT:
1891-
break;
1892-
default:
1893-
// Only insert ASCII printable characters (32–126)
1894-
if (this->payload >= 32 && this->payload <= 126) {
1895-
requestFocus();
1896-
insertTextAtCursor(String((char)this->payload));
1897-
}
1898-
break;
1868+
case INPUT_BROKER_RIGHT:
1869+
break;
1870+
default:
1871+
// Only insert ASCII printable characters (32–126)
1872+
if (this->payload >= 32 && this->payload <= 126) {
1873+
requestFocus();
1874+
insertTextAtCursor(String((char)this->payload));
18991875
}
1900-
// Prevent reprocessing stale payloads (e.g., lingering backspace after IME commits)
1901-
this->payload = 0;
1876+
break;
19021877
}
1878+
// Prevent reprocessing stale payloads (e.g., lingering backspace after IME commits)
1879+
this->payload = 0;
1880+
}
19031881
this->lastTouchMillis = millis();
19041882
this->notifyObservers(&e);
19051883
return INACTIVATE_AFTER_MS;
@@ -3130,3 +3108,5 @@ String CannedMessageModule::drawWithCursor(String text, int cursor)
31303108
String result = text.substring(0, cursor) + "_" + text.substring(cursor);
31313109
return result;
31323110
}
3111+
3112+
#endif

src/modules/CannedMessageModule.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
#if HAS_SCREEN
33
#include "ProtobufModule.h"
44
#include "input/InputBroker.h"
5-
#if defined(USE_TEXT_INPUT_IME) || defined(USE_U8G2_EINK_TEXT)
6-
#define MESHTASTIC_HAS_IME 1
7-
#endif
8-
9-
#if defined(MESHTASTIC_HAS_IME)
5+
#if defined(USE_U8G2_EINK_TEXT)
106
#include "modules/ChineseIme.h"
117
#endif
128

@@ -196,7 +192,7 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF
196192
std::vector<uint8_t> activeChannelIndices;
197193
std::vector<NodeEntry> filteredNodes;
198194

199-
#if defined(MESHTASTIC_HAS_IME)
195+
#if defined(USE_U8G2_EINK_TEXT)
200196
ChineseIme ime;
201197
ImeMode imeMode = ImeMode::EN;
202198
int imePage = 0;
@@ -232,7 +228,7 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF
232228
void moveCursorLeftUtf8();
233229
void moveCursorRightUtf8();
234230
void resetImeState();
235-
#if defined(MESHTASTIC_HAS_IME)
231+
#if defined(USE_U8G2_EINK_TEXT)
236232
void cycleImeMode();
237233
#endif
238234
#if defined(USE_VIRTUAL_KEYBOARD)

0 commit comments

Comments
 (0)