From 8943aa5a1532d3ed3ad5727aa18c00bad4b48c1a Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Thu, 20 Apr 2023 16:19:52 +0200 Subject: [PATCH] shell: Fix repeated window grabs in more scenarios --- src/shell/element/window.rs | 1 + src/shell/layout/floating/grabs/moving.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index b85139e4..3aca2632 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -435,6 +435,7 @@ impl PointerTarget for CosmicWindow { PointerTarget::enter(&p.window, seat, data, &event) } } else { + p.swap_focus(Focus::Window); PointerTarget::enter(&p.window, seat, data, event) } false diff --git a/src/shell/layout/floating/grabs/moving.rs b/src/shell/layout/floating/grabs/moving.rs index 5b0bea54..4623ffd0 100644 --- a/src/shell/layout/floating/grabs/moving.rs +++ b/src/shell/layout/floating/grabs/moving.rs @@ -222,7 +222,7 @@ impl MoveSurfaceGrab { // No more buttons are pressed, release the grab. let output = self.seat.active_output(); - let offset = if let Some(grab_state) = self + let position = if let Some(grab_state) = self .seat .user_data() .get::() @@ -266,7 +266,10 @@ impl MoveSurfaceGrab { .active_space_mut(&output) .floating_layer .map_internal(grab_state.window, &output, Some(window_location + offset)); - Some(grab_state.window_offset) + + let pointer_pos = handle.current_location(); + let relative_pos = state.common.shell.map_global_to_space(pointer_pos, &output); + Some(window_location + offset + (pointer_pos - relative_pos).to_i32_round()) } else { None } @@ -276,10 +279,10 @@ impl MoveSurfaceGrab { handle.unset_grab(state, serial, time); if self.window.alive() { - if let Some(offset) = offset { + if let Some(position) = position { handle.motion( state, - Some((PointerFocusTarget::from(self.window.clone()), offset)), + Some((PointerFocusTarget::from(self.window.clone()), position - self.window.geometry().loc)), &MotionEvent { location: handle.current_location(), serial: serial,