mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-27 21:58:18 +01:00
Allow new tag helpers for window API
This commit is contained in:
parent
7154a0bb95
commit
fd09e20ced
2 changed files with 21 additions and 59 deletions
|
@ -19,10 +19,12 @@ local tag_module = {}
|
||||||
---@field private _id integer The internal id of this tag.
|
---@field private _id integer The internal id of this tag.
|
||||||
local tag = {}
|
local tag = {}
|
||||||
|
|
||||||
|
---***You probably don't need to use this function.***
|
||||||
|
---
|
||||||
---Create a tag from `Tag|TagTable|TagTableNamed|string`.
|
---Create a tag from `Tag|TagTable|TagTableNamed|string`.
|
||||||
---@param tb Tag|TagTable|TagTableNamed|string
|
---@param tb Tag|TagTable|TagTableNamed|string
|
||||||
---@return Tag|nil
|
---@return Tag|nil
|
||||||
local function create_tag_from_params(tb)
|
function tag_module.create_tag_from_params(tb)
|
||||||
-- If creating from a tag object, just return the obj
|
-- If creating from a tag object, just return the obj
|
||||||
if tb.id then
|
if tb.id then
|
||||||
return tb --[[@as Tag]]
|
return tb --[[@as Tag]]
|
||||||
|
@ -232,7 +234,7 @@ end
|
||||||
---@param t Tag|TagTable|TagTableNamed|string
|
---@param t Tag|TagTable|TagTableNamed|string
|
||||||
---@see Tag.toggle — The corresponding object method
|
---@see Tag.toggle — The corresponding object method
|
||||||
function tag_module.toggle(t)
|
function tag_module.toggle(t)
|
||||||
local t = create_tag_from_params(t)
|
local t = tag_module.create_tag_from_params(t)
|
||||||
|
|
||||||
if t then
|
if t then
|
||||||
SendMsg({
|
SendMsg({
|
||||||
|
@ -269,7 +271,7 @@ end
|
||||||
---@param t Tag|TagTable|TagTableNamed|string
|
---@param t Tag|TagTable|TagTableNamed|string
|
||||||
---@see Tag.switch_to — The corresponding object method
|
---@see Tag.switch_to — The corresponding object method
|
||||||
function tag_module.switch_to(t)
|
function tag_module.switch_to(t)
|
||||||
local t = create_tag_from_params(t)
|
local t = tag_module.create_tag_from_params(t)
|
||||||
|
|
||||||
if t then
|
if t then
|
||||||
SendMsg({
|
SendMsg({
|
||||||
|
@ -305,7 +307,7 @@ end
|
||||||
---@param layout Layout The layout.
|
---@param layout Layout The layout.
|
||||||
---@see Tag.set_layout — The corresponding object method
|
---@see Tag.set_layout — The corresponding object method
|
||||||
function tag_module.set_layout(t, layout)
|
function tag_module.set_layout(t, layout)
|
||||||
local t = create_tag_from_params(t)
|
local t = tag_module.create_tag_from_params(t)
|
||||||
|
|
||||||
if t then
|
if t then
|
||||||
SendMsg({
|
SendMsg({
|
||||||
|
@ -337,12 +339,13 @@ end
|
||||||
---end
|
---end
|
||||||
---```
|
---```
|
||||||
---@param params TagTable|TagTableNamed|string
|
---@param params TagTable|TagTableNamed|string
|
||||||
|
---@return Tag|nil
|
||||||
---
|
---
|
||||||
---@see TagModule.get_on_output
|
---@see TagModule.get_on_output
|
||||||
---@see TagModule.get_by_name
|
---@see TagModule.get_by_name
|
||||||
---@see TagModule.get_all
|
---@see TagModule.get_all
|
||||||
function tag_module.get(params)
|
function tag_module.get(params)
|
||||||
return create_tag_from_params(params)
|
return tag_module.create_tag_from_params(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Get all tags on the specified output.
|
---Get all tags on the specified output.
|
||||||
|
|
|
@ -243,79 +243,38 @@ function window_module.get_all()
|
||||||
end
|
end
|
||||||
|
|
||||||
---Toggle the tag with the given name and (optional) output for the specified window.
|
---Toggle the tag with the given name and (optional) output for the specified window.
|
||||||
---You can also provide a tag object instead of a name and output.
|
|
||||||
---
|
---
|
||||||
---@param w Window
|
---@param w Window
|
||||||
---@param name string
|
---@param t Tag|TagTable|TagTableNamed|string
|
||||||
---@param output Output?
|
|
||||||
---@overload fun(w: Window, t: Tag)
|
|
||||||
---@see Window.toggle_tag — The corresponding object method
|
---@see Window.toggle_tag — The corresponding object method
|
||||||
function window_module.toggle_tag(w, name, output)
|
function window_module.toggle_tag(w, t)
|
||||||
if type(name) == "table" then
|
local t = require("tag").create_tag_from_params(t)
|
||||||
SendMsg({
|
|
||||||
ToggleTagOnWindow = {
|
|
||||||
window_id = w:id(),
|
|
||||||
tag_id = name--[[@as Tag]]:id(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local output = output or require("output").get_focused()
|
if t then
|
||||||
|
|
||||||
if output == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local tags = require("tag").get_by_name(name)
|
|
||||||
for _, t in pairs(tags) do
|
|
||||||
if t:output() and t:output():name() == output:name() then
|
|
||||||
SendMsg({
|
SendMsg({
|
||||||
ToggleTagOnWindow = {
|
ToggleTagOnWindow = {
|
||||||
window_id = w:id(),
|
window_id = w:id(),
|
||||||
tag_id = t:id(),
|
tag_id = t:id(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Move the specified window to the tag with the given name and (optional) output.
|
---Move the specified window to the tag with the given name and (optional) output.
|
||||||
---You can also provide a tag object instead of a name and output.
|
---
|
||||||
---@param w Window
|
---@param w Window
|
||||||
---@param name string
|
---@param t Tag|TagTable|TagTableNamed|string
|
||||||
---@param output Output?
|
|
||||||
---@overload fun(w: Window, t: Tag)
|
|
||||||
---@see Window.move_to_tag — The corresponding object method
|
---@see Window.move_to_tag — The corresponding object method
|
||||||
function window_module.move_to_tag(w, name, output)
|
function window_module.move_to_tag(w, t)
|
||||||
if type(name) == "table" then
|
local t = require("tag").create_tag_from_params(t)
|
||||||
SendMsg({
|
|
||||||
MoveWindowToTag = {
|
|
||||||
window_id = w:id(),
|
|
||||||
tag_id = name--[[@as Tag]]:id(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local output = output or require("output").get_focused()
|
if t then
|
||||||
|
|
||||||
if output == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local tags = require("tag").get_by_name(name)
|
|
||||||
for _, t in pairs(tags) do
|
|
||||||
if t:output() and t:output():name() == output:name() then
|
|
||||||
SendMsg({
|
SendMsg({
|
||||||
MoveWindowToTag = {
|
MoveWindowToTag = {
|
||||||
window_id = w:id(),
|
window_id = w:id(),
|
||||||
tag_id = t:id(),
|
tag_id = t:id(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue