mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-26 13:39:22 +02:00
0725549d45
Windows that have been maximized do not retain their maximized state across workspaces as workspaces are built on top of sending SW_HIDE and SW_SHOW events which at various points of the event loop end up overriding SW_SHOWMAXIMIZED and SW_SHOWMAXIMIZE. To handle this use case, I have added a new 'komorebic toggle-maximize' command which sends SW_MAXIMIZE for a window and keeps a record of the window in the focused workspace in the same way that monocle windows are tracked. In this way, komorebi can know when switching to a workspace if it has to restore a window to a native maximized state. Some additional edge cases are caught in this commit in showing and hiding workspaces, to also account for floating windows and monocle containers. resolve #12
113 lines
2.8 KiB
Rust
113 lines
2.8 KiB
Rust
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 cycle_direction::CycleDirection;
|
|
pub use layout::Layout;
|
|
pub use layout::LayoutFlip;
|
|
pub use operation_direction::OperationDirection;
|
|
pub use rect::Rect;
|
|
|
|
pub mod cycle_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),
|
|
StackWindow(OperationDirection),
|
|
ResizeWindow(OperationDirection, Sizing),
|
|
UnstackWindow,
|
|
CycleStack(CycleDirection),
|
|
MoveContainerToMonitorNumber(usize),
|
|
MoveContainerToWorkspaceNumber(usize),
|
|
Promote,
|
|
ToggleFloat,
|
|
ToggleMonocle,
|
|
ToggleMaximize,
|
|
// Current Workspace Commands
|
|
AdjustContainerPadding(Sizing, i32),
|
|
AdjustWorkspacePadding(Sizing, i32),
|
|
ChangeLayout(Layout),
|
|
FlipLayout(LayoutFlip),
|
|
// Monitor and Workspace Commands
|
|
EnsureWorkspaces(usize, usize),
|
|
NewWorkspace,
|
|
ToggleTiling,
|
|
Stop,
|
|
TogglePause,
|
|
Retile,
|
|
FocusMonitorNumber(usize),
|
|
FocusWorkspaceNumber(usize),
|
|
ContainerPadding(usize, usize, i32),
|
|
WorkspacePadding(usize, usize, i32),
|
|
WorkspaceTiling(usize, usize, bool),
|
|
WorkspaceName(usize, usize, String),
|
|
WorkspaceLayout(usize, usize, Layout),
|
|
// Configuration
|
|
ReloadConfiguration,
|
|
WatchConfiguration(bool),
|
|
FloatClass(String),
|
|
FloatExe(String),
|
|
FloatTitle(String),
|
|
IdentifyTrayApplication(ApplicationIdentifier, String),
|
|
State,
|
|
FocusFollowsMouse(bool),
|
|
}
|
|
|
|
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 ApplicationIdentifier {
|
|
Exe,
|
|
Class,
|
|
Title,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
|
|
#[strum(serialize_all = "snake_case")]
|
|
pub enum Sizing {
|
|
Increase,
|
|
Decrease,
|
|
}
|
|
|
|
impl Sizing {
|
|
pub 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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|