forge
Explore
Log in

Don't you dare go Hollow

Add set-window-width action

Browse files at this commit

8b0cb0bb57112bd15bc7ac04e6952d857dadcbcaIvan MolodetskikhParent: a24a6e4
niri-config/src/lib.rsmodified+11 -0
@@ -1241,6 +1241,12 @@ pub enum Action {
1241 MoveColumnToMonitorRight,1241 MoveColumnToMonitorRight,
1242 MoveColumnToMonitorDown,1242 MoveColumnToMonitorDown,
1243 MoveColumnToMonitorUp,1243 MoveColumnToMonitorUp,
1244+ SetWindowWidth(#[knuffel(argument, str)] SizeChange),
1245+ #[knuffel(skip)]
1246+ SetWindowWidthById {
1247+ id: u64,
1248+ change: SizeChange,
1249+ },
1244 SetWindowHeight(#[knuffel(argument, str)] SizeChange),1250 SetWindowHeight(#[knuffel(argument, str)] SizeChange),
1245 #[knuffel(skip)]1251 #[knuffel(skip)]
1246 SetWindowHeightById {1252 SetWindowHeightById {
@@ -1373,6 +1379,11 @@ impl From<niri_ipc::Action> for Action {
1373 niri_ipc::Action::MoveColumnToMonitorRight {} => Self::MoveColumnToMonitorRight,1379 niri_ipc::Action::MoveColumnToMonitorRight {} => Self::MoveColumnToMonitorRight,
1374 niri_ipc::Action::MoveColumnToMonitorDown {} => Self::MoveColumnToMonitorDown,1380 niri_ipc::Action::MoveColumnToMonitorDown {} => Self::MoveColumnToMonitorDown,
1375 niri_ipc::Action::MoveColumnToMonitorUp {} => Self::MoveColumnToMonitorUp,1381 niri_ipc::Action::MoveColumnToMonitorUp {} => Self::MoveColumnToMonitorUp,
1382+ niri_ipc::Action::SetWindowWidth { id: None, change } => Self::SetWindowWidth(change),
1383+ niri_ipc::Action::SetWindowWidth {
1384+ id: Some(id),
1385+ change,
1386+ } => Self::SetWindowWidthById { id, change },
1376 niri_ipc::Action::SetWindowHeight { id: None, change } => Self::SetWindowHeight(change),1387 niri_ipc::Action::SetWindowHeight { id: None, change } => Self::SetWindowHeight(change),
1377 niri_ipc::Action::SetWindowHeight {1388 niri_ipc::Action::SetWindowHeight {
1378 id: Some(id),1389 id: Some(id),
niri-ipc/src/lib.rsmodified+16 -0
@@ -362,6 +362,22 @@ pub enum Action {
362 MoveColumnToMonitorDown {},362 MoveColumnToMonitorDown {},
363 /// Move the focused column to the monitor above.363 /// Move the focused column to the monitor above.
364 MoveColumnToMonitorUp {},364 MoveColumnToMonitorUp {},
365+ /// Change the width of a window.
366+ #[cfg_attr(
367+ feature = "clap",
368+ clap(about = "Change the width of the focused window")
369+ )]
370+ SetWindowWidth {
371+ /// Id of the window whose width to set.
372+ ///
373+ /// If `None`, uses the focused window.
374+ #[cfg_attr(feature = "clap", arg(long))]
375+ id: Option<u64>,
376+
377+ /// How to change the width.
378+ #[cfg_attr(feature = "clap", arg())]
379+ change: SizeChange,
380+ },
365 /// Change the height of a window.381 /// Change the height of a window.
366 #[cfg_attr(382 #[cfg_attr(
367 feature = "clap",383 feature = "clap",
src/input/mod.rsmodified+10 -0
@@ -1237,6 +1237,16 @@ impl State {
1237 Action::SetColumnWidth(change) => {1237 Action::SetColumnWidth(change) => {
1238 self.niri.layout.set_column_width(change);1238 self.niri.layout.set_column_width(change);
1239 }1239 }
1240+ Action::SetWindowWidth(change) => {
1241+ self.niri.layout.set_window_width(None, change);
1242+ }
1243+ Action::SetWindowWidthById { id, change } => {
1244+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
1245+ let window = window.map(|(_, m)| m.window.clone());
1246+ if let Some(window) = window {
1247+ self.niri.layout.set_window_width(Some(&window), change);
1248+ }
1249+ }
1240 Action::SetWindowHeight(change) => {1250 Action::SetWindowHeight(change) => {
1241 self.niri.layout.set_window_height(None, change);1251 self.niri.layout.set_window_height(None, change);
1242 }1252 }
src/layout/mod.rsmodified+33 -0
@@ -2592,6 +2592,29 @@ impl<W: LayoutElement> Layout<W> {
2592 monitor.set_column_width(change);2592 monitor.set_column_width(change);
2593 }2593 }
2594 2594
2595+ pub fn set_window_width(&mut self, window: Option<&W::Id>, change: SizeChange) {
2596+ if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2597+ if window.is_none() || window == Some(move_.tile.window().id()) {
2598+ return;
2599+ }
2600+ }
2601+
2602+ let workspace = if let Some(window) = window {
2603+ Some(
2604+ self.workspaces_mut()
2605+ .find(|ws| ws.has_window(window))
2606+ .unwrap(),
2607+ )
2608+ } else {
2609+ self.active_workspace_mut()
2610+ };
2611+
2612+ let Some(workspace) = workspace else {
2613+ return;
2614+ };
2615+ workspace.set_window_width(window, change);
2616+ }
2617+
2595 pub fn set_window_height(&mut self, window: Option<&W::Id>, change: SizeChange) {2618 pub fn set_window_height(&mut self, window: Option<&W::Id>, change: SizeChange) {
2596 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {2619 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2597 if window.is_none() || window == Some(move_.tile.window().id()) {2620 if window.is_none() || window == Some(move_.tile.window().id()) {
@@ -4319,6 +4342,12 @@ mod tests {
4319 },4342 },
4320 MaximizeColumn,4343 MaximizeColumn,
4321 SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),4344 SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
4345+ SetWindowWidth {
4346+ #[proptest(strategy = "proptest::option::of(1..=5usize)")]
4347+ id: Option<usize>,
4348+ #[proptest(strategy = "arbitrary_size_change()")]
4349+ change: SizeChange,
4350+ },
4322 SetWindowHeight {4351 SetWindowHeight {
4323 #[proptest(strategy = "proptest::option::of(1..=5usize)")]4352 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
4324 id: Option<usize>,4353 id: Option<usize>,
@@ -4829,6 +4858,10 @@ mod tests {
4829 }4858 }
4830 Op::MaximizeColumn => layout.toggle_full_width(),4859 Op::MaximizeColumn => layout.toggle_full_width(),
4831 Op::SetColumnWidth(change) => layout.set_column_width(change),4860 Op::SetColumnWidth(change) => layout.set_column_width(change),
4861+ Op::SetWindowWidth { id, change } => {
4862+ let id = id.filter(|id| layout.has_window(id));
4863+ layout.set_window_width(id.as_ref(), change);
4864+ }
4832 Op::SetWindowHeight { id, change } => {4865 Op::SetWindowHeight { id, change } => {
4833 let id = id.filter(|id| layout.has_window(id));4866 let id = id.filter(|id| layout.has_window(id));
4834 layout.set_window_height(id.as_ref(), change);4867 layout.set_window_height(id.as_ref(), change);
src/layout/scrolling.rsmodified+16 -3
@@ -1996,13 +1996,26 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1996 cancel_resize_for_column(&mut self.interactive_resize, col);1996 cancel_resize_for_column(&mut self.interactive_resize, col);
1997 }1997 }
1998 1998
1999- pub fn set_column_width(&mut self, change: SizeChange) {1999+ pub fn set_window_width(&mut self, window: Option<&W::Id>, change: SizeChange) {
2000 if self.columns.is_empty() {2000 if self.columns.is_empty() {
2001 return;2001 return;
2002 }2002 }
2003 2003
2004- let col = &mut self.columns[self.active_column_idx];2004+ let (col, tile_idx) = if let Some(window) = window {
2005- col.set_column_width(change, None, true);2005+ self.columns
2006+ .iter_mut()
2007+ .find_map(|col| {
2008+ col.tiles
2009+ .iter()
2010+ .position(|tile| tile.window().id() == window)
2011+ .map(|tile_idx| (col, Some(tile_idx)))
2012+ })
2013+ .unwrap()
2014+ } else {
2015+ (&mut self.columns[self.active_column_idx], None)
2016+ };
2017+
2018+ col.set_column_width(change, tile_idx, true);
2006 2019
2007 cancel_resize_for_column(&mut self.interactive_resize, col);2020 cancel_resize_for_column(&mut self.interactive_resize, col);
2008 }2021 }
src/layout/workspace.rsmodified+11 -1
@@ -998,7 +998,17 @@ impl<W: LayoutElement> Workspace<W> {
998 if self.floating_is_active.get() {998 if self.floating_is_active.get() {
999 self.floating.set_window_width(None, change, true);999 self.floating.set_window_width(None, change, true);
1000 } else {1000 } else {
1001- self.scrolling.set_column_width(change);1001+ self.scrolling.set_window_width(None, change);
1002+ }
1003+ }
1004+
1005+ pub fn set_window_width(&mut self, window: Option<&W::Id>, change: SizeChange) {
1006+ if window.map_or(self.floating_is_active.get(), |id| {
1007+ self.floating.has_window(id)
1008+ }) {
1009+ self.floating.set_window_width(window, change, true);
1010+ } else {
1011+ self.scrolling.set_window_width(window, change);
1002 }1012 }
1003 }1013 }
1004 1014