Class pinnacle.util
Utility functions.
Fields
output
output
: pinnacle.util.output
= output
Output utilities.
Functions
function batch
function pinnacle.util.batch(requests: fun(): T[])
-> responses: T[]
Batches a set of requests that will be sent to the compositor all at once.
Normally, all API calls are blocking. For example, calling Window.get_all
then calling WindowHandle.props
on each returned window handle will block after each props
call waiting for the compositor to respond.
In order to mitigate this issue, you can batch up a set of API calls using this function. This will send all requests to the compositor at once without blocking, then wait for the compositor to respond.
You must wrap each request in a function, otherwise they would just get evaluated at the callsite in a blocking manner.
Example
local handles = window.get_all()
---@type (fun(): bool)[]
local requests = {}
-- Wrap each request to `focused` in another function
for i, handle in ipairs(handles) do
requests[i] = function()
return handle:focused()
end
end
-- Batch send these requests
local props = require("pinnacle.util").batch(requests)
-- `props` now contains the focus state of all the windows above
Parameters
requests
: fun(): T[]
- The requests that you want to batch up, wrapped in a function.
Returns
responses
:T[]
- The results of each request in the same order that they were inrequests
.
function deep_copy
function pinnacle.util.deep_copy(obj: T)
-> deep_copy: T
Creates a deep copy of an object.
Parameters
obj
: T
- The object to deep copy.
Returns
deep_copy
:T
- A deep copy ofobj
function bijective_table
function pinnacle.util.bijective_table(key_value_pairs: T)
-> bijective_table: T
Creates a table with entries key->value and value->key for all given pairs.
Parameters
key_value_pairs
: T
Returns
bijective_table
:T
- A table with pairs key->value and value->key
function make_bijective
function pinnacle.util.make_bijective(table: table)
Makes a table bijective by inserting value = key
entries for every key-value pair.
Parameters
table
: table