mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Add focus-floating/tiling actions
This commit is contained in:
@@ -1277,6 +1277,8 @@ pub enum Action {
|
||||
MoveWindowToTiling,
|
||||
#[knuffel(skip)]
|
||||
MoveWindowToTilingById(u64),
|
||||
FocusFloating,
|
||||
FocusTiling,
|
||||
SwitchFocusBetweenFloatingAndTiling,
|
||||
}
|
||||
|
||||
@@ -1427,6 +1429,8 @@ impl From<niri_ipc::Action> for Action {
|
||||
niri_ipc::Action::MoveWindowToTiling { id: Some(id) } => {
|
||||
Self::MoveWindowToTilingById(id)
|
||||
}
|
||||
niri_ipc::Action::FocusFloating {} => Self::FocusFloating,
|
||||
niri_ipc::Action::FocusTiling {} => Self::FocusTiling,
|
||||
niri_ipc::Action::SwitchFocusBetweenFloatingAndTiling {} => {
|
||||
Self::SwitchFocusBetweenFloatingAndTiling
|
||||
}
|
||||
|
||||
@@ -470,6 +470,10 @@ pub enum Action {
|
||||
#[cfg_attr(feature = "clap", arg(long))]
|
||||
id: Option<u64>,
|
||||
},
|
||||
/// Switches focus to the floating layout.
|
||||
FocusFloating {},
|
||||
/// Switches focus to the tiling layout.
|
||||
FocusTiling {},
|
||||
/// Toggles the focus between the floating and the tiling layout.
|
||||
SwitchFocusBetweenFloatingAndTiling {},
|
||||
}
|
||||
|
||||
@@ -1346,6 +1346,16 @@ impl State {
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
}
|
||||
Action::FocusFloating => {
|
||||
self.niri.layout.focus_floating();
|
||||
// FIXME: granular
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
Action::FocusTiling => {
|
||||
self.niri.layout.focus_tiling();
|
||||
// FIXME: granular
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
Action::SwitchFocusBetweenFloatingAndTiling => {
|
||||
self.niri.layout.switch_focus_floating_tiling();
|
||||
// FIXME: granular
|
||||
|
||||
@@ -2729,6 +2729,20 @@ impl<W: LayoutElement> Layout<W> {
|
||||
workspace.set_window_floating(window, floating);
|
||||
}
|
||||
|
||||
pub fn focus_floating(&mut self) {
|
||||
let Some(workspace) = self.active_workspace_mut() else {
|
||||
return;
|
||||
};
|
||||
workspace.focus_floating();
|
||||
}
|
||||
|
||||
pub fn focus_tiling(&mut self) {
|
||||
let Some(workspace) = self.active_workspace_mut() else {
|
||||
return;
|
||||
};
|
||||
workspace.focus_tiling();
|
||||
}
|
||||
|
||||
pub fn switch_focus_floating_tiling(&mut self) {
|
||||
let Some(workspace) = self.active_workspace_mut() else {
|
||||
return;
|
||||
@@ -4393,6 +4407,8 @@ mod tests {
|
||||
id: Option<usize>,
|
||||
floating: bool,
|
||||
},
|
||||
FocusFloating,
|
||||
FocusTiling,
|
||||
SwitchFocusFloatingTiling,
|
||||
SetParent {
|
||||
#[proptest(strategy = "1..=5usize")]
|
||||
@@ -4909,6 +4925,12 @@ mod tests {
|
||||
let id = id.filter(|id| layout.has_window(id));
|
||||
layout.set_window_floating(id.as_ref(), floating);
|
||||
}
|
||||
Op::FocusFloating => {
|
||||
layout.focus_floating();
|
||||
}
|
||||
Op::FocusTiling => {
|
||||
layout.focus_tiling();
|
||||
}
|
||||
Op::SwitchFocusFloatingTiling => {
|
||||
layout.switch_focus_floating_tiling();
|
||||
}
|
||||
|
||||
@@ -1157,6 +1157,18 @@ impl<W: LayoutElement> Workspace<W> {
|
||||
self.toggle_window_floating(id);
|
||||
}
|
||||
|
||||
pub fn focus_floating(&mut self) {
|
||||
if !self.floating_is_active.get() {
|
||||
self.switch_focus_floating_tiling();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn focus_tiling(&mut self) {
|
||||
if self.floating_is_active.get() {
|
||||
self.switch_focus_floating_tiling();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn switch_focus_floating_tiling(&mut self) {
|
||||
if self.floating.is_empty() {
|
||||
// If floating is empty, keep focus on scrolling.
|
||||
|
||||
Reference in New Issue
Block a user