From 0fdcf4e82219e9bde8451654e1fe3220a2975165 Mon Sep 17 00:00:00 2001 From: James Reed Date: Tue, 2 Jul 2019 17:23:59 -0600 Subject: [PATCH] Add awesome-launch.panel --- awesome-launch-0.1.0-1.rockspec | 1 + config.ld | 5 ++- panel.lua | 66 +++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 panel.lua diff --git a/awesome-launch-0.1.0-1.rockspec b/awesome-launch-0.1.0-1.rockspec index 51cae6f..54a3055 100644 --- a/awesome-launch-0.1.0-1.rockspec +++ b/awesome-launch-0.1.0-1.rockspec @@ -14,5 +14,6 @@ build = { modules = { ["awesome-launch"] = "init.lua", ["awesome-launch.uuid"] = "uuid.lua", + ["awesome-launch.panel"] = "panel.lua", }, } diff --git a/config.ld b/config.ld index 84aecab..48d2756 100644 --- a/config.ld +++ b/config.ld @@ -3,6 +3,9 @@ project='awesome-launch' title='awesome-launch API documentation' description='API documentation for awesome-launch, a library for Awesome WM' -file='init.lua' +file={ + 'init.lua', + 'panel.lua', +} -- vim: ft=lua diff --git a/panel.lua b/panel.lua new file mode 100644 index 0000000..a450b11 --- /dev/null +++ b/panel.lua @@ -0,0 +1,66 @@ +--- Launch clients as panels. +-- +-- @author James Reed <jcrd@tuta.io> +-- @copyright 2019 James Reed +-- @module awesome-launch.panel + +local awful = require("awful") +local gtable = require("gears.table") +local launch = require("awesome-launch") + +local panel = {} + +-- TODO: Reapply args on restart with rule source. +-- See: https://github.com/awesomeWM/awesome/issues/2725 +local function spawn(cmd, args) + local cb = args.callback + args.callback = function (c) + c.hidden = true + c.sticky = true + c.floating = true + awful.placement.scale(c, {to_percent=args.scale or 0.5}) + awful.placement.centered(c) + c:connect_signal("unfocus", function () c.hidden = true end) + if cb then cb(c) end + end + launch.spawn.single_instance(cmd, args) +end + +local function toggle(c) + if c == client.focus then + c.hidden = true + else + c.hidden = false + c:emit_signal("request::activate", "panel.toggle", {raise=true}) + end +end + +--- Toggle the visibility of a panel, spawning the command if necessary. +-- +-- A panel is a floating, centered client that can be scaled to a percentage of +-- its size. +-- +-- @param cmd The command. +-- @param args Table containing the single instance ID and additional arguments for spawn +-- @param args.id Single instance ID. +-- @param args.props Properties to apply to the client. +-- @param args.pwd Pathname to the working directory for new clients. +-- @param args.timeout Seconds after which to stop waiting for a client to spawn. +-- @param args.callback Function to call with client when it spawns. +-- @param args.factory The factory to use (see wm-launch's -f flag). +-- @param args.firejail If true, run cmd with firejail. +-- @param args.filter Function to filter clients that are considered. +-- @param args.scale Percent to scale client (see awful.placement.scale). +-- @function panel.toggle +function panel.toggle(cmd, args) + local c = launch.client.by_id(args.id) + if c then + toggle(c) + else + local a = {callback = function (c) toggle(c) end} + gtable.crush(a, args) + spawn(cmd, a) + end +end + +return panel