mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Add SwitchPresetWindowHeight by id
This commit is contained in:
@@ -1159,6 +1159,8 @@ pub enum Action {
|
|||||||
ResetWindowHeightById(u64),
|
ResetWindowHeightById(u64),
|
||||||
SwitchPresetColumnWidth,
|
SwitchPresetColumnWidth,
|
||||||
SwitchPresetWindowHeight,
|
SwitchPresetWindowHeight,
|
||||||
|
#[knuffel(skip)]
|
||||||
|
SwitchPresetWindowHeightById(u64),
|
||||||
MaximizeColumn,
|
MaximizeColumn,
|
||||||
SetColumnWidth(#[knuffel(argument, str)] SizeChange),
|
SetColumnWidth(#[knuffel(argument, str)] SizeChange),
|
||||||
SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget),
|
SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget),
|
||||||
@@ -1270,7 +1272,12 @@ impl From<niri_ipc::Action> for Action {
|
|||||||
niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight,
|
niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight,
|
||||||
niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id),
|
niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id),
|
||||||
niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth,
|
niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth,
|
||||||
niri_ipc::Action::SwitchPresetWindowHeight {} => Self::SwitchPresetWindowHeight,
|
niri_ipc::Action::SwitchPresetWindowHeight { id: None } => {
|
||||||
|
Self::SwitchPresetWindowHeight
|
||||||
|
}
|
||||||
|
niri_ipc::Action::SwitchPresetWindowHeight { id: Some(id) } => {
|
||||||
|
Self::SwitchPresetWindowHeightById(id)
|
||||||
|
}
|
||||||
niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn,
|
niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn,
|
||||||
niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change),
|
niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change),
|
||||||
niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout),
|
niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout),
|
||||||
|
|||||||
+7
-1
@@ -351,7 +351,13 @@ pub enum Action {
|
|||||||
/// Switch between preset column widths.
|
/// Switch between preset column widths.
|
||||||
SwitchPresetColumnWidth {},
|
SwitchPresetColumnWidth {},
|
||||||
/// Switch between preset window heights.
|
/// Switch between preset window heights.
|
||||||
SwitchPresetWindowHeight {},
|
SwitchPresetWindowHeight {
|
||||||
|
/// Id of the window whose height to switch.
|
||||||
|
///
|
||||||
|
/// If `None`, uses the focused window.
|
||||||
|
#[cfg_attr(feature = "clap", arg(long))]
|
||||||
|
id: Option<u64>,
|
||||||
|
},
|
||||||
/// Toggle the maximized state of the focused column.
|
/// Toggle the maximized state of the focused column.
|
||||||
MaximizeColumn {},
|
MaximizeColumn {},
|
||||||
/// Change the width of the focused column.
|
/// Change the width of the focused column.
|
||||||
|
|||||||
+8
-1
@@ -1036,7 +1036,14 @@ impl State {
|
|||||||
self.niri.layout.toggle_width();
|
self.niri.layout.toggle_width();
|
||||||
}
|
}
|
||||||
Action::SwitchPresetWindowHeight => {
|
Action::SwitchPresetWindowHeight => {
|
||||||
self.niri.layout.toggle_window_height();
|
self.niri.layout.toggle_window_height(None);
|
||||||
|
}
|
||||||
|
Action::SwitchPresetWindowHeightById(id) => {
|
||||||
|
let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
|
||||||
|
let window = window.map(|(_, m)| m.window.clone());
|
||||||
|
if let Some(window) = window {
|
||||||
|
self.niri.layout.toggle_window_height(Some(&window));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Action::CenterColumn => {
|
Action::CenterColumn => {
|
||||||
self.niri.layout.center_column();
|
self.niri.layout.center_column();
|
||||||
|
|||||||
+23
-7
@@ -1951,11 +1951,21 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
monitor.toggle_width();
|
monitor.toggle_width();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_window_height(&mut self) {
|
pub fn toggle_window_height(&mut self, window: Option<&W::Id>) {
|
||||||
let Some(monitor) = self.active_monitor() else {
|
let workspace = if let Some(window) = window {
|
||||||
|
Some(
|
||||||
|
self.workspaces_mut()
|
||||||
|
.find(|ws| ws.has_window(window))
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
self.active_workspace_mut()
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(workspace) = workspace else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
monitor.toggle_window_height();
|
workspace.toggle_window_height(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_full_width(&mut self) {
|
pub fn toggle_full_width(&mut self) {
|
||||||
@@ -3048,7 +3058,10 @@ mod tests {
|
|||||||
},
|
},
|
||||||
MoveColumnToOutput(#[proptest(strategy = "1..=5u8")] u8),
|
MoveColumnToOutput(#[proptest(strategy = "1..=5u8")] u8),
|
||||||
SwitchPresetColumnWidth,
|
SwitchPresetColumnWidth,
|
||||||
SwitchPresetWindowHeight,
|
SwitchPresetWindowHeight {
|
||||||
|
#[proptest(strategy = "proptest::option::of(1..=5usize)")]
|
||||||
|
id: Option<usize>,
|
||||||
|
},
|
||||||
MaximizeColumn,
|
MaximizeColumn,
|
||||||
SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
|
SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
|
||||||
SetWindowHeight {
|
SetWindowHeight {
|
||||||
@@ -3475,7 +3488,10 @@ mod tests {
|
|||||||
Op::MoveWorkspaceDown => layout.move_workspace_down(),
|
Op::MoveWorkspaceDown => layout.move_workspace_down(),
|
||||||
Op::MoveWorkspaceUp => layout.move_workspace_up(),
|
Op::MoveWorkspaceUp => layout.move_workspace_up(),
|
||||||
Op::SwitchPresetColumnWidth => layout.toggle_width(),
|
Op::SwitchPresetColumnWidth => layout.toggle_width(),
|
||||||
Op::SwitchPresetWindowHeight => layout.toggle_window_height(),
|
Op::SwitchPresetWindowHeight { id } => {
|
||||||
|
let id = id.filter(|id| layout.has_window(id));
|
||||||
|
layout.toggle_window_height(id.as_ref());
|
||||||
|
}
|
||||||
Op::MaximizeColumn => layout.toggle_full_width(),
|
Op::MaximizeColumn => layout.toggle_full_width(),
|
||||||
Op::SetColumnWidth(change) => layout.set_column_width(change),
|
Op::SetColumnWidth(change) => layout.set_column_width(change),
|
||||||
Op::SetWindowHeight { id, change } => {
|
Op::SetWindowHeight { id, change } => {
|
||||||
@@ -4458,8 +4474,8 @@ mod tests {
|
|||||||
min_max_size: Default::default(),
|
min_max_size: Default::default(),
|
||||||
},
|
},
|
||||||
Op::ConsumeOrExpelWindowLeft,
|
Op::ConsumeOrExpelWindowLeft,
|
||||||
Op::SwitchPresetWindowHeight,
|
Op::SwitchPresetWindowHeight { id: None },
|
||||||
Op::SwitchPresetWindowHeight,
|
Op::SwitchPresetWindowHeight { id: None },
|
||||||
];
|
];
|
||||||
for op in ops {
|
for op in ops {
|
||||||
op.apply(&mut layout);
|
op.apply(&mut layout);
|
||||||
|
|||||||
@@ -740,10 +740,6 @@ impl<W: LayoutElement> Monitor<W> {
|
|||||||
self.active_workspace().toggle_width();
|
self.active_workspace().toggle_width();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_window_height(&mut self) {
|
|
||||||
self.active_workspace().toggle_window_height();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn toggle_full_width(&mut self) {
|
pub fn toggle_full_width(&mut self) {
|
||||||
self.active_workspace().toggle_full_width();
|
self.active_workspace().toggle_full_width();
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-3
@@ -2373,13 +2373,26 @@ impl<W: LayoutElement> Workspace<W> {
|
|||||||
cancel_resize_for_column(&mut self.interactive_resize, col);
|
cancel_resize_for_column(&mut self.interactive_resize, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_window_height(&mut self) {
|
pub fn toggle_window_height(&mut self, window: Option<&W::Id>) {
|
||||||
if self.columns.is_empty() {
|
if self.columns.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let col = &mut self.columns[self.active_column_idx];
|
let (col, tile_idx) = if let Some(window) = window {
|
||||||
col.toggle_window_height(None, true);
|
self.columns
|
||||||
|
.iter_mut()
|
||||||
|
.find_map(|col| {
|
||||||
|
col.tiles
|
||||||
|
.iter()
|
||||||
|
.position(|tile| tile.window().id() == window)
|
||||||
|
.map(|tile_idx| (col, Some(tile_idx)))
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
} else {
|
||||||
|
(&mut self.columns[self.active_column_idx], None)
|
||||||
|
};
|
||||||
|
|
||||||
|
col.toggle_window_height(tile_idx, true);
|
||||||
|
|
||||||
cancel_resize_for_column(&mut self.interactive_resize, col);
|
cancel_resize_for_column(&mut self.interactive_resize, col);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user