From df1b832fceeddcdc1b012b79c21bedad57ff6a66 Mon Sep 17 00:00:00 2001 From: Funami580 Date: Wed, 6 Jul 2022 02:01:47 +0200 Subject: [PATCH] wayland: add global active_surface_id to fix pasting --- window/src/os/wayland/connection.rs | 5 +++++ window/src/os/wayland/pointer.rs | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/window/src/os/wayland/connection.rs b/window/src/os/wayland/connection.rs index 2a3c6d7a2..7b51823c0 100644 --- a/window/src/os/wayland/connection.rs +++ b/window/src/os/wayland/connection.rs @@ -42,6 +42,7 @@ pub struct WaylandConnection { pub(crate) keyboard_mapper: RefCell>, pub(crate) keyboard_window_id: RefCell>, pub(crate) surface_to_window_id: RefCell>, + pub(crate) active_surface_id: RefCell, /// Repeats per second pub(crate) key_repeat_rate: RefCell, @@ -161,6 +162,7 @@ impl WaylandConnection { keyboard_window_id: RefCell::new(None), last_serial: RefCell::new(0), surface_to_window_id: RefCell::new(HashMap::new()), + active_surface_id: RefCell::new(0), }) } @@ -173,6 +175,9 @@ impl WaylandConnection { WlKeyboardEvent::Enter { serial, surface, .. } => { + // update global active surface id + *self.active_surface_id.borrow_mut() = surface.as_ref().id(); + *self.last_serial.borrow_mut() = *serial; if let Some(&window_id) = self .surface_to_window_id diff --git a/window/src/os/wayland/pointer.rs b/window/src/os/wayland/pointer.rs index c619480ac..e127ce054 100644 --- a/window/src/os/wayland/pointer.rs +++ b/window/src/os/wayland/pointer.rs @@ -1,6 +1,7 @@ use super::copy_and_paste::*; use super::drag_and_drop::*; use crate::os::wayland::connection::WaylandConnection; +use crate::ConnectionOps; use smithay_client_toolkit as toolkit; use std::collections::HashMap; use std::sync::{Arc, Mutex}; @@ -30,7 +31,12 @@ struct Inner { impl Inner { fn handle_event(&mut self, evt: PointerEvent) { if let PointerEvent::Enter { surface, .. } = &evt { - self.active_surface_id = surface.as_ref().id(); + let surface_id = surface.as_ref().id(); + // update global active surface id + let conn = WaylandConnection::get().unwrap().wayland(); + *conn.active_surface_id.borrow_mut() = surface_id; + // update pointer-specific active surface id + self.active_surface_id = surface_id; } if let Some(serial) = event_serial(&evt) { self.serial = serial; @@ -47,7 +53,9 @@ impl Inner { } fn resolve_copy_and_paste(&mut self) -> Option>> { - if let Some(pending) = self.surface_to_pending.get(&self.active_surface_id) { + let conn = WaylandConnection::get().unwrap().wayland(); + let active_surface_id = conn.active_surface_id.borrow(); + if let Some(pending) = self.surface_to_pending.get(&active_surface_id) { Some(Arc::clone(&pending.lock().unwrap().copy_and_paste)) } else { None @@ -330,9 +338,6 @@ impl PointerDispatcher { inner .surface_to_pending .insert(surface.as_ref().id(), Arc::clone(pending)); - if inner.active_surface_id == 0 { - inner.active_surface_id = surface.as_ref().id(); - } } pub fn set_cursor(&self, name: &str, serial: Option) {