Skip to content

Commit

Permalink
Moved serial to WaylandState and increase it when a Done event is rec…
Browse files Browse the repository at this point in the history
…eived

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
  • Loading branch information
pentamassiv committed Jan 28, 2025
1 parent b8e8c61 commit 51981d5
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/linux/wayland.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -32,7 +34,7 @@ pub struct Con {
event_queue: EventQueue<WaylandState>,
state: WaylandState,
virtual_keyboard: Option<zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1>,
input_method: Option<(zwp_input_method_v2::ZwpInputMethodV2, u32)>,
input_method: Option<zwp_input_method_v2::ZwpInputMethodV2>,
virtual_pointer: Option<zwlr_virtual_pointer_v1::ZwlrVirtualPointerV1>,
base_time: std::time::Instant,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -321,6 +323,7 @@ impl Drop for Con {
struct WaylandState {
keyboard_manager: Option<zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1>,
im_manager: Option<zwp_input_method_manager_v2::ZwpInputMethodManagerV2>,
im_serial: Wrapping<u32>,
pointer_manager: Option<zwlr_virtual_pointer_manager_v1::ZwlrVirtualPointerManagerV1>,
seat: Option<wl_seat::WlSeat>,
/* output: Option<wl_output::WlOutput>,
Expand Down Expand Up @@ -432,13 +435,17 @@ impl Dispatch<zwp_input_method_manager_v2::ZwpInputMethodManagerV2, ()> for Wayl
}
impl Dispatch<zwp_input_method_v2::ZwpInputMethodV2, ()> 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<Self>,
) {
match event {
zwp_input_method_v2::Event::Done => state.im_serial += Wrapping(1u32),
_ => (), // TODO
}
warn!("Got a input method event {:?}", event);
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 51981d5

Please sign in to comment.