refactor(protocol): use SocketMessage from komorebi-protocol in the macOS daemon

Delete macOS's SocketMessage, as_bytes and FromStr and its now unused imports, and re-export the crate's SocketMessage from core. process_command stays an exhaustive match: the 41 variants macOS does not handle (33 Windows only, 6 Windows and KDE, 2 KDE only) get one explicit or-pattern arm that writes the 'not supported on this platform' reply and returns before anything else happens. Behaviour change: those variants used to fail to parse on macOS and now parse and are answered that way.

Verified: fast-check macOS (fake CC) cargo check --workspace --all-targets: PASS (0 errors, only the existing komorebi-bar warnings). macOS tests not run (cannot).
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:53 -07:00
1 parent 7483d5837e
commit a4996ac633
2 files changed
+47 -236

No files matched your search

+1 -236
View File
@@ -1,14 +1,6 @@
use crate::animation::AnimationPrefix;
use crate::core::animation::AnimationStyle;
use crate::core::pathext::ResolvedPathBuf;
use clap::ValueEnum;
use color_eyre::eyre;
use komorebi_themes::KomorebiTheme;
use serde::Deserialize;
use serde::Serialize;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::str::FromStr;
use strum::Display;
use strum::EnumString;
@@ -167,234 +159,7 @@ pub enum CrossBoundaryBehaviour {
Monitor,
}
// serde_as must be before derive
#[serde_with::serde_as]
#[derive(Clone, Debug, Serialize, Deserialize, Display)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(tag = "type", content = "content")]
pub enum SocketMessage {
// Window / Container Commands
FocusWindow(OperationDirection),
MoveWindow(OperationDirection),
PreselectDirection(OperationDirection),
CancelPreselect,
CycleFocusWindow(CycleDirection),
CycleMoveWindow(CycleDirection),
StackWindow(OperationDirection),
UnstackWindow,
CycleStack(CycleDirection),
CycleStackIndex(CycleDirection),
FocusStackWindow(usize),
StackAll,
UnstackAll,
ResizeWindowEdge(OperationDirection, Sizing),
ResizeWindowAxis(Axis, Sizing),
MoveContainerToLastWorkspace,
SendContainerToLastWorkspace,
MoveContainerToMonitorNumber(usize),
CycleMoveContainerToMonitor(CycleDirection),
MoveContainerToWorkspaceNumber(usize),
MoveContainerToNamedWorkspace(String),
CycleMoveContainerToWorkspace(CycleDirection),
SendContainerToMonitorNumber(usize),
CycleSendContainerToMonitor(CycleDirection),
SendContainerToWorkspaceNumber(usize),
CycleSendContainerToWorkspace(CycleDirection),
SendContainerToMonitorWorkspaceNumber(usize, usize),
MoveContainerToMonitorWorkspaceNumber(usize, usize),
SendContainerToNamedWorkspace(String),
CycleMoveWorkspaceToMonitor(CycleDirection),
MoveWorkspaceToMonitorNumber(usize),
SwapWorkspacesToMonitorNumber(usize),
// ForceFocus,
Close,
Minimize,
Promote,
PromoteSwap,
PromoteFocus,
PromoteWindow(OperationDirection),
EagerFocus(String),
LockMonitorWorkspaceContainer(usize, usize, usize),
UnlockMonitorWorkspaceContainer(usize, usize, usize),
ToggleLock,
ToggleFloat,
ToggleMonocle,
// ToggleMaximize,
ToggleWindowContainerBehaviour,
ToggleFloatOverride,
// WindowHidingBehaviour(HidingBehaviour),
ToggleCrossMonitorMoveBehaviour,
CrossMonitorMoveBehaviour(MoveBehaviour),
ToggleMonocleFocusBehaviour,
MonocleFocusBehaviour(MonocleFocusBehaviour),
UnmanagedWindowOperationBehaviour(OperationBehaviour),
// Current Workspace Commands
ManageFocusedWindow,
UnmanageFocusedWindow,
AdjustContainerPadding(Sizing, i32),
AdjustWorkspacePadding(Sizing, i32),
ChangeLayout(DefaultLayout),
CycleLayout(CycleDirection),
ScrollingLayoutColumns(NonZeroUsize),
ScrollingLayoutFullWidth,
CenterFocus,
Expand,
Pan(PanDirection),
PanGesture(PanGesture),
Consume(OperationDirection),
Expel,
ToggleColumnStack,
LayoutRatios(Option<Vec<f32>>, Option<Vec<f32>>),
// ChangeLayoutCustom(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
FlipLayout(Axis),
ToggleWorkspaceWindowContainerBehaviour,
ToggleWorkspaceFloatOverride,
// Monitor and Workspace Commands
// MonitorIndexPreference(usize, i32, i32, i32, i32),
DisplayIndexPreference(usize, String),
EnsureWorkspaces(usize, usize),
EnsureNamedWorkspaces(usize, Vec<String>),
NewWorkspace,
ToggleTiling,
Stop,
StopIgnoreRestore,
TogglePause,
Retile,
RetileWithResizeDimensions,
QuickSave,
QuickLoad,
Save(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
Load(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
CycleFocusMonitor(CycleDirection),
CycleFocusWorkspace(CycleDirection),
CycleFocusEmptyWorkspace(CycleDirection),
FocusMonitorNumber(usize),
FocusMonitorAtCursor,
FocusLastWorkspace,
CloseWorkspace,
FocusWorkspaceNumber(usize),
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),
// WorkspaceLayoutCustom(usize, usize, #[serde_as(as = "ResolvedPathBuf")] PathBuf),
// NamedWorkspaceLayoutCustom(String, #[serde_as(as = "ResolvedPathBuf")] PathBuf),
WorkspaceLayoutRule(usize, usize, usize, DefaultLayout),
NamedWorkspaceLayoutRule(String, usize, DefaultLayout),
// WorkspaceLayoutCustomRule(
// usize,
// usize,
// usize,
// #[serde_as(as = "ResolvedPathBuf")] PathBuf,
// ),
// NamedWorkspaceLayoutCustomRule(String, usize, #[serde_as(as = "ResolvedPathBuf")] PathBuf),
ClearWorkspaceLayoutRules(usize, usize),
ClearNamedWorkspaceLayoutRules(String),
ToggleWorkspaceLayer,
// Configuration
// ReloadConfiguration,
ReplaceConfiguration(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
ReloadStaticConfiguration(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
// WatchConfiguration(bool),
// CompleteConfiguration,
// AltFocusHack(bool),
Theme(Box<KomorebiTheme>),
Animation(bool, Option<AnimationPrefix>),
AnimationDuration(u64, Option<AnimationPrefix>),
AnimationFps(u64),
AnimationStyle(AnimationStyle, Option<AnimationPrefix>),
#[serde(alias = "ActiveWindowBorder")]
Border(bool),
#[serde(alias = "ActiveWindowBorderColour")]
BorderColour(WindowKind, u32, u32, u32),
// #[serde(alias = "ActiveWindowBorderStyle")]
// BorderStyle(BorderStyle),
BorderWidth(i32),
BorderOffset(i32),
// BorderImplementation(BorderImplementation),
// Transparency(bool),
// ToggleTransparency,
// TransparencyAlpha(u8),
// InvisibleBorders(Rect),
// StackbarMode(StackbarMode),
// StackbarLabel(StackbarLabel),
// StackbarFocusedTextColour(u32, u32, u32),
// StackbarUnfocusedTextColour(u32, u32, u32),
// StackbarBackgroundColour(u32, u32, u32),
// StackbarHeight(i32),
// StackbarTabWidth(i32),
// StackbarFontSize(i32),
// StackbarFontFamily(Option<String>),
WorkAreaOffset(Rect),
MonitorWorkAreaOffset(usize, Rect),
WorkspaceWorkAreaOffset(usize, usize, Rect),
ToggleWindowBasedWorkAreaOffset,
ResizeDelta(i32),
InitialWorkspaceRule(ApplicationIdentifier, String, usize, usize),
InitialNamedWorkspaceRule(ApplicationIdentifier, String, String),
WorkspaceRule(ApplicationIdentifier, String, usize, usize),
NamedWorkspaceRule(ApplicationIdentifier, String, String),
ClearWorkspaceRules(usize, usize),
ClearNamedWorkspaceRules(String),
ClearAllWorkspaceRules,
EnforceWorkspaceRules,
SessionFloatRule,
SessionFloatRules,
ClearSessionFloatRules,
#[serde(alias = "FloatRule")]
IgnoreRule(ApplicationIdentifier, String),
ManageRule(ApplicationIdentifier, String),
// IdentifyObjectNameChangeApplication(ApplicationIdentifier, String),
// IdentifyTrayApplication(ApplicationIdentifier, String),
// IdentifyLayeredApplication(ApplicationIdentifier, String),
// IdentifyBorderOverflowApplication(ApplicationIdentifier, String),
State,
GlobalState,
VisibleWindows,
MonitorInformation,
Query(StateQuery),
// FocusFollowsMouse(FocusFollowsMouseImplementation, bool),
// ToggleFocusFollowsMouse(FocusFollowsMouseImplementation),
MouseFollowsFocus(bool),
ToggleMouseFollowsFocus,
// RemoveTitleBar(ApplicationIdentifier, String),
// ToggleTitleBars,
AddSubscriberSocket(String),
AddSubscriberSocketWithOptions(String, SubscribeOptions),
RemoveSubscriberSocket(String),
// AddSubscriberPipe(String),
// RemoveSubscriberPipe(String),
ApplicationSpecificConfigurationSchema,
NotificationSchema,
SocketSchema,
StaticConfigSchema,
GenerateStaticConfig,
DebugWindow(i64),
}
impl SocketMessage {
pub fn as_bytes(&self) -> eyre::Result<Vec<u8>> {
Ok(serde_json::to_string(self)?.as_bytes().to_vec())
}
}
impl FromStr for SocketMessage {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(s)
}
}
pub use komorebi_protocol::message::SocketMessage;
#[cfg(test)]
mod tests {
@@ -1843,6 +1843,52 @@ impl WindowManager {
ANIMATION_STYLE_PER_ANIMATION.lock().clear();
}
},
// Messages of other platforms: answered, and nothing else happens
SocketMessage::AddSubscriberPipe(..)
| SocketMessage::AltFocusHack(..)
| SocketMessage::ApplyState(..)
| SocketMessage::BorderImplementation(..)
| SocketMessage::BorderStyle(..)
| SocketMessage::ChangeLayoutCustom(..)
| SocketMessage::CompleteConfiguration
| SocketMessage::FocusFollowsMouse(..)
| SocketMessage::ForceFocus
| SocketMessage::HotkeysState
| SocketMessage::IdentifyBorderOverflowApplication(..)
| SocketMessage::IdentifyLayeredApplication(..)
| SocketMessage::IdentifyObjectNameChangeApplication(..)
| SocketMessage::IdentifyTrayApplication(..)
| SocketMessage::InvisibleBorders(..)
| SocketMessage::MonitorIndexPreference(..)
| SocketMessage::NamedWorkspaceLayoutCustom(..)
| SocketMessage::NamedWorkspaceLayoutCustomRule(..)
| SocketMessage::ReloadConfiguration
| SocketMessage::ReloadHotkeys
| SocketMessage::RemoveSubscriberPipe(..)
| SocketMessage::RemoveTitleBar(..)
| SocketMessage::StackbarBackgroundColour(..)
| SocketMessage::StackbarFocusedTextColour(..)
| SocketMessage::StackbarFontFamily(..)
| SocketMessage::StackbarFontSize(..)
| SocketMessage::StackbarHeight(..)
| SocketMessage::StackbarLabel(..)
| SocketMessage::StackbarMode(..)
| SocketMessage::StackbarTabWidth(..)
| SocketMessage::StackbarUnfocusedTextColour(..)
| SocketMessage::ToggleFocusFollowsMouse(..)
| SocketMessage::ToggleMaximize
| SocketMessage::ToggleTitleBars
| SocketMessage::ToggleTransparency
| SocketMessage::Transparency(..)
| SocketMessage::TransparencyAlpha(..)
| SocketMessage::WatchConfiguration(..)
| SocketMessage::WindowHidingBehaviour(..)
| SocketMessage::WorkspaceLayoutCustom(..)
| SocketMessage::WorkspaceLayoutCustomRule(..)
=> {
reply.write_all(message.not_supported_reply().as_bytes())?;
return Ok(());
}
}
self.update_known_window_ids();