forge
Explore
Log in

Don't you dare go Hollow

Implement expand-column-to-available-width

Browse files at this commit

92cc2b89f75fd13d83208626fa49724216fbbf9eIvan MolodetskikhParent: 078383e
niri-config/src/lib.rsmodified+2 -0
@@ -1593,6 +1593,7 @@ pub enum Action {
1593 SwitchPresetWindowHeightById(u64),1593 SwitchPresetWindowHeightById(u64),
1594 MaximizeColumn,1594 MaximizeColumn,
1595 SetColumnWidth(#[knuffel(argument, str)] SizeChange),1595 SetColumnWidth(#[knuffel(argument, str)] SizeChange),
1596+ ExpandColumnToAvailableWidth,
1596 SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget),1597 SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget),
1597 ShowHotkeyOverlay,1598 ShowHotkeyOverlay,
1598 MoveWorkspaceToMonitorLeft,1599 MoveWorkspaceToMonitorLeft,
@@ -1794,6 +1795,7 @@ impl From<niri_ipc::Action> for Action {
1794 }1795 }
1795 niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn,1796 niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn,
1796 niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change),1797 niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change),
1798+ niri_ipc::Action::ExpandColumnToAvailableWidth {} => Self::ExpandColumnToAvailableWidth,
1797 niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout),1799 niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout),
1798 niri_ipc::Action::ShowHotkeyOverlay {} => Self::ShowHotkeyOverlay,1800 niri_ipc::Action::ShowHotkeyOverlay {} => Self::ShowHotkeyOverlay,
1799 niri_ipc::Action::MoveWorkspaceToMonitorLeft {} => Self::MoveWorkspaceToMonitorLeft,1801 niri_ipc::Action::MoveWorkspaceToMonitorLeft {} => Self::MoveWorkspaceToMonitorLeft,
niri-ipc/src/lib.rsmodified+2 -0
@@ -539,6 +539,8 @@ pub enum Action {
539 #[cfg_attr(feature = "clap", arg(allow_hyphen_values = true))]539 #[cfg_attr(feature = "clap", arg(allow_hyphen_values = true))]
540 change: SizeChange,540 change: SizeChange,
541 },541 },
542+ /// Expand the focused column to space not taken up by other fully visible columns.
543+ ExpandColumnToAvailableWidth {},
542 /// Switch between keyboard layouts.544 /// Switch between keyboard layouts.
543 SwitchLayout {545 SwitchLayout {
544 /// Layout to switch to.546 /// Layout to switch to.
resources/default-config.kdlmodified+5 -0
@@ -504,6 +504,11 @@ binds {
504 Mod+Ctrl+R { reset-window-height; }504 Mod+Ctrl+R { reset-window-height; }
505 Mod+F { maximize-column; }505 Mod+F { maximize-column; }
506 Mod+Shift+F { fullscreen-window; }506 Mod+Shift+F { fullscreen-window; }
507+
508+ // Expand the focused column to space not taken up by other fully visible columns.
509+ // Makes the column "fill the rest of the space".
510+ Mod+Ctrl+F { expand-column-to-available-width; }
511+
507 Mod+C { center-column; }512 Mod+C { center-column; }
508 513
509 // Finer width adjustments.514 // Finer width adjustments.
src/input/mod.rsmodified+3 -0
@@ -1511,6 +1511,9 @@ impl State {
1511 self.niri.layout.reset_window_height(Some(&window));1511 self.niri.layout.reset_window_height(Some(&window));
1512 }1512 }
1513 }1513 }
1514+ Action::ExpandColumnToAvailableWidth => {
1515+ self.niri.layout.expand_column_to_available_width();
1516+ }
1514 Action::ShowHotkeyOverlay => {1517 Action::ShowHotkeyOverlay => {
1515 if self.niri.hotkey_overlay.show() {1518 if self.niri.hotkey_overlay.show() {
1516 self.niri.queue_redraw_all();1519 self.niri.queue_redraw_all();
src/layout/mod.rsmodified+7 -0
@@ -2977,6 +2977,13 @@ impl<W: LayoutElement> Layout<W> {
2977 workspace.reset_window_height(window);2977 workspace.reset_window_height(window);
2978 }2978 }
2979 2979
2980+ pub fn expand_column_to_available_width(&mut self) {
2981+ let Some(monitor) = self.active_monitor() else {
2982+ return;
2983+ };
2984+ monitor.expand_column_to_available_width();
2985+ }
2986+
2980 pub fn toggle_window_floating(&mut self, window: Option<&W::Id>) {2987 pub fn toggle_window_floating(&mut self, window: Option<&W::Id>) {
2981 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {2988 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
2982 if window.is_none() || window == Some(move_.tile.window().id()) {2989 if window.is_none() || window == Some(move_.tile.window().id()) {
src/layout/monitor.rsmodified+4 -0
@@ -840,6 +840,10 @@ impl<W: LayoutElement> Monitor<W> {
840 self.active_workspace().set_column_width(change);840 self.active_workspace().set_column_width(change);
841 }841 }
842 842
843+ pub fn expand_column_to_available_width(&mut self) {
844+ self.active_workspace().expand_column_to_available_width();
845+ }
846+
843 pub fn move_workspace_down(&mut self) {847 pub fn move_workspace_down(&mut self) {
844 let mut new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);848 let mut new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);
845 if new_idx == self.active_workspace_idx {849 if new_idx == self.active_workspace_idx {
src/layout/scrolling.rsmodified+83 -0
@@ -2524,6 +2524,89 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2524 cancel_resize_for_column(&mut self.interactive_resize, col);2524 cancel_resize_for_column(&mut self.interactive_resize, col);
2525 }2525 }
2526 2526
2527+ pub fn expand_column_to_available_width(&mut self) {
2528+ if self.columns.is_empty() {
2529+ return;
2530+ }
2531+
2532+ let col = &mut self.columns[self.active_column_idx];
2533+ if col.is_fullscreen || col.is_full_width {
2534+ return;
2535+ }
2536+
2537+ if self.is_centering_focused_column() {
2538+ // Always-centered mode is different since the active window position cannot be
2539+ // controlled (it's always at the center). I guess you could come up with different
2540+ // logic here that computes the width in such a way so as to leave nearby columns fully
2541+ // on screen while taking into account that the active column will remain centered
2542+ // after resizing. But I'm not sure it's that useful? So let's do the simple thing.
2543+ let col = &mut self.columns[self.active_column_idx];
2544+ col.set_column_width(SizeChange::SetProportion(1.), None, true);
2545+ cancel_resize_for_column(&mut self.interactive_resize, col);
2546+ return;
2547+ }
2548+
2549+ // Consider the end of an ongoing animation because that's what compute to fit does too.
2550+ let view_x = self.target_view_pos();
2551+ let working_x = self.working_area.loc.x;
2552+ let working_w = self.working_area.size.w;
2553+
2554+ // Count all columns that are fully visible inside the working area.
2555+ let mut width_taken = 0.;
2556+ let mut leftmost_col_x = None;
2557+ let mut active_col_x = None;
2558+
2559+ let gap = self.options.gaps;
2560+ let col_xs = self.column_xs(self.data.iter().copied());
2561+ for (idx, col_x) in col_xs.take(self.columns.len()).enumerate() {
2562+ if col_x < view_x + working_x + gap {
2563+ // Column goes off-screen to the left.
2564+ continue;
2565+ }
2566+
2567+ leftmost_col_x.get_or_insert(col_x);
2568+
2569+ let width = self.data[idx].width;
2570+ if view_x + working_x + working_w < col_x + width + gap {
2571+ // Column goes off-screen to the right. We can stop here.
2572+ break;
2573+ }
2574+
2575+ if idx == self.active_column_idx {
2576+ active_col_x = Some(col_x);
2577+ }
2578+
2579+ width_taken += width + gap;
2580+ }
2581+
2582+ if active_col_x.is_none() {
2583+ // The active column wasn't fully on screen, so we can't meaningfully do anything.
2584+ return;
2585+ }
2586+
2587+ let available_width = working_w - gap - width_taken;
2588+ if available_width <= 0. {
2589+ // Nowhere to expand.
2590+ return;
2591+ }
2592+
2593+ let active_width = self.data[self.active_column_idx].width;
2594+
2595+ let col = &mut self.columns[self.active_column_idx];
2596+ col.width = ColumnWidth::Fixed(active_width + available_width);
2597+ col.preset_width_idx = None;
2598+ col.is_full_width = false;
2599+ col.update_tile_sizes(true);
2600+
2601+ cancel_resize_for_column(&mut self.interactive_resize, col);
2602+
2603+ // Put the leftmost window into the view.
2604+ let new_view_x = leftmost_col_x.unwrap() - gap - working_x;
2605+ self.animate_view_offset(self.active_column_idx, new_view_x - active_col_x.unwrap());
2606+ // Just in case.
2607+ self.animate_view_offset_to_column(None, self.active_column_idx, None);
2608+ }
2609+
2527 pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) -> bool {2610 pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) -> bool {
2528 let (mut col_idx, tile_idx) = self2611 let (mut col_idx, tile_idx) = self
2529 .columns2612 .columns
src/layout/tests.rsmodified+2 -0
@@ -496,6 +496,7 @@ enum Op {
496 #[proptest(strategy = "proptest::option::of(1..=5usize)")]496 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
497 id: Option<usize>,497 id: Option<usize>,
498 },498 },
499+ ExpandColumnToAvailableWidth,
499 ToggleWindowFloating {500 ToggleWindowFloating {
500 #[proptest(strategy = "proptest::option::of(1..=5usize)")]501 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
501 id: Option<usize>,502 id: Option<usize>,
@@ -1133,6 +1134,7 @@ impl Op {
1133 let id = id.filter(|id| layout.has_window(id));1134 let id = id.filter(|id| layout.has_window(id));
1134 layout.reset_window_height(id.as_ref());1135 layout.reset_window_height(id.as_ref());
1135 }1136 }
1137+ Op::ExpandColumnToAvailableWidth => layout.expand_column_to_available_width(),
1136 Op::ToggleWindowFloating { id } => {1138 Op::ToggleWindowFloating { id } => {
1137 let id = id.filter(|id| layout.has_window(id));1139 let id = id.filter(|id| layout.has_window(id));
1138 layout.toggle_window_floating(id.as_ref());1140 layout.toggle_window_floating(id.as_ref());
src/layout/workspace.rsmodified+7 -0
@@ -1128,6 +1128,13 @@ impl<W: LayoutElement> Workspace<W> {
1128 }1128 }
1129 }1129 }
1130 1130
1131+ pub fn expand_column_to_available_width(&mut self) {
1132+ if self.floating_is_active.get() {
1133+ return;
1134+ }
1135+ self.scrolling.expand_column_to_available_width();
1136+ }
1137+
1131 pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) {1138 pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) {
1132 let mut unfullscreen_to_floating = false;1139 let mut unfullscreen_to_floating = false;
1133 if self.floating.has_window(window) {1140 if self.floating.has_window(window) {