mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-30 14:12:21 +02:00
This commit introduces a number of refactors to layouts in general in order to enable navigation across custom layouts and integrate both default and custom layouts cleanly into komorebi and komorebic. Layout has been renamed to DefaultLayout, and Layout is now an enum with the variants Default and Custom, both of which implement the new traits Arrangement (for layout calculation) and Direction (for operation destination calculation). CustomLayout has been simplified to wrap Vec<Column> and no longer requires the primary column index to be explicitly defined as this can be looked up at runtime for any valid CustomLayout. Given the focus on ultrawide layouts for this feature, I have disabled (and have not yet written the logic for) vertical column splits in custom layouts. Since CustomLayouts will be loaded from a file path, a bunch of clap-related code generation stuff has been removed from the related enums and structs. Layout flipping has not yet been worked on for custom layouts. When switching between Default and Custom layout variants, the primary column index and the 0 element are swapped to ensure that the same window container is always at the focal point of every layout. Resizing/dragging to resize is in a bit of weird spot at the moment because the logic is only implemented for DefaultLayout::BSP right now and nothing else. I think eventually this will need to be extracted to a Resize trait and implemented on everything.
161 lines
4.3 KiB
Rust
161 lines
4.3 KiB
Rust
#![warn(clippy::all, clippy::nursery, clippy::pedantic)]
|
|
#![allow(clippy::missing_errors_doc)]
|
|
|
|
use std::path::PathBuf;
|
|
use std::str::FromStr;
|
|
|
|
use clap::ArgEnum;
|
|
use color_eyre::Result;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use strum::Display;
|
|
use strum::EnumString;
|
|
|
|
pub use arrangement::Arrangement;
|
|
pub use arrangement::Flip;
|
|
pub use custom_layout::CustomLayout;
|
|
pub use cycle_direction::CycleDirection;
|
|
pub use default_layout::DefaultLayout;
|
|
pub use direction::Direction;
|
|
pub use layout::Layout;
|
|
pub use operation_direction::OperationDirection;
|
|
pub use rect::Rect;
|
|
|
|
pub mod arrangement;
|
|
pub mod custom_layout;
|
|
pub mod cycle_direction;
|
|
pub mod default_layout;
|
|
pub mod direction;
|
|
pub mod layout;
|
|
pub mod operation_direction;
|
|
pub mod rect;
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Display)]
|
|
pub enum SocketMessage {
|
|
// Window / Container Commands
|
|
FocusWindow(OperationDirection),
|
|
MoveWindow(OperationDirection),
|
|
CycleFocusWindow(CycleDirection),
|
|
CycleMoveWindow(CycleDirection),
|
|
StackWindow(OperationDirection),
|
|
ResizeWindow(OperationDirection, Sizing),
|
|
UnstackWindow,
|
|
CycleStack(CycleDirection),
|
|
MoveContainerToMonitorNumber(usize),
|
|
MoveContainerToWorkspaceNumber(usize),
|
|
SendContainerToMonitorNumber(usize),
|
|
SendContainerToWorkspaceNumber(usize),
|
|
Promote,
|
|
ToggleFloat,
|
|
ToggleMonocle,
|
|
ToggleMaximize,
|
|
// Current Workspace Commands
|
|
ManageFocusedWindow,
|
|
UnmanageFocusedWindow,
|
|
AdjustContainerPadding(Sizing, i32),
|
|
AdjustWorkspacePadding(Sizing, i32),
|
|
ChangeLayout(DefaultLayout),
|
|
ChangeLayoutCustom(PathBuf),
|
|
FlipLayout(Flip),
|
|
// Monitor and Workspace Commands
|
|
EnsureWorkspaces(usize, usize),
|
|
NewWorkspace,
|
|
ToggleTiling,
|
|
Stop,
|
|
TogglePause,
|
|
Retile,
|
|
QuickSave,
|
|
QuickLoad,
|
|
Save(PathBuf),
|
|
Load(PathBuf),
|
|
CycleFocusMonitor(CycleDirection),
|
|
CycleFocusWorkspace(CycleDirection),
|
|
FocusMonitorNumber(usize),
|
|
FocusWorkspaceNumber(usize),
|
|
ContainerPadding(usize, usize, i32),
|
|
WorkspacePadding(usize, usize, i32),
|
|
WorkspaceTiling(usize, usize, bool),
|
|
WorkspaceName(usize, usize, String),
|
|
WorkspaceLayout(usize, usize, DefaultLayout),
|
|
WorkspaceLayoutCustom(usize, usize, PathBuf),
|
|
// Configuration
|
|
ReloadConfiguration,
|
|
WatchConfiguration(bool),
|
|
InvisibleBorders(Rect),
|
|
WorkAreaOffset(Rect),
|
|
WorkspaceRule(ApplicationIdentifier, String, usize, usize),
|
|
FloatRule(ApplicationIdentifier, String),
|
|
ManageRule(ApplicationIdentifier, String),
|
|
IdentifyTrayApplication(ApplicationIdentifier, String),
|
|
IdentifyBorderOverflow(ApplicationIdentifier, String),
|
|
State,
|
|
Query(StateQuery),
|
|
FocusFollowsMouse(FocusFollowsMouseImplementation, bool),
|
|
ToggleFocusFollowsMouse(FocusFollowsMouseImplementation),
|
|
}
|
|
|
|
impl SocketMessage {
|
|
pub fn as_bytes(&self) -> Result<Vec<u8>> {
|
|
Ok(serde_json::to_string(self)?.as_bytes().to_vec())
|
|
}
|
|
|
|
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
|
|
Ok(serde_json::from_slice(bytes)?)
|
|
}
|
|
}
|
|
|
|
impl FromStr for SocketMessage {
|
|
type Err = serde_json::Error;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
serde_json::from_str(s)
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
|
|
#[strum(serialize_all = "snake_case")]
|
|
pub enum StateQuery {
|
|
FocusedMonitorIndex,
|
|
FocusedWorkspaceIndex,
|
|
FocusedContainerIndex,
|
|
FocusedWindowIndex,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
|
|
#[strum(serialize_all = "snake_case")]
|
|
pub enum ApplicationIdentifier {
|
|
Exe,
|
|
Class,
|
|
Title,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
|
|
#[strum(serialize_all = "snake_case")]
|
|
pub enum FocusFollowsMouseImplementation {
|
|
Komorebi,
|
|
Windows,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
|
|
#[strum(serialize_all = "snake_case")]
|
|
pub enum Sizing {
|
|
Increase,
|
|
Decrease,
|
|
}
|
|
|
|
impl Sizing {
|
|
#[must_use]
|
|
pub const fn adjust_by(&self, value: i32, adjustment: i32) -> i32 {
|
|
match self {
|
|
Sizing::Increase => value + adjustment,
|
|
Sizing::Decrease => {
|
|
if value > 0 && value - adjustment >= 0 {
|
|
value - adjustment
|
|
} else {
|
|
value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|