mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-20 07:31:39 +01:00
feat(wm): implement container and focus promotion
Was going a little crazy without being able to promote a container to the biggest tile. This is pretty much a straight lift and shift from komorebi.
This commit is contained in:
1 parent
c1cf94b23f
commit
c91520c531
5 files changed
+76
No files matched your search
@@ -131,6 +131,9 @@ pub enum SocketMessage {
|
||||
ResizeWindowAxis(Axis, Sizing),
|
||||
Retile,
|
||||
RetileWithResizeDimensions,
|
||||
Promote,
|
||||
PromoteFocus,
|
||||
PromoteWindow(OperationDirection),
|
||||
}
|
||||
|
||||
impl SocketMessage {
|
||||
|
||||
@@ -65,6 +65,12 @@ impl WindowManager {
|
||||
tracing::info!("processing command: {message}");
|
||||
|
||||
match message {
|
||||
SocketMessage::Promote => self.promote_container_to_front()?,
|
||||
SocketMessage::PromoteFocus => self.promote_focus_to_front()?,
|
||||
SocketMessage::PromoteWindow(direction) => {
|
||||
self.focus_container_in_direction(direction)?;
|
||||
self.promote_container_to_front()?
|
||||
}
|
||||
SocketMessage::FocusWindow(direction) => {
|
||||
let focused_workspace = self.focused_workspace()?;
|
||||
match focused_workspace.layer {
|
||||
|
||||
@@ -1135,4 +1135,38 @@ impl WindowManager {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn promote_container_to_front(&mut self) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
if matches!(workspace.layout, Layout::Default(DefaultLayout::Grid)) {
|
||||
tracing::debug!("ignoring promote command for grid layout");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("promoting container");
|
||||
|
||||
workspace.promote_container()?;
|
||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn promote_focus_to_front(&mut self) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
if matches!(workspace.layout, Layout::Default(DefaultLayout::Grid)) {
|
||||
tracing::info!("ignoring promote focus command for grid layout");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("promoting focus");
|
||||
|
||||
let target_idx = match workspace.layout {
|
||||
Layout::Default(_) => 0,
|
||||
};
|
||||
|
||||
workspace.focus_container(target_idx);
|
||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||
}
|
||||
}
|
||||
@@ -476,6 +476,23 @@ impl Workspace {
|
||||
container
|
||||
}
|
||||
|
||||
pub fn promote_container(&mut self) -> eyre::Result<()> {
|
||||
let resize = self.resize_dimensions.remove(0);
|
||||
let container = self
|
||||
.remove_focused_container()
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
|
||||
let primary_idx = match self.layout {
|
||||
Layout::Default(_) => 0,
|
||||
};
|
||||
|
||||
let insertion_idx = self.insert_container_at_idx(primary_idx, container);
|
||||
self.resize_dimensions[insertion_idx] = resize;
|
||||
self.focus_container(primary_idx);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_container_to_back(&mut self, container: Container) {
|
||||
self.containers_mut().push_back(container);
|
||||
self.focus_last_container();
|
||||
|
||||
@@ -59,6 +59,7 @@ gen_enum_subcommand_args! {
|
||||
ChangeLayout: DefaultLayout,
|
||||
Stack: OperationDirection,
|
||||
CycleStack: CycleDirection,
|
||||
PromoteWindow: OperationDirection,
|
||||
}
|
||||
|
||||
macro_rules! gen_target_subcommand_args {
|
||||
@@ -137,6 +138,12 @@ enum SubCommand {
|
||||
/// Set the layout on the focused workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
ChangeLayout(ChangeLayout),
|
||||
/// Promote the focused window to the top of the tree
|
||||
Promote,
|
||||
/// Promote the user focus to the top of the tree
|
||||
PromoteFocus,
|
||||
/// Promote the window in the specified direction
|
||||
PromoteWindow(PromoteWindow),
|
||||
/// Focus the specified workspace on the focused monitor
|
||||
#[clap(arg_required_else_help = true)]
|
||||
FocusWorkspace(FocusWorkspace),
|
||||
@@ -202,6 +209,15 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::Retile => {
|
||||
send_message(&SocketMessage::Retile)?;
|
||||
}
|
||||
SubCommand::Promote => {
|
||||
send_message(&SocketMessage::Promote)?;
|
||||
}
|
||||
SubCommand::PromoteFocus => {
|
||||
send_message(&SocketMessage::PromoteFocus)?;
|
||||
}
|
||||
SubCommand::PromoteWindow(arg) => {
|
||||
send_message(&SocketMessage::PromoteWindow(arg.operation_direction))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user