refactor(komorebic-core): move the Windows subcommand definitions into the crate

WindowsCommands and the argument structs of the subcommands that are not in Messages (start, stop, check, kill, the border, stackbar and custom-layout commands, the app-specific-configuration converters and the ones whose help still differs between the trees) move from komorebic/src/main.rs to komorebic-core::platform::windows with their fields pub; the Windows main.rs keeps the handlers (2164 to 1520 lines). Three fields named after a protocol type that a struct of the same name shadows (BorderStyle, BorderImplementation, StackbarMode) are written with their full path. docgen-all now writes the Windows pages too, so no harness is needed any more.

Verified: oracle (step4/oracle-check.sh, Windows pages from the docgen-all example): windows 187 of 187 pages byte-identical, macos 158 of 158, kde 166 of 166; Windows cargo clippy --workspace --locked --all-targets -D warnings clean.
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent 001b7c98cd
commit 64457a97a3
4 files changed
+647 -646

No files matched your search

+2 -1
View File
@@ -21,11 +21,12 @@ fn main() -> std::io::Result<()> {
let out = PathBuf::from(args.next().expect("usage: docgen-all OUTDIR [platform]..."));
let mut platforms: Vec<String> = args.collect();
if platforms.is_empty() {
platforms = ["macos"].map(String::from).to_vec();
platforms = ["windows", "macos"].map(String::from).to_vec();
}
for platform in platforms {
let cli = match platform.as_str() {
"macos" => command::<komorebic_core::platform::macos::MacosCommands>(&META),
"windows" => command::<komorebic_core::platform::windows::WindowsCommands>(&META),
other => panic!("no platform {other} in this crate"),
};
let pages = write(cli, &DocFormat::PLAIN, &out.join(&platform))?;
@@ -1,3 +1,4 @@
//! The subcommands that a platform has and the others do not, or has differently.
pub mod macos;
pub mod windows;
@@ -0,0 +1,643 @@
//! The subcommands of komorebic for Windows that are not a message to the daemon in every `komorebic`.
use crate::args::*;
use clap::Parser;
use clap::Subcommand;
use komorebi_layouts::*;
use komorebi_protocol::animation::prefix::AnimationPrefix;
use komorebi_protocol::pathext::replace_env_in_path;
use komorebi_protocol::types::*;
use std::num::NonZeroUsize;
use std::path::PathBuf;
#[derive(Parser)]
pub struct WorkspaceCustomLayout {
/// Monitor index (zero-indexed)
pub monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
pub workspace: usize,
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
}
#[derive(Parser)]
pub struct NamedWorkspaceCustomLayout {
/// Target workspace name
pub workspace: String,
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
}
#[derive(Parser)]
pub struct WorkspaceCustomLayoutRule {
/// Monitor index (zero-indexed)
pub monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
pub workspace: usize,
/// The number of window containers on-screen required to trigger this layout rule
pub at_container_count: usize,
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
}
#[derive(Parser)]
pub struct NamedWorkspaceCustomLayoutRule {
/// Target workspace name
pub workspace: String,
/// The number of window containers on-screen required to trigger this layout rule
pub at_container_count: usize,
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
}
#[derive(Parser)]
pub struct InvisibleBorders {
/// Size of the left invisible border
pub left: i32,
/// Size of the top invisible border (usually 0)
pub top: i32,
/// Size of the right invisible border (usually left * 2)
pub right: i32,
/// Size of the bottom invisible border (usually the same as left)
pub bottom: i32,
}
#[derive(Parser)]
pub struct MonitorIndexPreference {
/// Preferred monitor index (zero-indexed)
pub index_preference: usize,
/// Left value of the monitor's size Rect
pub left: i32,
/// Top value of the monitor's size Rect
pub top: i32,
/// Right value of the monitor's size Rect
pub right: i32,
/// Bottom value of the monitor's size Rect
pub bottom: i32,
}
#[derive(Parser)]
pub struct ToggleFocusFollowsMouse {
#[clap(value_enum, short, long, default_value = "windows")]
pub implementation: FocusFollowsMouseImplementation,
}
#[derive(Parser)]
pub struct FocusFollowsMouse {
#[clap(value_enum, short, long, default_value = "windows")]
pub implementation: FocusFollowsMouseImplementation,
#[clap(value_enum)]
pub boolean_state: BooleanState,
}
#[derive(Parser)]
pub struct Transparency {
#[clap(value_enum)]
pub boolean_state: BooleanState,
}
#[derive(Parser)]
pub struct TransparencyAlpha {
/// Alpha
pub alpha: u8,
}
#[derive(Parser)]
pub struct BorderColour {
#[clap(value_enum, short, long, default_value = "single")]
pub window_kind: WindowKind,
/// Red
pub r: u32,
/// Green
pub g: u32,
/// Blue
pub b: u32,
}
#[derive(Parser)]
pub struct BorderStyle {
/// Desired border style
#[clap(value_enum)]
pub style: komorebi_protocol::types::BorderStyle,
}
#[derive(Parser)]
pub struct MonocleFocusBehaviour {
/// Desired monocle focus behaviour
#[clap(value_enum)]
pub behaviour: komorebi_protocol::types::MonocleFocusBehaviour,
}
#[derive(Parser)]
pub struct BorderImplementation {
/// Desired border implementation
#[clap(value_enum)]
pub style: komorebi_protocol::types::BorderImplementation,
}
#[derive(Parser)]
pub struct StackbarMode {
/// Desired stackbar mode
#[clap(value_enum)]
pub mode: komorebi_protocol::types::StackbarMode,
}
#[derive(Parser)]
pub struct Animation {
#[clap(value_enum)]
pub boolean_state: BooleanState,
/// Animation type to apply the state to. If not specified, sets global state
#[clap(value_enum, short, long)]
pub animation_type: Option<AnimationPrefix>,
}
#[derive(Parser)]
pub struct AnimationDuration {
/// Desired animation durations in ms
pub duration: u64,
/// Animation type to apply the duration to. If not specified, sets global duration
#[clap(value_enum, short, long)]
pub animation_type: Option<AnimationPrefix>,
}
#[derive(Parser)]
pub struct AnimationStyle {
/// Desired ease function for animation
#[clap(value_enum, short, long, default_value = "linear")]
pub style: komorebi_protocol::animation::AnimationStyle,
/// Animation type to apply the style to. If not specified, sets global style
#[clap(value_enum, short, long)]
pub animation_type: Option<AnimationPrefix>,
}
#[derive(Parser)]
pub struct Docgen {
/// Output directory for generated documentation files
#[clap(short, long)]
pub output: Option<PathBuf>,
}
#[derive(Parser)]
#[allow(clippy::struct_excessive_bools)]
pub struct Start {
/// Allow the use of komorebi's custom focus-follows-mouse implementation
#[clap(hide = true)]
#[clap(short, long = "ffm")]
pub ffm: bool,
/// Path to a static configuration JSON file
#[clap(short, long)]
#[clap(value_parser = replace_env_in_path)]
pub config: Option<PathBuf>,
/// Wait for `komorebic complete-configuration` to be sent before processing events
#[clap(short, long)]
pub await_configuration: bool,
/// Start a TCP server on the given port to allow the direct sending of SocketMessages
#[clap(short, long)]
pub tcp_port: Option<usize>,
/// Start whkd in a background process
#[clap(long)]
pub whkd: bool,
/// Start autohotkey configuration file
#[clap(hide = true)]
#[clap(long)]
pub ahk: bool,
/// Start komorebi-bar in a background process
#[clap(long)]
pub bar: bool,
/// Start masir in a background process for focus-follows-mouse
#[clap(long)]
pub masir: bool,
/// Do not attempt to auto-apply a dumped state temp file from a previously running instance of komorebi
#[clap(long)]
pub clean_state: bool,
}
#[derive(Parser)]
pub struct Stop {
/// Stop whkd if it is running as a background process
#[clap(long)]
pub whkd: bool,
/// Stop ahk if it is running as a background process
#[clap(hide = true)]
#[clap(long)]
pub ahk: bool,
/// Stop komorebi-bar if it is running as a background process
#[clap(long)]
pub bar: bool,
/// Stop masir if it is running as a background process
#[clap(long)]
pub masir: bool,
/// Do not restore windows after stopping komorebi
#[clap(long, hide = true)]
pub ignore_restore: bool,
}
#[derive(Parser)]
pub struct Kill {
/// Kill whkd if it is running as a background process
#[clap(long)]
pub whkd: bool,
/// Kill ahk if it is running as a background process
#[clap(hide = true)]
#[clap(long)]
pub ahk: bool,
/// Kill komorebi-bar if it is running as a background process
#[clap(long)]
pub bar: bool,
/// Kill masir if it is running as a background process
#[clap(long)]
pub masir: bool,
}
#[derive(Parser)]
pub struct LoadCustomLayout {
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
}
#[derive(Parser)]
pub struct SubscribePipe {
/// Name of the pipe to send event notifications to (without "\\.\pipe\" prepended)
pub named_pipe: String,
}
#[derive(Parser)]
pub struct UnsubscribePipe {
/// Name of the pipe to stop sending event notifications to (without "\\.\pipe\" prepended)
pub named_pipe: String,
}
#[derive(Parser)]
pub struct AhkAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
/// Optional YAML file of overrides to apply over the first file
#[clap(value_parser = replace_env_in_path)]
pub override_path: Option<PathBuf>,
}
#[derive(Parser)]
pub struct PwshAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
/// Optional YAML file of overrides to apply over the first file
#[clap(value_parser = replace_env_in_path)]
pub override_path: Option<PathBuf>,
}
#[derive(Parser)]
pub struct FormatAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
}
#[derive(Parser)]
pub struct ConvertAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
pub path: PathBuf,
}
#[derive(Parser)]
pub struct AltFocusHack {
#[clap(value_enum)]
pub boolean_state: BooleanState,
}
#[derive(Parser)]
pub struct EnableAutostart {
/// Path to a static configuration JSON file
#[clap(action, short, long)]
#[clap(value_parser = replace_env_in_path)]
pub config: Option<PathBuf>,
/// Enable komorebi's custom focus-follows-mouse implementation
#[clap(hide = true)]
#[clap(short, long = "ffm")]
pub ffm: bool,
/// Enable autostart of whkd
#[clap(long)]
pub whkd: bool,
/// Enable autostart of ahk
#[clap(hide = true)]
#[clap(long)]
pub ahk: bool,
/// Enable autostart of komorebi-bar
#[clap(long)]
pub bar: bool,
/// Enable autostart of masir
#[clap(long)]
pub masir: bool,
}
#[derive(Parser)]
pub struct Check {
/// Path to a static configuration JSON file
#[clap(action, short, long)]
#[clap(value_parser = replace_env_in_path)]
pub komorebi_config: Option<PathBuf>,
}
#[derive(Parser)]
pub struct EagerFocus {
/// Case-sensitive exe identifier
pub exe: String,
}
#[derive(Parser)]
pub struct ScrollingLayoutColumns {
/// Desired number of visible columns
pub count: NonZeroUsize,
}
#[derive(Parser)]
pub struct Pan {
/// The way that the view goes
#[clap(
value_enum,
required_unless_present = "stream",
conflicts_with = "stream"
)]
pub direction: Option<PanDirection>,
/// Read the gestures of fingers on a touchpad from standard input, as whkd writes them for
/// a swipe of three or four fingers, and pan with them
#[clap(long)]
pub stream: bool,
/// What the distances of a gesture are multiplied by, which is 1 if it is left out, with
/// --stream
#[clap(long)]
pub sensitivity: Option<f64>,
/// Go the other way to the fingers, with --stream
#[clap(long)]
pub reversed: bool,
/// Take a step for every two centimetres that the fingers go, and not move the view with
/// them, with --stream
#[clap(long)]
pub paging: bool,
}
#[derive(Parser)]
pub struct LayoutRatios {
/// Column width ratios (space-separated values between 0.1 and 0.9)
#[clap(short, long, num_args = 1..)]
pub columns: Option<Vec<f32>>,
/// Row height ratios (space-separated values between 0.1 and 0.9)
#[clap(short, long, num_args = 1..)]
pub rows: Option<Vec<f32>>,
}
#[derive(Parser)]
pub struct License {
/// Email address associated with an Individual Commercial Use License
pub email: String,
}
#[derive(Parser)]
pub struct Splash {
pub mdm_server: Option<String>,
}
#[derive(Subcommand)]
pub enum WindowsCommands {
#[clap(hide = true)]
Docgen(Docgen),
#[clap(hide = true)]
Splash(Splash),
/// Gather example configurations for a new-user quickstart
Quickstart,
/// Specify an email associated with an Individual Commercial Use License
#[clap(arg_required_else_help = true)]
License(License),
/// Start komorebi.exe as a background process
Start(Start),
/// Stop the komorebi.exe process and restore all hidden windows
Stop(Stop),
/// Kill background processes started by komorebic
Kill(Kill),
/// Check komorebi configuration and related files for common errors
Check(Check),
/// Show the path to komorebi.json
#[clap(alias = "config")]
Configuration,
/// Show the path to komorebi.bar.json
#[clap(alias = "bar-config")]
#[clap(alias = "bconfig")]
BarConfiguration,
/// Show the path to whkdrc
#[clap(alias = "whkd")]
Whkdrc,
/// Show the path to komorebi's data directory in %LOCALAPPDATA%
#[clap(alias = "datadir")]
DataDirectory,
/// Launch the komorebi-gui debugging tool
Gui,
/// Toggle the komorebi-shortcuts helper
ToggleShortcuts,
/// Subscribe to komorebi events using a Named Pipe
#[clap(arg_required_else_help = true)]
#[clap(alias = "subscribe")]
SubscribePipe(SubscribePipe),
/// Unsubscribe from komorebi events
#[clap(arg_required_else_help = true)]
#[clap(alias = "unsubscribe")]
UnsubscribePipe(UnsubscribePipe),
/// Tail komorebi.exe's process logs (cancel with Ctrl-C)
Log,
/// Forcibly focus the window at the cursor with a left mouse click
ForceFocus,
/// Focus the first managed window matching the given exe
#[clap(arg_required_else_help = true)]
EagerFocus(EagerFocus),
/// Set the invisible border dimensions around each window
#[clap(arg_required_else_help = true)]
InvisibleBorders(InvisibleBorders),
/// Set the number of visible columns for 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 to
/// the width that it had
ScrollingLayoutFullWidth,
/// Scroll the Scrolling layout so that the focused column is in the middle of the screen, once
CenterFocus,
/// Take the neighbouring window on one side into the focused column of the Scrolling layout
#[clap(arg_required_else_help = true)]
Consume(OneEnum<OperationDirection>),
/// Take the focused window out of its column in the Scrolling layout and put it in a column
/// of its own on the right
Expel,
/// Stack the windows of the focused column of the Scrolling layout, or spread the focused
/// stack out into a column with a window in each slot
ToggleColumnStack,
/// Move the view of the Scrolling layout a column to the left or the right, or with the
/// fingers on a touchpad, which does nothing in any other layout
#[clap(arg_required_else_help = true)]
Pan(Pan),
/// Set the layout column and row ratios for the focused workspace
LayoutRatios(LayoutRatios),
/// Load a custom layout from file for the focused workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
LoadCustomLayout(LoadCustomLayout),
/// Promote the user focus to the top of the tree
PromoteFocus,
/// Force the retiling of all managed windows
Retile,
/// Set the monitor index preference for a monitor identified using its size
#[clap(arg_required_else_help = true)]
MonitorIndexPreference(MonitorIndexPreference),
/// Set a custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
WorkspaceCustomLayout(WorkspaceCustomLayout),
/// Set a custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
NamedWorkspaceCustomLayout(NamedWorkspaceCustomLayout),
/// Add a dynamic custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
WorkspaceCustomLayoutRule(WorkspaceCustomLayoutRule),
/// Add a dynamic custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
NamedWorkspaceCustomLayoutRule(NamedWorkspaceCustomLayoutRule),
/// Toggle the behaviour for new windows (stacking or dynamic tiling)
ToggleWindowContainerBehaviour,
/// Toggle the behaviour for new windows (stacking or dynamic tiling) for currently focused
/// workspace. If there was no behaviour set for the workspace previously it takes the opposite
/// of the global value.
ToggleWorkspaceWindowContainerBehaviour,
/// Toggle native maximization for the focused window
ToggleMaximize,
/// Restore all hidden windows (debugging command)
RestoreWindows,
/// Reload legacy komorebi.ahk or komorebi.ps1 configurations (if they exist)
ReloadConfiguration,
/// Enable or disable watching of legacy komorebi.ahk or komorebi.ps1 configurations (if they exist)
#[clap(arg_required_else_help = true)]
WatchConfiguration(OneEnum<BooleanState>),
/// For legacy komorebi.ahk or komorebi.ps1 configurations, signal that the final configuration option has been sent
CompleteConfiguration,
/// DEPRECATED since v0.1.22
#[deprecated(note = "No longer required")]
#[clap(arg_required_else_help = true)]
#[clap(hide = true)]
AltFocusHack(AltFocusHack),
/// Set the window behaviour when switching workspaces / cycling stacks
#[clap(arg_required_else_help = true)]
WindowHidingBehaviour(OneEnum<HidingBehaviour>),
/// Set the behaviour when focusing in a direction while a monocle container is active
#[clap(arg_required_else_help = true)]
MonocleFocusBehaviour(MonocleFocusBehaviour),
/// Toggle the behaviour when focusing in a direction while a monocle container is active
ToggleMonocleFocusBehaviour,
/// Set the operation behaviour when the focused window is not managed
#[clap(arg_required_else_help = true)]
UnmanagedWindowOperationBehaviour(OneEnum<OperationBehaviour>),
/// Identify an application that sends EVENT_OBJECT_NAMECHANGE on launch
#[clap(arg_required_else_help = true)]
IdentifyObjectNameChangeApplication(ApplicationTarget),
/// Identify an application that closes to the system tray
#[clap(arg_required_else_help = true)]
IdentifyTrayApplication(ApplicationTarget),
/// Identify an application that has WS_EX_LAYERED, but should still be managed
#[clap(arg_required_else_help = true)]
IdentifyLayeredApplication(ApplicationTarget),
/// Whitelist an application for title bar removal
#[clap(arg_required_else_help = true)]
RemoveTitleBar(ApplicationTarget),
/// Toggle title bars for whitelisted applications
ToggleTitleBars,
/// Identify an application that has overflowing borders
#[clap(hide = true)]
#[clap(alias = "identify-border-overflow")]
IdentifyBorderOverflowApplication(ApplicationTarget),
/// Set the colour for a window border kind
#[clap(arg_required_else_help = true)]
#[clap(alias = "active-window-border-colour")]
BorderColour(BorderColour),
/// Set the border style
#[clap(arg_required_else_help = true)]
BorderStyle(BorderStyle),
/// Set the border implementation
#[clap(arg_required_else_help = true)]
BorderImplementation(BorderImplementation),
/// Set the stackbar mode
#[clap(arg_required_else_help = true)]
StackbarMode(StackbarMode),
/// Enable or disable transparency for unfocused windows
#[clap(arg_required_else_help = true)]
Transparency(Transparency),
/// Set the alpha value for unfocused window transparency
#[clap(arg_required_else_help = true)]
TransparencyAlpha(TransparencyAlpha),
/// Toggle transparency for unfocused windows
ToggleTransparency,
/// Enable or disable movement animations
#[clap(arg_required_else_help = true)]
Animation(Animation),
/// Set the duration for movement animations in ms
#[clap(arg_required_else_help = true)]
AnimationDuration(AnimationDuration),
/// Set the ease function for movement animations
#[clap(arg_required_else_help = true)]
AnimationStyle(AnimationStyle),
/// Enable or disable focus follows mouse for the operating system
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
FocusFollowsMouse(FocusFollowsMouse),
/// Toggle focus follows mouse for the operating system
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
ToggleFocusFollowsMouse(ToggleFocusFollowsMouse),
/// Generate common app-specific configurations and fixes to use in komorebi.ahk
#[clap(arg_required_else_help = true)]
#[clap(alias = "ahk-asc")]
AhkAppSpecificConfiguration(AhkAppSpecificConfiguration),
/// Generate common app-specific configurations and fixes in a PowerShell script
#[clap(arg_required_else_help = true)]
#[clap(alias = "pwsh-asc")]
PwshAppSpecificConfiguration(PwshAppSpecificConfiguration),
/// Convert a v1 ASC YAML file to a v2 ASC JSON file
#[clap(arg_required_else_help = true)]
#[clap(alias = "convert-asc")]
ConvertAppSpecificConfiguration(ConvertAppSpecificConfiguration),
/// Format a YAML file for use with the `app-specific-configuration` command
#[clap(arg_required_else_help = true)]
#[clap(alias = "fmt-asc")]
#[clap(hide = true)]
FormatAppSpecificConfiguration(FormatAppSpecificConfiguration),
/// Fetch the latest version of applications.json from komorebi-application-specific-configuration
#[clap(alias = "fetch-asc")]
FetchAppSpecificConfiguration,
/// Generate a JSON Schema for applications.json
#[clap(alias = "asc-schema")]
ApplicationSpecificConfigurationSchema,
/// Generate a JSON Schema of subscription notifications
NotificationSchema,
/// Generate a JSON Schema of socket messages
SocketSchema,
/// Generate a JSON Schema of the static configuration file
StaticConfigSchema,
/// Generates a static configuration JSON file based on the current window manager state
GenerateStaticConfig,
/// Generates the komorebi.lnk shortcut in shell:startup to autostart komorebi
EnableAutostart(EnableAutostart),
/// Deletes the komorebi.lnk shortcut in shell:startup to disable autostart
DisableAutostart,
}
+1 -645
View File
@@ -4,7 +4,6 @@
use chrono::Utc;
use komorebi_client::PathExt;
use komorebi_client::replace_env_in_path;
use komorebi_client::splash;
mod pan;
@@ -14,15 +13,12 @@ use std::io;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Write;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::process::Command;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::time::Duration;
use clap::Parser;
use clap::Subcommand;
use color_eyre::eyre;
use color_eyre::eyre::OptionExt;
use color_eyre::eyre::bail;
@@ -31,14 +27,12 @@ use komorebi_client::AppSpecificConfigurationPath;
use komorebi_client::ApplicationSpecificConfiguration;
use komorebi_client::send_message;
use komorebi_client::send_query;
use komorebic_core::args::ApplicationTarget;
use komorebic_core::args::BooleanState;
use komorebic_core::args::OneEnum;
use komorebic_core::cli::Cmd;
use komorebic_core::cli::Meta;
use komorebic_core::cli::command;
use komorebic_core::docgen::DocFormat;
use komorebic_core::messages::Messages;
use komorebic_core::platform::windows::*;
use lazy_static::lazy_static;
use miette::NamedSource;
use miette::Report;
@@ -55,15 +49,9 @@ use windows::Win32::UI::WindowsAndMessaging::ShowWindow;
use komorebi_client::ApplicationConfigurationGenerator;
use komorebi_client::ApplicationIdentifier;
use komorebi_client::FocusFollowsMouseImplementation;
use komorebi_client::HidingBehaviour;
use komorebi_client::OperationBehaviour;
use komorebi_client::OperationDirection;
use komorebi_client::PanDirection;
use komorebi_client::Rect;
use komorebi_client::SocketMessage;
use komorebi_client::StaticConfig;
use komorebi_client::WindowKind;
use komorebi_client::splash::ValidationFeedback;
lazy_static! {
@@ -121,638 +109,6 @@ struct ConfigurationError {
bad_bit: SourceSpan,
}
#[derive(Parser)]
pub struct WorkspaceCustomLayout {
/// Monitor index (zero-indexed)
monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
workspace: usize,
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
pub struct NamedWorkspaceCustomLayout {
/// Target workspace name
workspace: String,
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
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
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
pub struct NamedWorkspaceCustomLayoutRule {
/// Target workspace name
workspace: String,
/// 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
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
struct InvisibleBorders {
/// Size of the left invisible border
left: i32,
/// Size of the top invisible border (usually 0)
top: i32,
/// Size of the right invisible border (usually left * 2)
right: i32,
/// Size of the bottom invisible border (usually the same as left)
bottom: i32,
}
#[derive(Parser)]
struct MonitorIndexPreference {
/// Preferred monitor index (zero-indexed)
index_preference: usize,
/// Left value of the monitor's size Rect
left: i32,
/// Top value of the monitor's size Rect
top: i32,
/// Right value of the monitor's size Rect
right: i32,
/// Bottom value of the monitor's size Rect
bottom: i32,
}
#[derive(Parser)]
struct ToggleFocusFollowsMouse {
#[clap(value_enum, short, long, default_value = "windows")]
implementation: FocusFollowsMouseImplementation,
}
#[derive(Parser)]
struct FocusFollowsMouse {
#[clap(value_enum, short, long, default_value = "windows")]
implementation: FocusFollowsMouseImplementation,
#[clap(value_enum)]
boolean_state: BooleanState,
}
#[derive(Parser)]
struct Transparency {
#[clap(value_enum)]
boolean_state: BooleanState,
}
#[derive(Parser)]
struct TransparencyAlpha {
/// Alpha
alpha: u8,
}
#[derive(Parser)]
struct BorderColour {
#[clap(value_enum, short, long, default_value = "single")]
window_kind: WindowKind,
/// Red
r: u32,
/// Green
g: u32,
/// Blue
b: u32,
}
#[derive(Parser)]
struct BorderStyle {
/// Desired border style
#[clap(value_enum)]
style: komorebi_client::BorderStyle,
}
#[derive(Parser)]
struct MonocleFocusBehaviour {
/// Desired monocle focus behaviour
#[clap(value_enum)]
behaviour: komorebi_client::MonocleFocusBehaviour,
}
#[derive(Parser)]
struct BorderImplementation {
/// Desired border implementation
#[clap(value_enum)]
style: komorebi_client::BorderImplementation,
}
#[derive(Parser)]
struct StackbarMode {
/// Desired stackbar mode
#[clap(value_enum)]
mode: komorebi_client::StackbarMode,
}
#[derive(Parser)]
struct Animation {
#[clap(value_enum)]
boolean_state: BooleanState,
/// Animation type to apply the state to. If not specified, sets global state
#[clap(value_enum, short, long)]
animation_type: Option<komorebi_client::AnimationPrefix>,
}
#[derive(Parser)]
struct AnimationDuration {
/// Desired animation durations in ms
duration: u64,
/// Animation type to apply the duration to. If not specified, sets global duration
#[clap(value_enum, short, long)]
animation_type: Option<komorebi_client::AnimationPrefix>,
}
#[derive(Parser)]
struct AnimationStyle {
/// Desired ease function for animation
#[clap(value_enum, short, long, default_value = "linear")]
style: komorebi_client::AnimationStyle,
/// Animation type to apply the style to. If not specified, sets global style
#[clap(value_enum, short, long)]
animation_type: Option<komorebi_client::AnimationPrefix>,
}
#[derive(Parser)]
struct Docgen {
/// Output directory for generated documentation files
#[clap(short, long)]
output: Option<PathBuf>,
}
#[derive(Parser)]
#[allow(clippy::struct_excessive_bools)]
struct Start {
/// Allow the use of komorebi's custom focus-follows-mouse implementation
#[clap(hide = true)]
#[clap(short, long = "ffm")]
ffm: bool,
/// Path to a static configuration JSON file
#[clap(short, long)]
#[clap(value_parser = replace_env_in_path)]
config: Option<PathBuf>,
/// Wait for `komorebic complete-configuration` to be sent before processing events
#[clap(short, long)]
await_configuration: bool,
/// Start a TCP server on the given port to allow the direct sending of SocketMessages
#[clap(short, long)]
tcp_port: Option<usize>,
/// Start whkd in a background process
#[clap(long)]
whkd: bool,
/// Start autohotkey configuration file
#[clap(hide = true)]
#[clap(long)]
ahk: bool,
/// Start komorebi-bar in a background process
#[clap(long)]
bar: bool,
/// Start masir in a background process for focus-follows-mouse
#[clap(long)]
masir: bool,
/// Do not attempt to auto-apply a dumped state temp file from a previously running instance of komorebi
#[clap(long)]
clean_state: bool,
}
#[derive(Parser)]
struct Stop {
/// Stop whkd if it is running as a background process
#[clap(long)]
whkd: bool,
/// Stop ahk if it is running as a background process
#[clap(hide = true)]
#[clap(long)]
ahk: bool,
/// Stop komorebi-bar if it is running as a background process
#[clap(long)]
bar: bool,
/// Stop masir if it is running as a background process
#[clap(long)]
masir: bool,
/// Do not restore windows after stopping komorebi
#[clap(long, hide = true)]
ignore_restore: bool,
}
#[derive(Parser)]
struct Kill {
/// Kill whkd if it is running as a background process
#[clap(long)]
whkd: bool,
/// Kill ahk if it is running as a background process
#[clap(hide = true)]
#[clap(long)]
ahk: bool,
/// Kill komorebi-bar if it is running as a background process
#[clap(long)]
bar: bool,
/// Kill masir if it is running as a background process
#[clap(long)]
masir: bool,
}
#[derive(Parser)]
struct LoadCustomLayout {
/// JSON or YAML file from which the custom layout definition should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
struct SubscribePipe {
/// Name of the pipe to send event notifications to (without "\\.\pipe\" prepended)
named_pipe: String,
}
#[derive(Parser)]
struct UnsubscribePipe {
/// Name of the pipe to stop sending event notifications to (without "\\.\pipe\" prepended)
named_pipe: String,
}
#[derive(Parser)]
struct AhkAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
/// Optional YAML file of overrides to apply over the first file
#[clap(value_parser = replace_env_in_path)]
override_path: Option<PathBuf>,
}
#[derive(Parser)]
struct PwshAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
/// Optional YAML file of overrides to apply over the first file
#[clap(value_parser = replace_env_in_path)]
override_path: Option<PathBuf>,
}
#[derive(Parser)]
struct FormatAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
struct ConvertAppSpecificConfiguration {
/// YAML file from which the application-specific configurations should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
struct AltFocusHack {
#[clap(value_enum)]
boolean_state: BooleanState,
}
#[derive(Parser)]
struct EnableAutostart {
/// Path to a static configuration JSON file
#[clap(action, short, long)]
#[clap(value_parser = replace_env_in_path)]
config: Option<PathBuf>,
/// Enable komorebi's custom focus-follows-mouse implementation
#[clap(hide = true)]
#[clap(short, long = "ffm")]
ffm: bool,
/// Enable autostart of whkd
#[clap(long)]
whkd: bool,
/// Enable autostart of ahk
#[clap(hide = true)]
#[clap(long)]
ahk: bool,
/// Enable autostart of komorebi-bar
#[clap(long)]
bar: bool,
/// Enable autostart of masir
#[clap(long)]
masir: bool,
}
#[derive(Parser)]
struct Check {
/// Path to a static configuration JSON file
#[clap(action, short, long)]
#[clap(value_parser = replace_env_in_path)]
komorebi_config: Option<PathBuf>,
}
#[derive(Parser)]
struct EagerFocus {
/// Case-sensitive exe identifier
exe: String,
}
#[derive(Parser)]
struct ScrollingLayoutColumns {
/// Desired number of visible columns
count: NonZeroUsize,
}
#[derive(Parser)]
struct Pan {
/// The way that the view goes
#[clap(
value_enum,
required_unless_present = "stream",
conflicts_with = "stream"
)]
direction: Option<PanDirection>,
/// Read the gestures of fingers on a touchpad from standard input, as whkd writes them for
/// a swipe of three or four fingers, and pan with them
#[clap(long)]
stream: bool,
/// What the distances of a gesture are multiplied by, which is 1 if it is left out, with
/// --stream
#[clap(long)]
sensitivity: Option<f64>,
/// Go the other way to the fingers, with --stream
#[clap(long)]
reversed: bool,
/// Take a step for every two centimetres that the fingers go, and not move the view with
/// them, with --stream
#[clap(long)]
paging: bool,
}
#[derive(Parser)]
struct LayoutRatios {
/// Column width ratios (space-separated values between 0.1 and 0.9)
#[clap(short, long, num_args = 1..)]
columns: Option<Vec<f32>>,
/// Row height ratios (space-separated values between 0.1 and 0.9)
#[clap(short, long, num_args = 1..)]
rows: Option<Vec<f32>>,
}
#[derive(Parser)]
struct License {
/// Email address associated with an Individual Commercial Use License
email: String,
}
#[derive(Parser)]
struct Splash {
mdm_server: Option<String>,
}
#[derive(Subcommand)]
enum WindowsCommands {
#[clap(hide = true)]
Docgen(Docgen),
#[clap(hide = true)]
Splash(Splash),
/// Gather example configurations for a new-user quickstart
Quickstart,
/// Specify an email associated with an Individual Commercial Use License
#[clap(arg_required_else_help = true)]
License(License),
/// Start komorebi.exe as a background process
Start(Start),
/// Stop the komorebi.exe process and restore all hidden windows
Stop(Stop),
/// Kill background processes started by komorebic
Kill(Kill),
/// Check komorebi configuration and related files for common errors
Check(Check),
/// Show the path to komorebi.json
#[clap(alias = "config")]
Configuration,
/// Show the path to komorebi.bar.json
#[clap(alias = "bar-config")]
#[clap(alias = "bconfig")]
BarConfiguration,
/// Show the path to whkdrc
#[clap(alias = "whkd")]
Whkdrc,
/// Show the path to komorebi's data directory in %LOCALAPPDATA%
#[clap(alias = "datadir")]
DataDirectory,
/// Launch the komorebi-gui debugging tool
Gui,
/// Toggle the komorebi-shortcuts helper
ToggleShortcuts,
/// Subscribe to komorebi events using a Named Pipe
#[clap(arg_required_else_help = true)]
#[clap(alias = "subscribe")]
SubscribePipe(SubscribePipe),
/// Unsubscribe from komorebi events
#[clap(arg_required_else_help = true)]
#[clap(alias = "unsubscribe")]
UnsubscribePipe(UnsubscribePipe),
/// Tail komorebi.exe's process logs (cancel with Ctrl-C)
Log,
/// Forcibly focus the window at the cursor with a left mouse click
ForceFocus,
/// Focus the first managed window matching the given exe
#[clap(arg_required_else_help = true)]
EagerFocus(EagerFocus),
/// Set the invisible border dimensions around each window
#[clap(arg_required_else_help = true)]
InvisibleBorders(InvisibleBorders),
/// Set the number of visible columns for 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 to
/// the width that it had
ScrollingLayoutFullWidth,
/// Scroll the Scrolling layout so that the focused column is in the middle of the screen, once
CenterFocus,
/// Take the neighbouring window on one side into the focused column of the Scrolling layout
#[clap(arg_required_else_help = true)]
Consume(OneEnum<OperationDirection>),
/// Take the focused window out of its column in the Scrolling layout and put it in a column
/// of its own on the right
Expel,
/// Stack the windows of the focused column of the Scrolling layout, or spread the focused
/// stack out into a column with a window in each slot
ToggleColumnStack,
/// Move the view of the Scrolling layout a column to the left or the right, or with the
/// fingers on a touchpad, which does nothing in any other layout
#[clap(arg_required_else_help = true)]
Pan(Pan),
/// Set the layout column and row ratios for the focused workspace
LayoutRatios(LayoutRatios),
/// Load a custom layout from file for the focused workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
LoadCustomLayout(LoadCustomLayout),
/// Promote the user focus to the top of the tree
PromoteFocus,
/// Force the retiling of all managed windows
Retile,
/// Set the monitor index preference for a monitor identified using its size
#[clap(arg_required_else_help = true)]
MonitorIndexPreference(MonitorIndexPreference),
/// Set a custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
WorkspaceCustomLayout(WorkspaceCustomLayout),
/// Set a custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
NamedWorkspaceCustomLayout(NamedWorkspaceCustomLayout),
/// Add a dynamic custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
WorkspaceCustomLayoutRule(WorkspaceCustomLayoutRule),
/// Add a dynamic custom layout for the specified workspace
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
NamedWorkspaceCustomLayoutRule(NamedWorkspaceCustomLayoutRule),
/// Toggle the behaviour for new windows (stacking or dynamic tiling)
ToggleWindowContainerBehaviour,
/// Toggle the behaviour for new windows (stacking or dynamic tiling) for currently focused
/// workspace. If there was no behaviour set for the workspace previously it takes the opposite
/// of the global value.
ToggleWorkspaceWindowContainerBehaviour,
/// Toggle native maximization for the focused window
ToggleMaximize,
/// Restore all hidden windows (debugging command)
RestoreWindows,
/// Reload legacy komorebi.ahk or komorebi.ps1 configurations (if they exist)
ReloadConfiguration,
/// Enable or disable watching of legacy komorebi.ahk or komorebi.ps1 configurations (if they exist)
#[clap(arg_required_else_help = true)]
WatchConfiguration(OneEnum<BooleanState>),
/// For legacy komorebi.ahk or komorebi.ps1 configurations, signal that the final configuration option has been sent
CompleteConfiguration,
/// DEPRECATED since v0.1.22
#[deprecated(note = "No longer required")]
#[clap(arg_required_else_help = true)]
#[clap(hide = true)]
AltFocusHack(AltFocusHack),
/// Set the window behaviour when switching workspaces / cycling stacks
#[clap(arg_required_else_help = true)]
WindowHidingBehaviour(OneEnum<HidingBehaviour>),
/// Set the behaviour when focusing in a direction while a monocle container is active
#[clap(arg_required_else_help = true)]
MonocleFocusBehaviour(MonocleFocusBehaviour),
/// Toggle the behaviour when focusing in a direction while a monocle container is active
ToggleMonocleFocusBehaviour,
/// Set the operation behaviour when the focused window is not managed
#[clap(arg_required_else_help = true)]
UnmanagedWindowOperationBehaviour(OneEnum<OperationBehaviour>),
/// Identify an application that sends EVENT_OBJECT_NAMECHANGE on launch
#[clap(arg_required_else_help = true)]
IdentifyObjectNameChangeApplication(ApplicationTarget),
/// Identify an application that closes to the system tray
#[clap(arg_required_else_help = true)]
IdentifyTrayApplication(ApplicationTarget),
/// Identify an application that has WS_EX_LAYERED, but should still be managed
#[clap(arg_required_else_help = true)]
IdentifyLayeredApplication(ApplicationTarget),
/// Whitelist an application for title bar removal
#[clap(arg_required_else_help = true)]
RemoveTitleBar(ApplicationTarget),
/// Toggle title bars for whitelisted applications
ToggleTitleBars,
/// Identify an application that has overflowing borders
#[clap(hide = true)]
#[clap(alias = "identify-border-overflow")]
IdentifyBorderOverflowApplication(ApplicationTarget),
/// Set the colour for a window border kind
#[clap(arg_required_else_help = true)]
#[clap(alias = "active-window-border-colour")]
BorderColour(BorderColour),
/// Set the border style
#[clap(arg_required_else_help = true)]
BorderStyle(BorderStyle),
/// Set the border implementation
#[clap(arg_required_else_help = true)]
BorderImplementation(BorderImplementation),
/// Set the stackbar mode
#[clap(arg_required_else_help = true)]
StackbarMode(StackbarMode),
/// Enable or disable transparency for unfocused windows
#[clap(arg_required_else_help = true)]
Transparency(Transparency),
/// Set the alpha value for unfocused window transparency
#[clap(arg_required_else_help = true)]
TransparencyAlpha(TransparencyAlpha),
/// Toggle transparency for unfocused windows
ToggleTransparency,
/// Enable or disable movement animations
#[clap(arg_required_else_help = true)]
Animation(Animation),
/// Set the duration for movement animations in ms
#[clap(arg_required_else_help = true)]
AnimationDuration(AnimationDuration),
/// Set the ease function for movement animations
#[clap(arg_required_else_help = true)]
AnimationStyle(AnimationStyle),
/// Enable or disable focus follows mouse for the operating system
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
FocusFollowsMouse(FocusFollowsMouse),
/// Toggle focus follows mouse for the operating system
#[clap(hide = true)]
#[clap(arg_required_else_help = true)]
ToggleFocusFollowsMouse(ToggleFocusFollowsMouse),
/// Generate common app-specific configurations and fixes to use in komorebi.ahk
#[clap(arg_required_else_help = true)]
#[clap(alias = "ahk-asc")]
AhkAppSpecificConfiguration(AhkAppSpecificConfiguration),
/// Generate common app-specific configurations and fixes in a PowerShell script
#[clap(arg_required_else_help = true)]
#[clap(alias = "pwsh-asc")]
PwshAppSpecificConfiguration(PwshAppSpecificConfiguration),
/// Convert a v1 ASC YAML file to a v2 ASC JSON file
#[clap(arg_required_else_help = true)]
#[clap(alias = "convert-asc")]
ConvertAppSpecificConfiguration(ConvertAppSpecificConfiguration),
/// Format a YAML file for use with the `app-specific-configuration` command
#[clap(arg_required_else_help = true)]
#[clap(alias = "fmt-asc")]
#[clap(hide = true)]
FormatAppSpecificConfiguration(FormatAppSpecificConfiguration),
/// Fetch the latest version of applications.json from komorebi-application-specific-configuration
#[clap(alias = "fetch-asc")]
FetchAppSpecificConfiguration,
/// Generate a JSON Schema for applications.json
#[clap(alias = "asc-schema")]
ApplicationSpecificConfigurationSchema,
/// Generate a JSON Schema of subscription notifications
NotificationSchema,
/// Generate a JSON Schema of socket messages
SocketSchema,
/// Generate a JSON Schema of the static configuration file
StaticConfigSchema,
/// Generates a static configuration JSON file based on the current window manager state
GenerateStaticConfig,
/// Generates the komorebi.lnk shortcut in shell:startup to autostart komorebi
EnableAutostart(EnableAutostart),
/// Deletes the komorebi.lnk shortcut in shell:startup to disable autostart
DisableAutostart,
}
// print_query is a helper that queries komorebi and prints the response.
// panics on error.
fn print_query(message: &SocketMessage) {