diff --git a/Cargo.toml b/Cargo.toml index c6d5d96f..56c8f67c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,17 +71,4 @@ features = [ "Win32_System_WindowsProgramming", "Media", "Media_Control" -] - -[profile.dev-jeezy] -inherits = "dev" -debug = false -opt-level = 1 - -[profile.dev-jeezy.package."*"] -opt-level = 3 - -[profile.release-jeezy] -inherits = "release" -incremental = true -codegen-units = 256 \ No newline at end of file +] \ No newline at end of file diff --git a/justfile b/justfile index 26cd09ed..4b91d14a 100644 --- a/justfile +++ b/justfile @@ -19,22 +19,31 @@ install-targets *targets: "{{ targets }}" -split ' ' | ForEach-Object { just install-target $_ } install-target target: + cargo +stable install --path {{ target }} --locked --no-default-features + +install-targets-with-jsonschema *targets: + "{{ targets }}" -split ' ' | ForEach-Object { just install-target-with-jsonschema $_ } + +install-target-with-jsonschema target: cargo +stable install --path {{ target }} --locked install: just install-targets komorebic komorebic-no-console komorebi komorebi-bar komorebi-gui +install-with-jsonschema: + just install-targets-with-jsonschema komorebic komorebic-no-console komorebi komorebi-bar komorebi-gui + build-targets *targets: "{{ targets }}" -split ' ' | ForEach-Object { just build-target $_ } build-target target: - cargo +stable build --package {{ target }} --locked --profile release-jeezy + cargo +stable build --package {{ target }} --locked --release --no-default-features build: just build-targets komorebic komorebic-no-console komorebi komorebi-bar komorebi-gui copy-target target: - cp .\target\release-jeezy\{{ target }}.exe $Env:USERPROFILE\.cargo\bin + cp .\target\release\{{ target }}.exe $Env:USERPROFILE\.cargo\bin copy-targets *targets: "{{ targets }}" -split ' ' | ForEach-Object { just copy-target $_ } @@ -46,7 +55,7 @@ copy: just copy-targets komorebic komorebic-no-console komorebi komorebi-bar komorebi-gui run target: - cargo +stable run --bin {{ target }} --locked + cargo +stable run --bin {{ target }} --locked --no-default-features warn target $RUST_LOG="warn": just run {{ target }} @@ -61,7 +70,7 @@ trace target $RUST_LOG="trace": just run {{ target }} deadlock $RUST_LOG="trace": - cargo +stable run --bin komorebi --locked --features deadlock_detection + cargo +stable run --bin komorebi --locked --no-default-features --features deadlock_detection docgen: cargo run --package komorebic -- docgen diff --git a/komorebi-bar/Cargo.toml b/komorebi-bar/Cargo.toml index 42b002dd..1bd1ad8c 100644 --- a/komorebi-bar/Cargo.toml +++ b/komorebi-bar/Cargo.toml @@ -26,7 +26,7 @@ num-derive = "0.4" num-traits = "0.2" random_word = { version = "0.4", features = ["en"] } reqwest = { version = "0.12", features = ["blocking"] } -schemars = { workspace = true } +schemars = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true } starship-battery = "0.10" @@ -35,4 +35,8 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } windows = { workspace = true } windows-core = { workspace = true } -windows-icons = { git = "https://github.com/LGUG2Z/windows-icons", rev = "d67cc9920aa9b4883393e411fb4fa2ddd4c498b5" } \ No newline at end of file +windows-icons = { git = "https://github.com/LGUG2Z/windows-icons", rev = "d67cc9920aa9b4883393e411fb4fa2ddd4c498b5" } + +[features] +default = ["schemars"] +schemars = ["dep:schemars"] diff --git a/komorebi-bar/src/battery.rs b/komorebi-bar/src/battery.rs index 84ba5990..350c8ea8 100644 --- a/komorebi-bar/src/battery.rs +++ b/komorebi-bar/src/battery.rs @@ -8,7 +8,6 @@ use eframe::egui::Context; use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use starship_battery::units::ratio::percent; @@ -18,7 +17,8 @@ use std::process::Command; use std::time::Duration; use std::time::Instant; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct BatteryConfig { /// Enable the Battery widget pub enable: bool, diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index 38adb891..7d505cbe 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -6,13 +6,13 @@ use eframe::egui::TextBuffer; use eframe::egui::Vec2; use komorebi_client::KomorebiTheme; use komorebi_client::Rect; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::collections::HashMap; use std::path::PathBuf; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] /// The `komorebi.bar.json` configuration file reference for `v0.1.35` pub struct KomobarConfig { /// Bar height (default: 50) @@ -136,7 +136,8 @@ impl KomobarConfig { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct PositionConfig { /// The desired starting position of the bar (0,0 = top left of the screen) #[serde(alias = "position")] @@ -146,13 +147,15 @@ pub struct PositionConfig { pub end: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct FrameConfig { /// Margin inside the painted frame pub inner_margin: Position, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum MonitorConfigOrIndex { /// The monitor index where you want the bar to show @@ -161,7 +164,8 @@ pub enum MonitorConfigOrIndex { MonitorConfig(MonitorConfig), } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct MonitorConfig { /// Komorebi monitor index of the monitor on which to render the bar pub index: usize, @@ -172,7 +176,8 @@ pub struct MonitorConfig { pub type Padding = SpacingKind; pub type Margin = SpacingKind; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] // WARNING: To any developer messing with this code in the future: The order here matters! // `Grouped` needs to come last, otherwise serde might mistaken an `IndividualSpacingConfig` for a @@ -223,20 +228,23 @@ impl SpacingKind { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct GroupedSpacingConfig { pub vertical: Option, pub horizontal: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum GroupedSpacingOptions { Symmetrical(f32), Split(f32, f32), } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct IndividualSpacingConfig { pub top: f32, pub bottom: f32, @@ -338,7 +346,8 @@ impl KomobarConfig { } } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Position { /// X coordinate pub x: f32, @@ -364,7 +373,8 @@ impl From for Pos2 { } } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(tag = "palette")] pub enum KomobarTheme { /// A theme from catppuccin-egui @@ -400,7 +410,8 @@ impl From for KomobarTheme { } } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum LabelPrefix { /// Show no prefix None, @@ -412,7 +423,8 @@ pub enum LabelPrefix { IconAndText, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum DisplayFormat { /// Show only icon Icon, @@ -428,7 +440,8 @@ pub enum DisplayFormat { macro_rules! extend_enum { ($existing_enum:ident, $new_enum:ident, { $($(#[$meta:meta])* $variant:ident),* $(,)? }) => { - #[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize, schemars::JsonSchema, PartialEq)] + #[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)] + #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum $new_enum { // Add new variants $( @@ -460,12 +473,11 @@ extend_enum!(DisplayFormat, WorkspacesDisplayFormat, { #[cfg(test)] mod tests { - use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use serde_json::json; - #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] + #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] pub enum OriginalDisplayFormat { /// Show None Of The Things NoneOfTheThings, diff --git a/komorebi-bar/src/cpu.rs b/komorebi-bar/src/cpu.rs index 83017842..92713d3b 100644 --- a/komorebi-bar/src/cpu.rs +++ b/komorebi-bar/src/cpu.rs @@ -8,7 +8,6 @@ use eframe::egui::Context; use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::process::Command; @@ -17,7 +16,8 @@ use std::time::Instant; use sysinfo::RefreshKind; use sysinfo::System; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct CpuConfig { /// Enable the Cpu widget pub enable: bool, diff --git a/komorebi-bar/src/date.rs b/komorebi-bar/src/date.rs index f68dc0eb..4a748cca 100644 --- a/komorebi-bar/src/date.rs +++ b/komorebi-bar/src/date.rs @@ -9,12 +9,12 @@ use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; use eframe::egui::WidgetText; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; /// Custom format with additive modifiers for integer format specifiers -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct CustomModifiers { /// Custom format (https://docs.rs/chrono/latest/chrono/format/strftime/index.html) format: String, @@ -55,7 +55,8 @@ impl CustomModifiers { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct DateConfig { /// Enable the Date widget pub enable: bool, @@ -75,7 +76,8 @@ impl From for Date { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum DateFormat { /// Month/Date/Year format (09/08/24) MonthDateYear, diff --git a/komorebi-bar/src/keyboard.rs b/komorebi-bar/src/keyboard.rs index 14143e7d..7ba57846 100755 --- a/komorebi-bar/src/keyboard.rs +++ b/komorebi-bar/src/keyboard.rs @@ -8,7 +8,6 @@ use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; use eframe::egui::WidgetText; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::time::Duration; @@ -23,7 +22,8 @@ use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId; const DEFAULT_DATA_REFRESH_INTERVAL: u64 = 1; const ERROR_TEXT: &str = "Error"; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct KeyboardConfig { /// Enable the Input widget pub enable: bool, diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index e3b38133..858a518c 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -37,7 +37,6 @@ use komorebi_client::SocketMessage; use komorebi_client::Window; use komorebi_client::Workspace; use komorebi_client::WorkspaceLayer; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::cell::RefCell; @@ -47,7 +46,8 @@ use std::path::PathBuf; use std::rc::Rc; use std::sync::atomic::Ordering; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct KomorebiConfig { /// Configure the Workspaces widget pub workspaces: Option, @@ -61,7 +61,8 @@ pub struct KomorebiConfig { pub configuration_switcher: Option, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct KomorebiWorkspacesConfig { /// Enable the Komorebi Workspaces widget pub enable: bool, @@ -71,7 +72,8 @@ pub struct KomorebiWorkspacesConfig { pub display: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct KomorebiLayoutConfig { /// Enable the Komorebi Layout widget pub enable: bool, @@ -81,7 +83,8 @@ pub struct KomorebiLayoutConfig { pub display: Option, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct KomorebiWorkspaceLayerConfig { /// Enable the Komorebi Workspace Layer widget pub enable: bool, @@ -91,7 +94,8 @@ pub struct KomorebiWorkspaceLayerConfig { pub show_when_tiling: Option, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct KomorebiFocusedWindowConfig { /// Enable the Komorebi Focused Window widget pub enable: bool, @@ -101,7 +105,8 @@ pub struct KomorebiFocusedWindowConfig { pub display: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct KomorebiConfigurationSwitcherConfig { /// Enable the Komorebi Configurations widget pub enable: bool, diff --git a/komorebi-bar/src/komorebi_layout.rs b/komorebi-bar/src/komorebi_layout.rs index a2926f09..9e75f15b 100644 --- a/komorebi-bar/src/komorebi_layout.rs +++ b/komorebi-bar/src/komorebi_layout.rs @@ -14,7 +14,6 @@ use eframe::egui::StrokeKind; use eframe::egui::Ui; use eframe::egui::Vec2; use komorebi_client::SocketMessage; -use schemars::JsonSchema; use serde::de::Error; use serde::Deserialize; use serde::Deserializer; @@ -23,7 +22,8 @@ use serde_json::from_str; use std::fmt::Display; use std::fmt::Formatter; -#[derive(Copy, Clone, Debug, Serialize, JsonSchema, PartialEq)] +#[derive(Copy, Clone, Debug, Serialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum KomorebiLayout { Default(komorebi_client::DefaultLayout), diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index de6e0f0b..2c30d59f 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -30,7 +30,6 @@ use hotwatch::Hotwatch; use image::RgbaImage; use komorebi_client::SocketMessage; use komorebi_client::SubscribeOptions; -use schemars::gen::SchemaSettings; use std::collections::HashMap; use std::io::BufReader; use std::io::Read; @@ -125,8 +124,9 @@ fn main() -> color_eyre::Result<()> { let opts: Opts = Opts::parse(); + #[cfg(feature = "schemars")] if opts.schema { - let settings = SchemaSettings::default().with(|s| { + let settings = schemars::gen::SchemaSettings::default().with(|s| { s.option_nullable = false; s.option_add_null_type = false; s.inline_subschemas = true; diff --git a/komorebi-bar/src/media.rs b/komorebi-bar/src/media.rs index c163c2e8..40f2f249 100644 --- a/komorebi-bar/src/media.rs +++ b/komorebi-bar/src/media.rs @@ -10,13 +10,13 @@ use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; use eframe::egui::Vec2; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::sync::atomic::Ordering; use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct MediaConfig { /// Enable the Media widget pub enable: bool, diff --git a/komorebi-bar/src/memory.rs b/komorebi-bar/src/memory.rs index 7fcf7317..79d8b12a 100644 --- a/komorebi-bar/src/memory.rs +++ b/komorebi-bar/src/memory.rs @@ -8,7 +8,6 @@ use eframe::egui::Context; use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::process::Command; @@ -17,7 +16,8 @@ use std::time::Instant; use sysinfo::RefreshKind; use sysinfo::System; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct MemoryConfig { /// Enable the Memory widget pub enable: bool, diff --git a/komorebi-bar/src/network.rs b/komorebi-bar/src/network.rs index 3ee9bcaf..1e906fbd 100644 --- a/komorebi-bar/src/network.rs +++ b/komorebi-bar/src/network.rs @@ -9,7 +9,6 @@ use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; use num_derive::FromPrimitive; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::fmt; @@ -18,7 +17,8 @@ use std::time::Duration; use std::time::Instant; use sysinfo::Networks; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct NetworkConfig { /// Enable the Network widget pub enable: bool, diff --git a/komorebi-bar/src/render.rs b/komorebi-bar/src/render.rs index 4834d806..ae323e93 100644 --- a/komorebi-bar/src/render.rs +++ b/komorebi-bar/src/render.rs @@ -11,7 +11,6 @@ use eframe::egui::Margin; use eframe::egui::Shadow; use eframe::egui::TextStyle; use eframe::egui::Ui; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::sync::atomic::AtomicUsize; @@ -20,7 +19,8 @@ use std::sync::Arc; static SHOW_KOMOREBI_LAYOUT_OPTIONS: AtomicUsize = AtomicUsize::new(0); -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(tag = "kind")] pub enum Grouping { /// No grouping is applied @@ -339,7 +339,8 @@ impl RenderConfig { } } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct GroupingConfig { /// Styles for the grouping pub style: Option, @@ -349,7 +350,8 @@ pub struct GroupingConfig { pub rounding: Option, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum GroupingStyle { #[serde(alias = "CtByte")] Default, @@ -369,7 +371,8 @@ pub enum GroupingStyle { DefaultWithGlowB0O1S2, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum RoundingConfig { /// All 4 corners are the same diff --git a/komorebi-bar/src/storage.rs b/komorebi-bar/src/storage.rs index 805c34c5..4e271829 100644 --- a/komorebi-bar/src/storage.rs +++ b/komorebi-bar/src/storage.rs @@ -8,7 +8,6 @@ use eframe::egui::Context; use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::process::Command; @@ -16,7 +15,8 @@ use std::time::Duration; use std::time::Instant; use sysinfo::Disks; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct StorageConfig { /// Enable the Storage widget pub enable: bool, diff --git a/komorebi-bar/src/time.rs b/komorebi-bar/src/time.rs index 984da476..7ca6c1ac 100644 --- a/komorebi-bar/src/time.rs +++ b/komorebi-bar/src/time.rs @@ -14,11 +14,11 @@ use eframe::egui::TextFormat; use eframe::egui::Ui; use eframe::egui::Vec2; use eframe::epaint::StrokeKind; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct TimeConfig { /// Enable the Time widget pub enable: bool, @@ -38,7 +38,8 @@ impl From for Time { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum TimeFormat { /// Twelve-hour format (with seconds) TwelveHour, diff --git a/komorebi-bar/src/update.rs b/komorebi-bar/src/update.rs index d70f31d3..a80b7063 100644 --- a/komorebi-bar/src/update.rs +++ b/komorebi-bar/src/update.rs @@ -8,14 +8,14 @@ use eframe::egui::Context; use eframe::egui::Label; use eframe::egui::TextFormat; use eframe::egui::Ui; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::process::Command; use std::time::Duration; use std::time::Instant; -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct UpdateConfig { /// Enable the Update widget pub enable: bool, diff --git a/komorebi-bar/src/widget.rs b/komorebi-bar/src/widget.rs index aa205447..e0f02491 100644 --- a/komorebi-bar/src/widget.rs +++ b/komorebi-bar/src/widget.rs @@ -23,7 +23,6 @@ use crate::update::Update; use crate::update::UpdateConfig; use eframe::egui::Context; use eframe::egui::Ui; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; @@ -31,7 +30,8 @@ pub trait BarWidget { fn render(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig); } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum WidgetConfig { Battery(BatteryConfig), Cpu(CpuConfig), diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 39546b34..1d814cce 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -29,7 +29,7 @@ os_info = "3.10" parking_lot = "0.12" paste = { workspace = true } regex = "1" -schemars = { workspace = true } +schemars = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true } serde_yaml = { workspace = true } @@ -57,4 +57,6 @@ shadow-rs = { workspace = true } reqwest = { version = "0.12", features = ["blocking"] } [features] +default = ["schemars"] deadlock_detection = ["parking_lot/deadlock_detection"] +schemars = ["dep:schemars"] diff --git a/komorebi/src/animation/engine.rs b/komorebi/src/animation/engine.rs index ab12663c..bc0c7eba 100644 --- a/komorebi/src/animation/engine.rs +++ b/komorebi/src/animation/engine.rs @@ -1,7 +1,5 @@ use color_eyre::Result; -use schemars::JsonSchema; - use serde::Deserialize; use serde::Serialize; use std::sync::atomic::Ordering; @@ -13,7 +11,8 @@ use super::ANIMATION_DURATION_GLOBAL; use super::ANIMATION_FPS; use super::ANIMATION_MANAGER; -#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct AnimationEngine; impl AnimationEngine { diff --git a/komorebi/src/animation/mod.rs b/komorebi/src/animation/mod.rs index 4b2ab46c..31b7f402 100644 --- a/komorebi/src/animation/mod.rs +++ b/komorebi/src/animation/mod.rs @@ -18,11 +18,12 @@ pub mod prefix; pub mod render_dispatcher; pub use render_dispatcher::RenderDispatcher; pub mod style; -use schemars::JsonSchema; + use serde::Deserialize; use serde::Serialize; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum PerAnimationPrefixConfig { Prefix(HashMap), diff --git a/komorebi/src/animation/prefix.rs b/komorebi/src/animation/prefix.rs index e4920391..26a65ce2 100644 --- a/komorebi/src/animation/prefix.rs +++ b/komorebi/src/animation/prefix.rs @@ -1,24 +1,14 @@ use clap::ValueEnum; -use schemars::JsonSchema; + use serde::Deserialize; use serde::Serialize; use strum::Display; use strum::EnumString; #[derive( - Copy, - Clone, - Debug, - Hash, - PartialEq, - Eq, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, + Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, Display, EnumString, ValueEnum, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[strum(serialize_all = "snake_case")] #[serde(rename_all = "snake_case")] pub enum AnimationPrefix { diff --git a/komorebi/src/border_manager/mod.rs b/komorebi/src/border_manager/mod.rs index d86029cc..d3a7b9f1 100644 --- a/komorebi/src/border_manager/mod.rs +++ b/komorebi/src/border_manager/mod.rs @@ -19,7 +19,6 @@ use crossbeam_utils::atomic::AtomicCell; use crossbeam_utils::atomic::AtomicConsume; use lazy_static::lazy_static; use parking_lot::Mutex; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::collections::hash_map::Entry; @@ -698,7 +697,8 @@ fn remove_border( Ok(()) } -#[derive(Debug, Copy, Clone, Display, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Copy, Clone, Display, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum ZOrder { Top, NoTopMost, diff --git a/komorebi/src/colour.rs b/komorebi/src/colour.rs index 77622e25..385a1f52 100644 --- a/komorebi/src/colour.rs +++ b/komorebi/src/colour.rs @@ -1,14 +1,19 @@ use hex_color::HexColor; use komorebi_themes::Color32; +#[cfg(feature = "schemars")] use schemars::gen::SchemaGenerator; +#[cfg(feature = "schemars")] use schemars::schema::InstanceType; +#[cfg(feature = "schemars")] use schemars::schema::Schema; +#[cfg(feature = "schemars")] use schemars::schema::SchemaObject; -use schemars::JsonSchema; + use serde::Deserialize; use serde::Serialize; -#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum Colour { /// Colour represented as RGB @@ -54,7 +59,8 @@ impl From for Color32 { #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] pub struct Hex(HexColor); -impl JsonSchema for Hex { +#[cfg(feature = "schemars")] +impl schemars::JsonSchema for Hex { fn schema_name() -> String { String::from("Hex") } @@ -78,7 +84,8 @@ impl From for u32 { } } -#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Rgb { /// Red pub r: u32, diff --git a/komorebi/src/container.rs b/komorebi/src/container.rs index fd49d763..7dbf98ca 100644 --- a/komorebi/src/container.rs +++ b/komorebi/src/container.rs @@ -2,14 +2,14 @@ use std::collections::VecDeque; use getset::Getters; use nanoid::nanoid; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use crate::ring::Ring; use crate::window::Window; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Getters, JsonSchema)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Getters)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Container { #[getset(get = "pub")] id: String, diff --git a/komorebi/src/core/animation.rs b/komorebi/src/core/animation.rs index 258b50d5..e23f0a9b 100644 --- a/komorebi/src/core/animation.rs +++ b/komorebi/src/core/animation.rs @@ -1,22 +1,12 @@ use clap::ValueEnum; -use schemars::JsonSchema; + use serde::Deserialize; use serde::Serialize; use strum::Display; use strum::EnumString; -#[derive( - Copy, - Clone, - Debug, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, - PartialEq, -)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum AnimationStyle { Linear, EaseInSine, diff --git a/komorebi/src/core/arrangement.rs b/komorebi/src/core/arrangement.rs index 150b308a..7e750e1f 100644 --- a/komorebi/src/core/arrangement.rs +++ b/komorebi/src/core/arrangement.rs @@ -1,7 +1,6 @@ use std::num::NonZeroUsize; use clap::ValueEnum; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::Display; @@ -603,18 +602,8 @@ impl Arrangement for CustomLayout { } } -#[derive( - Clone, - Copy, - Debug, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, - PartialEq, -)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum Axis { Horizontal, Vertical, diff --git a/komorebi/src/core/asc.rs b/komorebi/src/core/asc.rs index 35bd5e57..7ae07a17 100644 --- a/komorebi/src/core/asc.rs +++ b/komorebi/src/core/asc.rs @@ -2,7 +2,6 @@ use crate::config_generation::ApplicationConfiguration; use crate::config_generation::ApplicationOptions; use crate::config_generation::MatchingRule; use color_eyre::Result; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::collections::BTreeMap; @@ -10,10 +9,12 @@ use std::ops::Deref; use std::ops::DerefMut; use std::path::PathBuf; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ApplicationSpecificConfiguration(pub BTreeMap); -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum AscApplicationRulesOrSchema { AscApplicationRules(AscApplicationRules), @@ -46,7 +47,8 @@ impl ApplicationSpecificConfiguration { } /// Rules that determine how an application is handled -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct AscApplicationRules { /// Rules to ignore specific windows #[serde(skip_serializing_if = "Option::is_none")] diff --git a/komorebi/src/core/config_generation.rs b/komorebi/src/core/config_generation.rs index f45c965c..0404d078 100644 --- a/komorebi/src/core/config_generation.rs +++ b/komorebi/src/core/config_generation.rs @@ -1,6 +1,5 @@ use clap::ValueEnum; use color_eyre::Result; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::Display; @@ -8,9 +7,8 @@ use strum::EnumString; use super::ApplicationIdentifier; -#[derive( - Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, JsonSchema, -)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[strum(serialize_all = "snake_case")] #[serde(rename_all = "snake_case")] pub enum ApplicationOptions { @@ -52,14 +50,16 @@ impl ApplicationOptions { } } -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum MatchingRule { Simple(IdWithIdentifier), Composite(Vec), } -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct WorkspaceMatchingRule { pub monitor_index: usize, pub workspace_index: usize, @@ -67,7 +67,8 @@ pub struct WorkspaceMatchingRule { pub initial_only: bool, } -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct IdWithIdentifier { pub kind: ApplicationIdentifier, pub id: String, @@ -75,7 +76,8 @@ pub struct IdWithIdentifier { pub matching_strategy: Option, } -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Display, JsonSchema)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Display)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum MatchingStrategy { Legacy, Equals, @@ -89,7 +91,8 @@ pub enum MatchingStrategy { DoesNotContain, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct IdWithIdentifierAndComment { pub kind: ApplicationIdentifier, pub id: String, @@ -109,7 +112,8 @@ impl From for IdWithIdentifier { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ApplicationConfiguration { pub name: String, pub identifier: IdWithIdentifier, @@ -133,7 +137,8 @@ impl ApplicationConfiguration { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ApplicationConfigurationGenerator; impl ApplicationConfigurationGenerator { diff --git a/komorebi/src/core/custom_layout.rs b/komorebi/src/core/custom_layout.rs index 45d439f7..376b918b 100644 --- a/komorebi/src/core/custom_layout.rs +++ b/komorebi/src/core/custom_layout.rs @@ -8,13 +8,13 @@ use std::path::Path; use color_eyre::eyre::anyhow; use color_eyre::eyre::bail; use color_eyre::Result; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use super::Rect; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct CustomLayout(Vec); impl Deref for CustomLayout { @@ -250,7 +250,8 @@ impl CustomLayout { } } -#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(tag = "column", content = "configuration")] pub enum Column { Primary(Option), @@ -258,18 +259,21 @@ pub enum Column { Tertiary(ColumnSplit), } -#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum ColumnWidth { WidthPercentage(f32), } -#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum ColumnSplit { Horizontal, Vertical, } -#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum ColumnSplitWithCapacity { Horizontal(usize), Vertical(usize), diff --git a/komorebi/src/core/cycle_direction.rs b/komorebi/src/core/cycle_direction.rs index 8fc0b685..e75dec60 100644 --- a/komorebi/src/core/cycle_direction.rs +++ b/komorebi/src/core/cycle_direction.rs @@ -1,15 +1,13 @@ use std::num::NonZeroUsize; use clap::ValueEnum; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::Display; use strum::EnumString; -#[derive( - Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, JsonSchema, -)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum CycleDirection { Previous, Next, diff --git a/komorebi/src/core/default_layout.rs b/komorebi/src/core/default_layout.rs index 61c96e2f..edbf9374 100644 --- a/komorebi/src/core/default_layout.rs +++ b/komorebi/src/core/default_layout.rs @@ -1,5 +1,4 @@ use clap::ValueEnum; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::Display; @@ -10,18 +9,9 @@ use super::Rect; use super::Sizing; #[derive( - Clone, - Copy, - Debug, - Serialize, - Deserialize, - Eq, - PartialEq, - Display, - EnumString, - ValueEnum, - JsonSchema, + Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, Display, EnumString, ValueEnum, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum DefaultLayout { BSP, Columns, diff --git a/komorebi/src/core/layout.rs b/komorebi/src/core/layout.rs index 7c8d70b5..909d29f6 100644 --- a/komorebi/src/core/layout.rs +++ b/komorebi/src/core/layout.rs @@ -1,4 +1,3 @@ -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; @@ -7,7 +6,8 @@ use super::CustomLayout; use super::DefaultLayout; use super::Direction; -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum Layout { Default(DefaultLayout), Custom(CustomLayout), diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index c9fd4c11..49297f97 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -8,7 +8,6 @@ use std::str::FromStr; use clap::ValueEnum; use color_eyre::eyre::anyhow; use color_eyre::Result; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::Display; @@ -45,7 +44,8 @@ pub mod operation_direction; pub mod pathext; pub mod rect; -#[derive(Clone, Debug, Serialize, Deserialize, Display, JsonSchema)] +#[derive(Clone, Debug, Serialize, Deserialize, Display)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(tag = "type", content = "content")] pub enum SocketMessage { // Window / Container Commands @@ -241,24 +241,23 @@ impl FromStr for SocketMessage { } } -#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] +#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct SubscribeOptions { /// Only emit notifications when the window manager state has changed pub filter_state_changes: bool, } -#[derive( - Debug, Copy, Clone, Eq, PartialEq, Display, Serialize, Deserialize, JsonSchema, ValueEnum, -)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Display, Serialize, Deserialize, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum StackbarMode { Always, Never, OnStack, } -#[derive( - Debug, Copy, Default, Clone, Eq, PartialEq, Display, Serialize, Deserialize, JsonSchema, -)] +#[derive(Debug, Copy, Default, Clone, Eq, PartialEq, Display, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum StackbarLabel { #[default] Process, @@ -266,18 +265,9 @@ pub enum StackbarLabel { } #[derive( - Default, - Copy, - Clone, - Debug, - Eq, - PartialEq, - Display, - Serialize, - Deserialize, - JsonSchema, - ValueEnum, + Default, Copy, Clone, Debug, Eq, PartialEq, Display, Serialize, Deserialize, ValueEnum, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum BorderStyle { #[default] /// Use the system border style @@ -289,18 +279,9 @@ pub enum BorderStyle { } #[derive( - Default, - Copy, - Clone, - Debug, - Eq, - PartialEq, - Display, - Serialize, - Deserialize, - JsonSchema, - ValueEnum, + Default, Copy, Clone, Debug, Eq, PartialEq, Display, Serialize, Deserialize, ValueEnum, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum BorderImplementation { #[default] /// Use the adjustable komorebi border implementation @@ -310,19 +291,9 @@ pub enum BorderImplementation { } #[derive( - Copy, - Clone, - Debug, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, - PartialEq, - Eq, - Hash, + Copy, Clone, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq, Eq, Hash, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum WindowKind { Single, Stack, @@ -331,9 +302,8 @@ pub enum WindowKind { Floating, } -#[derive( - Copy, Clone, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, JsonSchema, -)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum StateQuery { FocusedMonitorIndex, FocusedWorkspaceIndex, @@ -343,18 +313,9 @@ pub enum StateQuery { } #[derive( - Copy, - Clone, - Debug, - Eq, - PartialEq, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, + Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Display, EnumString, ValueEnum, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum ApplicationIdentifier { #[serde(alias = "exe")] Exe, @@ -366,18 +327,8 @@ pub enum ApplicationIdentifier { Path, } -#[derive( - Copy, - Clone, - Debug, - PartialEq, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, -)] +#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum FocusFollowsMouseImplementation { /// A custom FFM implementation (slightly more CPU-intensive) Komorebi, @@ -385,7 +336,8 @@ pub enum FocusFollowsMouseImplementation { Windows, } -#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct WindowManagementBehaviour { /// The current WindowContainerBehaviour to be used pub current_behaviour: WindowContainerBehaviour, @@ -396,18 +348,9 @@ pub struct WindowManagementBehaviour { } #[derive( - Clone, - Copy, - Debug, - Default, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, - PartialEq, + Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum WindowContainerBehaviour { /// Create a new container for each new window #[default] @@ -416,18 +359,8 @@ pub enum WindowContainerBehaviour { Append, } -#[derive( - Clone, - Copy, - Debug, - PartialEq, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, -)] +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum MoveBehaviour { /// Swap the window container with the window container at the edge of the adjacent monitor Swap, @@ -437,18 +370,8 @@ pub enum MoveBehaviour { NoOp, } -#[derive( - Clone, - Copy, - Debug, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, - PartialEq, -)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum CrossBoundaryBehaviour { /// Attempt to perform actions across a workspace boundary Workspace, @@ -456,18 +379,8 @@ pub enum CrossBoundaryBehaviour { Monitor, } -#[derive( - Copy, - Clone, - Debug, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, - PartialEq, -)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum HidingBehaviour { /// Use the SW_HIDE flag to hide windows when switching workspaces (has issues with Electron apps) Hide, @@ -477,18 +390,8 @@ pub enum HidingBehaviour { Cloak, } -#[derive( - Clone, - Copy, - Debug, - PartialEq, - Serialize, - Deserialize, - Display, - EnumString, - ValueEnum, - JsonSchema, -)] +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum OperationBehaviour { /// Process komorebic commands on temporarily unmanaged/floated windows Op, @@ -496,9 +399,8 @@ pub enum OperationBehaviour { NoOp, } -#[derive( - Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, JsonSchema, -)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum Sizing { Increase, Decrease, diff --git a/komorebi/src/core/operation_direction.rs b/komorebi/src/core/operation_direction.rs index 2fdda9bc..b2358904 100644 --- a/komorebi/src/core/operation_direction.rs +++ b/komorebi/src/core/operation_direction.rs @@ -1,7 +1,6 @@ use std::num::NonZeroUsize; use clap::ValueEnum; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::Display; @@ -10,9 +9,8 @@ use strum::EnumString; use super::direction::Direction; use super::Axis; -#[derive( - Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, JsonSchema, -)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum OperationDirection { Left, Right, diff --git a/komorebi/src/core/rect.rs b/komorebi/src/core/rect.rs index cc7b0492..285b7d00 100644 --- a/komorebi/src/core/rect.rs +++ b/komorebi/src/core/rect.rs @@ -1,9 +1,9 @@ -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use windows::Win32::Foundation::RECT; -#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Eq, PartialEq, JsonSchema)] +#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Rect { /// The left point in a Win32 Rect pub left: i32, diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 59b93b74..0d87323c 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -66,7 +66,6 @@ use color_eyre::Result; use os_info::Version; use parking_lot::Mutex; use regex::Regex; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use uds_windows::UnixStream; @@ -280,7 +279,8 @@ pub fn current_virtual_desktop() -> Option> { current } -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum NotificationEvent { WindowManager(WindowManagerEvent), @@ -288,7 +288,8 @@ pub enum NotificationEvent { Monitor(MonitorNotification), } -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Notification { pub event: NotificationEvent, pub state: State, diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index 914139a6..cf10646a 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -9,7 +9,6 @@ use getset::CopyGetters; use getset::Getters; use getset::MutGetters; use getset::Setters; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; @@ -26,17 +25,9 @@ use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_WORKSPACE_PADDING; #[derive( - Debug, - Clone, - Serialize, - Deserialize, - Getters, - CopyGetters, - MutGetters, - Setters, - JsonSchema, - PartialEq, + Debug, Clone, Serialize, Deserialize, Getters, CopyGetters, MutGetters, Setters, PartialEq, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Monitor { #[getset(get_copy = "pub", set = "pub")] pub id: isize, diff --git a/komorebi/src/monitor_reconciliator/mod.rs b/komorebi/src/monitor_reconciliator/mod.rs index 636b4d47..718d0a46 100644 --- a/komorebi/src/monitor_reconciliator/mod.rs +++ b/komorebi/src/monitor_reconciliator/mod.rs @@ -17,7 +17,6 @@ use crossbeam_channel::Receiver; use crossbeam_channel::Sender; use crossbeam_utils::atomic::AtomicConsume; use parking_lot::Mutex; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::collections::HashMap; @@ -28,7 +27,8 @@ use std::sync::OnceLock; pub mod hidden; -#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Copy, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(tag = "type", content = "content")] pub enum MonitorNotification { ResolutionScalingChanged, diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index b1149f44..28f7f83f 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1,3 +1,8 @@ +use color_eyre::eyre::anyhow; +use color_eyre::Result; +use miow::pipe::connect; +use net2::TcpStreamExt; +use parking_lot::Mutex; use std::collections::HashMap; use std::fs::File; use std::fs::OpenOptions; @@ -11,20 +16,11 @@ use std::str::FromStr; use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; - -use color_eyre::eyre::anyhow; -use color_eyre::Result; -use miow::pipe::connect; -use net2::TcpStreamExt; -use parking_lot::Mutex; -use schemars::gen::SchemaSettings; -use schemars::schema_for; use uds_windows::UnixStream; use crate::animation::ANIMATION_DURATION_PER_ANIMATION; use crate::animation::ANIMATION_ENABLED_PER_ANIMATION; use crate::animation::ANIMATION_STYLE_PER_ANIMATION; -use crate::core::config_generation::ApplicationConfiguration; use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; @@ -1828,35 +1824,49 @@ impl WindowManager { *STACKBAR_FONT_FAMILY.lock() = font_family.clone(); } SocketMessage::ApplicationSpecificConfigurationSchema => { - let asc = schema_for!(Vec); - let schema = serde_json::to_string_pretty(&asc)?; + #[cfg(feature = "schemars")] + { + let asc = schemars::schema_for!( + Vec + ); + let schema = serde_json::to_string_pretty(&asc)?; - reply.write_all(schema.as_bytes())?; + reply.write_all(schema.as_bytes())?; + } } SocketMessage::NotificationSchema => { - let notification = schema_for!(Notification); - let schema = serde_json::to_string_pretty(¬ification)?; + #[cfg(feature = "schemars")] + { + let notification = schemars::schema_for!(Notification); + let schema = serde_json::to_string_pretty(¬ification)?; - reply.write_all(schema.as_bytes())?; + reply.write_all(schema.as_bytes())?; + } } SocketMessage::SocketSchema => { - let socket_message = schema_for!(SocketMessage); - let schema = serde_json::to_string_pretty(&socket_message)?; + #[cfg(feature = "schemars")] + { + let socket_message = schemars::schema_for!(SocketMessage); + let schema = serde_json::to_string_pretty(&socket_message)?; - reply.write_all(schema.as_bytes())?; + reply.write_all(schema.as_bytes())?; + } } SocketMessage::StaticConfigSchema => { - let settings = SchemaSettings::default().with(|s| { - s.option_nullable = false; - s.option_add_null_type = false; - s.inline_subschemas = true; - }); + #[cfg(feature = "schemars")] + { + let settings = schemars::gen::SchemaSettings::default().with(|s| { + s.option_nullable = false; + s.option_add_null_type = false; + s.inline_subschemas = true; + }); - let gen = settings.into_generator(); - let socket_message = gen.into_root_schema_for::(); - let schema = serde_json::to_string_pretty(&socket_message)?; + let gen = settings.into_generator(); + let socket_message = gen.into_root_schema_for::(); + let schema = serde_json::to_string_pretty(&socket_message)?; - reply.write_all(schema.as_bytes())?; + reply.write_all(schema.as_bytes())?; + } } SocketMessage::GenerateStaticConfig => { let config = serde_json::to_string_pretty(&StaticConfig::from(&*self))?; diff --git a/komorebi/src/ring.rs b/komorebi/src/ring.rs index 325b9065..325c14f8 100644 --- a/komorebi/src/ring.rs +++ b/komorebi/src/ring.rs @@ -1,10 +1,10 @@ use std::collections::VecDeque; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Ring { elements: VecDeque, focused: usize, diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 84770773..8f75d5fa 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -7,14 +7,35 @@ use crate::animation::ANIMATION_FPS; use crate::animation::ANIMATION_STYLE_GLOBAL; use crate::animation::ANIMATION_STYLE_PER_ANIMATION; use crate::animation::DEFAULT_ANIMATION_FPS; +use crate::asc::ApplicationSpecificConfiguration; +use crate::asc::AscApplicationRulesOrSchema; use crate::border_manager; use crate::border_manager::ZOrder; use crate::border_manager::IMPLEMENTATION; use crate::border_manager::STYLE; use crate::colour::Colour; +use crate::config_generation::WorkspaceMatchingRule; +use crate::core::config_generation::ApplicationConfiguration; +use crate::core::config_generation::ApplicationConfigurationGenerator; +use crate::core::config_generation::ApplicationOptions; +use crate::core::config_generation::MatchingRule; +use crate::core::config_generation::MatchingStrategy; +use crate::core::resolve_home_path; +use crate::core::AnimationStyle; use crate::core::BorderImplementation; +use crate::core::BorderStyle; +use crate::core::DefaultLayout; +use crate::core::FocusFollowsMouseImplementation; +use crate::core::HidingBehaviour; +use crate::core::Layout; +use crate::core::MoveBehaviour; +use crate::core::OperationBehaviour; +use crate::core::Rect; +use crate::core::SocketMessage; use crate::core::StackbarLabel; use crate::core::StackbarMode; +use crate::core::WindowContainerBehaviour; +use crate::core::WindowManagementBehaviour; use crate::current_virtual_desktop; use crate::monitor; use crate::monitor::Monitor; @@ -61,35 +82,12 @@ use crate::TRANSPARENCY_BLACKLIST; use crate::TRAY_AND_MULTI_WINDOW_IDENTIFIERS; use crate::WINDOWS_11; use crate::WORKSPACE_MATCHING_RULES; - -use crate::asc::ApplicationSpecificConfiguration; -use crate::asc::AscApplicationRulesOrSchema; -use crate::config_generation::WorkspaceMatchingRule; -use crate::core::config_generation::ApplicationConfiguration; -use crate::core::config_generation::ApplicationConfigurationGenerator; -use crate::core::config_generation::ApplicationOptions; -use crate::core::config_generation::MatchingRule; -use crate::core::config_generation::MatchingStrategy; -use crate::core::resolve_home_path; -use crate::core::AnimationStyle; -use crate::core::BorderStyle; -use crate::core::DefaultLayout; -use crate::core::FocusFollowsMouseImplementation; -use crate::core::HidingBehaviour; -use crate::core::Layout; -use crate::core::MoveBehaviour; -use crate::core::OperationBehaviour; -use crate::core::Rect; -use crate::core::SocketMessage; -use crate::core::WindowContainerBehaviour; -use crate::core::WindowManagementBehaviour; use color_eyre::Result; use crossbeam_channel::Receiver; use hotwatch::EventKind; use hotwatch::Hotwatch; use parking_lot::Mutex; use regex::Regex; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use std::collections::HashMap; @@ -102,7 +100,8 @@ use std::sync::Arc; use uds_windows::UnixListener; use uds_windows::UnixStream; -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct BorderColours { /// Border colour when the container contains a single window #[serde(skip_serializing_if = "Option::is_none")] @@ -121,7 +120,8 @@ pub struct BorderColours { pub unfocused: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct WorkspaceConfig { /// Name pub name: String, @@ -243,7 +243,8 @@ impl From<&Workspace> for WorkspaceConfig { } } -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct MonitorConfig { /// Workspace configurations pub workspaces: Vec, @@ -301,7 +302,8 @@ impl From<&Monitor> for MonitorConfig { } } -#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] /// The `komorebi.json` static configuration file reference for `v0.1.35` pub struct StaticConfig { /// DEPRECATED from v0.1.22: no longer required @@ -449,7 +451,8 @@ pub struct StaticConfig { pub floating_window_aspect_ratio: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct AnimationsConfig { /// Enable or disable animations (default: false) pub enabled: PerAnimationPrefixConfig, @@ -464,7 +467,8 @@ pub struct AnimationsConfig { pub fps: Option, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(tag = "palette")] pub enum KomorebiTheme { /// A theme from catppuccin-egui @@ -614,7 +618,8 @@ impl StaticConfig { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct TabsConfig { /// Width of a stackbar tab #[serde(skip_serializing_if = "Option::is_none")] @@ -636,7 +641,8 @@ pub struct TabsConfig { pub font_size: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct StackbarConfig { /// Stackbar height #[serde(skip_serializing_if = "Option::is_none")] diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 91df0e37..d2367d33 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -11,13 +11,42 @@ use crate::animation::ANIMATION_MANAGER; use crate::animation::ANIMATION_STYLE_GLOBAL; use crate::animation::ANIMATION_STYLE_PER_ANIMATION; use crate::com::SetCloak; +use crate::core::config_generation::IdWithIdentifier; +use crate::core::config_generation::MatchingRule; +use crate::core::config_generation::MatchingStrategy; +use crate::core::ApplicationIdentifier; +use crate::core::HidingBehaviour; +use crate::core::Rect; use crate::focus_manager; use crate::stackbar_manager; +use crate::styles::ExtendedWindowStyle; +use crate::styles::WindowStyle; +use crate::transparency_manager; +use crate::window_manager_event::WindowManagerEvent; use crate::windows_api; +use crate::windows_api::WindowsApi; use crate::AnimationStyle; +use crate::FLOATING_APPLICATIONS; use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO; +use crate::HIDDEN_HWNDS; +use crate::HIDING_BEHAVIOUR; +use crate::IGNORE_IDENTIFIERS; +use crate::LAYERED_WHITELIST; +use crate::MANAGE_IDENTIFIERS; +use crate::NO_TITLEBAR; +use crate::PERMAIGNORE_CLASSES; +use crate::REGEX_IDENTIFIERS; use crate::SLOW_APPLICATION_COMPENSATION_TIME; use crate::SLOW_APPLICATION_IDENTIFIERS; +use crate::WSL2_UI_PROCESSES; +use color_eyre::eyre; +use color_eyre::Result; +use crossbeam_utils::atomic::AtomicConsume; +use regex::Regex; +use serde::ser::SerializeStruct; +use serde::Deserialize; +use serde::Serialize; +use serde::Serializer; use std::collections::HashMap; use std::convert::TryFrom; use std::fmt::Display; @@ -27,47 +56,15 @@ use std::sync::atomic::AtomicI32; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; - -use crate::core::config_generation::IdWithIdentifier; -use crate::core::config_generation::MatchingRule; -use crate::core::config_generation::MatchingStrategy; -use color_eyre::eyre; -use color_eyre::Result; -use crossbeam_utils::atomic::AtomicConsume; -use regex::Regex; -use schemars::JsonSchema; -use serde::ser::SerializeStruct; -use serde::Deserialize; -use serde::Serialize; -use serde::Serializer; use strum::Display; use strum::EnumString; use windows::Win32::Foundation::HWND; -use crate::core::ApplicationIdentifier; -use crate::core::HidingBehaviour; -use crate::core::Rect; - -use crate::styles::ExtendedWindowStyle; -use crate::styles::WindowStyle; -use crate::transparency_manager; -use crate::window_manager_event::WindowManagerEvent; -use crate::windows_api::WindowsApi; -use crate::FLOATING_APPLICATIONS; -use crate::HIDDEN_HWNDS; -use crate::HIDING_BEHAVIOUR; -use crate::IGNORE_IDENTIFIERS; -use crate::LAYERED_WHITELIST; -use crate::MANAGE_IDENTIFIERS; -use crate::NO_TITLEBAR; -use crate::PERMAIGNORE_CLASSES; -use crate::REGEX_IDENTIFIERS; -use crate::WSL2_UI_PROCESSES; - pub static MINIMUM_WIDTH: AtomicI32 = AtomicI32::new(0); pub static MINIMUM_HEIGHT: AtomicI32 = AtomicI32::new(0); -#[derive(Debug, Default, Clone, Copy, Deserialize, JsonSchema, PartialEq)] +#[derive(Debug, Default, Clone, Copy, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Window { pub hwnd: isize, } @@ -87,7 +84,8 @@ impl From for Window { } #[allow(clippy::module_name_repetitions)] -#[derive(Debug, Clone, Serialize, JsonSchema)] +#[derive(Debug, Clone, Serialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct WindowDetails { pub title: String, pub exe: String, @@ -299,9 +297,8 @@ impl RenderDispatcher for TransparencyRenderDispatcher { } } -#[derive( - Copy, Clone, Debug, Display, EnumString, Serialize, Deserialize, JsonSchema, PartialEq, -)] +#[derive(Copy, Clone, Debug, Display, EnumString, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum AspectRatio { /// A predefined aspect ratio @@ -316,9 +313,8 @@ impl Default for AspectRatio { } } -#[derive( - Copy, Clone, Debug, Default, Display, EnumString, Serialize, Deserialize, JsonSchema, PartialEq, -)] +#[derive(Copy, Clone, Debug, Default, Display, EnumString, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum PredefinedAspectRatio { /// 21:9 Ultrawide, diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index aaebe47d..fce739fb 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -19,7 +19,6 @@ use hotwatch::notify::ErrorKind as NotifyErrorKind; use hotwatch::EventKind; use hotwatch::Hotwatch; use parking_lot::Mutex; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use uds_windows::UnixListener; @@ -126,7 +125,8 @@ pub struct WindowManager { } #[allow(clippy::struct_excessive_bools)] -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct State { pub monitors: Ring, pub monitor_usr_idx_map: HashMap, @@ -191,7 +191,8 @@ impl State { } #[allow(clippy::struct_excessive_bools)] -#[derive(Debug, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct GlobalState { pub border_enabled: bool, pub border_colours: BorderColours, diff --git a/komorebi/src/window_manager_event.rs b/komorebi/src/window_manager_event.rs index 0c02770c..dec2a0b1 100644 --- a/komorebi/src/window_manager_event.rs +++ b/komorebi/src/window_manager_event.rs @@ -1,7 +1,6 @@ use std::fmt::Display; use std::fmt::Formatter; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; @@ -12,7 +11,8 @@ use crate::OBJECT_NAME_CHANGE_ON_LAUNCH; use crate::OBJECT_NAME_CHANGE_TITLE_IGNORE_LIST; use crate::REGEX_IDENTIFIERS; -#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema)] +#[derive(Debug, Copy, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[serde(tag = "type", content = "content")] pub enum WindowManagerEvent { Destroy(WinEvent, Window), diff --git a/komorebi/src/winevent.rs b/komorebi/src/winevent.rs index 9d0968bd..1fdcde39 100644 --- a/komorebi/src/winevent.rs +++ b/komorebi/src/winevent.rs @@ -1,6 +1,5 @@ #![allow(clippy::use_self)] -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; use strum::Display; @@ -89,7 +88,8 @@ use windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_EVENTID_START; use windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_PROPID_END; use windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_PROPID_START; -#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Display, JsonSchema)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Display)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[repr(u32)] #[allow(dead_code)] pub enum WinEvent { diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index feed1671..db2c9f20 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -10,7 +10,6 @@ use getset::CopyGetters; use getset::Getters; use getset::MutGetters; use getset::Setters; -use schemars::JsonSchema; use serde::Deserialize; use serde::Serialize; @@ -43,17 +42,9 @@ use crate::REMOVE_TITLEBARS; #[allow(clippy::struct_field_names)] #[derive( - Debug, - Clone, - Serialize, - Deserialize, - Getters, - CopyGetters, - MutGetters, - Setters, - JsonSchema, - PartialEq, + Debug, Clone, Serialize, Deserialize, Getters, CopyGetters, MutGetters, Setters, PartialEq, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Workspace { #[getset(get = "pub", set = "pub")] pub name: Option, @@ -103,7 +94,8 @@ pub struct Workspace { pub workspace_config: Option, } -#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum WorkspaceLayer { #[default] Tiling, @@ -169,9 +161,9 @@ pub enum WorkspaceWindowLocation { CopyGetters, MutGetters, Setters, - JsonSchema, PartialEq, )] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] /// Settings setup either by the parent monitor or by the `WindowManager` pub struct WorkspaceGlobals { pub container_padding: Option, diff --git a/komorebic/Cargo.toml b/komorebic/Cargo.toml index 096b125a..6059274c 100644 --- a/komorebic/Cargo.toml +++ b/komorebic/Cargo.toml @@ -21,7 +21,7 @@ miette = { version = "7", features = ["fancy"] } paste = { workspace = true } powershell_script = "1.0" reqwest = { version = "0.12", features = ["blocking"] } -schemars = { workspace = true } +schemars = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true } shadow-rs = { workspace = true } @@ -34,5 +34,9 @@ windows = { workspace = true } reqwest = { version = "0.12", features = ["blocking"] } shadow-rs = { workspace = true } +[features] +default = ["schemars"] +schemars = ["dep:schemars"] + [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(FALSE)'] } \ No newline at end of file diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 1ad1cef4..d4e2d588 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -26,15 +26,12 @@ use komorebi_client::resolve_home_path; use komorebi_client::send_message; use komorebi_client::send_query; use komorebi_client::ApplicationSpecificConfiguration; -use komorebi_client::Notification; use lazy_static::lazy_static; use miette::NamedSource; use miette::Report; use miette::SourceOffset; use miette::SourceSpan; use paste::paste; -use schemars::gen::SchemaSettings; -use schemars::schema_for; use serde::Deserialize; use sysinfo::ProcessesToUpdate; use which::which; @@ -2973,31 +2970,43 @@ if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { ); } SubCommand::ApplicationSpecificConfigurationSchema => { - let asc = schema_for!(ApplicationSpecificConfiguration); - let schema = serde_json::to_string_pretty(&asc)?; - println!("{schema}"); + #[cfg(feature = "schemars")] + { + let asc = schemars::schema_for!(ApplicationSpecificConfiguration); + let schema = serde_json::to_string_pretty(&asc)?; + println!("{schema}"); + } } SubCommand::NotificationSchema => { - let notification = schema_for!(Notification); - let schema = serde_json::to_string_pretty(¬ification)?; - println!("{schema}"); + #[cfg(feature = "schemars")] + { + let notification = schemars::schema_for!(komorebi_client::Notification); + let schema = serde_json::to_string_pretty(¬ification)?; + println!("{schema}"); + } } SubCommand::SocketSchema => { - let socket_message = schema_for!(SocketMessage); - let schema = serde_json::to_string_pretty(&socket_message)?; - println!("{schema}"); + #[cfg(feature = "schemars")] + { + let socket_message = schemars::schema_for!(SocketMessage); + let schema = serde_json::to_string_pretty(&socket_message)?; + println!("{schema}"); + } } SubCommand::StaticConfigSchema => { - let settings = SchemaSettings::default().with(|s| { - s.option_nullable = false; - s.option_add_null_type = false; - s.inline_subschemas = true; - }); + #[cfg(feature = "schemars")] + { + let settings = schemars::gen::SchemaSettings::default().with(|s| { + s.option_nullable = false; + s.option_add_null_type = false; + s.inline_subschemas = true; + }); - let gen = settings.into_generator(); - let socket_message = gen.into_root_schema_for::(); - let schema = serde_json::to_string_pretty(&socket_message)?; - println!("{schema}"); + let gen = settings.into_generator(); + let socket_message = gen.into_root_schema_for::(); + let schema = serde_json::to_string_pretty(&socket_message)?; + println!("{schema}"); + } } SubCommand::GenerateStaticConfig => { print_query(&SocketMessage::GenerateStaticConfig);