From 51981d524d353d64b0a491a9208dfb5b6647372c Mon Sep 17 00:00:00 2001 From: pentamassiv Date: Thu, 5 Dec 2024 18:00:34 +0100 Subject: [PATCH] Moved serial to WaylandState and increase it when a Done event is received The serial needs to increase each time a Done event is received. We do a roundtrip before sending the commit event to make sure we handled all Done events the compositor sent --- src/linux/wayland.rs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/linux/wayland.rs b/src/linux/wayland.rs index a89cf350..f262672b 100644 --- a/src/linux/wayland.rs +++ b/src/linux/wayland.rs @@ -1,10 +1,12 @@ -use std::collections::VecDeque; -use std::convert::TryInto; -use std::env; -use std::os::unix::io::AsFd; -use std::os::unix::net::UnixStream; -use std::path::PathBuf; -use std::time::Instant; +use std::{ + collections::VecDeque, + convert::TryInto as _, + env, + num::Wrapping, + os::unix::{io::AsFd, net::UnixStream}, + path::PathBuf, + time::Instant, +}; use log::{debug, error, trace, warn}; use wayland_client::{ @@ -32,7 +34,7 @@ pub struct Con { event_queue: EventQueue, state: WaylandState, virtual_keyboard: Option, - input_method: Option<(zwp_input_method_v2::ZwpInputMethodV2, u32)>, + input_method: Option, virtual_pointer: Option, base_time: std::time::Instant, } @@ -141,7 +143,7 @@ impl Con { .state .im_manager .as_ref() - .map(|im_mgr| (im_mgr.get_input_method(seat, &qh, ()), 0)); + .map(|im_mgr| im_mgr.get_input_method(seat, &qh, ())); }; // Setup virtual pointer @@ -321,6 +323,7 @@ impl Drop for Con { struct WaylandState { keyboard_manager: Option, im_manager: Option, + im_serial: Wrapping, pointer_manager: Option, seat: Option, /* output: Option, @@ -432,13 +435,17 @@ impl Dispatch for Wayl } impl Dispatch for WaylandState { fn event( - _state: &mut Self, + state: &mut Self, _vk: &zwp_input_method_v2::ZwpInputMethodV2, event: zwp_input_method_v2::Event, (): &(), _: &Connection, _qh: &QueueHandle, ) { + match event { + zwp_input_method_v2::Event::Done => state.im_serial += Wrapping(1u32), + _ => (), // TODO + } warn!("Got a input method event {:?}", event); } } @@ -541,9 +548,12 @@ impl Keyboard for Con { is_alive(im)?; trace!("fast text input with imput_method protocol"); + // Process all previous events so that the serial number is correct + self.event_queue + .roundtrip(&mut self.state) + .map_err(|_| InputError::Simulate("The roundtrip on Wayland failed"))?; im.commit_string(text.to_string()); - im.commit(*serial); - *serial = serial.wrapping_add(1); + im.commit(self.state.im_serial.0); // TODO: Change to flush() self.event_queue