2023-08-01 18:06:35 +02:00
-- SPDX-License-Identifier: GPL-3.0-or-later
2023-07-01 04:34:07 +02:00
2023-08-29 02:47:29 +02:00
---Tag management.
---
---This module provides utilities for creating and manipulating tags.
---
---A tag is a sort of marker for each of your windows. It allows you to present windows in ways that
---traditional workspaces cannot.
---
---More specifically:
2023-09-08 03:48:41 +02:00
---
2023-08-29 02:47:29 +02:00
--- - A window can have multiple tags.
2023-09-08 03:48:41 +02:00
--- - This means that you can have one window show up across multiple "workspaces" if you come
2023-08-29 02:47:29 +02:00
--- something like i3.
--- - An output can display multiple tags at once.
2023-09-08 03:48:41 +02:00
--- - This allows you to toggle a tag and have windows on both tags display at once.
2023-08-29 02:47:29 +02:00
--- This is helpful if you, say, want to reference a browser window while coding; you toggle your
--- browser's tag and temporarily reference it while you work without having to change screens.
---
2023-10-18 10:44:42 +02:00
---Many of the functions in this module take `TagConstructor`.
---This is a convenience so you don't have to get a tag handle every time you want to do
2023-08-29 02:47:29 +02:00
---something with tags.
---
---Instead, you can pass in either:
2023-09-08 03:48:41 +02:00
---
2023-08-29 02:47:29 +02:00
--- - A string of the tag's name (ex. "1")
2023-09-08 03:48:41 +02:00
--- - This will get the first tag with that name on the focused output.
2023-10-18 10:44:42 +02:00
--- - A table where `name` is the name and `output` is the output (or its name) (ex. { name = "1", output = "DP-1" })
2023-09-08 03:48:41 +02:00
--- - This will get the first tag with that name on the specified output.
2023-10-18 10:44:42 +02:00
--- - A tag handle itself
--- - If you already have a tag handle, it will be used directly.
2023-08-29 02:47:29 +02:00
---
---If you need to get tags beyond the first with the same name, use a `get` function and find what you need.
2023-10-18 10:44:42 +02:00
---@class Tag
local tag = { }
2023-07-18 19:37:40 +02:00
2023-07-13 01:50:41 +02:00
---@alias Layout
---| "MasterStack" # One master window on the left with all other windows stacked to the right.
---| "Dwindle" # Windows split in half towards the bottom right corner.
---| "Spiral" # Windows split in half in a spiral.
2023-07-18 03:40:56 +02:00
---| "CornerTopLeft" # One main corner window in the top left with a column of windows on the right and a row on the bottom.
---| "CornerTopRight" # One main corner window in the top right with a column of windows on the left and a row on the bottom.
---| "CornerBottomLeft" # One main corner window in the bottom left with a column of windows on the right and a row on the top.
---| "CornerBottomRight" # One main corner window in the bottom right with a column of windows on the left and a row on the top.
2023-07-13 01:50:41 +02:00
2023-10-18 10:44:42 +02:00
---@alias TagTable { name: string, output: (string|OutputHandle)? }
2023-09-08 03:36:49 +02:00
2023-10-18 10:44:42 +02:00
---@alias TagConstructor TagHandle|TagTable|string
2023-08-22 03:17:27 +02:00
2023-10-18 10:44:42 +02:00
---A tag handle.
2023-08-29 02:47:29 +02:00
---
2023-10-18 10:44:42 +02:00
---This is a handle to a tag that can be passed to windows and such.
---
---This can be retrieved through the various `get` functions in the `Tag` module.
2023-08-27 05:26:32 +02:00
---@classmod
2023-10-18 10:44:42 +02:00
---@class TagHandle
2023-10-19 03:16:26 +02:00
---@field private _id TagId The internal id of this tag.
2023-10-18 10:44:42 +02:00
local tag_handle = { }
2023-07-18 17:31:08 +02:00
2023-07-22 04:02:02 +02:00
---Create a tag from an id.
---The id is the unique identifier for each tag.
---@param id TagId
2023-10-18 10:44:42 +02:00
---@return TagHandle
2023-07-22 04:02:02 +02:00
local function create_tag ( id )
2023-10-18 10:44:42 +02:00
---@type TagHandle
2023-07-22 04:02:02 +02:00
local t = { _id = id }
2023-07-18 17:31:08 +02:00
-- Copy functions over
2023-10-18 10:44:42 +02:00
for k , v in pairs ( tag_handle ) do
2023-07-20 22:22:22 +02:00
t [ k ] = v
2023-07-18 17:31:08 +02:00
end
2023-07-20 22:22:22 +02:00
return t
end
---Get this tag's internal id.
2023-07-22 04:02:02 +02:00
---***You probably won't need to use this.***
2023-10-19 03:16:26 +02:00
---@return TagId
2023-10-18 10:44:42 +02:00
function tag_handle : id ( )
2023-07-20 22:22:22 +02:00
return self._id
2023-07-18 17:31:08 +02:00
end
2023-07-18 19:37:40 +02:00
---Get this tag's active status.
2023-07-20 01:55:22 +02:00
---@return boolean|nil active `true` if the tag is active, `false` if not, and `nil` if the tag doesn't exist.
2023-10-18 10:44:42 +02:00
---@see Tag.active — The corresponding module function
function tag_handle : active ( )
return tag.active ( self )
2023-07-18 19:37:40 +02:00
end
2023-07-20 01:55:22 +02:00
---Get this tag's name.
---@return string|nil name The name of this tag, or nil if it doesn't exist.
2023-10-18 10:44:42 +02:00
---@see Tag.name — The corresponding module function
function tag_handle : name ( )
return tag.name ( self )
2023-07-18 19:37:40 +02:00
end
2023-07-20 01:55:22 +02:00
---Get this tag's output.
2023-10-18 10:44:42 +02:00
---@return OutputHandle|nil output The output this tag is on, or nil if the tag doesn't exist.
---@see Tag.output — The corresponding module function
function tag_handle : output ( )
return tag.output ( self )
2023-07-20 01:55:22 +02:00
end
2023-07-21 21:36:32 +02:00
---Switch to this tag.
2023-10-18 10:44:42 +02:00
---@see Tag.switch_to — The corresponding module function
function tag_handle : switch_to ( )
tag.switch_to ( self )
2023-07-21 21:36:32 +02:00
end
---Toggle this tag.
2023-10-18 10:44:42 +02:00
---@see Tag.toggle — The corresponding module function
function tag_handle : toggle ( )
tag.toggle ( self )
2023-07-21 21:36:32 +02:00
end
2023-07-18 19:37:40 +02:00
---Set this tag's layout.
---@param layout Layout
2023-10-18 10:44:42 +02:00
---@see Tag.set_layout — The corresponding module function
function tag_handle : set_layout ( layout )
tag.set_layout ( self , layout )
2023-07-18 19:37:40 +02:00
end
-----------------------------------------------------------
2023-07-01 04:34:07 +02:00
2023-07-20 23:54:26 +02:00
---Add tags to the specified output.
2023-07-01 04:34:07 +02:00
---
2023-07-20 23:54:26 +02:00
---### Examples
2023-07-01 04:34:07 +02:00
---```lua
2023-07-20 01:55:22 +02:00
---local op = output.get_by_name("DP-1")
---if op ~= nil then
--- tag.add(op, "1", "2", "3", "4", "5") -- Add tags with names 1-5
2023-07-11 18:59:38 +02:00
---end
2023-10-18 10:44:42 +02:00
---
2023-09-08 03:48:41 +02:00
--- -- You can also pass in a table.
2023-07-20 23:54:26 +02:00
---local tags = {"Terminal", "Browser", "Code", "Potato", "Email"}
2023-09-08 03:48:41 +02:00
---tag.add(op, tags)
2023-07-11 18:59:38 +02:00
---```
2023-10-18 10:44:42 +02:00
---@param output OutputHandle The output you want these tags to be added to.
2023-07-20 23:54:26 +02:00
---@param ... string The names of the new tags you want to add.
2023-10-18 10:44:42 +02:00
---@overload fun(output: OutputHandle, tag_names: string[])
---@see OutputHandle.add_tags — The corresponding object method
function tag . add ( output , ... )
2023-07-20 23:54:26 +02:00
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
SendMsg ( {
AddTags = {
output_name = output : name ( ) ,
tag_names = tag_names ,
} ,
} )
else
local tag_names = varargs [ 1 ] --[=[@as string[]]=]
SendMsg ( {
AddTags = {
output_name = output : name ( ) ,
tag_names = tag_names ,
} ,
} )
end
2023-07-01 04:34:07 +02:00
end
2023-08-22 03:17:27 +02:00
---Toggle a tag on the specified output. If the output isn't specified, toggle it on the currently focused output instead.
2023-07-11 18:59:38 +02:00
---
2023-07-18 22:12:23 +02:00
---### Example
2023-07-11 18:59:38 +02:00
---
---```lua
2023-07-11 23:10:31 +02:00
---local op = output.get_by_name("DP-1")
2023-08-22 03:17:27 +02:00
---
---tag.toggle("1") -- Toggle tag 1 on the focused output
---
2023-09-09 11:09:28 +02:00
---tag.toggle({ name = "1", output = "DP-1" }) -- Toggle tag 1 on "DP-1"
---tag.toggle({ name = "1", output = op }) -- Same as above
2023-08-22 03:17:27 +02:00
---
2023-10-18 10:44:42 +02:00
--- -- Using a tag handle
---local t = tag.get("1") -- `t` is the tag with the name "1" on the focused output
2023-08-22 03:17:27 +02:00
---tag.toggle(t)
2023-07-11 18:59:38 +02:00
---```
2023-09-08 03:36:49 +02:00
---@param t TagConstructor
2023-10-18 10:44:42 +02:00
---@see TagHandle.toggle — The corresponding object method
function tag . toggle ( t )
local t = tag.get ( t )
2023-08-22 03:17:27 +02:00
if t then
2023-07-21 21:36:32 +02:00
SendMsg ( {
ToggleTag = {
2023-08-22 03:17:27 +02:00
tag_id = t : id ( ) ,
2023-07-21 21:36:32 +02:00
} ,
} )
end
2023-07-01 04:34:07 +02:00
end
2023-07-11 23:10:31 +02:00
---Switch to a tag on the specified output, deactivating any other active tags on it.
2023-08-22 03:17:27 +02:00
---If the output is not specified, this uses the currently focused output instead.
2023-07-11 18:59:38 +02:00
---
---This is used to replicate what a traditional workspace is on some other Wayland compositors.
---
2023-07-22 04:02:02 +02:00
---### Examples
2023-07-11 18:59:38 +02:00
---```lua
2023-08-22 03:17:27 +02:00
---local op = output.get_by_name("DP-1")
---
---tag.switch_to("1") -- Switch to tag 1 on the focused output
---
2023-09-09 11:09:28 +02:00
---tag.switch_to({ name = "1", output = "DP-1" }) -- Switch to tag 1 on "DP-1"
---tag.switch_to({ name = "1", output = op }) -- Same as above
2023-08-22 03:17:27 +02:00
---
2023-10-18 10:44:42 +02:00
--- -- Using a tag handle
2023-08-22 03:17:27 +02:00
---local t = tag.get_by_name("1")[1] -- `t` is the first tag with the name "1"
---tag.switch_to(t)
2023-07-11 18:59:38 +02:00
---```
2023-09-08 03:36:49 +02:00
---@param t TagConstructor
2023-10-18 10:44:42 +02:00
---@see TagHandle.switch_to — The corresponding object method
function tag . switch_to ( t )
local t = tag.get ( t )
2023-08-22 03:17:27 +02:00
if t then
2023-07-21 21:36:32 +02:00
SendMsg ( {
SwitchToTag = {
2023-08-22 03:17:27 +02:00
tag_id = t : id ( ) ,
2023-07-21 21:36:32 +02:00
} ,
} )
end
2023-07-02 02:06:37 +02:00
end
2023-07-21 21:36:32 +02:00
---Set a layout for the tag on the specified output. If no output is provided, set it for the tag on the currently focused one.
2023-07-22 04:02:02 +02:00
---
---### Examples
---```lua
2023-08-22 03:17:27 +02:00
---local op = output.get_by_name("DP-1")
2023-07-22 04:02:02 +02:00
---
2023-08-22 03:17:27 +02:00
---tag.set_layout("1", "Dwindle") -- Set tag 1 on the focused output to "Dwindle"
---
2023-09-08 03:36:49 +02:00
---tag.set_layout({ name = "1", output = "DP-1" }, "Dwindle") -- Set tag 1 on "DP-1" to "Dwindle"
---tag.set_layout({ name = "1", output = op }, "Dwindle") -- Same as above
2023-08-22 03:17:27 +02:00
---
2023-10-18 10:44:42 +02:00
--- -- Using a tag handle
2023-08-22 03:17:27 +02:00
---local t = tag.get_by_name("1")[1] -- `t` is the first tag with the name "1"
2023-07-22 04:02:02 +02:00
---tag.set_layout(t, "Dwindle")
---```
2023-08-22 03:17:27 +02:00
---
2023-09-08 03:36:49 +02:00
---@param t TagConstructor
2023-07-21 21:36:32 +02:00
---@param layout Layout The layout.
2023-10-18 10:44:42 +02:00
---@see TagHandle.set_layout — The corresponding object method
function tag . set_layout ( t , layout )
local t = tag.get ( t )
2023-08-22 03:17:27 +02:00
if t then
2023-07-21 21:36:32 +02:00
SendMsg ( {
SetLayout = {
2023-08-22 03:17:27 +02:00
tag_id = t : id ( ) ,
2023-07-21 21:36:32 +02:00
layout = layout ,
} ,
} )
end
2023-08-22 03:17:27 +02:00
end
2023-07-21 21:36:32 +02:00
2023-08-22 03:17:27 +02:00
---Get a tag with the specified name and optional output.
---
---If the output isn't specified, the focused one is used.
---
---If you have duplicate tags on an output, this returns the first one.
---If you need access to all duplicates, use `tag.get_on_output`, `tag.get_by_name`, or `tag.get_all`
---and filter for what you need.
---
---### Examples
---```lua
---local t = tag.get("1")
2023-09-08 03:36:49 +02:00
---local t = tag.get({ name = "1", output = "HDMI-A-0" })
2023-08-22 03:17:27 +02:00
---
---local op = output.get_by_name("DP-2")
---if op ~= nil then
--- local t = tag.get({ name = "Code", output = op })
---end
---```
2023-09-08 03:36:49 +02:00
---@param params TagConstructor
2023-10-19 03:16:26 +02:00
---@return TagHandle
2023-08-22 03:17:27 +02:00
---
2023-10-18 10:44:42 +02:00
---@see Tag.get_on_output — Get all tags on an output
---@see Tag.get_by_name — Get all tags with some name
---@see Tag.get_all — Get all tags
function tag . get ( params )
2023-09-08 03:36:49 +02:00
-- If creating from a tag object, just return the obj
if params.id then
2023-10-18 10:44:42 +02:00
return params --[[@as TagHandle]]
2023-09-08 03:36:49 +02:00
end
-- string passed in
if type ( params ) == " string " then
local op = require ( " output " ) . get_focused ( )
if op == nil then
2023-10-19 03:16:26 +02:00
return create_tag ( " None " )
2023-09-08 03:36:49 +02:00
end
2023-10-18 10:44:42 +02:00
local tags = tag.get_by_name ( params )
2023-09-08 03:36:49 +02:00
for _ , t in pairs ( tags ) do
if t : output ( ) and t : output ( ) : name ( ) == op : name ( ) then
return t
end
end
2023-10-19 03:16:26 +02:00
return create_tag ( " None " )
2023-09-08 03:36:49 +02:00
end
-- TagTable was passed in
local params = params --[[@as TagTable]]
local tag_name = params.name
local op = params.output
if op == nil then
local o = require ( " output " ) . get_focused ( )
if o == nil then
2023-10-19 03:16:26 +02:00
return create_tag ( " None " )
2023-09-08 03:36:49 +02:00
end
op = o
elseif type ( op ) == " string " then
local o = require ( " output " ) . get_by_name ( op )
if o == nil then
2023-10-19 03:16:26 +02:00
return create_tag ( " None " )
2023-09-08 03:36:49 +02:00
end
op = o
end
2023-10-18 10:44:42 +02:00
local tags = tag.get_by_name ( tag_name )
2023-09-08 03:36:49 +02:00
for _ , t in pairs ( tags ) do
if t : output ( ) and t : output ( ) : name ( ) == op : name ( ) then
return t
end
end
2023-10-19 03:16:26 +02:00
return create_tag ( " None " )
2023-07-13 01:50:41 +02:00
end
2023-07-18 17:31:08 +02:00
---Get all tags on the specified output.
---
2023-07-22 04:02:02 +02:00
---### Example
2023-07-18 17:31:08 +02:00
---```lua
2023-07-22 04:02:02 +02:00
---local op = output.get_focused()
---if op ~= nil then
--- local tags = tag.get_on_output(op) -- All tags on the focused output
---end
2023-07-18 17:31:08 +02:00
---```
2023-10-18 10:44:42 +02:00
---@param output OutputHandle
---@return TagHandle[]
2023-07-22 04:02:02 +02:00
---
---@see Output.tags — The corresponding object method
2023-10-18 10:44:42 +02:00
function tag . get_on_output ( output )
2023-07-21 22:04:39 +02:00
local response = Request ( {
2023-07-20 22:22:22 +02:00
GetOutputProps = {
output_name = output : name ( ) ,
2023-07-18 17:31:08 +02:00
} ,
2023-07-21 22:04:39 +02:00
} )
2023-07-18 17:31:08 +02:00
2023-07-20 22:22:22 +02:00
local tag_ids = response.RequestResponse . response.OutputProps . tag_ids
2023-07-18 17:31:08 +02:00
2023-10-18 10:44:42 +02:00
---@type TagHandle[]
2023-07-18 17:31:08 +02:00
local tags = { }
2023-07-20 22:22:22 +02:00
if tag_ids == nil then
return tags
end
2023-07-18 22:12:23 +02:00
for _ , tag_id in pairs ( tag_ids ) do
2023-07-22 04:02:02 +02:00
table.insert ( tags , create_tag ( tag_id ) )
2023-07-18 17:31:08 +02:00
end
return tags
end
2023-07-20 01:55:22 +02:00
---Get all tags with this name across all outputs.
2023-07-22 04:02:02 +02:00
---
---### Example
---```lua
2023-09-08 03:48:41 +02:00
--- -- Given one monitor with the tags "OBS", "OBS", "VSCode", and "Spotify"...
2023-07-22 04:02:02 +02:00
---local tags = tag.get_by_name("OBS")
2023-09-08 03:48:41 +02:00
--- -- ...will have 2 tags in `tags`, while...
2023-07-22 04:02:02 +02:00
---local no_tags = tag.get_by_name("Firefox")
2023-09-08 03:48:41 +02:00
--- -- ...will have `no_tags` be empty.
2023-07-22 04:02:02 +02:00
---```
---@param name string The name of the tag(s) you want.
2023-10-18 10:44:42 +02:00
---@return TagHandle[]
function tag . get_by_name ( name )
local t_s = tag.get_all ( )
2023-07-20 23:05:26 +02:00
2023-10-18 10:44:42 +02:00
---@type TagHandle[]
2023-07-20 23:05:26 +02:00
local tags = { }
2023-07-21 21:36:32 +02:00
for _ , t in pairs ( t_s ) do
2023-07-20 23:05:26 +02:00
if t : name ( ) == name then
table.insert ( tags , t )
end
end
return tags
end
2023-07-22 04:02:02 +02:00
---Get all tags across all outputs.
---
---### Example
---```lua
2023-09-08 03:48:41 +02:00
--- -- With two monitors with the same tags: "1", "2", "3", "4", and "5"...
2023-07-22 04:02:02 +02:00
---local tags = tag.get_all()
2023-09-08 03:48:41 +02:00
--- -- ...`tags` should have 10 tags, with 5 pairs of those names across both outputs.
2023-07-22 04:02:02 +02:00
---```
2023-10-18 10:44:42 +02:00
---@return TagHandle[]
function tag . get_all ( )
2023-07-21 22:04:39 +02:00
local response = Request ( " GetTags " )
2023-07-20 01:55:22 +02:00
local tag_ids = response.RequestResponse . response.Tags . tag_ids
2023-10-18 10:44:42 +02:00
---@type TagHandle[]
2023-07-20 01:55:22 +02:00
local tags = { }
for _ , tag_id in pairs ( tag_ids ) do
2023-07-22 04:02:02 +02:00
table.insert ( tags , create_tag ( tag_id ) )
2023-07-20 01:55:22 +02:00
end
return tags
end
2023-07-22 04:02:02 +02:00
---Get the specified tag's name.
---
---### Example
---```lua
2023-09-08 03:48:41 +02:00
--- -- Assuming the tag `Terminal` exists...
2023-07-22 04:02:02 +02:00
---print(tag.name(tag.get_by_name("Terminal")[1]))
2023-09-08 03:48:41 +02:00
--- -- ...should print `Terminal`.
2023-07-22 04:02:02 +02:00
---```
2023-10-18 10:44:42 +02:00
---@param t TagHandle
2023-07-22 04:02:02 +02:00
---@return string|nil
2023-10-18 10:44:42 +02:00
---@see TagHandle.name — The corresponding object method
function tag . name ( t )
2023-07-22 04:02:02 +02:00
local response = Request ( {
GetTagProps = {
tag_id = t : id ( ) ,
} ,
} )
local name = response.RequestResponse . response.TagProps . name
return name
end
---Get whether or not the specified tag is active.
2023-10-18 10:44:42 +02:00
---@param t TagHandle
2023-07-22 04:02:02 +02:00
---@return boolean|nil
2023-10-18 10:44:42 +02:00
---@see TagHandle.active — The corresponding object method
function tag . active ( t )
2023-07-22 04:02:02 +02:00
local response = Request ( {
GetTagProps = {
tag_id = t : id ( ) ,
} ,
} )
local active = response.RequestResponse . response.TagProps . active
return active
end
---Get the output the specified tag is on.
2023-10-18 10:44:42 +02:00
---@param t TagHandle
---@return OutputHandle|nil
---@see Output.get_for_tag — The called function
---@see TagHandle.output — The corresponding object method
function tag . output ( t )
2023-07-22 04:02:02 +02:00
return require ( " output " ) . get_for_tag ( t )
end
2023-09-09 11:01:55 +02:00
---@class LayoutCycler
2023-10-18 10:44:42 +02:00
---@field next fun(output: (OutputHandle|OutputName)?) Change the first active tag on `output` to its next layout. If `output` is empty, the focused output is used.
---@field prev fun(output: (OutputHandle|OutputName)?) Change the first active tag on `output` to its previous layout. If `output` is empty, the focused output is used.
2023-09-09 11:01:55 +02:00
2023-10-18 10:44:42 +02:00
---Create a `LayoutCycler` to cycle layouts on tags.
---
---Given an array of layouts, this will create a table with two functions;
---one will cycle forward the layout for the active tag, and one will cycle backward.
2023-09-10 03:52:52 +02:00
---
--- ### Example
---```lua
---local layout_cycler = tag.layout_cycler({ "Dwindle", "Spiral", "MasterStack" })
---
2023-10-18 10:44:42 +02:00
---layout_cycler.next() -- Go to the next layout on the first active tag of the focused output
---layout_cycler.prev() -- Go to the previous layout on the first active tag of the focused output
2023-09-10 03:52:52 +02:00
---
---layout_cycler.next("DP-1") -- Do the above but on "DP-1" instead
2023-10-18 10:44:42 +02:00
---layout_cycler.prev(output.get_by_name("DP-1")) -- With an output handle
2023-09-10 03:52:52 +02:00
---```
2023-09-09 11:01:55 +02:00
---@param layouts Layout[] The available layouts.
---@return LayoutCycler layout_cycler A table with the functions `next` and `prev`, which will cycle layouts for the given tag.
2023-10-18 10:44:42 +02:00
function tag . layout_cycler ( layouts )
2023-09-09 11:01:55 +02:00
local indices = { }
-- Return empty functions if layouts is empty
if # layouts == 0 then
return {
next = function ( _ ) end ,
prev = function ( _ ) end ,
}
end
return {
2023-10-18 10:44:42 +02:00
---@param output (OutputHandle|OutputName)?
2023-09-09 11:01:55 +02:00
next = function ( output )
if type ( output ) == " string " then
output = require ( " output " ) . get_by_name ( output )
end
output = output or require ( " output " ) . get_focused ( )
if output == nil then
return
end
local tags = output : tags ( )
for _ , tg in pairs ( tags ) do
if tg : active ( ) then
local id = tg : id ( )
if id == nil then
return
end
if # layouts == 1 then
indices [ id ] = 1
elseif indices [ id ] == nil then
indices [ id ] = 2
else
if indices [ id ] + 1 > # layouts then
indices [ id ] = 1
else
indices [ id ] = indices [ id ] + 1
end
end
tg : set_layout ( layouts [ indices [ id ] ] )
break
end
end
end ,
2023-10-18 10:44:42 +02:00
---@param output (OutputHandle|OutputName)?
2023-09-09 11:01:55 +02:00
prev = function ( output )
if type ( output ) == " string " then
output = require ( " output " ) . get_by_name ( output )
end
output = output or require ( " output " ) . get_focused ( )
if output == nil then
return
end
local tags = output : tags ( )
for _ , tg in pairs ( tags ) do
if tg : active ( ) then
local id = tg : id ( )
if id == nil then
return
end
if # layouts == 1 then
indices [ id ] = 1
elseif indices [ id ] == nil then
indices [ id ] = # layouts - 1
else
if indices [ id ] - 1 < 1 then
indices [ id ] = # layouts
else
indices [ id ] = indices [ id ] - 1
end
end
tg : set_layout ( layouts [ indices [ id ] ] )
break
end
end
end ,
}
end
2023-10-18 10:44:42 +02:00
return tag