submission: Handle submitting strings

This commit is contained in:
Dorota Czaplejewicz
2020-01-14 13:13:42 +00:00
parent d1bc23e9d8
commit 42cb73cd8c
6 changed files with 126 additions and 23 deletions

View File

@ -1,5 +1,9 @@
/*! Manages zwp_input_method_v2 protocol.
*
* Library module.
*/
use std::boxed::Box;
use std::ffi;
use std::ffi::CString;
use std::num::Wrapping;
use std::string::String;
@ -31,7 +35,7 @@ pub mod c {
#[allow(improper_ctypes)] // IMService will never be dereferenced in C
pub fn imservice_connect_listeners(im: *mut InputMethod, imservice: *const IMService);
pub fn eek_input_method_commit_string(im: *mut InputMethod, text: *const c_char);
pub fn eek_input_method_commit(im: *mut InputMethod, serial: u32);
fn eekboard_context_service_set_hint_purpose(state: *const StateManager, hint: u32, purpose: u32);
fn server_context_service_show_keyboard(imservice: *const UIManager);
fn server_context_service_hide_keyboard(imservice: *const UIManager);
@ -332,8 +336,6 @@ pub struct IMService {
pub enum SubmitError {
/// The input method had not been activated
NotActive,
/// Submitted text has null bytes
NullBytes(ffi::NulError),
}
impl IMService {
@ -361,10 +363,9 @@ impl IMService {
imservice
}
pub fn commit_string(&self, text: &str) -> Result<(), SubmitError> {
pub fn commit_string(&self, text: &CString) -> Result<(), SubmitError> {
match self.current.active {
true => {
let text = CString::new(text).map_err(SubmitError::NullBytes)?;
unsafe {
c::eek_input_method_commit_string(self.im, text.as_ptr())
}
@ -373,4 +374,21 @@ impl IMService {
false => Err(SubmitError::NotActive),
}
}
pub fn commit(&mut self) -> Result<(), SubmitError> {
match self.current.active {
true => {
unsafe {
c::eek_input_method_commit(self.im, self.serial.0)
}
self.serial += Wrapping(1u32);
Ok(())
},
false => Err(SubmitError::NotActive),
}
}
pub fn is_active(&self) -> bool {
self.current.active
}
}