diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index f28076ae..b333c75e 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -11,8 +11,7 @@ use std::{ use crate::{ config::WorkspaceLayout, shell::{ - focus::target::WindowGroup, - layout::{floating::SeatMoveGrabState, tiling::ANIMATION_DURATION}, + focus::target::WindowGroup, grabs::SeatMoveGrabState, layout::tiling::ANIMATION_DURATION, CosmicMapped, CosmicMappedRenderElement, WorkspaceRenderElement, }, state::{Common, Fps}, diff --git a/src/input/mod.rs b/src/input/mod.rs index 49b5ff41..a8460e5a 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -4,9 +4,8 @@ use crate::{ config::{Action, Config, KeyPattern, WorkspaceLayout}, shell::{ focus::{target::PointerFocusTarget, FocusDirection}, - grabs::ResizeEdge, + grabs::{ResizeEdge, SeatMoveGrabState}, layout::{ - floating::SeatMoveGrabState, tiling::{Direction, FocusResult, MoveResult}, }, OverviewMode, ResizeDirection, ResizeMode, Workspace, diff --git a/src/shell/grabs.rs b/src/shell/grabs/mod.rs similarity index 99% rename from src/shell/grabs.rs rename to src/shell/grabs/mod.rs index 668ffd39..35a8d094 100644 --- a/src/shell/grabs.rs +++ b/src/shell/grabs/mod.rs @@ -15,6 +15,9 @@ use super::{ layout::{floating::ResizeSurfaceGrab, tiling::ResizeForkGrab}, }; +mod moving; +pub use self::moving::*; + bitflags::bitflags! { pub struct ResizeEdge: u32 { const TOP = 0b0001; diff --git a/src/shell/layout/floating/grabs/moving.rs b/src/shell/grabs/moving.rs similarity index 81% rename from src/shell/layout/floating/grabs/moving.rs rename to src/shell/grabs/moving.rs index 404aa4cc..9231ff12 100644 --- a/src/shell/layout/floating/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -103,14 +103,15 @@ impl MoveGrabState { } } -pub struct MoveSurfaceGrab { +pub struct MoveGrab { window: CosmicMapped, start_data: PointerGrabStartData, seat: Seat, outputs: HashSet, + tiling: bool, } -impl PointerGrab for MoveSurfaceGrab { +impl PointerGrab for MoveGrab { fn motion( &mut self, state: &mut State, @@ -182,7 +183,7 @@ impl PointerGrab for MoveSurfaceGrab { } } -impl MoveSurfaceGrab { +impl MoveGrab { pub fn new( start_data: PointerGrabStartData, window: CosmicMapped, @@ -190,7 +191,8 @@ impl MoveSurfaceGrab { initial_cursor_location: Point, initial_window_location: Point, indicator_thickness: u8, - ) -> MoveSurfaceGrab { + was_tiled: bool, + ) -> MoveGrab { let output = seat.active_output(); let mut outputs = HashSet::new(); outputs.insert(output.clone()); @@ -198,8 +200,7 @@ impl MoveSurfaceGrab { let grab_state = MoveGrabState { window: window.clone(), - window_offset: dbg!(initial_window_location) - - dbg!(initial_cursor_location.to_i32_round()), + window_offset: initial_window_location - initial_cursor_location.to_i32_round(), indicator_thickness, }; @@ -209,14 +210,19 @@ impl MoveSurfaceGrab { .unwrap() .borrow_mut() = Some(grab_state); - MoveSurfaceGrab { + MoveGrab { window, start_data, seat: seat.clone(), outputs, + tiling: was_tiled, } } + pub fn is_tiling_grab(&self) -> bool { + self.tiling + } + fn ungrab( &mut self, state: &mut State, @@ -239,6 +245,9 @@ impl MoveSurfaceGrab { + grab_state.window_offset; let workspace_handle = state.common.shell.active_space(&output).handle; + for old_output in self.outputs.iter().filter(|o| *o != &output) { + grab_state.window.output_leave(old_output); + } for (window, _) in grab_state.window.windows() { state .common @@ -252,29 +261,40 @@ impl MoveSurfaceGrab { .toplevel_enter_output(&window, &output); } - let offset = state - .common - .shell - .active_space(&output) - .floating_layer - .space - .output_geometry(&output) - .unwrap() - .loc; - grab_state.window.set_geometry(Rectangle::from_loc_and_size( - window_location + offset, - grab_state.window.geometry().size, - )); - state - .common - .shell - .active_space_mut(&output) - .floating_layer - .map_internal(grab_state.window, &output, Some(window_location + offset)); + if self.tiling { + Some( + state + .common + .shell + .active_space_mut(&output) + .tiling_layer + .drop_window(grab_state.window, &output, handle.current_location()), + ) + } else { + let offset = state + .common + .shell + .active_space(&output) + .floating_layer + .space + .output_geometry(&output) + .unwrap() + .loc; + grab_state.window.set_geometry(Rectangle::from_loc_and_size( + window_location + offset, + grab_state.window.geometry().size, + )); + state + .common + .shell + .active_space_mut(&output) + .floating_layer + .map_internal(grab_state.window, &output, Some(window_location + 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()) + 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 } diff --git a/src/shell/layout/floating/grabs/mod.rs b/src/shell/layout/floating/grabs/mod.rs index 65700de7..1ec08053 100644 --- a/src/shell/layout/floating/grabs/mod.rs +++ b/src/shell/layout/floating/grabs/mod.rs @@ -1,5 +1,3 @@ -mod moving; mod resize; -pub use self::moving::*; pub use self::resize::*; diff --git a/src/shell/layout/tiling/grabs/mod.rs b/src/shell/layout/tiling/grabs/mod.rs new file mode 100644 index 00000000..1ec08053 --- /dev/null +++ b/src/shell/layout/tiling/grabs/mod.rs @@ -0,0 +1,3 @@ +mod resize; + +pub use self::resize::*; diff --git a/src/shell/layout/tiling/grabs.rs b/src/shell/layout/tiling/grabs/resize.rs similarity index 99% rename from src/shell/layout/tiling/grabs.rs rename to src/shell/layout/tiling/grabs/resize.rs index a897f65d..f5cbb694 100644 --- a/src/shell/layout/tiling/grabs.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -19,7 +19,7 @@ use smithay::{ utils::{IsAlive, Logical, Point}, }; -use super::{Data, TilingLayout}; +use super::super::{Data, TilingLayout}; #[derive(Debug, Clone, PartialEq)] pub struct ResizeForkTarget { diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index 6bacf04a..c9f4e57b 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -4,8 +4,9 @@ use crate::{ BackdropShader, GlMultiError, GlMultiFrame, GlMultiRenderer, }, shell::{ + grabs::MoveGrab, layout::{ - floating::{FloatingLayout, MoveSurfaceGrab}, + floating::FloatingLayout, tiling::{TilingLayout, ANIMATION_DURATION}, }, OverviewMode, @@ -363,7 +364,7 @@ impl Workspace { output: &Output, start_data: PointerGrabStartData, indicator_thickness: u8, - ) -> Option { + ) -> Option { let pointer = seat.get_pointer().unwrap(); let pos = pointer.current_location(); @@ -382,21 +383,18 @@ impl Workspace { } let was_floating = self.floating_layer.unmap(&mapped); - //let was_tiled = self.tiling_layer.unmap(&mapped); - //assert!(was_floating != was_tiled); + let was_tiled = self.tiling_layer.unmap_as_placeholder(&mapped); + assert!(was_floating != was_tiled.is_some()); - if was_floating { - Some(MoveSurfaceGrab::new( - start_data, - mapped, - seat, - pos, - initial_window_location, - indicator_thickness, - )) - } else { - None // TODO - } + Some(MoveGrab::new( + start_data, + mapped, + seat, + pos, + initial_window_location, + indicator_thickness, + was_tiled.is_some(), + )) } pub fn toggle_tiling(&mut self, seat: &Seat) { diff --git a/src/state.rs b/src/state.rs index 4ec87119..8d7aa914 100644 --- a/src/state.rs +++ b/src/state.rs @@ -7,7 +7,7 @@ use crate::{ x11::X11State, }, config::{Config, OutputConfig}, - shell::{layout::floating::SeatMoveGrabState, Shell}, + shell::{grabs::SeatMoveGrabState, Shell}, utils::prelude::*, wayland::protocols::{ drm::WlDrmState,