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,
|
MoveWindowToTiling,
|
||||||
#[knuffel(skip)]
|
#[knuffel(skip)]
|
||||||
MoveWindowToTilingById(u64),
|
MoveWindowToTilingById(u64),
|
||||||
|
FocusFloating,
|
||||||
|
FocusTiling,
|
||||||
SwitchFocusBetweenFloatingAndTiling,
|
SwitchFocusBetweenFloatingAndTiling,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1427,6 +1429,8 @@ impl From<niri_ipc::Action> for Action {
|
|||||||
niri_ipc::Action::MoveWindowToTiling { id: Some(id) } => {
|
niri_ipc::Action::MoveWindowToTiling { id: Some(id) } => {
|
||||||
Self::MoveWindowToTilingById(id)
|
Self::MoveWindowToTilingById(id)
|
||||||
}
|
}
|
||||||
|
niri_ipc::Action::FocusFloating {} => Self::FocusFloating,
|
||||||
|
niri_ipc::Action::FocusTiling {} => Self::FocusTiling,
|
||||||
niri_ipc::Action::SwitchFocusBetweenFloatingAndTiling {} => {
|
niri_ipc::Action::SwitchFocusBetweenFloatingAndTiling {} => {
|
||||||
Self::SwitchFocusBetweenFloatingAndTiling
|
Self::SwitchFocusBetweenFloatingAndTiling
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -470,6 +470,10 @@ pub enum Action {
|
|||||||
#[cfg_attr(feature = "clap", arg(long))]
|
#[cfg_attr(feature = "clap", arg(long))]
|
||||||
id: Option<u64>,
|
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.
|
/// Toggles the focus between the floating and the tiling layout.
|
||||||
SwitchFocusBetweenFloatingAndTiling {},
|
SwitchFocusBetweenFloatingAndTiling {},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1346,6 +1346,16 @@ impl State {
|
|||||||
self.niri.queue_redraw_all();
|
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 => {
|
Action::SwitchFocusBetweenFloatingAndTiling => {
|
||||||
self.niri.layout.switch_focus_floating_tiling();
|
self.niri.layout.switch_focus_floating_tiling();
|
||||||
// FIXME: granular
|
// FIXME: granular
|
||||||
|
|||||||
@@ -2729,6 +2729,20 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
workspace.set_window_floating(window, floating);
|
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) {
|
pub fn switch_focus_floating_tiling(&mut self) {
|
||||||
let Some(workspace) = self.active_workspace_mut() else {
|
let Some(workspace) = self.active_workspace_mut() else {
|
||||||
return;
|
return;
|
||||||
@@ -4393,6 +4407,8 @@ mod tests {
|
|||||||
id: Option<usize>,
|
id: Option<usize>,
|
||||||
floating: bool,
|
floating: bool,
|
||||||
},
|
},
|
||||||
|
FocusFloating,
|
||||||
|
FocusTiling,
|
||||||
SwitchFocusFloatingTiling,
|
SwitchFocusFloatingTiling,
|
||||||
SetParent {
|
SetParent {
|
||||||
#[proptest(strategy = "1..=5usize")]
|
#[proptest(strategy = "1..=5usize")]
|
||||||
@@ -4909,6 +4925,12 @@ mod tests {
|
|||||||
let id = id.filter(|id| layout.has_window(id));
|
let id = id.filter(|id| layout.has_window(id));
|
||||||
layout.set_window_floating(id.as_ref(), floating);
|
layout.set_window_floating(id.as_ref(), floating);
|
||||||
}
|
}
|
||||||
|
Op::FocusFloating => {
|
||||||
|
layout.focus_floating();
|
||||||
|
}
|
||||||
|
Op::FocusTiling => {
|
||||||
|
layout.focus_tiling();
|
||||||
|
}
|
||||||
Op::SwitchFocusFloatingTiling => {
|
Op::SwitchFocusFloatingTiling => {
|
||||||
layout.switch_focus_floating_tiling();
|
layout.switch_focus_floating_tiling();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1157,6 +1157,18 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
self.toggle_window_floating(id);
|
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) {
|
pub fn switch_focus_floating_tiling(&mut self) {
|
||||||
if self.floating.is_empty() {
|
if self.floating.is_empty() {
|
||||||
// If floating is empty, keep focus on scrolling.
|
// If floating is empty, keep focus on scrolling.
|
||||||
|
|||||||
Reference in New Issue
Block a user