wayland: dispatcher: listen for input method (de-)activate events
Hide the keyboard by default and show it when the user is in some text field.
This commit is contained in:
parent
b5d09e655b
commit
a9f3010076
2 changed files with 58 additions and 6 deletions
|
|
@ -32,6 +32,8 @@ use wayland::wlr_layer_shell_unstable_v1::zwlr_layer_shell_v1;
|
|||
use wayland::wlr_layer_shell_unstable_v1::zwlr_layer_surface_v1;
|
||||
use wayland::fractional_scale_v1::wp_fractional_scale_manager_v1;
|
||||
use wayland::fractional_scale_v1::wp_fractional_scale_v1;
|
||||
use wayland::input_method_unstable_v2::zwp_input_method_manager_v2;
|
||||
use wayland::input_method_unstable_v2::zwp_input_method_v2;
|
||||
use wayland::viewporter::wp_viewporter;
|
||||
use wayland::viewporter::wp_viewport;
|
||||
use wayland::virtual_keyboard_unstable_v1::zwp_virtual_keyboard_manager_v1;
|
||||
|
|
@ -57,6 +59,10 @@ impl Dispatcher {
|
|||
let vk_man = globals.bind(&queue, 1..=1, ())
|
||||
.expect("Compositor must implement zwp_virtual_keyboard_manager_v1");
|
||||
|
||||
let im_man: zwp_input_method_manager_v2::ZwpInputMethodManagerV2
|
||||
= globals.bind(&queue, 1..=1, ())
|
||||
.expect("Compositor must implement zwp_input_method_manager_v2");
|
||||
|
||||
let frac_scale_man = match globals.bind(&queue, 1..=1, ()) {
|
||||
Ok(g) => Some(g),
|
||||
Err(_) => None,
|
||||
|
|
@ -67,6 +73,8 @@ impl Dispatcher {
|
|||
Err(_) => None,
|
||||
};
|
||||
|
||||
im_man.get_input_method(&seat, &queue, ());
|
||||
|
||||
let disp = Surface::new(queue.clone(),
|
||||
&shm, compositor, layer_shell,
|
||||
frac_scale_man, vper, 185)?;
|
||||
|
|
@ -94,6 +102,18 @@ impl Dispatcher {
|
|||
{
|
||||
self.seat.button_mut().dispatch_timers();
|
||||
}
|
||||
|
||||
fn show(&self)
|
||||
{
|
||||
let mut gfx = self.gfx.lock().unwrap();
|
||||
gfx.display_mut().show();
|
||||
}
|
||||
|
||||
fn hide(&self)
|
||||
{
|
||||
let mut gfx = self.gfx.lock().unwrap();
|
||||
gfx.display_mut().hide();
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<wl_buffer::WlBuffer, u32> for Dispatcher {
|
||||
|
|
@ -366,6 +386,42 @@ impl Dispatch<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, ()> for Dispatcher {
|
|||
}
|
||||
}
|
||||
|
||||
impl Dispatch<zwp_input_method_manager_v2::ZwpInputMethodManagerV2, ()> for Dispatcher {
|
||||
fn event(_ctx: &mut Dispatcher,
|
||||
_im_man: &zwp_input_method_manager_v2::ZwpInputMethodManagerV2,
|
||||
_evt: zwp_input_method_manager_v2::Event,
|
||||
_data: &(),
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Dispatcher>)
|
||||
{
|
||||
eprintln!("warn: unknown zwp_input_method_manager_v2 event emitted");
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<zwp_input_method_v2::ZwpInputMethodV2, ()> for Dispatcher {
|
||||
fn event(ctx: &mut Dispatcher,
|
||||
_im: &zwp_input_method_v2::ZwpInputMethodV2,
|
||||
evt: zwp_input_method_v2::Event,
|
||||
_data: &(),
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Dispatcher>)
|
||||
{
|
||||
match evt {
|
||||
zwp_input_method_v2::Event::Activate => {
|
||||
ctx.show();
|
||||
},
|
||||
zwp_input_method_v2::Event::Deactivate => {
|
||||
ctx.hide();
|
||||
},
|
||||
zwp_input_method_v2::Event::TextChangeCause { .. } => (),
|
||||
zwp_input_method_v2::Event::ContentType { .. } => (),
|
||||
zwp_input_method_v2::Event::SurroundingText { .. } => (),
|
||||
zwp_input_method_v2::Event::Done => (),
|
||||
_ => eprintln!("warn: unknown zwp_input_method_v2 event emitted"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1, ()> for Dispatcher {
|
||||
fn event(_ctx: &mut Dispatcher,
|
||||
_vk_man: &zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1,
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ impl<T: Dispatch<WlBuffer, u32>
|
|||
let buf1 = Buffer::new(queue.clone(), shm, 0)?;
|
||||
let buf2 = Buffer::new(queue.clone(), shm, 1)?;
|
||||
|
||||
let mut surf = Surface {
|
||||
Ok(Surface {
|
||||
bufs: [buf1, buf2],
|
||||
|
||||
queue: queue.clone(),
|
||||
|
|
@ -81,11 +81,7 @@ impl<T: Dispatch<WlBuffer, u32>
|
|||
configured: false,
|
||||
scale: 120,
|
||||
height,
|
||||
};
|
||||
|
||||
surf.show();
|
||||
|
||||
Ok(surf)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn configured(&self) -> bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue