Incorporating comments from reddit. Thanks u/sigprof.
1. Removed unintended global names 2. The default history file changed to `gfs.get_cache_dir() .. "/history_machi"` 3. `editor` will detect if the layout is machi before start 4. Added `machi_` prefix for machi fields in the layout objects.
This commit is contained in:
parent
65da3ca70d
commit
2ca22c2cc1
|
@ -32,8 +32,7 @@ The editor will restore the last setups of the layouts based on their names.
|
||||||
## Editor
|
## Editor
|
||||||
|
|
||||||
Call `editor = machi.editor.create()` to create an editor.
|
Call `editor = machi.editor.create()` to create an editor.
|
||||||
To edit the current layout on screen `scr`, call `editor.start_interactive(scr)`.
|
To edit the layout `l` on screen `s`, call `editor.start_interactive(s = awful.screen.focused(), l = awful.layout.get(s))`.
|
||||||
If `screen` is ignored, `screen.focused()` will be used.
|
|
||||||
|
|
||||||
### The layout editing command
|
### The layout editing command
|
||||||
|
|
||||||
|
|
39
editor.lua
39
editor.lua
|
@ -11,12 +11,14 @@ local api = {
|
||||||
keygrabber = require("awful.keygrabber"),
|
keygrabber = require("awful.keygrabber"),
|
||||||
naughty = require("naughty"),
|
naughty = require("naughty"),
|
||||||
gears = require("gears"),
|
gears = require("gears"),
|
||||||
|
gfs = require("gears.filesystem"),
|
||||||
lgi = require("lgi"),
|
lgi = require("lgi"),
|
||||||
dpi = require("beautiful.xresources").apply_dpi,
|
dpi = require("beautiful.xresources").apply_dpi,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function with_alpha(col, alpha)
|
local function with_alpha(col, alpha)
|
||||||
_, r, g, b, a = col:get_rgba()
|
local r, g, b
|
||||||
|
_, r, g, b, _ = col:get_rgba()
|
||||||
return api.lgi.cairo.SolidPattern.create_rgba(r, g, b, alpha)
|
return api.lgi.cairo.SolidPattern.create_rgba(r, g, b, alpha)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,12 +71,12 @@ end
|
||||||
-- @param cycle whether to cycle the region if the window is already in machi
|
-- @param cycle whether to cycle the region if the window is already in machi
|
||||||
-- @return whether any actions have been taken on the client
|
-- @return whether any actions have been taken on the client
|
||||||
local function fit_region(c, cycle)
|
local function fit_region(c, cycle)
|
||||||
layout = api.layout.get(c.screen)
|
local layout = api.layout.get(c.screen)
|
||||||
regions = layout.get_regions and layout.get_regions(c.screen.workarea)
|
local regions = layout.machi_get_regions and layout.machi_get_regions(c.screen.workarea)
|
||||||
if type(regions) ~= "table" or #regions < 1 then
|
if type(regions) ~= "table" or #regions < 1 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
current_region = c.machi_region or 1
|
local current_region = c.machi_region or 1
|
||||||
if not is_tiling(c) then
|
if not is_tiling(c) then
|
||||||
-- find out which region has the most intersection, calculated by a cap b / a cup b
|
-- find out which region has the most intersection, calculated by a cap b / a cup b
|
||||||
c.machi_region = machi.layout.find_region(c, regions)
|
c.machi_region = machi.layout.find_region(c, regions)
|
||||||
|
@ -157,7 +159,7 @@ end
|
||||||
local function create(data)
|
local function create(data)
|
||||||
if data == nil then
|
if data == nil then
|
||||||
data = restore_data({
|
data = restore_data({
|
||||||
history_file = ".machi_history",
|
history_file = api.gfs.get_cache_dir() .. "/history_machi",
|
||||||
history_save_max = 100,
|
history_save_max = 100,
|
||||||
gap = api.beautiful.useless_gap,
|
gap = api.beautiful.useless_gap,
|
||||||
})
|
})
|
||||||
|
@ -445,11 +447,21 @@ local function create(data)
|
||||||
return key
|
return key
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_interactive(screen)
|
local function start_interactive(screen, layout)
|
||||||
|
screen = screen or api.screen.focused()
|
||||||
|
layout = layout or api.layout.get(screen)
|
||||||
|
|
||||||
|
if layout.machi_set_cmd == nil then
|
||||||
|
api.naughty.notify({
|
||||||
|
text = "The layout to edit is not machi",
|
||||||
|
timeout = 3,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local cmd_index = #data.cmds + 1
|
local cmd_index = #data.cmds + 1
|
||||||
data.cmds[cmd_index] = ""
|
data.cmds[cmd_index] = ""
|
||||||
|
|
||||||
screen = screen or api.screen.focused()
|
|
||||||
local screen_x = screen.geometry.x
|
local screen_x = screen.geometry.x
|
||||||
local screen_y = screen.geometry.y
|
local screen_y = screen.geometry.y
|
||||||
|
|
||||||
|
@ -577,7 +589,7 @@ local function create(data)
|
||||||
print("restore history #" .. tostring(cmd_index) .. ":" .. data.cmds[cmd_index])
|
print("restore history #" .. tostring(cmd_index) .. ":" .. data.cmds[cmd_index])
|
||||||
init(screen.workarea)
|
init(screen.workarea)
|
||||||
for i = 1, #data.cmds[cmd_index] do
|
for i = 1, #data.cmds[cmd_index] do
|
||||||
cmd = data.cmds[cmd_index]:sub(i, i)
|
local cmd = data.cmds[cmd_index]:sub(i, i)
|
||||||
|
|
||||||
push_history()
|
push_history()
|
||||||
local ret = handle_command(cmd)
|
local ret = handle_command(cmd)
|
||||||
|
@ -608,8 +620,6 @@ local function create(data)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if key == "Return" then
|
if key == "Return" then
|
||||||
local layout = api.layout.get(screen)
|
|
||||||
|
|
||||||
table.remove(data.cmds, #data.cmds)
|
table.remove(data.cmds, #data.cmds)
|
||||||
-- remove duplicated entries
|
-- remove duplicated entries
|
||||||
local j = 1
|
local j = 1
|
||||||
|
@ -624,7 +634,7 @@ 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
|
||||||
data.last_cmd[layout.name] = current_cmd
|
data.last_cmd[layout.machi_instance_name] = current_cmd
|
||||||
|
|
||||||
if data.history_file then
|
if data.history_file then
|
||||||
local file, err = io.open(data.history_file, "w")
|
local file, err = io.open(data.history_file, "w")
|
||||||
|
@ -654,11 +664,8 @@ local function create(data)
|
||||||
if to_exit then
|
if to_exit then
|
||||||
print("interactive layout editing ends")
|
print("interactive layout editing ends")
|
||||||
if to_apply then
|
if to_apply then
|
||||||
local layout = api.layout.get(screen)
|
layout.machi_set_cmd(current_cmd)
|
||||||
if layout.set_cmd then
|
api.layout.arrange(screen)
|
||||||
layout.set_cmd(current_cmd)
|
|
||||||
api.layout.arrange(screen)
|
|
||||||
end
|
|
||||||
api.gears.timer{
|
api.gears.timer{
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
autostart = true,
|
autostart = true,
|
||||||
|
|
13
layout.lua
13
layout.lua
|
@ -36,7 +36,7 @@ local function find_region(c, regions)
|
||||||
return choice
|
return choice
|
||||||
end
|
end
|
||||||
|
|
||||||
function create(name, editor)
|
local function create(name, editor)
|
||||||
local priv = {
|
local priv = {
|
||||||
name = name,
|
name = name,
|
||||||
editor = editor,
|
editor = editor,
|
||||||
|
@ -53,7 +53,7 @@ function create(name, editor)
|
||||||
return priv.regions_cache[key]
|
return priv.regions_cache[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
function arrange(p)
|
local function arrange(p)
|
||||||
local wa = p.workarea
|
local wa = p.workarea
|
||||||
local cls = p.clients
|
local cls = p.clients
|
||||||
local regions = get_regions(wa)
|
local regions = get_regions(wa)
|
||||||
|
@ -87,7 +87,7 @@ function create(name, editor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_cmd(cmd)
|
local function set_cmd(cmd)
|
||||||
if priv.cmd ~= cmd then
|
if priv.cmd ~= cmd then
|
||||||
priv.cmd = cmd
|
priv.cmd = cmd
|
||||||
priv.regions_cache = {}
|
priv.regions_cache = {}
|
||||||
|
@ -129,11 +129,12 @@ function create(name, editor)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name = name,
|
name = "machi",
|
||||||
arrange = arrange,
|
arrange = arrange,
|
||||||
set_cmd = set_cmd,
|
|
||||||
get_regions = get_regions,
|
|
||||||
resize_handler = resize_handler,
|
resize_handler = resize_handler,
|
||||||
|
machi_instance_name = name,
|
||||||
|
machi_set_cmd = set_cmd,
|
||||||
|
machi_get_regions = get_regions,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ local function max(a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function with_alpha(col, alpha)
|
local function with_alpha(col, alpha)
|
||||||
_, r, g, b, a = col:get_rgba()
|
local r, g, b
|
||||||
|
_, r, g, b, _ = col:get_rgba()
|
||||||
return api.lgi.cairo.SolidPattern.create_rgba(r, g, b, alpha)
|
return api.lgi.cairo.SolidPattern.create_rgba(r, g, b, alpha)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,9 +57,9 @@ local function start(c)
|
||||||
local screen_y = screen.geometry.y
|
local screen_y = screen.geometry.y
|
||||||
|
|
||||||
local layout = api.layout.get(screen)
|
local layout = api.layout.get(screen)
|
||||||
if c.floating or layout.get_regions == nil then return end
|
if c.floating or layout.machi_get_regions == nil then return end
|
||||||
|
|
||||||
local regions = layout.get_regions(c.screen.workarea)
|
local regions = layout.machi_get_regions(c.screen.workarea)
|
||||||
|
|
||||||
local infobox = api.wibox({
|
local infobox = api.wibox({
|
||||||
screen = screen,
|
screen = screen,
|
||||||
|
|
Loading…
Reference in New Issue