allow non-persistent layout
This commit is contained in:
parent
942895916f
commit
8b48e9582f
15
README.md
15
README.md
|
@ -33,16 +33,13 @@ The package comes with the icon for `layoutbox`, which can be set with the follo
|
|||
|
||||
Use `layout = machi.layout.create(name, editor)` to instantiate the layout with an editor object.
|
||||
|
||||
`name` can be a string or a function taking a tag object and returning a string.
|
||||
`name` can be a string or a function returning a string (see `init.lua` and "Advanced" below).
|
||||
This is used for having different actual layout dependent on tags.
|
||||
|
||||
`editor` are used for editing and persisting the layouts.
|
||||
`machi.default_editor` can be used, or see below on creating editors.
|
||||
You can create multiple layouts with different names and share the same editor.
|
||||
|
||||
The default layout, `machi.default_layout`, uses the screen geometry and the tag name for name, thus allows the actual layout to be tag- and screen-dependent.
|
||||
To differentiate tags with the same name, you may need a more advanced naming function.
|
||||
|
||||
## Editor
|
||||
|
||||
Call `editor = machi.editor.create()` to create an editor.
|
||||
|
@ -130,6 +127,16 @@ So far, the key binding is not configurable. One has to modify the source code t
|
|||
`machi.editor.fit_region(c, cycle = false)` will fit a floating client into the closest region.
|
||||
If `cycle` is true, it then moves the window by cycling all regions.
|
||||
|
||||
## Advanced
|
||||
|
||||
# `name` as a function in `machi.layout.create`
|
||||
|
||||
When passed in as a function, `name` takes the tag `t` and a boolean flag `p` and returns a function for the tag-dependent name of the layout.
|
||||
Flag `p` is set true when the name is used for persisting the layout. If the layout is not intented to persist, returning `nil` when `p` is true to skip persisting.
|
||||
|
||||
The default layout, `machi.default_layout`, uses the screen geometry and the tag name for name, thus allows the actual layout to be tag- and screen-dependent.
|
||||
To differentiate tags with the same name, you may need a more advanced naming function.
|
||||
|
||||
## Caveats
|
||||
|
||||
`beautiful.useless_gap` is handled differently in layout-machi and it doesn't cooperate well with the standard way.
|
||||
|
|
33
editor.lua
33
editor.lua
|
@ -652,25 +652,26 @@ local function create(data)
|
|||
end
|
||||
-- bring the current cmd to the front
|
||||
data.cmds[#data.cmds + 1] = current_cmd
|
||||
if not layout.is_dynamic then
|
||||
data.last_cmd[layout.machi_get_instance_name(tag)] = current_cmd
|
||||
end
|
||||
|
||||
if data.history_file then
|
||||
local file, err = io.open(data.history_file, "w")
|
||||
if err then
|
||||
print("cannot save history to " .. data.history_file)
|
||||
else
|
||||
for i = max(1, #data.cmds - data.history_save_max + 1), #data.cmds do
|
||||
print("save cmd " .. data.cmds[i])
|
||||
file:write(data.cmds[i] .. "\n")
|
||||
end
|
||||
for name, cmd in pairs(data.last_cmd) do
|
||||
print("save last cmd " .. cmd .. " for " .. name)
|
||||
file:write("+" .. name .. "\n" .. cmd .. "\n")
|
||||
local instance_name = layout.machi_get_instance_name(tag, true)
|
||||
if instance_name ~= nil then
|
||||
data.last_cmd[instance_name] = current_cmd
|
||||
if data.history_file then
|
||||
local file, err = io.open(data.history_file, "w")
|
||||
if err then
|
||||
print("cannot save history to " .. data.history_file)
|
||||
else
|
||||
for i = max(1, #data.cmds - data.history_save_max + 1), #data.cmds do
|
||||
print("save cmd " .. data.cmds[i])
|
||||
file:write(data.cmds[i] .. "\n")
|
||||
end
|
||||
for name, cmd in pairs(data.last_cmd) do
|
||||
print("save last cmd " .. cmd .. " for " .. name)
|
||||
file:write("+" .. name .. "\n" .. cmd .. "\n")
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
|
||||
current_info = "Saved!"
|
||||
|
|
2
init.lua
2
init.lua
|
@ -3,7 +3,7 @@ local editor = require(... .. ".editor")
|
|||
local switcher = require(... .. ".switcher")
|
||||
local default_editor = editor.create()
|
||||
local default_layout = layout.create(
|
||||
function (tag)
|
||||
function (tag, _persist)
|
||||
if tag.machi_name_cache == nil then
|
||||
tag.machi_name_cache =
|
||||
tostring(tag.screen.geometry.width) .. "x" .. tostring(tag.screen.geometry.height) .. "+" ..
|
||||
|
|
|
@ -51,11 +51,11 @@ local function create(name, editor)
|
|||
if type(name) == "function" then
|
||||
get_instance_name = name
|
||||
else
|
||||
get_instance_name = function (tag) return name end
|
||||
get_instance_name = function () return name end
|
||||
end
|
||||
|
||||
local function get_instance(tag)
|
||||
local name = get_instance_name(tag)
|
||||
local name = get_instance_name(tag, false)
|
||||
if instances[name] == nil then
|
||||
instances[name] = {
|
||||
cmd = editor.get_last_cmd(name),
|
||||
|
|
Loading…
Reference in New Issue