shell: Generalize move grab
This commit is contained in:
parent
9b70372f44
commit
a8a5ee466a
9 changed files with 73 additions and 53 deletions
|
|
@ -11,8 +11,7 @@ use std::{
|
||||||
use crate::{
|
use crate::{
|
||||||
config::WorkspaceLayout,
|
config::WorkspaceLayout,
|
||||||
shell::{
|
shell::{
|
||||||
focus::target::WindowGroup,
|
focus::target::WindowGroup, grabs::SeatMoveGrabState, layout::tiling::ANIMATION_DURATION,
|
||||||
layout::{floating::SeatMoveGrabState, tiling::ANIMATION_DURATION},
|
|
||||||
CosmicMapped, CosmicMappedRenderElement, WorkspaceRenderElement,
|
CosmicMapped, CosmicMappedRenderElement, WorkspaceRenderElement,
|
||||||
},
|
},
|
||||||
state::{Common, Fps},
|
state::{Common, Fps},
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@ use crate::{
|
||||||
config::{Action, Config, KeyPattern, WorkspaceLayout},
|
config::{Action, Config, KeyPattern, WorkspaceLayout},
|
||||||
shell::{
|
shell::{
|
||||||
focus::{target::PointerFocusTarget, FocusDirection},
|
focus::{target::PointerFocusTarget, FocusDirection},
|
||||||
grabs::ResizeEdge,
|
grabs::{ResizeEdge, SeatMoveGrabState},
|
||||||
layout::{
|
layout::{
|
||||||
floating::SeatMoveGrabState,
|
|
||||||
tiling::{Direction, FocusResult, MoveResult},
|
tiling::{Direction, FocusResult, MoveResult},
|
||||||
},
|
},
|
||||||
OverviewMode, ResizeDirection, ResizeMode, Workspace,
|
OverviewMode, ResizeDirection, ResizeMode, Workspace,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ use super::{
|
||||||
layout::{floating::ResizeSurfaceGrab, tiling::ResizeForkGrab},
|
layout::{floating::ResizeSurfaceGrab, tiling::ResizeForkGrab},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod moving;
|
||||||
|
pub use self::moving::*;
|
||||||
|
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
pub struct ResizeEdge: u32 {
|
pub struct ResizeEdge: u32 {
|
||||||
const TOP = 0b0001;
|
const TOP = 0b0001;
|
||||||
|
|
@ -103,14 +103,15 @@ impl MoveGrabState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MoveSurfaceGrab {
|
pub struct MoveGrab {
|
||||||
window: CosmicMapped,
|
window: CosmicMapped,
|
||||||
start_data: PointerGrabStartData<State>,
|
start_data: PointerGrabStartData<State>,
|
||||||
seat: Seat<State>,
|
seat: Seat<State>,
|
||||||
outputs: HashSet<Output>,
|
outputs: HashSet<Output>,
|
||||||
|
tiling: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PointerGrab<State> for MoveSurfaceGrab {
|
impl PointerGrab<State> for MoveGrab {
|
||||||
fn motion(
|
fn motion(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
|
|
@ -182,7 +183,7 @@ impl PointerGrab<State> for MoveSurfaceGrab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MoveSurfaceGrab {
|
impl MoveGrab {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
start_data: PointerGrabStartData<State>,
|
start_data: PointerGrabStartData<State>,
|
||||||
window: CosmicMapped,
|
window: CosmicMapped,
|
||||||
|
|
@ -190,7 +191,8 @@ impl MoveSurfaceGrab {
|
||||||
initial_cursor_location: Point<f64, Logical>,
|
initial_cursor_location: Point<f64, Logical>,
|
||||||
initial_window_location: Point<i32, Logical>,
|
initial_window_location: Point<i32, Logical>,
|
||||||
indicator_thickness: u8,
|
indicator_thickness: u8,
|
||||||
) -> MoveSurfaceGrab {
|
was_tiled: bool,
|
||||||
|
) -> MoveGrab {
|
||||||
let output = seat.active_output();
|
let output = seat.active_output();
|
||||||
let mut outputs = HashSet::new();
|
let mut outputs = HashSet::new();
|
||||||
outputs.insert(output.clone());
|
outputs.insert(output.clone());
|
||||||
|
|
@ -198,8 +200,7 @@ impl MoveSurfaceGrab {
|
||||||
|
|
||||||
let grab_state = MoveGrabState {
|
let grab_state = MoveGrabState {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
window_offset: dbg!(initial_window_location)
|
window_offset: initial_window_location - initial_cursor_location.to_i32_round(),
|
||||||
- dbg!(initial_cursor_location.to_i32_round()),
|
|
||||||
indicator_thickness,
|
indicator_thickness,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -209,14 +210,19 @@ impl MoveSurfaceGrab {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.borrow_mut() = Some(grab_state);
|
.borrow_mut() = Some(grab_state);
|
||||||
|
|
||||||
MoveSurfaceGrab {
|
MoveGrab {
|
||||||
window,
|
window,
|
||||||
start_data,
|
start_data,
|
||||||
seat: seat.clone(),
|
seat: seat.clone(),
|
||||||
outputs,
|
outputs,
|
||||||
|
tiling: was_tiled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_tiling_grab(&self) -> bool {
|
||||||
|
self.tiling
|
||||||
|
}
|
||||||
|
|
||||||
fn ungrab(
|
fn ungrab(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State,
|
state: &mut State,
|
||||||
|
|
@ -239,6 +245,9 @@ impl MoveSurfaceGrab {
|
||||||
+ grab_state.window_offset;
|
+ grab_state.window_offset;
|
||||||
|
|
||||||
let workspace_handle = state.common.shell.active_space(&output).handle;
|
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() {
|
for (window, _) in grab_state.window.windows() {
|
||||||
state
|
state
|
||||||
.common
|
.common
|
||||||
|
|
@ -252,29 +261,40 @@ impl MoveSurfaceGrab {
|
||||||
.toplevel_enter_output(&window, &output);
|
.toplevel_enter_output(&window, &output);
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset = state
|
if self.tiling {
|
||||||
.common
|
Some(
|
||||||
.shell
|
state
|
||||||
.active_space(&output)
|
.common
|
||||||
.floating_layer
|
.shell
|
||||||
.space
|
.active_space_mut(&output)
|
||||||
.output_geometry(&output)
|
.tiling_layer
|
||||||
.unwrap()
|
.drop_window(grab_state.window, &output, handle.current_location()),
|
||||||
.loc;
|
)
|
||||||
grab_state.window.set_geometry(Rectangle::from_loc_and_size(
|
} else {
|
||||||
window_location + offset,
|
let offset = state
|
||||||
grab_state.window.geometry().size,
|
.common
|
||||||
));
|
.shell
|
||||||
state
|
.active_space(&output)
|
||||||
.common
|
.floating_layer
|
||||||
.shell
|
.space
|
||||||
.active_space_mut(&output)
|
.output_geometry(&output)
|
||||||
.floating_layer
|
.unwrap()
|
||||||
.map_internal(grab_state.window, &output, Some(window_location + offset));
|
.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 pointer_pos = handle.current_location();
|
||||||
let relative_pos = state.common.shell.map_global_to_space(pointer_pos, &output);
|
let relative_pos = state.common.shell.map_global_to_space(pointer_pos, &output);
|
||||||
Some(window_location + offset + (pointer_pos - relative_pos).to_i32_round())
|
Some(window_location + offset + (pointer_pos - relative_pos).to_i32_round())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
mod moving;
|
|
||||||
mod resize;
|
mod resize;
|
||||||
|
|
||||||
pub use self::moving::*;
|
|
||||||
pub use self::resize::*;
|
pub use self::resize::*;
|
||||||
|
|
|
||||||
3
src/shell/layout/tiling/grabs/mod.rs
Normal file
3
src/shell/layout/tiling/grabs/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
mod resize;
|
||||||
|
|
||||||
|
pub use self::resize::*;
|
||||||
|
|
@ -19,7 +19,7 @@ use smithay::{
|
||||||
utils::{IsAlive, Logical, Point},
|
utils::{IsAlive, Logical, Point},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{Data, TilingLayout};
|
use super::super::{Data, TilingLayout};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ResizeForkTarget {
|
pub struct ResizeForkTarget {
|
||||||
|
|
@ -4,8 +4,9 @@ use crate::{
|
||||||
BackdropShader, GlMultiError, GlMultiFrame, GlMultiRenderer,
|
BackdropShader, GlMultiError, GlMultiFrame, GlMultiRenderer,
|
||||||
},
|
},
|
||||||
shell::{
|
shell::{
|
||||||
|
grabs::MoveGrab,
|
||||||
layout::{
|
layout::{
|
||||||
floating::{FloatingLayout, MoveSurfaceGrab},
|
floating::FloatingLayout,
|
||||||
tiling::{TilingLayout, ANIMATION_DURATION},
|
tiling::{TilingLayout, ANIMATION_DURATION},
|
||||||
},
|
},
|
||||||
OverviewMode,
|
OverviewMode,
|
||||||
|
|
@ -363,7 +364,7 @@ impl Workspace {
|
||||||
output: &Output,
|
output: &Output,
|
||||||
start_data: PointerGrabStartData<State>,
|
start_data: PointerGrabStartData<State>,
|
||||||
indicator_thickness: u8,
|
indicator_thickness: u8,
|
||||||
) -> Option<MoveSurfaceGrab> {
|
) -> Option<MoveGrab> {
|
||||||
let pointer = seat.get_pointer().unwrap();
|
let pointer = seat.get_pointer().unwrap();
|
||||||
let pos = pointer.current_location();
|
let pos = pointer.current_location();
|
||||||
|
|
||||||
|
|
@ -382,21 +383,18 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
let was_floating = self.floating_layer.unmap(&mapped);
|
let was_floating = self.floating_layer.unmap(&mapped);
|
||||||
//let was_tiled = self.tiling_layer.unmap(&mapped);
|
let was_tiled = self.tiling_layer.unmap_as_placeholder(&mapped);
|
||||||
//assert!(was_floating != was_tiled);
|
assert!(was_floating != was_tiled.is_some());
|
||||||
|
|
||||||
if was_floating {
|
Some(MoveGrab::new(
|
||||||
Some(MoveSurfaceGrab::new(
|
start_data,
|
||||||
start_data,
|
mapped,
|
||||||
mapped,
|
seat,
|
||||||
seat,
|
pos,
|
||||||
pos,
|
initial_window_location,
|
||||||
initial_window_location,
|
indicator_thickness,
|
||||||
indicator_thickness,
|
was_tiled.is_some(),
|
||||||
))
|
))
|
||||||
} else {
|
|
||||||
None // TODO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_tiling(&mut self, seat: &Seat<State>) {
|
pub fn toggle_tiling(&mut self, seat: &Seat<State>) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
x11::X11State,
|
x11::X11State,
|
||||||
},
|
},
|
||||||
config::{Config, OutputConfig},
|
config::{Config, OutputConfig},
|
||||||
shell::{layout::floating::SeatMoveGrabState, Shell},
|
shell::{grabs::SeatMoveGrabState, Shell},
|
||||||
utils::prelude::*,
|
utils::prelude::*,
|
||||||
wayland::protocols::{
|
wayland::protocols::{
|
||||||
drm::WlDrmState,
|
drm::WlDrmState,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue