diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-06-13 10:30:56 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-06-13 10:30:56 +0200 |
commit | 0ded3ecd3bb65b37602e2ad06d657b47dd3025e7 (patch) | |
tree | 58e00ab1a6d567b9e777a93482e0fd10b9c9d306 /stack.lua | |
parent | 044a445cdc2f25f9f069eb95113812cd19f1c0fe (diff) |
workspace: avoid unnecessary page stealing
When switching to a different desktop, the current code would use the
last-used tag even if it is currently displayed. Instead, keep a
per-desktop stack of free tags and pick the first of those.
Diffstat (limited to 'stack.lua')
-rw-r--r-- | stack.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/stack.lua b/stack.lua new file mode 100644 index 0000000..bee5fd3 --- /dev/null +++ b/stack.lua @@ -0,0 +1,38 @@ +local M = {} + +local Stack = {} + +function Stack:push(v) + table.insert(self._et, v) +end + +function Stack:pop() + return table.remove(self._et) +end + +function Stack:remove(it) + local idx = nil + for i, v in ipairs(self._et) do + if v == it then + idx = i + break + end + end + if idx == nil then + error(it .. " not in stack") + end + table.remove(self._et, idx) +end + +function Stack:new() + local o = setmetatable({}, self) + self.__index = self + + o._et = {} + + return o +end + +M.Stack = Stack + +return M |