feat(wm): add visual feedback for preselections

This commit adds visual feedback in the form of a ghost tile for
preselections made by the preselect-direction command.

A container with the id "PRESELECT" will be added to the workspace, and
replaced when the next manage-able window is spawned.

A new command, cancel-preselect has been added to remove both the
preselection index and the ghost tile if the user changes their mind.
This commit is contained in:
LGUG2Z committed 2025-11-02 11:03:11 -08:00
1 parent fe8dbca204
commit 34db2e2c90
8 files changed
+62 -5

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# cancel-preselect
```
Cancel a workspace preselect set by the preselect-direction command, if one exists
Usage: komorebic cancel-preselect
Options:
-h, --help
Print help
```
+12
View File
@@ -40,6 +40,18 @@ impl Lockable for Container {
}
impl Container {
pub fn preselect() -> Self {
Self {
id: "PRESELECT".to_string(),
locked: false,
windows: Default::default(),
}
}
pub fn is_preselect(&self) -> bool {
self.id == "PRESELECT"
}
pub fn idx_from_exe(&self, exe: &str) -> Option<usize> {
for (idx, window) in self.windows().iter().enumerate() {
if let Some(window_exe) = window.exe()
+1
View File
@@ -257,6 +257,7 @@ pub enum SocketMessage {
FocusWindow(OperationDirection),
MoveWindow(OperationDirection),
PreselectDirection(OperationDirection),
CancelPreselect,
CycleFocusWindow(CycleDirection),
CycleMoveWindow(CycleDirection),
StackWindow(OperationDirection),
+17 -1
View File
@@ -228,9 +228,25 @@ impl WindowManager {
}
SocketMessage::PreselectDirection(direction) => {
let focused_workspace = self.focused_workspace()?;
if matches!(focused_workspace.layer, WorkspaceLayer::Tiling) {
let mut update = false;
if focused_workspace.preselected_container_idx.is_some() {
tracing::warn!(
"ignoring command as this workspace already has a direction preselect set"
);
} else if matches!(focused_workspace.layer, WorkspaceLayer::Tiling) {
self.preselect_container_in_direction(direction)?;
update = true;
}
if update {
self.focused_workspace_mut()?.update()?;
}
}
SocketMessage::CancelPreselect => {
let focused_workspace = self.focused_workspace_mut()?;
focused_workspace.cancel_preselect();
focused_workspace.update()?;
}
SocketMessage::MoveWindow(direction) => {
let focused_workspace = self.focused_workspace()?;
+1 -1
View File
@@ -482,7 +482,7 @@ impl WindowManager {
_ => new_idx,
};
workspace.preselect_container_index(adjusted_idx);
workspace.preselect_container_idx(adjusted_idx);
}
None => {
+13 -3
View File
@@ -220,8 +220,16 @@ impl Workspace {
self.focus_container(j);
}
pub fn preselect_container_index(&mut self, insertion_index: usize) {
self.preselected_container_idx = Some(insertion_index);
pub fn preselect_container_idx(&mut self, insertion_idx: usize) {
self.preselected_container_idx = Some(insertion_idx);
self.insert_container_at_idx(insertion_idx, Container::preselect());
}
pub fn cancel_preselect(&mut self) {
if let Some(idx) = self.preselected_container_idx {
self.containers_mut().remove_respecting_locks(idx);
self.preselected_container_idx = None;
}
}
pub fn new_idx_for_direction(&self, direction: OperationDirection) -> Option<usize> {
@@ -297,6 +305,7 @@ impl Workspace {
let next_idx = if let Some(idx) = self.preselected_container_idx {
let next = idx;
self.preselected_container_idx = None;
self.remove_container_by_idx(next);
next
} else if self.containers().is_empty() {
0
@@ -1055,7 +1064,8 @@ impl Workspace {
// make sure we are never holding on to empty containers
self.prune_duplicate_windows()?;
let focused_container_idx = self.focused_container_idx();
self.containers_mut().retain(|c| !c.windows().is_empty());
self.containers_mut()
.retain(|c| c.is_preselect() || !c.windows().is_empty());
// make sure we are never focused on a no longer existent final empty container
if focused_container_idx >= self.containers().len() {
+5
View File
@@ -764,6 +764,8 @@ enum SubCommand {
/// Preselect the specified direction for the next window to be spawned on supported layouts
#[clap(arg_required_else_help = true)]
PreselectDirection(PreselectDirection),
/// Cancel a workspace preselect set by the preselect-direction command, if one exists
CancelPreselect,
/// Minimize the focused window
Minimize,
/// Close the focused window
@@ -1680,6 +1682,9 @@ fn main() -> eyre::Result<()> {
SubCommand::PreselectDirection(arg) => {
send_message(&SocketMessage::PreselectDirection(arg.operation_direction))?;
}
SubCommand::CancelPreselect => {
send_message(&SocketMessage::CancelPreselect)?;
}
SubCommand::CycleFocus(arg) => {
send_message(&SocketMessage::CycleFocusWindow(arg.cycle_direction))?;
}
+1
View File
@@ -87,6 +87,7 @@ nav:
- cli/focus.md
- cli/move.md
- cli/preselect-direction.md
- cli/cancel-preselect.md
- cli/minimize.md
- cli/close.md
- cli/cycle-focus.md