mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
feat(scrolling): add full-width, expand and center-focus commands
The model could take the full width, fill the room that the columns in view leave, and centre a column, but nothing called it. These commands do, the first in the scrolling-layout family that scrolling-layout-columns started, and the others named plainly, center-focus to match promote-focus: - scrolling-layout-full-width - expand - center-focus Each is about the container that has focus now, even if focus moved since the last layout, and does nothing until there is a strip, or in another layout. A column made the full width of the screen takes the gaps into account, so that it fills the screen exactly. expand makes the focused column as wide as it can be without moving another column out of view, which is the full width of the screen when it is the only one in view or when the focused column is always centred, and does nothing when there is no room. Nothing changes in the shared layouts crate, so Windows is not affected.
This commit is contained in:
1 parent
2fb9dfdffa
commit
b496bd8858
9 files changed
+260
-1
No files matched your search
@@ -0,0 +1,15 @@
|
||||
# center-focus
|
||||
|
||||
```
|
||||
Centre the user focus on the screen, once
|
||||
|
||||
In the Scrolling layout the screen scrolls so that the focused column is in the middle of it. Only
|
||||
the Scrolling layout scrolls, so this does nothing in the other layouts.
|
||||
|
||||
Usage: komorebic center-focus
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help (see a summary with '-h')
|
||||
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
# expand
|
||||
|
||||
```
|
||||
Make the focused column of the Scrolling layout fill the room that the columns in view leave on the
|
||||
screen, which does nothing in any other layout
|
||||
|
||||
Usage: komorebic expand
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help
|
||||
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
# scrolling-layout-full-width
|
||||
|
||||
```
|
||||
Make the focused column of the Scrolling layout as wide as the screen, or put it back
|
||||
|
||||
Usage: komorebic scrolling-layout-full-width
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
Print help
|
||||
|
||||
```
|
||||
@@ -51,6 +51,21 @@ screen wide, and is not stretched to fill it.
|
||||
A lone window is a third of the screen wide, at the left edge. To have it fill the screen, or to take it out of the
|
||||
layout for a while, use [`komorebic toggle-monocle`](../cli/toggle-monocle.md).
|
||||
|
||||
## Full width and centring
|
||||
|
||||
- [`komorebic scrolling-layout-full-width`](../cli/scrolling-layout-full-width.md) makes the focused column as wide as the
|
||||
screen, or puts it back to the width that it had.
|
||||
- [`komorebic center-focus`](../cli/center-focus.md) scrolls the screen so that the focused column is in the middle of
|
||||
it, once. `center_focused_column` does it every time that focus moves instead.
|
||||
- [`komorebic expand`](../cli/expand.md) makes the focused column as wide as it can be without moving another column out
|
||||
of view: it takes up the room that the columns on the screen leave. It does nothing when there is none, and in the
|
||||
other layouts. With `center_focused_column` set to `"Always"` it makes the column the full width of the screen, or
|
||||
puts it back, as `scrolling-layout-full-width` does.
|
||||
|
||||
A column that you make the full width of the screen takes the gaps into account, so that it fills the screen exactly.
|
||||
Nothing else moves to make room for a column that gets wider: the focused column keeps its left edge, and the screen
|
||||
scrolls only if the column no longer fits.
|
||||
|
||||
## Scrolling
|
||||
|
||||
The row scrolls only when it has to.
|
||||
@@ -95,6 +110,5 @@ These are not done yet.
|
||||
|
||||
- A window that will not get as narrow as its column, which is what many apps do, is not noticed, so it can overlap the
|
||||
column next to it.
|
||||
- There are no commands for stepping through preset widths, or for making a column the full width of the screen.
|
||||
- Every window has a border, including the windows resting at the edges, so you may see a thin line of one at the edge
|
||||
of the screen.
|
||||
@@ -333,6 +333,9 @@ pub enum SocketMessage {
|
||||
ChangeLayout(DefaultLayout),
|
||||
CycleLayout(CycleDirection),
|
||||
ScrollingLayoutColumns(NonZeroUsize),
|
||||
ScrollingLayoutFullWidth,
|
||||
CenterFocus,
|
||||
Expand,
|
||||
LayoutRatios(Option<Vec<f32>>, Option<Vec<f32>>),
|
||||
// ChangeLayoutCustom(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
|
||||
FlipLayout(Axis),
|
||||
@@ -484,3 +487,22 @@ impl FromStr for SocketMessage {
|
||||
serde_json::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_scrolling_command_goes_over_the_socket_as_it_is() {
|
||||
for message in [
|
||||
SocketMessage::ScrollingLayoutFullWidth,
|
||||
SocketMessage::CenterFocus,
|
||||
SocketMessage::Expand,
|
||||
] {
|
||||
let bytes = message.as_bytes().unwrap();
|
||||
let read: SocketMessage = String::from_utf8(bytes.clone()).unwrap().parse().unwrap();
|
||||
|
||||
assert_eq!(read.as_bytes().unwrap(), bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1496,6 +1496,18 @@ impl WindowManager {
|
||||
.set_scrolling_columns(count.into());
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
SocketMessage::ScrollingLayoutFullWidth => {
|
||||
self.focused_workspace_mut()?.toggle_scrolling_full_width();
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
SocketMessage::CenterFocus => {
|
||||
self.focused_workspace_mut()?.center_scrolling_column();
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
SocketMessage::Expand => {
|
||||
self.focused_workspace_mut()?.expand_scrolling_column();
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
SocketMessage::LayoutRatios(ref columns, ref rows) => {
|
||||
use crate::core::validate_ratios;
|
||||
|
||||
|
||||
@@ -192,6 +192,52 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
/// Make the space agree with which container has focus, and give back the id of that
|
||||
/// container, for a command that is about the focused column.
|
||||
///
|
||||
/// There is nothing to do until a layout has made the space, and in a layout that is not
|
||||
/// Scrolling.
|
||||
fn focused_scrolling_column(&mut self) -> Option<String> {
|
||||
if !self.is_scrolling() || self.scrolling.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.sync_scrolling_containers();
|
||||
|
||||
self.focused_container()
|
||||
.map(|container| container.id.clone())
|
||||
}
|
||||
|
||||
/// Make the focused column as wide as the screen, or give it back the width that it had.
|
||||
pub(crate) fn toggle_scrolling_full_width(&mut self) {
|
||||
if let Some(id) = self.focused_scrolling_column()
|
||||
&& let Some(space) = self.scrolling.as_mut()
|
||||
{
|
||||
space.toggle_full_width(&id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Make the focused column as wide as it can be without scrolling anything else out of view,
|
||||
/// which is to fill the room that the columns in view leave. Only the Scrolling layout has
|
||||
/// columns to expand.
|
||||
pub(crate) fn expand_scrolling_column(&mut self) {
|
||||
if self.is_scrolling()
|
||||
&& self.focused_scrolling_column().is_some()
|
||||
&& let Some(space) = self.scrolling.as_mut()
|
||||
{
|
||||
space.expand_to_available_width();
|
||||
}
|
||||
}
|
||||
|
||||
/// Centre the focused column on the screen, this once.
|
||||
pub(crate) fn center_scrolling_column(&mut self) {
|
||||
if self.focused_scrolling_column().is_some()
|
||||
&& let Some(space) = self.scrolling.as_mut()
|
||||
{
|
||||
space.center_column();
|
||||
}
|
||||
}
|
||||
|
||||
/// Make the focused column wider or narrower. Only the horizontal edges mean anything, since
|
||||
/// a column is as tall as the viewport.
|
||||
///
|
||||
@@ -554,6 +600,84 @@ mod tests {
|
||||
assert!(workspace.scrolling.is_none());
|
||||
}
|
||||
|
||||
/// A workspace with a layout, which is what makes the strip that the width commands act on.
|
||||
fn laid_out(columns: usize, containers: usize, focus: usize) -> Workspace {
|
||||
let mut workspace = workspace(columns, containers);
|
||||
workspace.focus_container(focus);
|
||||
workspace.layout_scrolling(&AREA, 0);
|
||||
workspace
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_full_width_is_toggled_on_and_off() {
|
||||
let mut workspace = laid_out(3, 3, 1);
|
||||
|
||||
workspace.toggle_scrolling_full_width();
|
||||
assert_eq!(widths(&workspace.layout_scrolling(&AREA, 0))[1], 1200);
|
||||
|
||||
workspace.toggle_scrolling_full_width();
|
||||
assert_eq!(widths(&workspace.layout_scrolling(&AREA, 0))[1], 400);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_column_is_centred_once() {
|
||||
let mut workspace = laid_out(3, 2, 0);
|
||||
assert_eq!(workspace.layout_scrolling(&AREA, 0)[0].rect.left, AREA.left);
|
||||
|
||||
workspace.center_scrolling_column();
|
||||
|
||||
// the work area is 1200 wide and starts at 100, and the column is 400 wide
|
||||
assert_eq!(
|
||||
workspace.layout_scrolling(&AREA, 0)[0].rect.left,
|
||||
AREA.left + 400
|
||||
);
|
||||
|
||||
// and it is centred once, so moving on to the next column does not keep it centred
|
||||
workspace.focus_container(1);
|
||||
let lefts: Vec<_> = workspace
|
||||
.layout_scrolling(&AREA, 0)
|
||||
.iter()
|
||||
.map(|placement| placement.rect.left)
|
||||
.collect();
|
||||
assert_eq!(lefts, [500, 900]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_commands_are_about_the_container_that_has_focus_now() {
|
||||
let mut workspace = laid_out(3, 3, 0);
|
||||
|
||||
// focus moved since the layout, and the next layout has not been made yet
|
||||
workspace.focus_container(2);
|
||||
workspace.toggle_scrolling_full_width();
|
||||
|
||||
assert_eq!(
|
||||
widths(&workspace.layout_scrolling(&AREA, 0)),
|
||||
[400, 400, 1200]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_commands_do_nothing_before_there_is_a_layout() {
|
||||
let mut workspace = workspace(3, 3);
|
||||
|
||||
workspace.toggle_scrolling_full_width();
|
||||
workspace.center_scrolling_column();
|
||||
|
||||
assert!(workspace.scrolling.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_commands_do_nothing_in_a_layout_that_is_not_scrolling() {
|
||||
let mut workspace = laid_out(3, 3, 1);
|
||||
let before = workspace.scrolling.clone();
|
||||
workspace.layout = Layout::Default(DefaultLayout::BSP);
|
||||
|
||||
workspace.toggle_scrolling_full_width();
|
||||
workspace.center_scrolling_column();
|
||||
|
||||
assert_eq!(workspace.scrolling, before);
|
||||
}
|
||||
|
||||
/// A workspace with a window in every container, which is how closing a window finds a container.
|
||||
fn workspace_of_windows(columns: usize, count: u32) -> Workspace {
|
||||
let mut workspace = Workspace {
|
||||
@@ -675,4 +799,29 @@ mod tests {
|
||||
[300, 300, 300]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expanding_fills_the_room_that_the_columns_in_view_leave() {
|
||||
let mut workspace = workspace(3, 2);
|
||||
workspace.layout_scrolling(&AREA, 0);
|
||||
workspace.focus_container(1);
|
||||
let before = workspace.layout_scrolling(&AREA, 0);
|
||||
|
||||
workspace.expand_scrolling_column();
|
||||
let after = workspace.layout_scrolling(&AREA, 0);
|
||||
|
||||
// the focused column takes the third of the screen that was empty, and no more
|
||||
assert_eq!(after[1].rect.right, before[1].rect.right + (AREA.right / 3));
|
||||
assert_eq!(after[0], before[0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expanding_does_nothing_where_there_are_no_columns() {
|
||||
let mut workspace = workspace(3, 2);
|
||||
workspace.layout = Layout::Default(DefaultLayout::BSP);
|
||||
|
||||
workspace.expand_scrolling_column();
|
||||
|
||||
assert!(workspace.scrolling.is_none());
|
||||
}
|
||||
}
|
||||
@@ -986,6 +986,16 @@ enum SubCommand {
|
||||
/// Set how many columns fit across the Scrolling layout on the focused workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
ScrollingLayoutColumns(ScrollingLayoutColumns),
|
||||
/// Make the focused column of the Scrolling layout as wide as the screen, or put it back
|
||||
ScrollingLayoutFullWidth,
|
||||
/// Centre the user focus on the screen, once
|
||||
///
|
||||
/// In the Scrolling layout the screen scrolls so that the focused column is in the middle of
|
||||
/// it. Only the Scrolling layout scrolls, so this does nothing in the other layouts.
|
||||
CenterFocus,
|
||||
/// Make the focused column of the Scrolling layout fill the room that the columns in view
|
||||
/// leave on the screen, which does nothing in any other layout
|
||||
Expand,
|
||||
/// Set the layout column and row ratios for the focused workspace
|
||||
LayoutRatios(LayoutRatios),
|
||||
// /// Load a custom layout from file for the focused workspace
|
||||
@@ -2367,6 +2377,15 @@ exit 1
|
||||
SubCommand::ScrollingLayoutColumns(args) => {
|
||||
send_message(&SocketMessage::ScrollingLayoutColumns(args.count))?;
|
||||
}
|
||||
SubCommand::ScrollingLayoutFullWidth => {
|
||||
send_message(&SocketMessage::ScrollingLayoutFullWidth)?;
|
||||
}
|
||||
SubCommand::CenterFocus => {
|
||||
send_message(&SocketMessage::CenterFocus)?;
|
||||
}
|
||||
SubCommand::Expand => {
|
||||
send_message(&SocketMessage::Expand)?;
|
||||
}
|
||||
SubCommand::LayoutRatios(args) => {
|
||||
if args.columns.is_none() && args.rows.is_none() {
|
||||
println!(
|
||||
|
||||
@@ -145,10 +145,13 @@ nav:
|
||||
- cli/change-layout.md
|
||||
- cli/cycle-layout.md
|
||||
- cli/scrolling-layout-columns.md
|
||||
- cli/scrolling-layout-full-width.md
|
||||
- cli/flip-layout.md
|
||||
- cli/promote.md
|
||||
- cli/promote-swap.md
|
||||
- cli/promote-focus.md
|
||||
- cli/center-focus.md
|
||||
- cli/expand.md
|
||||
- cli/promote-window.md
|
||||
- cli/retile.md
|
||||
- cli/display-index-preference.md
|
||||
|
||||
Reference in new issue
Block a user