Skip to content

Commit

Permalink
shell: Have Move-shortcut for floating layer and fullscreen windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Sep 20, 2023
1 parent 3d10ca6 commit 4709a1d
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 69 deletions.
4 changes: 1 addition & 3 deletions src/config/key_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only

use crate::shell::{
focus::FocusDirection, grabs::ResizeEdge, layout::tiling::Direction, ResizeDirection,
};
use crate::shell::{focus::FocusDirection, grabs::ResizeEdge, Direction, ResizeDirection};
use serde::Deserialize;
use smithay::{
backend::input::KeyState,
Expand Down
9 changes: 5 additions & 4 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use crate::{
shell::{
focus::{target::PointerFocusTarget, FocusDirection},
grabs::{ResizeEdge, SeatMoveGrabState},
layout::tiling::{Direction, MoveResult, SwapWindowGrab, TilingLayout},
FocusResult, OverviewMode, ResizeDirection, ResizeMode, Trigger, Workspace,
layout::tiling::{SwapWindowGrab, TilingLayout},
Direction, FocusResult, MoveResult, OverviewMode, ResizeDirection, ResizeMode, Trigger,
Workspace,
},
state::Common,
utils::prelude::*,
Expand Down Expand Up @@ -1373,7 +1374,7 @@ impl State {
return; // TODO, is this what we want? How do we indicate the switch?
}

match workspace.tiling_layer.move_current_node(direction, seat) {
match workspace.move_current_element(direction, seat) {
MoveResult::MoveFurther(_move_further) => {
match (direction, self.common.config.static_conf.workspace_layout) {
(Direction::Left, WorkspaceLayout::Horizontal)
Expand Down Expand Up @@ -1417,7 +1418,7 @@ impl State {
MoveResult::ShiftFocus(shift) => {
Common::set_focus(self, Some(&shift), seat, None);
}
MoveResult::Done => {
_ => {
if let Some(focused_window) = workspace.focus_stack.get(seat).last() {
if workspace.is_tiled(focused_window) {
self.common.shell.set_overview_mode(
Expand Down
6 changes: 2 additions & 4 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ use tracing::debug;

use super::{
focus::FocusDirection,
layout::{
floating::ResizeState,
tiling::{Direction, NodeDesc},
},
layout::{floating::ResizeState, tiling::NodeDesc},
Direction,
};

space_elements! {
Expand Down
5 changes: 1 addition & 4 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use super::{CosmicMapped, CosmicSurface, CosmicWindow};
use crate::{
shell::{
focus::FocusDirection,
grabs::MoveGrab,
layout::tiling::{Direction, NodeDesc},
Shell, Trigger,
focus::FocusDirection, grabs::MoveGrab, layout::tiling::NodeDesc, Direction, Shell, Trigger,
},
state::State,
utils::iced::{IcedElement, Program},
Expand Down
18 changes: 14 additions & 4 deletions src/shell/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,22 @@ impl Shell {
serial: Option<Serial>,
) {
// update FocusStack and notify layouts about new focus (if any window)
if let Some(KeyboardFocusTarget::Element(mapped)) = target {
if let Some(workspace) = state.common.shell.space_for_mut(mapped) {
let element = match target {
Some(KeyboardFocusTarget::Element(mapped)) => Some(mapped.clone()),
Some(KeyboardFocusTarget::Fullscreen(window)) => state
.common
.shell
.element_for_surface(&window.surface())
.cloned(),
_ => None,
};

if let Some(mapped) = element {
if let Some(workspace) = state.common.shell.space_for_mut(&mapped) {
let mut focus_stack = workspace.focus_stack.get_mut(active_seat);
if Some(mapped) != focus_stack.last() {
if Some(&mapped) != focus_stack.last() {
trace!(?mapped, "Focusing window.");
focus_stack.append(mapped);
focus_stack.append(&mapped);
// also remove popup grabs, if we are switching focus
if let Some(mut popup_grab) = active_seat
.user_data()
Expand Down
68 changes: 62 additions & 6 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ use smithay::{
};
use std::collections::HashMap;

use crate::shell::focus::FocusDirection;
use crate::shell::FocusResult;
use crate::{
backend::render::{element::AsGlowRenderer, IndicatorShader, Key, Usage},
shell::{
element::{
resize_indicator::ResizeIndicator, stack::CosmicStackRenderElement,
window::CosmicWindowRenderElement, CosmicMapped, CosmicMappedRenderElement,
resize_indicator::ResizeIndicator,
stack::{CosmicStackRenderElement, MoveResult as StackMoveResult},
window::CosmicWindowRenderElement,
CosmicMapped, CosmicMappedRenderElement, CosmicWindow,
},
focus::target::KeyboardFocusTarget,
focus::{target::KeyboardFocusTarget, FocusDirection},
grabs::ResizeEdge,
CosmicSurface, ResizeDirection, ResizeMode,
CosmicSurface, Direction, FocusResult, MoveResult, ResizeDirection, ResizeMode,
},
state::State,
utils::prelude::*,
Expand Down Expand Up @@ -423,6 +423,62 @@ impl FloatingLayout {
.unwrap_or(FocusResult::None)
}

pub fn move_current_element<'a>(
&mut self,
direction: Direction,
seat: &Seat<State>,
) -> MoveResult {
let Some(target) = seat.get_keyboard().unwrap().current_focus() else {
return MoveResult::None
};

let Some(focused) = (match target {
KeyboardFocusTarget::Popup(popup) => {
let Some(toplevel_surface) = (match popup {
PopupKind::Xdg(xdg) => get_popup_toplevel(&xdg),
}) else {
return MoveResult::None
};
self.space.elements().find(|elem| elem.wl_surface().as_ref() == Some(&toplevel_surface))
},
KeyboardFocusTarget::Element(elem) => self.space.elements().find(|e| *e == &elem),
_ => None,
}) else {
return MoveResult::None
};

match focused.handle_move(direction) {
StackMoveResult::Handled => return MoveResult::Done,
StackMoveResult::MoveOut(surface, loop_handle) => {
let mapped: CosmicMapped = CosmicWindow::new(surface, loop_handle).into();
let output = seat.active_output();
let pos = self.space.element_geometry(focused).unwrap().loc
+ match direction {
Direction::Up => Point::from((5, -10)),
Direction::Down => Point::from((5, 10)),
Direction::Left => Point::from((-10, 5)),
Direction::Right => Point::from((10, 5)),
};
let position = self
.space
.output_geometry(&output)
.unwrap()
.overlaps({
let mut geo = mapped.geometry();
geo.loc += pos;
geo
})
.then_some(pos);

self.map_internal(mapped.clone(), &output, position);
return MoveResult::ShiftFocus(KeyboardFocusTarget::Element(mapped));
}
StackMoveResult::Default => {}
};

MoveResult::MoveFurther(KeyboardFocusTarget::Element(focused.clone()))
}

pub fn mapped(&self) -> impl Iterator<Item = &CosmicMapped> {
self.space.elements().rev()
}
Expand Down
35 changes: 4 additions & 31 deletions src/shell/layout/tiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{
},
grabs::ResizeEdge,
layout::Orientation,
CosmicSurface, FocusResult, OutputNotMapped, OverviewMode, ResizeDirection, ResizeMode,
Trigger,
CosmicSurface, Direction, FocusResult, MoveResult, OutputNotMapped, OverviewMode,
ResizeDirection, ResizeMode, Trigger,
},
utils::{prelude::*, tween::EaseRectangle},
wayland::{
Expand Down Expand Up @@ -112,33 +112,6 @@ pub struct NodeDesc {
pub stack_window: Option<CosmicSurface>,
}

#[derive(Debug, serde::Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
Left,
Right,
Up,
Down,
}

impl std::ops::Not for Direction {
type Output = Self;
fn not(self) -> Self::Output {
match self {
Direction::Left => Direction::Right,
Direction::Right => Direction::Left,
Direction::Up => Direction::Down,
Direction::Down => Direction::Up,
}
}
}

#[derive(Debug, Clone, PartialEq)]
pub enum MoveResult {
Done,
MoveFurther(KeyboardFocusTarget),
ShiftFocus(KeyboardFocusTarget),
}

#[derive(Debug, Clone, PartialEq)]
enum TargetZone {
Initial,
Expand Down Expand Up @@ -1454,12 +1427,12 @@ impl TilingLayout {
let mut tree = queue.trees.back().unwrap().0.copy_clone();

let Some(target) = seat.get_keyboard().unwrap().current_focus() else {
return MoveResult::Done;
return MoveResult::None;
};
let Some((node_id, data)) =
TilingLayout::currently_focused_node(&mut tree, &seat.active_output(), target)
else {
return MoveResult::Done;
return MoveResult::None;
};

// stacks may handle movement internally
Expand Down
40 changes: 37 additions & 3 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use self::{
grabs::ResizeEdge,
layout::{
floating::{FloatingLayout, ResizeState},
tiling::{Direction, NodeDesc, TilingLayout},
tiling::{NodeDesc, TilingLayout},
},
};

Expand Down Expand Up @@ -1500,13 +1500,47 @@ impl Shell {
.get_mut(to_idx, to_output)
.unwrap(); // checked above
let focus_stack = to_workspace.focus_stack.get(&seat);
if window_state == ManagedState::Floating {
if window_state.layer == ManagedLayer::Floating {
to_workspace.floating_layer.map(mapped.clone(), &seat, None);
} else {
to_workspace
.tiling_layer
.map(mapped.clone(), &seat, focus_stack.iter(), direction);
}
let focus_target = match window_state.was_fullscreen {
Some(true) => {
to_workspace.fullscreen_request(
&mapped.active_window(),
&to_output,
state.common.event_loop_handle.clone(),
);
KeyboardFocusTarget::from(
to_workspace
.fullscreen
.get(to_output)
.unwrap()
.window
.clone(),
)
}
Some(false) => {
to_workspace.maximize_request(
&mapped.active_window(),
&to_output,
state.common.event_loop_handle.clone(),
);
KeyboardFocusTarget::from(
to_workspace
.fullscreen
.get(to_output)
.unwrap()
.window
.clone(),
)
}
None => KeyboardFocusTarget::from(mapped.clone()),
};

for (toplevel, _) in mapped.windows() {
if from_output != to_output {
state
Expand All @@ -1531,7 +1565,7 @@ impl Shell {
}

if follow {
Common::set_focus(state, Some(&KeyboardFocusTarget::from(mapped)), &seat, None);
Common::set_focus(state, Some(&focus_target), &seat, None);
}
Ok(new_pos)
}
Expand Down
Loading

0 comments on commit 4709a1d

Please sign in to comment.