From 8c52fc6eb1b2d4abafd16070ddbe18b0defcc2d1 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 28 Jun 2023 19:20:06 +0200 Subject: [PATCH] input: Add resize mode actions --- src/config/mod.rs | 5 ++++- src/input/mod.rs | 47 +++++++++++++++++++++++++++++------------------ src/shell/mod.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 20 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 87e82348..c75dabe4 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::{ - shell::{focus::FocusDirection, layout::tiling::Direction, Shell, WorkspaceAmount}, + shell::{ + focus::FocusDirection, layout::tiling::Direction, ResizeDirection, Shell, WorkspaceAmount, + }, state::{BackendData, Data, State}, wayland::protocols::output_configuration::OutputConfigurationState, }; @@ -1015,6 +1017,7 @@ pub enum Action { ToggleTiling, ToggleWindowFloating, + Resizing(ResizeDirection), Maximize, Spawn(String), } diff --git a/src/input/mod.rs b/src/input/mod.rs index 89de945f..71804b70 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::{ - config::{Action, Config, KeyModifiers, WorkspaceLayout}, + config::{Action, Config, KeyPattern, WorkspaceLayout}, shell::{ focus::{target::PointerFocusTarget, FocusDirection}, layout::{ @@ -219,7 +219,7 @@ impl State { let serial = SERIAL_COUNTER.next_serial(); let time = Event::time_msec(&event); - if let Some((action, mods)) = seat + if let Some((action, pattern)) = seat .get_keyboard() .unwrap() .input( @@ -297,7 +297,7 @@ impl State { .add(&handle); return FilterResult::Intercept(Some(( action.clone(), - binding.modifiers.clone(), + binding.clone(), ))); } } @@ -308,7 +308,7 @@ impl State { ) .flatten() { - self.handle_action(action, seat, serial, time, mods, None) + self.handle_action(action, seat, serial, time, pattern, None) } break; } @@ -659,7 +659,7 @@ impl State { seat: &Seat, serial: Serial, time: u32, - mods: KeyModifiers, + pattern: KeyPattern, direction: Option, ) { match action { @@ -717,7 +717,7 @@ impl State { .activate(¤t_output, workspace) .is_err() { - self.handle_action(Action::NextOutput, seat, serial, time, mods, direction); + self.handle_action(Action::NextOutput, seat, serial, time, pattern, direction); } } Action::PreviousWorkspace => { @@ -735,7 +735,14 @@ impl State { .activate(¤t_output, workspace) .is_err() { - self.handle_action(Action::PreviousOutput, seat, serial, time, mods, direction); + self.handle_action( + Action::PreviousOutput, + seat, + serial, + time, + pattern, + direction, + ); } } Action::LastWorkspace => { @@ -793,7 +800,7 @@ impl State { seat, serial, time, - mods, + pattern, direction, ) } @@ -827,7 +834,7 @@ impl State { seat, serial, time, - mods, + pattern, direction, ) } @@ -998,7 +1005,7 @@ impl State { seat, serial, time, - mods, + pattern, direction, ), (FocusDirection::Right, WorkspaceLayout::Horizontal) @@ -1008,7 +1015,7 @@ impl State { seat, serial, time, - mods, + pattern, direction, ), (FocusDirection::Left, WorkspaceLayout::Vertical) @@ -1018,7 +1025,7 @@ impl State { seat, serial, time, - mods, + pattern, direction, ), (FocusDirection::Right, WorkspaceLayout::Vertical) @@ -1028,7 +1035,7 @@ impl State { seat, serial, time, - mods, + pattern, direction, ), _ => {} @@ -1057,7 +1064,7 @@ impl State { seat, serial, time, - mods, + pattern, Some(direction), ), (Direction::Right, WorkspaceLayout::Horizontal) @@ -1066,7 +1073,7 @@ impl State { seat, serial, time, - mods, + pattern, Some(direction), ), (Direction::Left, WorkspaceLayout::Vertical) @@ -1075,7 +1082,7 @@ impl State { seat, serial, time, - mods, + pattern, Some(direction), ), (Direction::Right, WorkspaceLayout::Vertical) @@ -1084,7 +1091,7 @@ impl State { seat, serial, time, - mods, + pattern, Some(direction), ), } @@ -1095,7 +1102,7 @@ impl State { 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(Some(mods)); + self.common.shell.set_overview_mode(Some(pattern.modifiers)); } } } @@ -1110,6 +1117,10 @@ impl State { workspace.maximize_toggle(&window, ¤t_output); } } + Action::Resizing(direction) => self + .common + .shell + .set_resize_mode(Some((pattern, direction))), Action::ToggleOrientation => { let output = seat.active_output(); let workspace = self.common.shell.active_space_mut(&output); diff --git a/src/shell/mod.rs b/src/shell/mod.rs index bacada6f..5b34487c 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -34,7 +34,7 @@ use smithay::{ }; use crate::{ - config::{Config, KeyModifiers, OutputConfig, WorkspaceMode as ConfigMode}, + config::{Config, KeyModifiers, KeyPattern, OutputConfig, WorkspaceMode as ConfigMode}, utils::prelude::*, wayland::protocols::{ toplevel_info::ToplevelInfoState, @@ -70,6 +70,19 @@ pub enum OverviewMode { Ended(Instant), } +#[derive(Debug, Clone, Copy, serde::Deserialize, PartialEq, Eq, Hash)] +pub enum ResizeDirection { + Inwards, + Outwards, +} + +#[derive(Debug, Clone)] +pub enum ResizeMode { + None, + Started(KeyPattern, Instant, ResizeDirection), + Ended(Instant, ResizeDirection), +} + pub struct Shell { pub popups: PopupManager, pub outputs: Vec, @@ -88,6 +101,7 @@ pub struct Shell { gaps: (u8, u8), overview_mode: OverviewMode, + resize_mode: ResizeMode, } #[derive(Debug)] @@ -546,6 +560,7 @@ impl Shell { gaps: config.static_conf.gaps, overview_mode: OverviewMode::None, + resize_mode: ResizeMode::None, } } @@ -1112,6 +1127,7 @@ impl Shell { sets.values().any(|set| set.previously_active.is_some()) } }) || !matches!(self.overview_mode, OverviewMode::None) + || !matches!(self.resize_mode, ResizeMode::None) || self .workspaces .spaces() @@ -1146,6 +1162,31 @@ impl Shell { self.overview_mode.clone() } + pub fn set_resize_mode(&mut self, enabled: Option<(KeyPattern, ResizeDirection)>) { + if let Some((pattern, direction)) = enabled { + if let ResizeMode::Started(old_pattern, _, old_direction) = &mut self.resize_mode { + *old_pattern = pattern; + *old_direction = direction; + } else { + self.resize_mode = ResizeMode::Started(pattern, Instant::now(), direction); + } + } else { + if let ResizeMode::Started(_, _, direction) = &self.resize_mode { + self.resize_mode = ResizeMode::Ended(Instant::now(), *direction); + } + } + } + + pub fn resize_mode(&mut self) -> ResizeMode { + if let ResizeMode::Ended(timestamp, _) = self.resize_mode { + if Instant::now().duration_since(timestamp) > ANIMATION_DURATION { + self.resize_mode = ResizeMode::None; + } + } + + self.resize_mode.clone() + } + pub fn refresh(&mut self) { #[cfg(feature = "debug")] puffin::profile_function!();