Fix text input on kiosk: add keycodeToChar fallback for email/license pages
The kiosk lacks an input method framework, so SDL2 never generates TextInputEvent. The WiFi password page already had a keycodeToChar fallback but email and license key pages did not — characters were never appended to inputText. Also removes excessive debug logging from the previous commit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
8b0cf81e85
commit
df5e64d38a
@@ -42,6 +42,9 @@ type LicenseKeyPage struct {
|
||||
|
||||
// isFirstTimeSetup tracks whether page was loaded empty (first-time setup)
|
||||
isFirstTimeSetup bool
|
||||
|
||||
// Text input deduplication
|
||||
textInputSupported bool
|
||||
}
|
||||
|
||||
// isValidLicenseKey checks if the license key has exactly 16 alphanumeric characters
|
||||
@@ -120,9 +123,7 @@ func (p *LicenseKeyPage) Init(app ApplicationInterface) error {
|
||||
p.isFirstTimeSetup = true
|
||||
}
|
||||
|
||||
logger.Info("[LicenseKeyPage.Init] Calling sdl.StartTextInput(), isFirstTimeSetup=%v", p.isFirstTimeSetup)
|
||||
sdl.StartTextInput()
|
||||
logger.Info("[LicenseKeyPage.Init] After StartTextInput: IsTextInputActive=%v", sdl.IsTextInputActive())
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -158,36 +159,28 @@ func formatLicenseKey(input string) string {
|
||||
// HandleEvent processes SDL events and handles them appropriately for the LicenseKeyPage.
|
||||
func (p *LicenseKeyPage) HandleEvent(event *sdl.Event) error {
|
||||
actualEvent := *event
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] Event type: %T", actualEvent)
|
||||
|
||||
isActive := sdl.IsTextInputActive()
|
||||
if !isActive {
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] TextInput not active, calling StartTextInput()")
|
||||
if !sdl.IsTextInputActive() {
|
||||
sdl.StartTextInput()
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] After StartTextInput: IsTextInputActive=%v", sdl.IsTextInputActive())
|
||||
}
|
||||
|
||||
switch e := actualEvent.(type) {
|
||||
case *sdl.TextInputEvent:
|
||||
text := e.GetText()
|
||||
// Add the new character and reformat
|
||||
p.inputText += text
|
||||
p.inputText = formatLicenseKey(p.inputText)
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] TextInputEvent: received=%q, inputText=%q", text, p.inputText)
|
||||
// Clear error when user starts typing
|
||||
p.errorMessage = ""
|
||||
case *sdl.KeyboardEvent:
|
||||
eventType := "KEYDOWN"
|
||||
if e.Type == sdl.KEYUP {
|
||||
eventType = "KEYUP"
|
||||
if !p.textInputSupported {
|
||||
// First TextInputEvent: the keyboard fallback already
|
||||
// handled this character, so just record that text input
|
||||
// is supported and skip the duplicate append.
|
||||
p.textInputSupported = true
|
||||
} else {
|
||||
// Add the new character and reformat
|
||||
p.inputText += e.GetText()
|
||||
p.inputText = formatLicenseKey(p.inputText)
|
||||
// Clear error when user starts typing
|
||||
p.errorMessage = ""
|
||||
}
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] KeyboardEvent: type=%s, sym=%d (%s), scancode=%d, mod=0x%04x",
|
||||
eventType, e.Keysym.Sym, sdl.GetKeyName(e.Keysym.Sym), e.Keysym.Scancode, e.Keysym.Mod)
|
||||
|
||||
case *sdl.KeyboardEvent:
|
||||
if e.Type == sdl.KEYDOWN {
|
||||
switch e.Keysym.Sym {
|
||||
case sdl.K_ESCAPE:
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] ESCAPE pressed, isFirstTimeSetup=%v", p.isFirstTimeSetup)
|
||||
// Block escape during first-time setup
|
||||
if p.isFirstTimeSetup {
|
||||
return nil
|
||||
@@ -196,7 +189,6 @@ func (p *LicenseKeyPage) HandleEvent(event *sdl.Event) error {
|
||||
sdl.StopTextInput()
|
||||
p.App.UnwindToPage(&Settings{})
|
||||
case sdl.K_RETURN:
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] RETURN pressed, inputText=%q", p.inputText)
|
||||
// Validate license key - check empty first, then length, then characters
|
||||
cleaned := strings.ReplaceAll(p.inputText, "-", "")
|
||||
if cleaned == "" {
|
||||
@@ -246,10 +238,20 @@ func (p *LicenseKeyPage) HandleEvent(event *sdl.Event) error {
|
||||
cleaned = cleaned[:len(cleaned)-1]
|
||||
}
|
||||
p.inputText = formatLicenseKey(cleaned)
|
||||
logger.Info("[LicenseKeyPage.HandleEvent] BACKSPACE: inputText=%q", p.inputText)
|
||||
// Clear error when user edits input
|
||||
p.errorMessage = ""
|
||||
}
|
||||
default:
|
||||
// Keyboard fallback: if TextInputEvent is not supported,
|
||||
// convert printable keycodes to characters directly.
|
||||
// This handles kiosk systems without an input method framework.
|
||||
if !p.textInputSupported {
|
||||
if ch := keycodeToChar(e.Keysym.Sym, e.Keysym.Mod); ch != 0 {
|
||||
p.inputText += string(ch)
|
||||
p.inputText = formatLicenseKey(p.inputText)
|
||||
p.errorMessage = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,7 +474,6 @@ func (p *LicenseKeyPage) Destroy() error {
|
||||
p.errorTextureID = 0
|
||||
}
|
||||
|
||||
logger.Info("[LicenseKeyPage.Destroy] Calling sdl.StopTextInput()")
|
||||
sdl.StopTextInput()
|
||||
return p.Base.Destroy()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user