feat(cli): migrate a bunch of cfg cmds

This commit migrates a whole bunch of interactive runtime configuration
komorebic commands and implements their corresponding SocketMessage
variants.

Largely lifted as-is from komorebi for Windows.
This commit is contained in:
LGUG2Z committed 2025-09-24 08:39:54 -07:00
1 parent 0b17721580
commit b2d4dff929
8 files changed
+870 -85

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ pub use komorebi::core::default_layout::DefaultLayout;
pub use komorebi::core::operation_direction::OperationDirection;
pub use komorebi::core::pathext::PathExt;
pub use komorebi::core::pathext::replace_env_in_path;
pub use komorebi::core::rect::Rect;
use std::borrow::Borrow;
use std::io::BufReader;
use std::io::Read;
+1
View File
@@ -1,6 +1,7 @@
[package]
name = "komorebi"
version = "0.1.0"
description = "A tiling window manager for macOS"
edition = "2024"
[dependencies]
+41 -23
View File
@@ -3,10 +3,12 @@ use crate::core::cycle_direction::CycleDirection;
use crate::core::default_layout::DefaultLayout;
use crate::core::operation_direction::OperationDirection;
use crate::core::pathext::ResolvedPathBuf;
use crate::core::rect::Rect;
use clap::ValueEnum;
use color_eyre::eyre;
use serde::Deserialize;
use serde::Serialize;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::str::FromStr;
use strum::Display;
@@ -40,6 +42,22 @@ pub enum Sizing {
Decrease,
}
impl Sizing {
#[must_use]
pub const fn adjust_by(&self, value: i32, adjustment: i32) -> i32 {
match self {
Self::Increase => value + adjustment,
Self::Decrease => {
if value > 0 && value - adjustment >= 0 {
value - adjustment
} else {
value
}
}
}
}
}
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct WindowManagementBehaviour {
/// The current WindowContainerBehaviour to be used
@@ -233,11 +251,11 @@ pub enum SocketMessage {
// Current Workspace Commands
// ManageFocusedWindow,
// UnmanageFocusedWindow,
// AdjustContainerPadding(Sizing, i32),
// AdjustWorkspacePadding(Sizing, i32),
AdjustContainerPadding(Sizing, i32),
AdjustWorkspacePadding(Sizing, i32),
ChangeLayout(DefaultLayout),
CycleLayout(CycleDirection),
// ScrollingLayoutColumns(NonZeroUsize),
ScrollingLayoutColumns(NonZeroUsize),
// ChangeLayoutCustom(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
FlipLayout(Axis),
ToggleWorkspaceWindowContainerBehaviour,
@@ -247,7 +265,7 @@ pub enum SocketMessage {
// DisplayIndexPreference(usize, String),
// EnsureWorkspaces(usize, usize),
// EnsureNamedWorkspaces(usize, Vec<String>),
// NewWorkspace,
NewWorkspace,
ToggleTiling,
// Stop,
// StopIgnoreRestore,
@@ -269,21 +287,21 @@ pub enum SocketMessage {
FocusWorkspaceNumbers(usize),
FocusMonitorWorkspaceNumber(usize, usize),
FocusNamedWorkspace(String),
// ContainerPadding(usize, usize, i32),
// NamedWorkspaceContainerPadding(String, i32),
// FocusedWorkspaceContainerPadding(i32),
// WorkspacePadding(usize, usize, i32),
// NamedWorkspacePadding(String, i32),
// FocusedWorkspacePadding(i32),
// WorkspaceTiling(usize, usize, bool),
// NamedWorkspaceTiling(String, bool),
// WorkspaceName(usize, usize, String),
// WorkspaceLayout(usize, usize, DefaultLayout),
// NamedWorkspaceLayout(String, DefaultLayout),
ContainerPadding(usize, usize, i32),
NamedWorkspaceContainerPadding(String, i32),
FocusedWorkspaceContainerPadding(i32),
WorkspacePadding(usize, usize, i32),
NamedWorkspacePadding(String, i32),
FocusedWorkspacePadding(i32),
WorkspaceTiling(usize, usize, bool),
NamedWorkspaceTiling(String, bool),
WorkspaceName(usize, usize, String),
WorkspaceLayout(usize, usize, DefaultLayout),
NamedWorkspaceLayout(String, DefaultLayout),
// WorkspaceLayoutCustom(usize, usize, #[serde_as(as = "ResolvedPathBuf")] PathBuf),
// NamedWorkspaceLayoutCustom(String, #[serde_as(as = "ResolvedPathBuf")] PathBuf),
// WorkspaceLayoutRule(usize, usize, usize, DefaultLayout),
// NamedWorkspaceLayoutRule(String, usize, DefaultLayout),
WorkspaceLayoutRule(usize, usize, usize, DefaultLayout),
NamedWorkspaceLayoutRule(String, usize, DefaultLayout),
// WorkspaceLayoutCustomRule(
// usize,
// usize,
@@ -291,8 +309,8 @@ pub enum SocketMessage {
// #[serde_as(as = "ResolvedPathBuf")] PathBuf,
// ),
// NamedWorkspaceLayoutCustomRule(String, usize, #[serde_as(as = "ResolvedPathBuf")] PathBuf),
// ClearWorkspaceLayoutRules(usize, usize),
// ClearNamedWorkspaceLayoutRules(String),
ClearWorkspaceLayoutRules(usize, usize),
ClearNamedWorkspaceLayoutRules(String),
ToggleWorkspaceLayer,
// Configuration
// ReloadConfiguration,
@@ -328,11 +346,11 @@ pub enum SocketMessage {
// StackbarTabWidth(i32),
// StackbarFontSize(i32),
// StackbarFontFamily(Option<String>),
// WorkAreaOffset(Rect),
// MonitorWorkAreaOffset(usize, Rect),
// WorkspaceWorkAreaOffset(usize, usize, Rect),
WorkAreaOffset(Rect),
MonitorWorkAreaOffset(usize, Rect),
WorkspaceWorkAreaOffset(usize, usize, Rect),
ToggleWindowBasedWorkAreaOffset,
// ResizeDelta(i32),
ResizeDelta(i32),
InitialWorkspaceRule(ApplicationIdentifier, String, usize, usize),
InitialNamedWorkspaceRule(ApplicationIdentifier, String, String),
WorkspaceRule(ApplicationIdentifier, String, usize, usize),
+4
View File
@@ -180,6 +180,10 @@ impl Monitor {
Ok(())
}
pub fn new_workspace_idx(&self) -> usize {
self.workspaces().len()
}
#[tracing::instrument(skip(self))]
pub fn move_container_to_workspace(
&mut self,
+149
View File
@@ -14,6 +14,8 @@ use crate::core::config_generation::IdWithIdentifier;
use crate::core::config_generation::MatchingRule;
use crate::core::config_generation::MatchingStrategy;
use crate::core::config_generation::WorkspaceMatchingRule;
use crate::core::default_layout::LayoutOptions;
use crate::core::default_layout::ScrollingLayoutOptions;
use crate::core::layout::Layout;
use crate::core::operation_direction::OperationDirection;
use crate::core::rect::Rect;
@@ -1235,6 +1237,153 @@ impl WindowManager {
}));
}
}
SocketMessage::NewWorkspace => {
self.new_workspace()?;
}
SocketMessage::ContainerPadding(monitor_idx, workspace_idx, size) => {
self.set_container_padding(monitor_idx, workspace_idx, size)?;
}
SocketMessage::NamedWorkspaceContainerPadding(ref workspace, size) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
self.set_container_padding(monitor_idx, workspace_idx, size)?;
}
}
SocketMessage::WorkspacePadding(monitor_idx, workspace_idx, size) => {
self.set_workspace_padding(monitor_idx, workspace_idx, size)?;
}
SocketMessage::NamedWorkspacePadding(ref workspace, size) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
self.set_workspace_padding(monitor_idx, workspace_idx, size)?;
}
}
SocketMessage::FocusedWorkspaceContainerPadding(adjustment) => {
let focused_monitor_idx = self.focused_monitor_idx();
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
self.set_container_padding(focused_monitor_idx, focused_workspace_idx, adjustment)?;
}
SocketMessage::FocusedWorkspacePadding(adjustment) => {
let focused_monitor_idx = self.focused_monitor_idx();
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
self.set_workspace_padding(focused_monitor_idx, focused_workspace_idx, adjustment)?;
}
SocketMessage::WorkspaceTiling(monitor_idx, workspace_idx, tile) => {
self.set_workspace_tiling(monitor_idx, workspace_idx, tile)?;
}
SocketMessage::WorkspaceLayout(monitor_idx, workspace_idx, layout) => {
self.set_workspace_layout_default(monitor_idx, workspace_idx, layout)?;
}
SocketMessage::WorkspaceLayoutRule(
monitor_idx,
workspace_idx,
at_container_count,
layout,
) => {
self.add_workspace_layout_default_rule(
monitor_idx,
workspace_idx,
at_container_count,
layout,
)?;
}
SocketMessage::NamedWorkspaceTiling(ref workspace, tile) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
self.set_workspace_tiling(monitor_idx, workspace_idx, tile)?;
}
}
SocketMessage::WorkspaceName(monitor_idx, workspace_idx, ref name) => {
self.set_workspace_name(monitor_idx, workspace_idx, name.to_string())?;
}
SocketMessage::NamedWorkspaceLayout(ref workspace, layout) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
self.set_workspace_layout_default(monitor_idx, workspace_idx, layout)?;
}
}
SocketMessage::ClearWorkspaceLayoutRules(monitor_idx, workspace_idx) => {
self.clear_workspace_layout_rules(monitor_idx, workspace_idx)?;
}
SocketMessage::WorkAreaOffset(rect) => {
self.work_area_offset = Option::from(rect);
self.retile_all(false)?;
}
SocketMessage::MonitorWorkAreaOffset(monitor_idx, rect) => {
if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx) {
monitor.work_area_offset = Option::from(rect);
self.retile_all(false)?;
}
}
SocketMessage::WorkspaceWorkAreaOffset(monitor_idx, workspace_idx, rect) => {
if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx)
&& let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx)
{
workspace.work_area_offset = Option::from(rect);
self.retile_all(false)?
}
}
SocketMessage::ResizeDelta(delta) => {
self.resize_delta = delta;
}
SocketMessage::AdjustContainerPadding(sizing, adjustment) => {
self.adjust_container_padding(sizing, adjustment)?;
}
SocketMessage::AdjustWorkspacePadding(sizing, adjustment) => {
self.adjust_workspace_padding(sizing, adjustment)?;
}
SocketMessage::ScrollingLayoutColumns(count) => {
let focused_workspace = self.focused_workspace_mut()?;
let options = match focused_workspace.layout_options {
Some(mut opts) => {
if let Some(scrolling) = &mut opts.scrolling {
scrolling.columns = count.into();
}
opts
}
None => LayoutOptions {
scrolling: Some(ScrollingLayoutOptions {
columns: count.into(),
}),
},
};
focused_workspace.layout_options = Some(options);
self.update_focused_workspace(false, false)?;
}
SocketMessage::NamedWorkspaceLayoutRule(ref workspace, at_container_count, layout) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
self.add_workspace_layout_default_rule(
monitor_idx,
workspace_idx,
at_container_count,
layout,
)?;
}
}
SocketMessage::ClearNamedWorkspaceLayoutRules(ref workspace) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
self.clear_workspace_layout_rules(monitor_idx, workspace_idx)?;
}
}
}
self.update_known_window_ids();
+254
View File
@@ -597,6 +597,40 @@ impl WindowManager {
self.update_focused_workspace(self.mouse_follows_focus, false)
}
#[tracing::instrument(skip(self))]
pub fn set_workspace_layout_default(
&mut self,
monitor_idx: usize,
workspace_idx: usize,
layout: DefaultLayout,
) -> eyre::Result<()> {
tracing::info!("setting workspace layout");
let focused_monitor_idx = self.focused_monitor_idx();
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_eyre("there is no monitor")?;
workspace.layout = Layout::Default(layout);
// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update()?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
}
}
pub fn focused_workspace_idx(&self) -> eyre::Result<usize> {
Ok(self
.focused_monitor()
@@ -645,6 +679,21 @@ impl WindowManager {
.ok_or_eyre("there is no workspace")
}
#[tracing::instrument(skip(self))]
pub fn new_workspace(&mut self) -> eyre::Result<()> {
tracing::info!("adding new workspace");
let mouse_follows_focus = self.mouse_follows_focus;
let monitor = self
.focused_monitor_mut()
.ok_or_eyre("there is no workspace")?;
monitor.focus_workspace(monitor.new_workspace_idx())?;
monitor.load_focused_workspace(mouse_follows_focus)?;
self.update_focused_workspace(self.mouse_follows_focus, false)
}
pub fn focused_container(&self) -> eyre::Result<&Container> {
self.focused_workspace()?
.focused_container()
@@ -2268,4 +2317,209 @@ impl WindowManager {
float_rule_placement: self.window_management_behaviour.float_rule_placement,
}
}
#[tracing::instrument(skip(self))]
pub fn set_workspace_padding(
&mut self,
monitor_idx: usize,
workspace_idx: usize,
size: i32,
) -> eyre::Result<()> {
tracing::info!("setting workspace padding");
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_eyre("there is no monitor")?;
workspace.workspace_padding = Option::from(size);
self.update_focused_workspace(false, false)
}
#[tracing::instrument(skip(self))]
pub fn set_workspace_name(
&mut self,
monitor_idx: usize,
workspace_idx: usize,
name: String,
) -> eyre::Result<()> {
tracing::info!("setting workspace name");
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_eyre("there is no monitor")?;
workspace.name = Option::from(name.clone());
// monitor.workspace_names.insert(workspace_idx, name);
Ok(())
}
#[tracing::instrument(skip(self))]
pub fn set_container_padding(
&mut self,
monitor_idx: usize,
workspace_idx: usize,
size: i32,
) -> eyre::Result<()> {
tracing::info!("setting container padding");
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_eyre("there is no monitor")?;
workspace.container_padding = Option::from(size);
self.update_focused_workspace(false, false)
}
#[tracing::instrument(skip(self))]
pub fn set_workspace_tiling(
&mut self,
monitor_idx: usize,
workspace_idx: usize,
tile: bool,
) -> eyre::Result<()> {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_eyre("there is no monitor")?;
workspace.tile = tile;
self.update_focused_workspace(false, false)
}
#[tracing::instrument(skip(self))]
pub fn add_workspace_layout_default_rule(
&mut self,
monitor_idx: usize,
workspace_idx: usize,
at_container_count: usize,
layout: DefaultLayout,
) -> eyre::Result<()> {
tracing::info!("setting workspace layout");
let focused_monitor_idx = self.focused_monitor_idx();
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_eyre("there is no monitor")?;
let rules: &mut Vec<(usize, Layout)> = &mut workspace.layout_rules;
rules.retain(|pair| pair.0 != at_container_count);
rules.push((at_container_count, Layout::Default(layout)));
rules.sort_by(|a, b| a.0.cmp(&b.0));
// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update()?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
}
}
#[tracing::instrument(skip(self))]
pub fn clear_workspace_layout_rules(
&mut self,
monitor_idx: usize,
workspace_idx: usize,
) -> eyre::Result<()> {
tracing::info!("clearing workspace layout rules");
let focused_monitor_idx = self.focused_monitor_idx();
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_eyre("there is no monitor")?;
let rules: &mut Vec<(usize, Layout)> = &mut workspace.layout_rules;
rules.clear();
// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update()?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
}
}
#[tracing::instrument(skip(self))]
pub fn adjust_workspace_padding(
&mut self,
sizing: Sizing,
adjustment: i32,
) -> eyre::Result<()> {
tracing::info!("adjusting workspace padding");
let workspace = self.focused_workspace_mut()?;
let padding = workspace
.workspace_padding
.ok_or_eyre("there is no workspace padding")?;
workspace.workspace_padding = Option::from(sizing.adjust_by(padding, adjustment));
self.update_focused_workspace(false, false)
}
#[tracing::instrument(skip(self))]
pub fn adjust_container_padding(
&mut self,
sizing: Sizing,
adjustment: i32,
) -> eyre::Result<()> {
tracing::info!("adjusting container padding");
let workspace = self.focused_workspace_mut()?;
let padding = workspace
.container_padding
.ok_or_eyre("there is no container padding")?;
workspace.container_padding = Option::from(sizing.adjust_by(padding, adjustment));
self.update_focused_workspace(false, false)
}
}
+4
View File
@@ -1,6 +1,7 @@
[package]
name = "komorebic"
version = "0.1.0"
description = "The command-line interface for Komorebi, a tiling window manager for macOS"
edition = "2024"
[dependencies]
@@ -20,3 +21,6 @@ sysinfo = { workspace = true }
[build-dependencies]
reqwest = { version = "0.12", features = ["blocking"] }
shadow-rs = { workspace = true }
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(FALSE)'] }
+416 -62
View File
@@ -2,6 +2,7 @@
use chrono::Utc;
use clap::Parser;
use clap::ValueEnum;
use color_eyre::eyre;
use fs_tail::TailedFile;
use komorebi_client::ApplicationIdentifier;
@@ -10,6 +11,7 @@ use komorebi_client::CycleDirection;
use komorebi_client::DefaultLayout;
use komorebi_client::OperationDirection;
use komorebi_client::PathExt;
use komorebi_client::Rect;
use komorebi_client::Sizing;
use komorebi_client::SocketMessage;
use komorebi_client::StateQuery;
@@ -21,6 +23,7 @@ use std::fs::File;
use std::fs::OpenOptions;
use std::io::BufRead;
use std::io::Write;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::process::Command;
use std::process::Stdio;
@@ -55,6 +58,21 @@ lazy_static! {
shadow_rs::shadow!(build);
#[derive(Copy, Clone, ValueEnum)]
enum BooleanState {
Enable,
Disable,
}
impl From<BooleanState> for bool {
fn from(b: BooleanState) -> Self {
match b {
BooleanState::Enable => true,
BooleanState::Disable => false,
}
}
}
macro_rules! gen_enum_subcommand_args {
// SubCommand Pattern: Enum Type
( $( $name:ident: $element:ty ),+ $(,)? ) => {
@@ -144,6 +162,149 @@ gen_named_target_subcommand_args! {
ClearNamedWorkspaceLayoutRules
}
// Thanks to @danielhenrymantilla for showing me how to use cfg_attr with an optional argument like
// this on the Rust Programming Language Community Discord Server
macro_rules! gen_workspace_subcommand_args {
// Workspace Property: #[enum] Value Enum (if the value is an Enum)
// Workspace Property: Value Type (if the value is anything else)
( $( $name:ident: $(#[enum] $(@$value_enum:tt)?)? $value:ty ),+ $(,)? ) => (
pastey::paste! {
$(
#[derive(clap::Parser)]
pub struct [<Workspace $name>] {
/// Monitor index (zero-indexed)
monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
workspace: usize,
$(#[clap(value_enum)] $($value_enum)?)?
#[cfg_attr(
all($(FALSE $($value_enum)?)?),
doc = ""$name " of the workspace as a "$value ""
)]
value: $value,
}
)+
}
)
}
gen_workspace_subcommand_args! {
Name: String,
Layout: #[enum] DefaultLayout,
Tiling: #[enum] BooleanState,
}
macro_rules! gen_named_workspace_subcommand_args {
// Workspace Property: #[enum] Value Enum (if the value is an Enum)
// Workspace Property: Value Type (if the value is anything else)
( $( $name:ident: $(#[enum] $(@$value_enum:tt)?)? $value:ty ),+ $(,)? ) => (
pastey::paste! {
$(
#[derive(clap::Parser)]
pub struct [<NamedWorkspace $name>] {
/// Target workspace name
workspace: String,
$(#[clap(value_enum)] $($value_enum)?)?
#[cfg_attr(
all($(FALSE $($value_enum)?)?),
doc = ""$name " of the workspace as a "$value ""
)]
value: $value,
}
)+
}
)
}
gen_named_workspace_subcommand_args! {
Layout: #[enum] DefaultLayout,
Tiling: #[enum] BooleanState,
}
macro_rules! gen_focused_workspace_padding_subcommand_args {
// SubCommand Pattern
( $( $name:ident ),+ $(,)? ) => {
$(
#[derive(clap::Parser)]
pub struct $name {
/// Pixels size to set as an integer
size: i32,
}
)+
};
}
gen_focused_workspace_padding_subcommand_args! {
FocusedWorkspaceContainerPadding,
FocusedWorkspacePadding,
}
macro_rules! gen_padding_subcommand_args {
// SubCommand Pattern
( $( $name:ident ),+ $(,)? ) => {
$(
#[derive(clap::Parser)]
pub struct $name {
/// Monitor index (zero-indexed)
monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
workspace: usize,
/// Pixels to pad with as an integer
size: i32,
}
)+
};
}
gen_padding_subcommand_args! {
ContainerPadding,
WorkspacePadding,
}
macro_rules! gen_named_padding_subcommand_args {
// SubCommand Pattern
( $( $name:ident ),+ $(,)? ) => {
$(
#[derive(clap::Parser)]
pub struct $name {
/// Target workspace name
workspace: String,
/// Pixels to pad with as an integer
size: i32,
}
)+
};
}
gen_named_padding_subcommand_args! {
NamedWorkspaceContainerPadding,
NamedWorkspacePadding,
}
macro_rules! gen_padding_adjustment_subcommand_args {
// SubCommand Pattern
( $( $name:ident ),+ $(,)? ) => {
$(
#[derive(clap::Parser)]
pub struct $name {
#[clap(value_enum)]
sizing: Sizing,
/// Pixels to adjust by as an integer
adjustment: i32,
}
)+
};
}
gen_padding_adjustment_subcommand_args! {
AdjustContainerPadding,
AdjustWorkspacePadding,
}
macro_rules! gen_application_target_subcommand_args {
// SubCommand Pattern
( $( $name:ident ),+ $(,)? ) => {
@@ -169,6 +330,15 @@ gen_application_target_subcommand_args! {
RemoveTitleBar,
}
#[derive(Parser)]
pub struct ClearWorkspaceLayoutRules {
/// Monitor index (zero-indexed)
monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
workspace: usize,
}
#[derive(Parser)]
struct InitialWorkspaceRule {
#[clap(value_enum)]
@@ -243,6 +413,54 @@ struct ResizeAxis {
sizing: Sizing,
}
#[derive(Parser)]
struct ResizeDelta {
/// The delta of pixels by which to increase or decrease window dimensions when resizing
pixels: i32,
}
#[derive(Parser)]
struct GlobalWorkAreaOffset {
/// Size of the left work area offset (set right to left * 2 to maintain right padding)
left: i32,
/// Size of the top work area offset (set bottom to the same value to maintain bottom padding)
top: i32,
/// Size of the right work area offset
right: i32,
/// Size of the bottom work area offset
bottom: i32,
}
#[derive(Parser)]
struct MonitorWorkAreaOffset {
/// Monitor index (zero-indexed)
monitor: usize,
/// Size of the left work area offset (set right to left * 2 to maintain right padding)
left: i32,
/// Size of the top work area offset (set bottom to the same value to maintain bottom padding)
top: i32,
/// Size of the right work area offset
right: i32,
/// Size of the bottom work area offset
bottom: i32,
}
#[derive(Parser)]
struct WorkspaceWorkAreaOffset {
/// Monitor index (zero-indexed)
monitor: usize,
/// Workspace index (zero-indexed)
workspace: usize,
/// Size of the left work area offset (set right to left * 2 to maintain right padding)
left: i32,
/// Size of the top work area offset (set bottom to the same value to maintain bottom padding)
top: i32,
/// Size of the right work area offset
right: i32,
/// Size of the bottom work area offset
bottom: i32,
}
#[derive(Parser)]
struct FocusMonitorWorkspace {
/// Target monitor index (zero-indexed)
@@ -285,6 +503,12 @@ struct EagerFocus {
exe: String,
}
#[derive(Parser)]
struct ScrollingLayoutColumns {
/// Desired number of visible columns
count: NonZeroUsize,
}
#[derive(Parser)]
#[clap(author, about, version = build::CLAP_LONG_VERSION)]
struct Opts {
@@ -492,46 +716,46 @@ enum SubCommand {
/// Swap focused monitor workspaces with specified monitor
#[clap(arg_required_else_help = true)]
SwapWorkspacesWithMonitor(SwapWorkspacesWithMonitor),
// /// Create and append a new workspace on the focused monitor
// NewWorkspace,
// /// Set the resize delta (used by resize-edge and resize-axis)
// #[clap(arg_required_else_help = true)]
// ResizeDelta(ResizeDelta),
/// Create and append a new workspace on the focused monitor
NewWorkspace,
/// Set the resize delta (used by resize-edge and resize-axis)
#[clap(arg_required_else_help = true)]
ResizeDelta(ResizeDelta),
// /// Set the invisible border dimensions around each window
// #[clap(arg_required_else_help = true)]
// InvisibleBorders(InvisibleBorders),
// /// Set offsets to exclude parts of the work area from tiling
// #[clap(arg_required_else_help = true)]
// GlobalWorkAreaOffset(GlobalWorkAreaOffset),
// /// Set offsets for a monitor to exclude parts of the work area from tiling
// #[clap(arg_required_else_help = true)]
// MonitorWorkAreaOffset(MonitorWorkAreaOffset),
// /// Set offsets for a workspace to exclude parts of the work area from tiling
// #[clap(arg_required_else_help = true)]
// WorkspaceWorkAreaOffset(WorkspaceWorkAreaOffset),
/// Set offsets to exclude parts of the work area from tiling
#[clap(arg_required_else_help = true)]
GlobalWorkAreaOffset(GlobalWorkAreaOffset),
/// Set offsets for a monitor to exclude parts of the work area from tiling
#[clap(arg_required_else_help = true)]
MonitorWorkAreaOffset(MonitorWorkAreaOffset),
/// Set offsets for a workspace to exclude parts of the work area from tiling
#[clap(arg_required_else_help = true)]
WorkspaceWorkAreaOffset(WorkspaceWorkAreaOffset),
/// Toggle application of the window-based work area offset for the focused workspace
ToggleWindowBasedWorkAreaOffset,
// /// Set container padding on the focused workspace
// #[clap(arg_required_else_help = true)]
// FocusedWorkspaceContainerPadding(FocusedWorkspaceContainerPadding),
// /// Set workspace padding on the focused workspace
// #[clap(arg_required_else_help = true)]
// FocusedWorkspacePadding(FocusedWorkspacePadding),
// /// Adjust container padding on the focused workspace
// #[clap(arg_required_else_help = true)]
// AdjustContainerPadding(AdjustContainerPadding),
// /// Adjust workspace padding on the focused workspace
// #[clap(arg_required_else_help = true)]
// AdjustWorkspacePadding(AdjustWorkspacePadding),
/// Set container padding on the focused workspace
#[clap(arg_required_else_help = true)]
FocusedWorkspaceContainerPadding(FocusedWorkspaceContainerPadding),
/// Set workspace padding on the focused workspace
#[clap(arg_required_else_help = true)]
FocusedWorkspacePadding(FocusedWorkspacePadding),
/// Adjust container padding on the focused workspace
#[clap(arg_required_else_help = true)]
AdjustContainerPadding(AdjustContainerPadding),
/// Adjust workspace padding on the focused workspace
#[clap(arg_required_else_help = true)]
AdjustWorkspacePadding(AdjustWorkspacePadding),
/// Set the layout on the focused workspace
#[clap(arg_required_else_help = true)]
ChangeLayout(ChangeLayout),
/// Cycle between available layouts
#[clap(arg_required_else_help = true)]
CycleLayout(CycleLayout),
// /// Set the number of visible columns for the Scrolling layout on the focused workspace
// #[clap(arg_required_else_help = true)]
// ScrollingLayoutColumns(ScrollingLayoutColumns),
/// Set the number of visible columns for the Scrolling layout on the focused workspace
#[clap(arg_required_else_help = true)]
ScrollingLayoutColumns(ScrollingLayoutColumns),
// /// Load a custom layout from file for the focused workspace
// #[clap(hide = true)]
// #[clap(arg_required_else_help = true)]
@@ -559,24 +783,24 @@ enum SubCommand {
// /// Create these many named workspaces for the specified monitor
// #[clap(arg_required_else_help = true)]
// EnsureNamedWorkspaces(EnsureNamedWorkspaces),
// /// Set the container padding for the specified workspace
// #[clap(arg_required_else_help = true)]
// ContainerPadding(ContainerPadding),
// /// Set the container padding for the specified workspace
// #[clap(arg_required_else_help = true)]
// NamedWorkspaceContainerPadding(NamedWorkspaceContainerPadding),
// /// Set the workspace padding for the specified workspace
// #[clap(arg_required_else_help = true)]
// WorkspacePadding(WorkspacePadding),
// /// Set the workspace padding for the specified workspace
// #[clap(arg_required_else_help = true)]
// NamedWorkspacePadding(NamedWorkspacePadding),
// /// Set the layout for the specified workspace
// #[clap(arg_required_else_help = true)]
// WorkspaceLayout(WorkspaceLayout),
// /// Set the layout for the specified workspace
// #[clap(arg_required_else_help = true)]
// NamedWorkspaceLayout(NamedWorkspaceLayout),
/// Set the container padding for the specified workspace
#[clap(arg_required_else_help = true)]
ContainerPadding(ContainerPadding),
/// Set the container padding for the specified workspace
#[clap(arg_required_else_help = true)]
NamedWorkspaceContainerPadding(NamedWorkspaceContainerPadding),
/// Set the workspace padding for the specified workspace
#[clap(arg_required_else_help = true)]
WorkspacePadding(WorkspacePadding),
/// Set the workspace padding for the specified workspace
#[clap(arg_required_else_help = true)]
NamedWorkspacePadding(NamedWorkspacePadding),
/// Set the layout for the specified workspace
#[clap(arg_required_else_help = true)]
WorkspaceLayout(WorkspaceLayout),
/// Set the layout for the specified workspace
#[clap(arg_required_else_help = true)]
NamedWorkspaceLayout(NamedWorkspaceLayout),
// /// Set a custom layout for the specified workspace
// #[clap(hide = true)]
// #[clap(arg_required_else_help = true)]
@@ -599,21 +823,21 @@ enum SubCommand {
// #[clap(hide = true)]
// #[clap(arg_required_else_help = true)]
// NamedWorkspaceCustomLayoutRule(NamedWorkspaceCustomLayoutRule),
// /// Clear all dynamic layout rules for the specified workspace
// #[clap(arg_required_else_help = true)]
// ClearWorkspaceLayoutRules(ClearWorkspaceLayoutRules),
// /// Clear all dynamic layout rules for the specified workspace
// #[clap(arg_required_else_help = true)]
// ClearNamedWorkspaceLayoutRules(ClearNamedWorkspaceLayoutRules),
// /// Enable or disable window tiling for the specified workspace
// #[clap(arg_required_else_help = true)]
// WorkspaceTiling(WorkspaceTiling),
// /// Enable or disable window tiling for the specified workspace
// #[clap(arg_required_else_help = true)]
// NamedWorkspaceTiling(NamedWorkspaceTiling),
// /// Set the workspace name for the specified workspace
// #[clap(arg_required_else_help = true)]
// WorkspaceName(WorkspaceName),
/// Clear all dynamic layout rules for the specified workspace
#[clap(arg_required_else_help = true)]
ClearWorkspaceLayoutRules(ClearWorkspaceLayoutRules),
/// Clear all dynamic layout rules for the specified workspace
#[clap(arg_required_else_help = true)]
ClearNamedWorkspaceLayoutRules(ClearNamedWorkspaceLayoutRules),
/// Enable or disable window tiling for the specified workspace
#[clap(arg_required_else_help = true)]
WorkspaceTiling(WorkspaceTiling),
/// Enable or disable window tiling for the specified workspace
#[clap(arg_required_else_help = true)]
NamedWorkspaceTiling(NamedWorkspaceTiling),
/// Set the workspace name for the specified workspace
#[clap(arg_required_else_help = true)]
WorkspaceName(WorkspaceName),
/// Toggle the behaviour for new windows (stacking or dynamic tiling)
ToggleWindowContainerBehaviour,
/// Enable or disable float override, which makes it so every new window opens in floating mode
@@ -1248,6 +1472,136 @@ fn main() -> eyre::Result<()> {
SubCommand::EagerFocus(arg) => {
send_message(&SocketMessage::EagerFocus(arg.exe))?;
}
SubCommand::NewWorkspace => {
send_message(&SocketMessage::NewWorkspace)?;
}
SubCommand::WorkspaceName(name) => {
send_message(&SocketMessage::WorkspaceName(
name.monitor,
name.workspace,
name.value,
))?;
}
SubCommand::ResizeDelta(arg) => {
send_message(&SocketMessage::ResizeDelta(arg.pixels))?;
}
SubCommand::MonitorWorkAreaOffset(arg) => {
send_message(&SocketMessage::MonitorWorkAreaOffset(
arg.monitor,
Rect {
left: arg.left,
top: arg.top,
right: arg.right,
bottom: arg.bottom,
},
))?;
}
SubCommand::GlobalWorkAreaOffset(arg) => {
send_message(&SocketMessage::WorkAreaOffset(Rect {
left: arg.left,
top: arg.top,
right: arg.right,
bottom: arg.bottom,
}))?;
}
SubCommand::WorkspaceWorkAreaOffset(arg) => {
send_message(&SocketMessage::WorkspaceWorkAreaOffset(
arg.monitor,
arg.workspace,
Rect {
left: arg.left,
top: arg.top,
right: arg.right,
bottom: arg.bottom,
},
))?;
}
SubCommand::ContainerPadding(arg) => {
send_message(&SocketMessage::ContainerPadding(
arg.monitor,
arg.workspace,
arg.size,
))?;
}
SubCommand::NamedWorkspaceContainerPadding(arg) => {
send_message(&SocketMessage::NamedWorkspaceContainerPadding(
arg.workspace,
arg.size,
))?;
}
SubCommand::WorkspacePadding(arg) => {
send_message(&SocketMessage::WorkspacePadding(
arg.monitor,
arg.workspace,
arg.size,
))?;
}
SubCommand::NamedWorkspacePadding(arg) => {
send_message(&SocketMessage::NamedWorkspacePadding(
arg.workspace,
arg.size,
))?;
}
SubCommand::FocusedWorkspacePadding(arg) => {
send_message(&SocketMessage::FocusedWorkspacePadding(arg.size))?;
}
SubCommand::FocusedWorkspaceContainerPadding(arg) => {
send_message(&SocketMessage::FocusedWorkspaceContainerPadding(arg.size))?;
}
SubCommand::AdjustWorkspacePadding(arg) => {
send_message(&SocketMessage::AdjustWorkspacePadding(
arg.sizing,
arg.adjustment,
))?;
}
SubCommand::AdjustContainerPadding(arg) => {
send_message(&SocketMessage::AdjustContainerPadding(
arg.sizing,
arg.adjustment,
))?;
}
SubCommand::WorkspaceLayout(arg) => {
send_message(&SocketMessage::WorkspaceLayout(
arg.monitor,
arg.workspace,
arg.value,
))?;
}
SubCommand::NamedWorkspaceLayout(arg) => {
send_message(&SocketMessage::NamedWorkspaceLayout(
arg.workspace,
arg.value,
))?;
}
SubCommand::WorkspaceTiling(arg) => {
send_message(&SocketMessage::WorkspaceTiling(
arg.monitor,
arg.workspace,
arg.value.into(),
))?;
}
SubCommand::NamedWorkspaceTiling(arg) => {
send_message(&SocketMessage::NamedWorkspaceTiling(
arg.workspace,
arg.value.into(),
))?;
}
SubCommand::ScrollingLayoutColumns(arg) => {
send_message(&SocketMessage::ScrollingLayoutColumns(arg.count))?;
}
SubCommand::ClearWorkspaceLayoutRules(arg) => {
send_message(&SocketMessage::ClearWorkspaceLayoutRules(
arg.monitor,
arg.workspace,
))?;
}
SubCommand::ClearNamedWorkspaceLayoutRules(arg) => {
send_message(&SocketMessage::ClearNamedWorkspaceLayoutRules(
arg.workspace,
))?;
}
}
Ok(())