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.
|
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.
|
This is used for having different actual layout dependent on tags.
|
||||||
|
|
||||||
`editor` are used for editing and persisting the layouts.
|
`editor` are used for editing and persisting the layouts.
|
||||||
`machi.default_editor` can be used, or see below on creating editors.
|
`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.
|
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
|
## Editor
|
||||||
|
|
||||||
Call `editor = machi.editor.create()` to create an 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.
|
`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.
|
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
|
## Caveats
|
||||||
|
|
||||||
`beautiful.useless_gap` is handled differently in layout-machi and it doesn't cooperate well with the standard way.
|
`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
|
end
|
||||||
-- bring the current cmd to the front
|
-- bring the current cmd to the front
|
||||||
data.cmds[#data.cmds + 1] = current_cmd
|
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 instance_name = layout.machi_get_instance_name(tag, true)
|
||||||
local file, err = io.open(data.history_file, "w")
|
if instance_name ~= nil then
|
||||||
if err then
|
data.last_cmd[instance_name] = current_cmd
|
||||||
print("cannot save history to " .. data.history_file)
|
if data.history_file then
|
||||||
else
|
local file, err = io.open(data.history_file, "w")
|
||||||
for i = max(1, #data.cmds - data.history_save_max + 1), #data.cmds do
|
if err then
|
||||||
print("save cmd " .. data.cmds[i])
|
print("cannot save history to " .. data.history_file)
|
||||||
file:write(data.cmds[i] .. "\n")
|
else
|
||||||
end
|
for i = max(1, #data.cmds - data.history_save_max + 1), #data.cmds do
|
||||||
for name, cmd in pairs(data.last_cmd) do
|
print("save cmd " .. data.cmds[i])
|
||||||
print("save last cmd " .. cmd .. " for " .. name)
|
file:write(data.cmds[i] .. "\n")
|
||||||
file:write("+" .. name .. "\n" .. cmd .. "\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
|
end
|
||||||
|
file:close()
|
||||||
end
|
end
|
||||||
file:close()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
current_info = "Saved!"
|
current_info = "Saved!"
|
||||||
|
|
2
init.lua
2
init.lua
|
@ -3,7 +3,7 @@ local editor = require(... .. ".editor")
|
||||||
local switcher = require(... .. ".switcher")
|
local switcher = require(... .. ".switcher")
|
||||||
local default_editor = editor.create()
|
local default_editor = editor.create()
|
||||||
local default_layout = layout.create(
|
local default_layout = layout.create(
|
||||||
function (tag)
|
function (tag, _persist)
|
||||||
if tag.machi_name_cache == nil then
|
if tag.machi_name_cache == nil then
|
||||||
tag.machi_name_cache =
|
tag.machi_name_cache =
|
||||||
tostring(tag.screen.geometry.width) .. "x" .. tostring(tag.screen.geometry.height) .. "+" ..
|
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
|
if type(name) == "function" then
|
||||||
get_instance_name = name
|
get_instance_name = name
|
||||||
else
|
else
|
||||||
get_instance_name = function (tag) return name end
|
get_instance_name = function () return name end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_instance(tag)
|
local function get_instance(tag)
|
||||||
local name = get_instance_name(tag)
|
local name = get_instance_name(tag, false)
|
||||||
if instances[name] == nil then
|
if instances[name] == nil then
|
||||||
instances[name] = {
|
instances[name] = {
|
||||||
cmd = editor.get_last_cmd(name),
|
cmd = editor.get_last_cmd(name),
|
||||||
|
|
Loading…
Reference in New Issue