mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	applets/swkbd: Add callback support
This commit is contained in:
		
							parent
							
								
									2ff7ed4200
								
							
						
					
					
						commit
						8078256a88
					
				
					 6 changed files with 154 additions and 64 deletions
				
			
		|  | @ -39,10 +39,6 @@ ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) cons | |||
|         // TODO: check the profanity filter
 | ||||
|         LOG_INFO(Frontend, "App requested swkbd profanity filter, but its not implemented."); | ||||
|     } | ||||
|     if (config.filters.enable_callback) { | ||||
|         // TODO: check the callback
 | ||||
|         LOG_INFO(Frontend, "App requested a swkbd callback, but its not implemented."); | ||||
|     } | ||||
|     return ValidationError::None; | ||||
| } | ||||
| 
 | ||||
|  | @ -132,11 +128,21 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) { | |||
|         return error; | ||||
|     } | ||||
|     data = {text, button}; | ||||
|     data_ready = true; | ||||
|     return ValidationError::None; | ||||
| } | ||||
| 
 | ||||
| void DefaultKeyboard::Setup(const Frontend::KeyboardConfig& config) { | ||||
|     SoftwareKeyboard::Setup(config); | ||||
| bool SoftwareKeyboard::DataReady() { | ||||
|     return data_ready; | ||||
| } | ||||
| 
 | ||||
| const KeyboardData& SoftwareKeyboard::ReceiveData() { | ||||
|     data_ready = false; | ||||
|     return data; | ||||
| } | ||||
| 
 | ||||
| void DefaultKeyboard::Execute(const Frontend::KeyboardConfig& config) { | ||||
|     SoftwareKeyboard::Execute(config); | ||||
| 
 | ||||
|     auto cfg = Service::CFG::GetModule(Core::System::GetInstance()); | ||||
|     ASSERT_MSG(cfg, "CFG Module missing!"); | ||||
|  | @ -157,4 +163,8 @@ void DefaultKeyboard::Setup(const Frontend::KeyboardConfig& config) { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| void DefaultKeyboard::ShowError(const std::string& error) { | ||||
|     LOG_ERROR(Applet_SWKBD, "Default keyboard text is unaccepted! error: {}", error); | ||||
| } | ||||
| 
 | ||||
| } // namespace Frontend
 | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <atomic> | ||||
| #include <unordered_map> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
|  | @ -82,13 +83,27 @@ enum class ValidationError { | |||
| 
 | ||||
| class SoftwareKeyboard { | ||||
| public: | ||||
|     virtual void Setup(const KeyboardConfig& config) { | ||||
|         this->config = KeyboardConfig(config); | ||||
|     /**
 | ||||
|      * Executes the software keyboard, configured with the given parameters. | ||||
|      */ | ||||
|     virtual void Execute(const KeyboardConfig& config) { | ||||
|         this->config = config; | ||||
|     } | ||||
| 
 | ||||
|     const KeyboardData& ReceiveData() const { | ||||
|         return data; | ||||
|     } | ||||
|     /**
 | ||||
|      * Whether the result data is ready to be received. | ||||
|      */ | ||||
|     bool DataReady(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Receives the current result data stored in the applet, and clears the ready state. | ||||
|      */ | ||||
|     const KeyboardData& ReceiveData(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Shows an error text returned by the callback. | ||||
|      */ | ||||
|     virtual void ShowError(const std::string& error) = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Validates if the provided string breaks any of the filter rules. This is meant to be called | ||||
|  | @ -118,11 +133,14 @@ public: | |||
| protected: | ||||
|     KeyboardConfig config; | ||||
|     KeyboardData data; | ||||
| 
 | ||||
|     std::atomic_bool data_ready = false; | ||||
| }; | ||||
| 
 | ||||
| class DefaultKeyboard final : public SoftwareKeyboard { | ||||
| public: | ||||
|     void Setup(const KeyboardConfig& config) override; | ||||
|     void Execute(const KeyboardConfig& config) override; | ||||
|     void ShowError(const std::string& error) override; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Frontend
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue