Merge branch 'race' into 'master'
imservice: Set up UI according to current needs when it shows up See merge request Librem5/squeekboard!407
This commit is contained in:
@ -6,6 +6,7 @@
|
|||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::mem;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
|
|
||||||
@ -41,8 +42,8 @@ pub mod c {
|
|||||||
pub fn eek_input_method_delete_surrounding_text(im: *mut InputMethod, before: u32, after: u32);
|
pub fn eek_input_method_delete_surrounding_text(im: *mut InputMethod, before: u32, after: u32);
|
||||||
pub fn eek_input_method_commit(im: *mut InputMethod, serial: u32);
|
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 eekboard_context_service_set_hint_purpose(state: *const StateManager, hint: u32, purpose: u32);
|
||||||
fn server_context_service_show_keyboard(imservice: *const UIManager);
|
pub fn server_context_service_show_keyboard(imservice: *const UIManager);
|
||||||
fn server_context_service_keyboard_release_visibility(imservice: *const UIManager);
|
pub fn server_context_service_keyboard_release_visibility(imservice: *const UIManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
|
// The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
|
||||||
@ -152,10 +153,8 @@ pub mod c {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if active_changed {
|
if active_changed {
|
||||||
|
imservice.apply_active_to_ui();
|
||||||
if imservice.current.active {
|
if imservice.current.active {
|
||||||
if let Some(ui) = imservice.ui_manager {
|
|
||||||
unsafe { server_context_service_show_keyboard(ui); }
|
|
||||||
}
|
|
||||||
unsafe {
|
unsafe {
|
||||||
eekboard_context_service_set_hint_purpose(
|
eekboard_context_service_set_hint_purpose(
|
||||||
imservice.state_manager,
|
imservice.state_manager,
|
||||||
@ -163,10 +162,6 @@ pub mod c {
|
|||||||
imservice.current.content_purpose.clone() as u32,
|
imservice.current.content_purpose.clone() as u32,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if let Some(ui) = imservice.ui_manager {
|
|
||||||
unsafe { server_context_service_keyboard_release_visibility(ui); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,7 +335,7 @@ pub struct IMService {
|
|||||||
/// Unowned reference. Be careful, it's shared with C at large
|
/// Unowned reference. Be careful, it's shared with C at large
|
||||||
state_manager: *const c::StateManager,
|
state_manager: *const c::StateManager,
|
||||||
/// Unowned reference. Be careful, it's shared with C at large
|
/// Unowned reference. Be careful, it's shared with C at large
|
||||||
pub ui_manager: Option<*const c::UIManager>,
|
ui_manager: Option<*const c::UIManager>,
|
||||||
|
|
||||||
pending: IMProtocolState,
|
pending: IMProtocolState,
|
||||||
current: IMProtocolState, // turn current into an idiomatic representation?
|
current: IMProtocolState, // turn current into an idiomatic representation?
|
||||||
@ -377,7 +372,28 @@ impl IMService {
|
|||||||
}
|
}
|
||||||
imservice
|
imservice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_ui_manager(&mut self, mut ui_manager: Option<*const c::UIManager>) {
|
||||||
|
mem::swap(&mut self.ui_manager, &mut ui_manager);
|
||||||
|
// Now ui_manager is what was previously self.ui_manager.
|
||||||
|
// If there wasn't any, we need to consider if UI was requested.
|
||||||
|
if let None = ui_manager {
|
||||||
|
self.apply_active_to_ui();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_active_to_ui(&self) {
|
||||||
|
if self.is_active() {
|
||||||
|
if let Some(ui) = self.ui_manager {
|
||||||
|
unsafe { c::server_context_service_show_keyboard(ui); }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(ui) = self.ui_manager {
|
||||||
|
unsafe { c::server_context_service_keyboard_release_visibility(ui); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn commit_string(&self, text: &CString) -> Result<(), SubmitError> {
|
pub fn commit_string(&self, text: &CString) -> Result<(), SubmitError> {
|
||||||
match self.current.active {
|
match self.current.active {
|
||||||
true => {
|
true => {
|
||||||
|
|||||||
@ -84,11 +84,11 @@ pub mod c {
|
|||||||
}
|
}
|
||||||
let submission: &mut Submission = unsafe { &mut *submission };
|
let submission: &mut Submission = unsafe { &mut *submission };
|
||||||
if let Some(ref mut imservice) = &mut submission.imservice {
|
if let Some(ref mut imservice) = &mut submission.imservice {
|
||||||
imservice.ui_manager = if ui_manager.is_null() {
|
imservice.set_ui_manager(if ui_manager.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(ui_manager)
|
Some(ui_manager)
|
||||||
}
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user