mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-27 21:58:18 +01:00
Merge tag.add and tag.add_table
This commit is contained in:
parent
2d42f01b8a
commit
afc0818805
3 changed files with 35 additions and 44 deletions
|
@ -22,16 +22,11 @@ end
|
||||||
|
|
||||||
---Add tags to this output. See `tag.add`.
|
---Add tags to this output. See `tag.add`.
|
||||||
---@param ... string The names of the tags you want to add.
|
---@param ... string The names of the tags you want to add.
|
||||||
|
---@overload fun(self: self, tag_names: string[])
|
||||||
function op:add_tags(...)
|
function op:add_tags(...)
|
||||||
require("tag").add(self, ...)
|
require("tag").add(self, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Add tags to this output as a table. See `tag.add_table`.
|
|
||||||
---@param names string[] The names of the tags you want to add, as a table.
|
|
||||||
function op:add_tags_table(names)
|
|
||||||
require("tag").add_table(self, names)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Get this output's make.
|
---Get this output's make.
|
||||||
---@return string|nil
|
---@return string|nil
|
||||||
function op:make()
|
function op:make()
|
||||||
|
|
|
@ -83,13 +83,11 @@ end
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
|
|
||||||
---Add tags.
|
---Add tags to the specified output.
|
||||||
---
|
---
|
||||||
---If you need to add the names as a table, use `tag.add_table` instead.
|
---You can also do `output_object:add_tags(...)`.
|
||||||
---
|
---
|
||||||
---You can also do `op:add_tags(...)`.
|
---### Examples
|
||||||
---
|
|
||||||
---### Example
|
|
||||||
---
|
---
|
||||||
---```lua
|
---```lua
|
||||||
---local op = output.get_by_name("DP-1")
|
---local op = output.get_by_name("DP-1")
|
||||||
|
@ -97,10 +95,18 @@ end
|
||||||
--- tag.add(op, "1", "2", "3", "4", "5") -- Add tags with names 1-5
|
--- tag.add(op, "1", "2", "3", "4", "5") -- Add tags with names 1-5
|
||||||
---end
|
---end
|
||||||
---```
|
---```
|
||||||
|
---You can also pass in a table.
|
||||||
|
---```lua
|
||||||
|
---local tags = {"Terminal", "Browser", "Code", "Potato", "Email"}
|
||||||
|
---tag.add(op, tags) -- Add tags with those names
|
||||||
|
---```
|
||||||
---@param output Output The output you want these tags to be added to.
|
---@param output Output The output you want these tags to be added to.
|
||||||
---@param ... string The names of the new tags you want to add.
|
---@param ... string The names of the new tags you want to add.
|
||||||
|
---@overload fun(output: Output, tag_names: string[])
|
||||||
function tag.add(output, ...)
|
function tag.add(output, ...)
|
||||||
local tag_names = table.pack(...)
|
local varargs = { ... }
|
||||||
|
if type(varargs[1]) == "string" then
|
||||||
|
local tag_names = varargs
|
||||||
tag_names["n"] = nil -- remove the length to make it a true array for serializing
|
tag_names["n"] = nil -- remove the length to make it a true array for serializing
|
||||||
|
|
||||||
SendMsg({
|
SendMsg({
|
||||||
|
@ -109,28 +115,16 @@ function tag.add(output, ...)
|
||||||
tag_names = tag_names,
|
tag_names = tag_names,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
else
|
||||||
|
local tag_names = varargs[1] --[=[@as string[]]=]
|
||||||
|
|
||||||
---Like `tag.add`, but with a table of strings instead.
|
|
||||||
---
|
|
||||||
---### Example
|
|
||||||
---
|
|
||||||
---```lua
|
|
||||||
---local tags = { "Terminal", "Browser", "Mail", "Gaming", "Potato" }
|
|
||||||
---local output = output.get_by_name("DP-1")
|
|
||||||
---if output ~= nil then
|
|
||||||
--- tag.add(output, tags) -- Add tags with the names above
|
|
||||||
---end
|
|
||||||
---```
|
|
||||||
---@param output Output The output you want these tags to be added to.
|
|
||||||
---@param names string[] The names of the new tags you want to add, as a table.
|
|
||||||
function tag.add_table(output, names)
|
|
||||||
SendMsg({
|
SendMsg({
|
||||||
AddTags = {
|
AddTags = {
|
||||||
output_name = output:name(),
|
output_name = output:name(),
|
||||||
tag_names = names,
|
tag_names = tag_names,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Toggle a tag on the specified output. If `output` isn't specified, toggle it on the currently focused output instead.
|
---Toggle a tag on the specified output. If `output` isn't specified, toggle it on the currently focused output instead.
|
||||||
|
|
|
@ -138,9 +138,11 @@ require("pinnacle").setup(function(pinnacle)
|
||||||
-- Tags ---------------------------------------------------------------------------
|
-- Tags ---------------------------------------------------------------------------
|
||||||
|
|
||||||
output.connect_for_all(function(op)
|
output.connect_for_all(function(op)
|
||||||
op:add_tags("1", "2", "3", "4", "5")
|
-- op:add_tags("1", "2", "3", "4", "5")
|
||||||
-- Same as tag.add(op, "1", "2", "3", "4", "5")
|
-- Same as tag.add(op, "1", "2", "3", "4", "5")
|
||||||
tag.toggle("1", op)
|
|
||||||
|
local tags_table = { "Terminal", "Browser", "Code", "Email", "Potato" }
|
||||||
|
op:add_tags(tags_table)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@type Layout[]
|
---@type Layout[]
|
||||||
|
|
Loading…
Reference in a new issue