shell: Generalize move grab

This commit is contained in:
Victoria Brekenfeld 2023-07-17 21:11:23 +02:00
parent 9b70372f44
commit a8a5ee466a
9 changed files with 73 additions and 53 deletions

View file

@ -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},

View file

@ -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,

View file

@ -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;

View file

@ -103,14 +103,15 @@ impl MoveGrabState {
}
}
pub struct MoveSurfaceGrab {
pub struct MoveGrab {
window: CosmicMapped,
start_data: PointerGrabStartData<State>,
seat: Seat<State>,
outputs: HashSet<Output>,
tiling: bool,
}
impl PointerGrab<State> for MoveSurfaceGrab {
impl PointerGrab<State> for MoveGrab {
fn motion(
&mut self,
state: &mut State,
@ -182,7 +183,7 @@ impl PointerGrab<State> for MoveSurfaceGrab {
}
}
impl MoveSurfaceGrab {
impl MoveGrab {
pub fn new(
start_data: PointerGrabStartData<State>,
window: CosmicMapped,
@ -190,7 +191,8 @@ impl MoveSurfaceGrab {
initial_cursor_location: Point<f64, Logical>,
initial_window_location: Point<i32, Logical>,
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
}

View file

@ -1,5 +1,3 @@
mod moving;
mod resize;
pub use self::moving::*;
pub use self::resize::*;

View file

@ -0,0 +1,3 @@
mod resize;
pub use self::resize::*;

View file

@ -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 {

View file

@ -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<State>,
indicator_thickness: u8,
) -> Option<MoveSurfaceGrab> {
) -> Option<MoveGrab> {
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<State>) {

View file

@ -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,