kdeconnect-proto 0.1.1

A pure Rust modular implementation of the KDE Connect protocol
Documentation
//! This plugin allows users to use their devices as pressure sensitive drawing tablets.
use serde::{Deserialize, Serialize};

#[cfg(not(feature = "std"))]
use alloc::string::String;

/// This packet either starts or stops a drawing tablet session. The session is started when this
/// packet is sent with a start action. When it is started, it includes the information necessary
/// to create a fake drawing tablet device on the receiver. The session is ended when this packet
/// is sent with an end action, or the device disconnects. It is valid to send both a start or an
/// end packet regardless whether a session exists or not. If a session exists and a start packet
/// is sent, the session will be first ended, and then another session will be started. If no
/// session exists and an end packet is sent, nothing will happen.
///
/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectdigitizersession>
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DigitizerSessionPacket {
    /// (Only valid for a start action) An integer describing the width of the faked drawing tablet device. Not necessarily the width of the sending device's screen.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub width: Option<u64>,

    /// (Only valid for a start action) An integer describing the height of the faked drawing tablet device. Not necessarily the height of the sending device's screen.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub height: Option<u64>,

    /// (Only valid for a start action) An integer describing the horizontal resolution of the device in pixels/mm.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub resolution_x: Option<u64>,

    /// (Only valid for a start action) An integer describing the vertical resolution of the device in pixels/mm.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub resolution_y: Option<u64>,
}

/// This packet is a stylus (or finger) event. kdeconnect.digitizer packets must not be sent until
/// a session has been started. You may start a session by sending the kdeconnect.digitizer.session
/// packet with the field action set to start, and filling the appropriate fields.
///
/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectdigitizer>
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DigitizerPacket {
    /// An optional boolean describing whether the device is currently tracking the tool. This is set to false when the tool exits the hover range, for example.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub active: Option<bool>,

    /// An optional boolean describing whether the tool is currently touching the screen. Only the last value is used.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub touching: Option<bool>,

    /// An optional string enum describing the type of tool the user has equipped.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub tool: Option<String>,

    /// An optional integer describing the current absolute X position of the tool.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub x: Option<u64>,

    /// An optional integer describing the current absolute Y position of the tool.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub y: Option<u64>,

    /// An optional floating point number describing how hard the tool is pressing on the screen.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub pressure: Option<f64>,
}