i3_client_trees (i3_client v0.3.0)

View Source

Functions for processing i3 layout trees.

All functions assume they receive the whole tree, as returned by i3_client:get_tree/1,2.

Summary

Functions

Returns a Query List Comprehension (QLC) query handle.

Functions

table(Table)

-spec table(Table) -> QueryHandle when Table :: map(), QueryHandle :: qlc:query_handle().

Equivalent to table(Tree, dfs).

table(Table, Algo)

-spec table(Table, Algo) -> QueryHandle
               when Table :: map(), Algo :: dfs | bfs, QueryHandle :: qlc:query_handle().

Returns a Query List Comprehension (QLC) query handle.

The qlc module provides a query language, very similar to list comprehensions, which allows iterator style traversal of data structures. Calling table/1,2 is the means to make the i3 tree Tree usable to QLC.

The Algo argument can be either dfs or bfs which stand for depth-first and breadth-first traversal respectively. Usually, depth-first traversal is preferred so it's the default when calling table/1.

Examples:

An example query for the focused node:

0> {ok, Pid} = i3_client:start_link([]),
1> {ok, Tree} = i3_client:get_tree(Pid),
2> QH = qlc:q([Node || #{~"focused" := true} = Node <- i3_client_trees:table(Tree)]).
3> [#{~"focused" := true}] = qlc:eval(QH)

Info

It is necessary to add the following line to the source code:

-include_lib("stdlib/include/qlc.hrl").