From 94ede1e8f1524ae6d896e5504164190eddffa7dc Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 8 Sep 2021 23:18:07 +0300 Subject: [PATCH] window: implement window movement by dragging on Wayland --- wezterm-gui/src/termwindow/mouseevent.rs | 1 + window/src/lib.rs | 9 +++++++++ window/src/os/wayland/copy_and_paste.rs | 2 +- window/src/os/wayland/pointer.rs | 2 ++ window/src/os/wayland/window.rs | 12 +++++++++--- window/src/os/x_and_wayland.rs | 8 ++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs index 3bac62e82..59093c3e8 100644 --- a/wezterm-gui/src/termwindow/mouseevent.rs +++ b/wezterm-gui/src/termwindow/mouseevent.rs @@ -321,6 +321,7 @@ impl super::TermWindow { TabBarItem::None => { // Potentially starting a drag by the tab bar self.window_drag_position.replace(event.clone()); + context.request_drag_move(); } }, WMEK::Press(MousePress::Middle) => match self.tab_bar.hit_test(x) { diff --git a/window/src/lib.rs b/window/src/lib.rs index bec2ab5f1..9004d1281 100644 --- a/window/src/lib.rs +++ b/window/src/lib.rs @@ -220,9 +220,18 @@ pub trait WindowOps { /// Resize the inner or client area of the window fn set_inner_size(&self, width: usize, height: usize); + /// Requests the windowing system to start a window drag. + /// + /// This is only implemented on backends that handle + /// window movement on the server side (Wayland). + fn request_drag_move(&self) {} + /// Changes the location of the window on the screen. /// The coordinates are of the top left pixel of the /// client area. + /// + /// This is only implemented on backends that allow + /// windows to move themselves (not Wayland). fn set_window_position(&self, _coords: ScreenPoint) {} /// inform the windowing system of the current textual diff --git a/window/src/os/wayland/copy_and_paste.rs b/window/src/os/wayland/copy_and_paste.rs index 907d839d4..f5d5db5bc 100644 --- a/window/src/os/wayland/copy_and_paste.rs +++ b/window/src/os/wayland/copy_and_paste.rs @@ -10,7 +10,7 @@ use wayland_client::Attached; #[derive(Default)] pub struct CopyAndPaste { data_offer: Option, - last_serial: u32, + pub(crate) last_serial: u32, } impl std::fmt::Debug for CopyAndPaste { diff --git a/window/src/os/wayland/pointer.rs b/window/src/os/wayland/pointer.rs index 8acb93c13..ec081d313 100644 --- a/window/src/os/wayland/pointer.rs +++ b/window/src/os/wayland/pointer.rs @@ -94,6 +94,7 @@ pub struct PointerDispatcher { auto_pointer: ThemedPointer, #[allow(dead_code)] themer: ThemeManager, + pub(crate) seat: WlSeat, } #[derive(Clone, Debug)] @@ -237,6 +238,7 @@ impl PointerDispatcher { data_device, themer, auto_pointer, + seat: seat.clone(), }) } diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 0b32317bb..1b037b10a 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -793,9 +793,9 @@ impl WindowOps for WaylandWindow { }); } - fn set_window_position(&self, coords: ScreenPoint) { + fn request_drag_move(&self) { WaylandConnection::with_window_inner(self.0, move |inner| { - inner.set_window_position(coords); + inner.request_drag_move(); Ok(()) }); } @@ -1000,7 +1000,13 @@ impl WaylandWindowInner { } } - fn set_window_position(&self, _coords: ScreenPoint) {} + fn request_drag_move(&self) { + if let Some(window) = self.window.as_ref() { + let serial = self.copy_and_paste.lock().unwrap().last_serial; + let conn = Connection::get().unwrap().wayland(); + window.start_interactive_move(&conn.pointer.seat, serial); + } + } /// Change the title for the window manager fn set_title(&mut self, title: &str) { diff --git a/window/src/os/x_and_wayland.rs b/window/src/os/x_and_wayland.rs index 5e4b1e56c..3251a1568 100644 --- a/window/src/os/x_and_wayland.rs +++ b/window/src/os/x_and_wayland.rs @@ -285,6 +285,14 @@ impl WindowOps for Window { } } + fn request_drag_move(&self) { + match self { + Self::X11(x) => x.request_drag_move(), + #[cfg(feature = "wayland")] + Self::Wayland(w) => w.request_drag_move(), + } + } + fn set_window_position(&self, coords: ScreenPoint) { match self { Self::X11(x) => x.set_window_position(coords),