diff options
Diffstat (limited to 'scroll/scripts')
-rw-r--r-- | scroll/scripts/scratchpad.lua | 41 | ||||
-rw-r--r-- | scroll/scripts/swallow.lua | 32 |
2 files changed, 73 insertions, 0 deletions
diff --git a/scroll/scripts/scratchpad.lua b/scroll/scripts/scratchpad.lua new file mode 100644 index 0000000..7e078d6 --- /dev/null +++ b/scroll/scripts/scratchpad.lua @@ -0,0 +1,41 @@ +local args, _ = ... +local id = "" +local spawn = "" + +for i, arg in ipairs(args) do + if i <= 1 then + id = arg + else + spawn = spawn .. " " .. arg + end +end + +local function exists(id) + local is_in_array = false + local cons = scroll.scratchpad_get_containers() + for _, con in ipairs(cons) do + local views = scroll.container_get_views(con) + for _, view in ipairs(views) do + local app_id = scroll.view_get_app_id(view) + if (app_id == id) then + is_in_array = true + end + end + end + return is_in_array +end + +local function is_focused(id) + local view = scroll.focused_view() + local app_id = scroll.view_get_app_id(view) + return app_id == id +end + +if (not exists(id)) then + scroll.command(nil, "exec kitty --class " .. id .. spawn) +end +if (is_focused(id)) then + scroll.command(nill, "scratchpad show") +else + scroll.command(nil, "[app_id=\"" .. id .. "\"] scratchpad show") +end diff --git a/scroll/scripts/swallow.lua b/scroll/scripts/swallow.lua new file mode 100644 index 0000000..5760886 --- /dev/null +++ b/scroll/scripts/swallow.lua @@ -0,0 +1,32 @@ +local function candidate(view) + local app_id = scroll.view_get_app_id(view) + if app_id == "mpv" then + local pview = scroll.view_get_parent_view(view) + if pview ~= nil and pview ~= view then + local papp_id = scroll.view_get_app_id(pview) + if papp_id == "kitty" then + return scroll.view_get_container(pview) + end + end + end + return nil +end + +local function on_create(view, _) + local parent = candidate(view) + if parent ~= nil then + scroll.command(parent, "move scratchpad") + end +end + +local function on_destroy(view, _) + local parent = candidate(view) + if parent ~= nil then + scroll.command(nil, "scratchpad show; floating toggle") + end +end + +scroll.add_callback("view_map", on_create, nil) +scroll.add_callback("view_unmap", on_destroy, nil) + + |