From 9da918bc40e1b12ca28fa2c3d75479a434895789 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Thu, 19 Oct 2023 20:19:00 -0500 Subject: [PATCH] Move stuff to where they should be --- api/rust/src/input.rs | 34 ++++++++++++++++++++- api/rust/src/lib.rs | 16 ++++++++-- api/rust/src/msg.rs | 68 +++++------------------------------------- api/rust/src/output.rs | 8 ++++- api/rust/src/tag.rs | 22 ++++++++++++-- api/rust/src/window.rs | 25 +++++++++++++++- 6 files changed, 105 insertions(+), 68 deletions(-) diff --git a/api/rust/src/input.rs b/api/rust/src/input.rs index 1ea8ea4..91304e4 100644 --- a/api/rust/src/input.rs +++ b/api/rust/src/input.rs @@ -1,7 +1,7 @@ use xkbcommon::xkb::Keysym; use crate::{ - msg::{Args, CallbackId, KeyIntOrString, Modifier, MouseEdge, Msg}, + msg::{Args, CallbackId, KeyIntOrString, Msg}, send_msg, CALLBACK_VEC, }; @@ -69,17 +69,34 @@ impl Input { } } +/// A mouse button. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum MouseButton { + /// The left mouse button. Left = 0x110, + /// The right mouse button. Right, + /// The middle mouse button, pressed usually by clicking the scroll wheel. Middle, + /// Side, + /// Extra, + /// Forward, + /// Back, } +/// The edge on which you want things to trigger. +#[derive(Debug, Hash, serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, Eq)] +pub enum MouseEdge { + /// Actions will be triggered on button press. + Press, + /// Actions will be triggered on button release. + Release, +} + impl From for KeyIntOrString { fn from(value: char) -> Self { Self::String(value.to_string()) @@ -97,3 +114,18 @@ impl From for KeyIntOrString { Self::Int(value.raw()) } } + +/// A modifier key. +#[derive(Debug, PartialEq, Eq, Copy, Clone, serde::Serialize, serde::Deserialize)] +pub enum Modifier { + /// The shift key. + Shift, + /// The control key. + Ctrl, + /// The alt key. + Alt, + /// The super key. + /// + /// This is also known as the Windows key, meta, or Mod4 for those coming from Xorg. + Super, +} diff --git a/api/rust/src/lib.rs b/api/rust/src/lib.rs index 74111a8..c0205fe 100644 --- a/api/rust/src/lib.rs +++ b/api/rust/src/lib.rs @@ -1,3 +1,7 @@ +#![warn(missing_docs)] + +//! The Rust implementation of the Pinnacle API. + mod input; mod msg; mod output; @@ -6,9 +10,9 @@ mod tag; mod window; use input::Input; +pub use input::Modifier; pub use input::MouseButton; -pub use msg::Modifier; -pub use msg::MouseEdge; +pub use input::MouseEdge; use output::Output; use tag::Tag; use window::Window; @@ -172,10 +176,18 @@ fn request(request: Request) -> RequestResponse { response } +/// The entry to configuration. +/// +/// This struct houses every submodule you'll need to configure Pinnacle. pub struct Pinnacle { + /// Process management. pub process: Process, + /// Window management. pub window: Window, + /// Input management. pub input: Input, + /// Output management. pub output: Output, + /// Tag management. pub tag: Tag, } diff --git a/api/rust/src/msg.rs b/api/rust/src/msg.rs index ac05dc9..5508f68 100644 --- a/api/rust/src/msg.rs +++ b/api/rust/src/msg.rs @@ -1,48 +1,15 @@ use std::num::NonZeroU32; +use crate::{ + output::OutputName, + tag::{Layout, TagId}, + window::{FloatingOrTiled, FullscreenOrMaximized, WindowId}, + Modifier, MouseEdge, +}; + #[derive(Debug, Hash, PartialEq, Eq, serde::Serialize, serde::Deserialize, Clone, Copy)] pub struct CallbackId(pub u32); -#[derive(Debug, Hash, serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, Eq)] -pub enum MouseEdge { - Press, - Release, -} - -/// A unique identifier for each window. -#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -pub enum WindowId { - /// A config API returned an invalid window. It should be using this variant. - None, - /// A valid window id. - #[serde(untagged)] - Some(u32), -} - -#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize)] -pub enum TagId { - None, - #[serde(untagged)] - Some(u32), -} - -/// A unique identifier for an output. -/// -/// An empty string represents an invalid output. -#[derive(Debug, Hash, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)] -pub struct OutputName(pub String); - -#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)] -pub enum Layout { - MasterStack, - Dwindle, - Spiral, - CornerTopLeft, - CornerTopRight, - CornerBottomLeft, - CornerBottomRight, -} - #[derive(Debug, PartialEq, Copy, Clone, serde::Serialize)] pub enum AccelProfile { Flat, @@ -110,19 +77,6 @@ pub struct WindowRuleCondition { tag: Option>, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize)] -pub enum FloatingOrTiled { - Floating, - Tiled, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -pub enum FullscreenOrMaximized { - Neither, - Fullscreen, - Maximized, -} - #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)] pub struct WindowRule { /// Set the output the window will open on. @@ -292,14 +246,6 @@ pub enum KeyIntOrString { String(String), } -#[derive(Debug, PartialEq, Eq, Copy, Clone, serde::Serialize, serde::Deserialize)] -pub enum Modifier { - Shift, - Ctrl, - Alt, - Super, -} - #[derive(Debug, serde::Serialize, serde::Deserialize, Clone)] pub enum Args { /// Send a message with lines from the spawned process. diff --git a/api/rust/src/output.rs b/api/rust/src/output.rs index 9f3aa68..b0d56c9 100644 --- a/api/rust/src/output.rs +++ b/api/rust/src/output.rs @@ -1,10 +1,16 @@ use crate::{ - msg::{Args, CallbackId, Msg, OutputName, Request, RequestResponse}, + msg::{Args, CallbackId, Msg, Request, RequestResponse}, request, send_msg, tag::{Tag, TagHandle}, CALLBACK_VEC, }; +/// A unique identifier for an output. +/// +/// An empty string represents an invalid output. +#[derive(Debug, Hash, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)] +pub struct OutputName(pub String); + /// Output management. pub struct Output; diff --git a/api/rust/src/tag.rs b/api/rust/src/tag.rs index 89f1ce9..74466de 100644 --- a/api/rust/src/tag.rs +++ b/api/rust/src/tag.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use crate::{ - msg::{Layout, Msg, OutputName, Request, RequestResponse, TagId}, - output::{Output, OutputHandle}, + msg::{Msg, Request, RequestResponse}, + output::{Output, OutputHandle, OutputName}, request, send_msg, }; @@ -115,6 +115,13 @@ impl LayoutCycler { } } +#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize)] +pub enum TagId { + None, + #[serde(untagged)] + Some(u32), +} + pub struct TagHandle(pub TagId); pub struct TagProperties { @@ -160,3 +167,14 @@ impl TagHandle { send_msg(msg).unwrap() } } + +#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)] +pub enum Layout { + MasterStack, + Dwindle, + Spiral, + CornerTopLeft, + CornerTopRight, + CornerBottomLeft, + CornerBottomRight, +} diff --git a/api/rust/src/window.rs b/api/rust/src/window.rs index 7597420..1fec9e9 100644 --- a/api/rust/src/window.rs +++ b/api/rust/src/window.rs @@ -1,10 +1,20 @@ use crate::{ - msg::{FullscreenOrMaximized, Msg, Request, RequestResponse, WindowId}, + msg::{Msg, Request, RequestResponse}, request, send_msg, tag::TagHandle, MouseButton, }; +/// A unique identifier for each window. +#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum WindowId { + /// A config API returned an invalid window. It should be using this variant. + None, + /// A valid window id. + #[serde(untagged)] + Some(u32), +} + pub struct Window; impl Window { @@ -125,3 +135,16 @@ impl WindowHandle { send_msg(msg).unwrap(); } } + +#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize)] +pub enum FloatingOrTiled { + Floating, + Tiled, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum FullscreenOrMaximized { + Neither, + Fullscreen, + Maximized, +}