private void DestroyFrontend() { Logger.Debug?.Print(LogClass.ServiceAm, $"Destroying software keyboard frontend"); _keyboardRenderer?.Dispose(); _keyboardRenderer = null; if (_dynamicTextInputHandler != null) { _dynamicTextInputHandler.TextChangedEvent -= HandleTextChangedEvent; _dynamicTextInputHandler.KeyPressedEvent -= HandleKeyPressedEvent; _dynamicTextInputHandler.Dispose(); _dynamicTextInputHandler = null; } if (_npads != null) { _npads.NpadButtonDownEvent -= HandleNpadButtonDownEvent; _npads.NpadButtonUpEvent -= HandleNpadButtonUpEvent; _npads = null; } }
public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession) { _normalSession = normalSession; _interactiveSession = interactiveSession; _interactiveSession.DataAvailable += OnInteractiveData; var launchParams = _normalSession.Pop(); var keyboardConfig = _normalSession.Pop(); if (keyboardConfig.Length == Marshal.SizeOf <SoftwareKeyboardInitialize>()) { // Initialize the keyboard applet in background mode. _isBackground = true; _keyboardBackgroundInitialize = ReadStruct <SoftwareKeyboardInitialize>(keyboardConfig); InlineKeyboardState state = InlineKeyboardState.Uninitialized; SetInlineState(state); string acceptKeyName; string cancelKeyName; if (_device.UiHandler != null) { _dynamicTextInputHandler = _device.UiHandler.CreateDynamicTextInputHandler(); _dynamicTextInputHandler.TextChanged += DynamicTextChanged; acceptKeyName = _dynamicTextInputHandler.AcceptKeyName; cancelKeyName = _dynamicTextInputHandler.CancelKeyName; } else { Logger.Error?.Print(LogClass.ServiceAm, "GUI Handler is not set, software keyboard applet will not work properly"); acceptKeyName = ""; cancelKeyName = ""; } _keyboardRenderer = new SoftwareKeyboardRenderer(acceptKeyName, cancelKeyName); _interactiveSession.Push(InlineResponses.FinishedInitialize(state)); return(ResultCode.Success); } else { // Initialize the keyboard applet in foreground mode. _isBackground = false; if (keyboardConfig.Length < Marshal.SizeOf <SoftwareKeyboardConfig>()) { Logger.Error?.Print(LogClass.ServiceAm, $"SoftwareKeyboardConfig size mismatch. Expected {Marshal.SizeOf<SoftwareKeyboardConfig>():x}. Got {keyboardConfig.Length:x}"); } else { _keyboardForegroundConfig = ReadStruct <SoftwareKeyboardConfig>(keyboardConfig); } if (!_normalSession.TryPop(out _transferMemory)) { Logger.Error?.Print(LogClass.ServiceAm, "SwKbd Transfer Memory is null"); } if (_keyboardForegroundConfig.UseUtf8) { _encoding = Encoding.UTF8; } _foregroundState = SoftwareKeyboardState.Ready; ExecuteForegroundKeyboard(); return(ResultCode.Success); } }
public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession) { lock (_lock) { _normalSession = normalSession; _interactiveSession = interactiveSession; _interactiveSession.DataAvailable += OnInteractiveData; var launchParams = _normalSession.Pop(); var keyboardConfig = _normalSession.Pop(); _isBackground = keyboardConfig.Length == Marshal.SizeOf <SoftwareKeyboardInitialize>(); if (_isBackground) { // Initialize the keyboard applet in background mode. _keyboardBackgroundInitialize = ReadStruct <SoftwareKeyboardInitialize>(keyboardConfig); _backgroundState = InlineKeyboardState.Uninitialized; if (_device.UiHandler == null) { Logger.Error?.Print(LogClass.ServiceAm, "GUI Handler is not set, software keyboard applet will not work properly"); } else { // Create a text handler that converts keyboard strokes to strings. _dynamicTextInputHandler = _device.UiHandler.CreateDynamicTextInputHandler(); _dynamicTextInputHandler.TextChangedEvent += HandleTextChangedEvent; _dynamicTextInputHandler.KeyPressedEvent += HandleKeyPressedEvent; _npads = new NpadReader(_device); _npads.NpadButtonDownEvent += HandleNpadButtonDownEvent; _npads.NpadButtonUpEvent += HandleNpadButtonUpEvent; _keyboardRenderer = new SoftwareKeyboardRenderer(_device.UiHandler.HostUiTheme); } return(ResultCode.Success); } else { // Initialize the keyboard applet in foreground mode. if (keyboardConfig.Length < Marshal.SizeOf <SoftwareKeyboardConfig>()) { Logger.Error?.Print(LogClass.ServiceAm, $"SoftwareKeyboardConfig size mismatch. Expected {Marshal.SizeOf<SoftwareKeyboardConfig>():x}. Got {keyboardConfig.Length:x}"); } else { _keyboardForegroundConfig = ReadStruct <SoftwareKeyboardConfig>(keyboardConfig); } if (!_normalSession.TryPop(out _transferMemory)) { Logger.Error?.Print(LogClass.ServiceAm, "SwKbd Transfer Memory is null"); } if (_keyboardForegroundConfig.UseUtf8) { _encoding = Encoding.UTF8; } _foregroundState = SoftwareKeyboardState.Ready; ExecuteForegroundKeyboard(); return(ResultCode.Success); } } }