aboutsummaryrefslogtreecommitdiff
path: root/niri-ipc
diff options
context:
space:
mode:
authorOli Strik <oliverstrik@gmail.com>2024-07-12 07:21:52 +0200
committerGitHub <noreply@github.com>2024-07-12 05:21:52 +0000
commit519611c6c8da094717b0bfdba28e4942b78b4728 (patch)
treee4ad7b9c730d2d9cbf71ccdfbde25fc33bb52261 /niri-ipc
parenta283c34dbbad44dfddfa4b5eafa6d8e3b47b7c14 (diff)
downloadniri-519611c6c8da094717b0bfdba28e4942b78b4728.tar.gz
niri-519611c6c8da094717b0bfdba28e4942b78b4728.tar.bz2
niri-519611c6c8da094717b0bfdba28e4942b78b4728.zip
Add schemars::JsonSchema trait to ipc types (#536)
* feat: add schemars JsonSchema trait to ipc types * niri-ipc: use feature-flag for deriving schemars::JsonSchema --------- Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
Diffstat (limited to 'niri-ipc')
-rw-r--r--niri-ipc/Cargo.toml2
-rw-r--r--niri-ipc/src/lib.rs19
2 files changed, 21 insertions, 0 deletions
diff --git a/niri-ipc/Cargo.toml b/niri-ipc/Cargo.toml
index e0963116..1861799a 100644
--- a/niri-ipc/Cargo.toml
+++ b/niri-ipc/Cargo.toml
@@ -9,8 +9,10 @@ repository.workspace = true
[dependencies]
clap = { workspace = true, optional = true }
+schemars = { version = "0.8.21", optional = true }
serde.workspace = true
serde_json.workspace = true
[features]
clap = ["dep:clap"]
+json-schema = ["dep:schemars"]
diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs
index 16817df3..7317436c 100644
--- a/niri-ipc/src/lib.rs
+++ b/niri-ipc/src/lib.rs
@@ -11,6 +11,7 @@ pub use socket::{Socket, SOCKET_PATH_ENV};
/// Request from client to niri.
#[derive(Debug, Serialize, Deserialize, Clone)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Request {
/// Request the version string for the running niri instance.
Version,
@@ -51,6 +52,7 @@ pub type Reply = Result<Response, String>;
/// Successful response from niri to client.
#[derive(Debug, Serialize, Deserialize, Clone)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Response {
/// A request that does not need a response was handled successfully.
Handled,
@@ -77,6 +79,7 @@ pub enum Response {
#[cfg_attr(feature = "clap", derive(clap::Parser))]
#[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))]
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Action {
/// Exit niri.
Quit {
@@ -278,6 +281,7 @@ pub enum Action {
/// Change in window or column size.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum SizeChange {
/// Set the size in logical pixels.
SetFixed(i32),
@@ -291,6 +295,7 @@ pub enum SizeChange {
/// Workspace reference (index or name) to operate on.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum WorkspaceReferenceArg {
/// Index of the workspace.
Index(u8),
@@ -300,6 +305,7 @@ pub enum WorkspaceReferenceArg {
/// Layout to switch to.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum LayoutSwitchTarget {
/// The next configured layout.
Next,
@@ -314,6 +320,7 @@ pub enum LayoutSwitchTarget {
#[cfg_attr(feature = "clap", derive(clap::Parser))]
#[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))]
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum OutputAction {
/// Turn off the output.
Off,
@@ -362,6 +369,7 @@ pub enum OutputAction {
/// Output mode to set.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum ModeToSet {
/// Niri will pick the mode automatically.
Automatic,
@@ -371,6 +379,7 @@ pub enum ModeToSet {
/// Output mode as set in the config file.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct ConfiguredMode {
/// Width in physical pixels.
pub width: u16,
@@ -382,6 +391,7 @@ pub struct ConfiguredMode {
/// Output scale to set.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum ScaleToSet {
/// Niri will pick the scale automatically.
Automatic,
@@ -394,6 +404,7 @@ pub enum ScaleToSet {
#[cfg_attr(feature = "clap", derive(clap::Subcommand))]
#[cfg_attr(feature = "clap", command(subcommand_value_name = "POSITION"))]
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Position Values"))]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum PositionToSet {
/// Position the output automatically.
#[cfg_attr(feature = "clap", command(name = "auto"))]
@@ -406,6 +417,7 @@ pub enum PositionToSet {
/// Output position as set in the config file.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "clap", derive(clap::Args))]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct ConfiguredPosition {
/// Logical X position.
pub x: i32,
@@ -415,6 +427,7 @@ pub struct ConfiguredPosition {
/// Connected output.
#[derive(Debug, Serialize, Deserialize, Clone)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Output {
/// Name of the output.
pub name: String,
@@ -442,6 +455,7 @@ pub struct Output {
/// Output mode.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Mode {
/// Width in physical pixels.
pub width: u16,
@@ -455,6 +469,7 @@ pub struct Mode {
/// Logical output in the compositor's coordinate space.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct LogicalOutput {
/// Logical X position.
pub x: i32,
@@ -473,6 +488,7 @@ pub struct LogicalOutput {
/// Output transform, which goes counter-clockwise.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum Transform {
/// Untransformed.
Normal,
@@ -500,6 +516,7 @@ pub enum Transform {
/// Toplevel window.
#[derive(Serialize, Deserialize, Debug, Clone)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Window {
/// Title, if set.
pub title: Option<String>,
@@ -509,6 +526,7 @@ pub struct Window {
/// Output configuration change result.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub enum OutputConfigChanged {
/// The target output was connected and the change was applied.
Applied,
@@ -518,6 +536,7 @@ pub enum OutputConfigChanged {
/// A workspace.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
+#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
pub struct Workspace {
/// Index of the workspace on its monitor.
///