diff --git a/api/lua/msg.lua b/api/lua/msg.lua index 4e7aa5b..241d773 100644 --- a/api/lua/msg.lua +++ b/api/lua/msg.lua @@ -62,7 +62,7 @@ ---@field ConnectForAllOutputs { output_name: string }? ---@alias WindowId integer | "None" ----@alias TagId integer +---@alias TagId integer | "None" ---@alias RequestId integer ---@alias OutputName string diff --git a/api/lua/tag.lua b/api/lua/tag.lua index 8b95e6f..8cd188c 100644 --- a/api/lua/tag.lua +++ b/api/lua/tag.lua @@ -54,7 +54,7 @@ local tag = {} ---This can be retrieved through the various `get` functions in the `Tag` module. ---@classmod ---@class TagHandle ----@field private _id integer The internal id of this tag. +---@field private _id TagId The internal id of this tag. local tag_handle = {} ---Create a tag from an id. @@ -74,7 +74,7 @@ end ---Get this tag's internal id. ---***You probably won't need to use this.*** ----@return integer +---@return TagId function tag_handle:id() return self._id end @@ -275,7 +275,7 @@ end ---end ---``` ---@param params TagConstructor ----@return TagHandle|nil +---@return TagHandle --- ---@see Tag.get_on_output — Get all tags on an output ---@see Tag.get_by_name — Get all tags with some name @@ -290,7 +290,7 @@ function tag.get(params) if type(params) == "string" then local op = require("output").get_focused() if op == nil then - return nil + return create_tag("None") end local tags = tag.get_by_name(params) @@ -300,7 +300,7 @@ function tag.get(params) end end - return nil + return create_tag("None") end -- TagTable was passed in @@ -311,13 +311,13 @@ function tag.get(params) if op == nil then local o = require("output").get_focused() if o == nil then - return nil + return create_tag("None") end op = o elseif type(op) == "string" then local o = require("output").get_by_name(op) if o == nil then - return nil + return create_tag("None") end op = o end @@ -329,7 +329,7 @@ function tag.get(params) end end - return nil + return create_tag("None") end ---Get all tags on the specified output. diff --git a/src/tag.rs b/src/tag.rs index 1404b0e..37b3d13 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -17,11 +17,15 @@ use crate::{ static TAG_ID_COUNTER: AtomicU32 = AtomicU32::new(0); #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize)] -pub struct TagId(u32); +pub enum TagId { + None, + #[serde(untagged)] + Some(u32), +} impl TagId { fn next() -> Self { - Self(TAG_ID_COUNTER.fetch_add(1, Ordering::Relaxed)) + Self::Some(TAG_ID_COUNTER.fetch_add(1, Ordering::Relaxed)) } pub fn tag(&self, state: &State) -> Option {