mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-21 00:01:26 +02:00
feat(wm): add dynamic layout selection rules
This commit adds a new feature which allows the user to specify a set of rules for a specific workspace that will be used to calculate which layout to apply to that workspace at any given time. The rule consists of a usize, which identifies the threshold of window containers which need to be visible on the workspace to activate the rule, and a layout, which will be applied to the workspace when the rule is activated. Both default and custom layouts can be used in workspace layout rules. When a workspace has layout rules in effect, manually changing the layout will not work again until the rules for that workspace have been cleared. This feature came about after trying but failing to modify the custom layout code in such a way that the width percentage of a primary column in a custom layout might be propagated to the fallback columnar layout when the tertiary column threshold is not met. Although this new feature introduces more complexity, it is strictly opt-in and can be completely ignored if the user has no interest in adjusting layouts based on the visible window count. re #121
This commit is contained in:
@@ -171,6 +171,15 @@ gen_workspace_subcommand_args! {
|
||||
Tiling: #[enum] BooleanState,
|
||||
}
|
||||
|
||||
#[derive(Parser, AhkFunction)]
|
||||
pub struct ClearWorkspaceLayoutRules {
|
||||
/// Monitor index (zero-indexed)
|
||||
monitor: usize,
|
||||
|
||||
/// Workspace index on the specified monitor (zero-indexed)
|
||||
workspace: usize,
|
||||
}
|
||||
|
||||
#[derive(Parser, AhkFunction)]
|
||||
pub struct WorkspaceCustomLayout {
|
||||
/// Monitor index (zero-indexed)
|
||||
@@ -183,6 +192,35 @@ pub struct WorkspaceCustomLayout {
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Parser, AhkFunction)]
|
||||
pub struct WorkspaceLayoutRule {
|
||||
/// Monitor index (zero-indexed)
|
||||
monitor: usize,
|
||||
|
||||
/// Workspace index on the specified monitor (zero-indexed)
|
||||
workspace: usize,
|
||||
|
||||
/// The number of window containers on-screen required to trigger this layout rule
|
||||
at_container_count: usize,
|
||||
|
||||
layout: DefaultLayout,
|
||||
}
|
||||
|
||||
#[derive(Parser, AhkFunction)]
|
||||
pub struct WorkspaceCustomLayoutRule {
|
||||
/// Monitor index (zero-indexed)
|
||||
monitor: usize,
|
||||
|
||||
/// Workspace index on the specified monitor (zero-indexed)
|
||||
workspace: usize,
|
||||
|
||||
/// The number of window containers on-screen required to trigger this layout rule
|
||||
at_container_count: usize,
|
||||
|
||||
/// JSON or YAML file from which the custom layout definition should be loaded
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Parser, AhkFunction)]
|
||||
struct Resize {
|
||||
#[clap(arg_enum)]
|
||||
@@ -526,6 +564,15 @@ enum SubCommand {
|
||||
/// Set a custom layout for the specified workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
WorkspaceCustomLayout(WorkspaceCustomLayout),
|
||||
/// Add a dynamic layout rule for the specified workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
WorkspaceLayoutRule(WorkspaceLayoutRule),
|
||||
/// Add a dynamic custom layout for the specified workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
WorkspaceCustomLayoutRule(WorkspaceCustomLayoutRule),
|
||||
/// Clear all dynamic layout rules for the specified workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
ClearWorkspaceLayoutRules(ClearWorkspaceLayoutRules),
|
||||
/// Enable or disable window tiling for the specified workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
WorkspaceTiling(WorkspaceTiling),
|
||||
@@ -760,6 +807,34 @@ fn main() -> Result<()> {
|
||||
.as_bytes()?,
|
||||
)?;
|
||||
}
|
||||
SubCommand::WorkspaceLayoutRule(arg) => {
|
||||
send_message(
|
||||
&*SocketMessage::WorkspaceLayoutRule(
|
||||
arg.monitor,
|
||||
arg.workspace,
|
||||
arg.at_container_count,
|
||||
arg.layout,
|
||||
)
|
||||
.as_bytes()?,
|
||||
)?;
|
||||
}
|
||||
SubCommand::WorkspaceCustomLayoutRule(arg) => {
|
||||
send_message(
|
||||
&*SocketMessage::WorkspaceLayoutCustomRule(
|
||||
arg.monitor,
|
||||
arg.workspace,
|
||||
arg.at_container_count,
|
||||
resolve_windows_path(&arg.path)?,
|
||||
)
|
||||
.as_bytes()?,
|
||||
)?;
|
||||
}
|
||||
SubCommand::ClearWorkspaceLayoutRules(arg) => {
|
||||
send_message(
|
||||
&*SocketMessage::ClearWorkspaceLayoutRules(arg.monitor, arg.workspace)
|
||||
.as_bytes()?,
|
||||
)?;
|
||||
}
|
||||
SubCommand::WorkspaceTiling(arg) => {
|
||||
send_message(
|
||||
&*SocketMessage::WorkspaceTiling(arg.monitor, arg.workspace, arg.value.into())
|
||||
|
||||
Reference in New Issue
Block a user