From 8cee91c88fce2ff69bd659ccf22c86f0a691e3a1 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 18 Apr 2024 21:19:05 -0700 Subject: [PATCH] Support touch drag for SSD toplevels, and stacks We already direct touch events to Iced, and the Cosmic `HeaderBar` widget already recognizes drags from touch events. So it seems updating `last_seat` is all that was needed for windows SSDs. For stacks, the same works, plus moving using the same logic for detecting drags that is used for mouse events. --- src/shell/element/stack.rs | 88 +++++++++++++++++++++---------------- src/shell/element/window.rs | 5 ++- 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index bdcaef3b..92a56bbf 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -596,6 +596,45 @@ impl CosmicStack { pub(crate) fn force_redraw(&self) { self.0.force_redraw(); } + + fn start_drag(&self, data: &mut State, seat: &Seat, serial: Serial) { + if let Some(dragged_out) = self + .0 + .with_program(|p| p.potential_drag.lock().unwrap().take()) + { + if let Some(surface) = self + .0 + .with_program(|p| p.windows.lock().unwrap().get(dragged_out).cloned()) + { + let seat = seat.clone(); + surface.try_force_undecorated(false); + surface.send_configure(); + if let Some(surface) = surface.wl_surface() { + let _ = data.common.event_loop_handle.insert_idle(move |state| { + let res = state.common.shell.write().unwrap().move_request( + &surface, + &seat, + serial, + ReleaseMode::NoMouseButtons, + true, + &state.common.config, + &state.common.event_loop_handle, + &state.common.xdg_activation_state, + ); + if let Some((grab, focus)) = res { + if grab.is_touch_grab() { + seat.get_touch().unwrap().set_grab(state, grab, serial); + } else { + seat.get_pointer() + .unwrap() + .set_grab(state, grab, serial, focus); + } + } + }); + } + } + } + } } #[derive(Debug, Clone, Copy)] @@ -1196,43 +1235,7 @@ impl PointerTarget for CosmicStack { || event.location.x < 64.0 || event.location.x > (active_window_geo.size.w as f64 - 64.0) { - if let Some(dragged_out) = self - .0 - .with_program(|p| p.potential_drag.lock().unwrap().take()) - { - if let Some(surface) = self - .0 - .with_program(|p| p.windows.lock().unwrap().get(dragged_out).cloned()) - { - let seat = seat.clone(); - let serial = event.serial; - surface.try_force_undecorated(false); - surface.send_configure(); - if let Some(surface) = surface.wl_surface() { - let _ = data.common.event_loop_handle.insert_idle(move |state| { - let res = state.common.shell.write().unwrap().move_request( - &surface, - &seat, - serial, - ReleaseMode::NoMouseButtons, - true, - &state.common.config, - &state.common.event_loop_handle, - &state.common.xdg_activation_state, - ); - if let Some((grab, focus)) = res { - if grab.is_touch_grab() { - seat.get_touch().unwrap().set_grab(state, grab, serial); - } else { - seat.get_pointer() - .unwrap() - .set_grab(state, grab, serial, focus); - } - } - }); - } - } - } + self.start_drag(data, seat, event.serial); } } @@ -1423,6 +1426,7 @@ impl TouchTarget for CosmicStack { fn down(&self, seat: &Seat, data: &mut State, event: &DownEvent, seq: Serial) { let mut event = event.clone(); let active_window_geo = self.0.with_program(|p| { + *p.last_seat.lock().unwrap() = Some((seat.clone(), event.serial)); p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)].geometry() }); event.location -= active_window_geo.loc.to_f64(); @@ -1439,7 +1443,15 @@ impl TouchTarget for CosmicStack { p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)].geometry() }); event.location -= active_window_geo.loc.to_f64(); - TouchTarget::motion(&self.0, seat, data, &event, seq) + TouchTarget::motion(&self.0, seat, data, &event, seq); + + if event.location.y < 0.0 + || event.location.y > TAB_HEIGHT as f64 + || event.location.x < 64.0 + || event.location.x > (active_window_geo.size.w as f64 - 64.0) + { + self.start_drag(data, seat, seq); + } } fn frame(&self, seat: &Seat, data: &mut State, seq: Serial) { diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index fb28150a..6e572d26 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -866,7 +866,10 @@ impl PointerTarget for CosmicWindow { impl TouchTarget for CosmicWindow { fn down(&self, seat: &Seat, data: &mut State, event: &DownEvent, seq: Serial) { let mut event = event.clone(); - event.location -= self.0.with_program(|p| p.window.geometry().loc.to_f64()); + self.0.with_program(|p| { + event.location -= p.window.geometry().loc.to_f64(); + *p.last_seat.lock().unwrap() = Some((seat.clone(), event.serial)); + }); TouchTarget::down(&self.0, seat, data, &event, seq) }