diff --git a/README.md b/README.md index 77d6b41..581972a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ The package comes with the icon for `layoutbox`, which can be set with the follo `require("beautiful").layout_machi = machi.get_icon()` +By default, any machi layout will use the layout command from `machi.layout.default_cmd`, which is initialized as `dw66.` (see interpretation below). +You can change it after loading the module. + ## Use the layout Use `local layout = machi.layout.create(name, editor)` to instantiate the layout with an editor object. diff --git a/layout.lua b/layout.lua index 2ee6e75..0a4d423 100644 --- a/layout.lua +++ b/layout.lua @@ -10,6 +10,7 @@ local DEBUG = -1 local module = { log_level = WARNING, + default_cmd = "dw66.", } local function log(level, msg) @@ -120,7 +121,7 @@ function module.create(name, editor) get_instance_name = function () return name, true end end - local function get_instance(tag) + local function get_instance_(tag) local name, persistent = get_instance_name(tag) if instances[name] == nil then instances[name] = { @@ -132,18 +133,19 @@ function module.create(name, editor) end local function get_regions(workarea, tag) - local instance = get_instance(tag) - if instance.cmd == nil then return {}, false end + local instance = get_instance_(tag) + local cmd = instance.cmd or module.default_cmd + if cmd == nil then return {}, false end local key = tostring(workarea.width) .. "x" .. tostring(workarea.height) .. "+" .. tostring(workarea.x) .. "+" .. tostring(workarea.y) if instance.regions_cache[key] == nil then - instance.regions_cache[key] = editor.run_cmd(workarea, instance.cmd) + instance.regions_cache[key] = editor.run_cmd(workarea, cmd) end - return instance.regions_cache[key], instance.cmd:sub(1,1) == "d" + return instance.regions_cache[key], cmd:sub(1,1) == "d" end local function set_cmd(cmd, tag) - local instance = get_instance(tag) + local instance = get_instance_(tag) if instance.cmd ~= cmd then instance.cmd = cmd instance.regions_cache = {}