Skip to content

Commit

Permalink
linux: wayland: Flush the Wayland queue and don't wait for a roundtrip
Browse files Browse the repository at this point in the history
On sway, the roundtrip never finished until e.g the workspace was switched. The move_mouse and scroll functions would not finish otherwise. Changing this to flush fixes the issue (see enigo-rs#396 for more details)
  • Loading branch information
pentamassiv committed Feb 26, 2025
1 parent ca8fbf9 commit 6c310c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- linux: wayland: Fix the serial number of input_method events
- linux: wayland: Correct whitespace and nullbyte at the end of the keymap
- linux: wayland: Send messages in the correct order and make sure Wayland objects are created before they are used
- linux: wayland: Flush the Wayland queue when moving the mouse and simulating a scroll instead of waiting for a roundtrip

# 0.3.0
## Changed
Expand Down
35 changes: 10 additions & 25 deletions src/linux/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,14 @@ impl Con {
if direction == Direction::Press || direction == Direction::Click {
trace!("vk.key({time}, {keycode}, 1)");
vk.key(time, keycode, 1);
self.event_queue
.flush()
.map_err(|_| InputError::Simulate("Flushing Wayland queue failed"))?;

self.flush()?;
}
if direction == Direction::Release || direction == Direction::Click {
trace!("vk.key({time}, {keycode}, 0)");
vk.key(time, keycode, 0);
self.event_queue
.flush()
.map_err(|_| InputError::Simulate("Flushing Wayland queue failed"))?;

self.flush()?;
}
Ok(())
}
Expand All @@ -337,9 +335,7 @@ impl Con {
// Send the modifier event
vk.modifiers(modifiers, 0, 0, 0);

self.event_queue
.flush()
.map_err(|_| InputError::Simulate("Flushing Wayland queue failed"))?;
self.flush()?;

Ok(())
}
Expand Down Expand Up @@ -686,9 +682,7 @@ impl Keyboard for Con {
im.commit_string(text.to_string());
im.commit(self.state.im_serial.0);

self.event_queue
.flush()
.map_err(|_| InputError::Simulate("Flushing Wayland queue failed"))?;
self.flush()?;

Ok(Some(()))
}
Expand Down Expand Up @@ -766,9 +760,8 @@ impl Mouse for Con {
vp.button(time, button, wl_pointer::ButtonState::Released);
vp.frame(); // TODO: Check if this is needed
}
self.event_queue
.flush()
.map_err(|_| InputError::Simulate("Flushing Wayland queue failed"))

self.flush()
}

fn move_mouse(&mut self, x: i32, y: i32, coordinate: Coordinate) -> InputResult<()> {
Expand Down Expand Up @@ -803,11 +796,7 @@ impl Mouse for Con {
}
vp.frame(); // TODO: Check if this is needed

// TODO: Change to flush()
self.event_queue
.roundtrip(&mut self.state)
.map_err(|_| InputError::Simulate("The roundtrip on Wayland failed"))
.map(|_| ())
self.flush()
}

fn scroll(&mut self, length: i32, axis: Axis) -> InputResult<()> {
Expand All @@ -827,11 +816,7 @@ impl Mouse for Con {
vp.axis(time, axis, length.into());
vp.frame(); // TODO: Check if this is needed

// TODO: Change to flush()
self.event_queue
.roundtrip(&mut self.state)
.map_err(|_| InputError::Simulate("The roundtrip on Wayland failed"))
.map(|_| ())
self.flush()
}

fn main_display(&self) -> InputResult<(i32, i32)> {
Expand Down

0 comments on commit 6c310c2

Please sign in to comment.