Add Window::set_ime_purpose
This adds a way to set the purpose for the IME input, implemented only on Wayland for now.
This commit is contained in:
parent
8f8da0f8bb
commit
1b4045dcb2
15 changed files with 160 additions and 22 deletions
|
|
@ -9,7 +9,7 @@ use crate::event::{Ime, WindowEvent};
|
|||
use crate::platform_impl::wayland;
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
|
||||
use super::{Preedit, TextInputHandler, TextInputInner};
|
||||
use super::{Preedit, TextInputHandler, TextInputInner, ZwpTextInputV3Ext};
|
||||
|
||||
#[inline]
|
||||
pub(super) fn handle_text_input(
|
||||
|
|
@ -32,6 +32,7 @@ pub(super) fn handle_text_input(
|
|||
// Enable text input on that surface.
|
||||
if window_handle.ime_allowed.get() {
|
||||
text_input.enable();
|
||||
text_input.set_content_type_by_purpose(window_handle.ime_purpose.get());
|
||||
text_input.commit();
|
||||
event_sink.push_window_event(WindowEvent::Ime(Ime::Enabled), window_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
use sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use sctk::reexports::client::Attached;
|
||||
use sctk::reexports::protocols::unstable::text_input::v3::client::zwp_text_input_manager_v3::ZwpTextInputManagerV3;
|
||||
use sctk::reexports::protocols::unstable::text_input::v3::client::zwp_text_input_v3::ZwpTextInputV3;
|
||||
use sctk::reexports::protocols::unstable::text_input::v3::client::zwp_text_input_v3::{
|
||||
ContentHint, ContentPurpose, ZwpTextInputV3,
|
||||
};
|
||||
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::WindowId;
|
||||
use crate::window::ImePurpose;
|
||||
|
||||
mod handlers;
|
||||
|
||||
|
|
@ -14,6 +17,21 @@ pub struct TextInputHandler {
|
|||
text_input: ZwpTextInputV3,
|
||||
}
|
||||
|
||||
trait ZwpTextInputV3Ext {
|
||||
fn set_content_type_by_purpose(&self, purpose: ImePurpose);
|
||||
}
|
||||
|
||||
impl ZwpTextInputV3Ext for ZwpTextInputV3 {
|
||||
fn set_content_type_by_purpose(&self, purpose: ImePurpose) {
|
||||
let (hint, purpose) = match purpose {
|
||||
ImePurpose::Normal => (ContentHint::None, ContentPurpose::Normal),
|
||||
ImePurpose::Password => (ContentHint::SensitiveData, ContentPurpose::Password),
|
||||
ImePurpose::Terminal => (ContentHint::None, ContentPurpose::Terminal),
|
||||
};
|
||||
self.set_content_type(hint, purpose);
|
||||
}
|
||||
}
|
||||
|
||||
impl TextInputHandler {
|
||||
#[inline]
|
||||
pub fn set_ime_position(&self, x: i32, y: i32) {
|
||||
|
|
@ -22,8 +40,15 @@ impl TextInputHandler {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_input_allowed(&self, allowed: bool) {
|
||||
if allowed {
|
||||
pub fn set_content_type_by_purpose(&self, purpose: ImePurpose) {
|
||||
self.text_input.set_content_type_by_purpose(purpose);
|
||||
self.text_input.commit();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_input_allowed(&self, allowed: Option<ImePurpose>) {
|
||||
if let Some(purpose) = allowed {
|
||||
self.text_input.set_content_type_by_purpose(purpose);
|
||||
self.text_input.enable();
|
||||
} else {
|
||||
self.text_input.disable();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue