-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.lua
104 lines (95 loc) · 3.19 KB
/
panel.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- This project is licensed under the MIT License (see LICENSE).
--- Launch clients as panels.
--
-- @author James Reed <[email protected]>
-- @copyright 2019-2020 James Reed
-- @module awesome-launch.panel
local awful = require("awful")
local gtable = require("gears.table")
local gtimer = require("gears.timer")
local launch = require("awesome-launch")
local panel = {}
--- Function to handle toggling of a panel client.
--
-- By default, the client's hidden state is toggled.
--
-- @param c The client being toggled.
-- @param state The toggle state: `true` if being toggled into view, `false`
-- otherwise.
-- @function panel.toggle_func
function panel.toggle_func(c, state)
c.hidden = not state
end
--- Function to handle setup of a panel client.
--
-- By default, the client is hidden and made sticky.
--
-- @param c The client being setup.
-- @function panel.setup_func
function panel.setup_func(c)
c.hidden = true
c.sticky = true
end
-- 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.floating = true
c.skip_taskbar = true
c.launch_panel = true
awful.placement.scale(c, {to_percent=args.scale or 0.5})
awful.placement.centered(c)
if panel.setup_func then
panel.setup_func(c)
end
c:connect_signal("unfocus", function ()
gtimer.delayed_call(function ()
local valid = pcall(function () return c.valid end) and c.valid
if valid and not (client.focus and client.focus.floating) then
panel.toggle_func(c, false)
end
end)
end)
if cb then
cb(c)
end
panel.toggle_func(c, true)
end
launch.spawn.single_instance(cmd, args)
end
local function toggle(c)
if c == client.focus then
panel.toggle_func(c, false)
else
panel.toggle_func(c, true)
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.systemd If true, run cmd with systemd-run.
-- @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
spawn(cmd, args)
end
end
return panel