Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/awesome/teardrop.lua
987 views
1
----------------------------------------------------------------
2
-- Drop-down applications manager for the awesome window manager
3
----------------------------------------------------------------
4
-- Coded by: Lucas de Vries <[email protected]>
5
-- Hacked by: Adrian C. <[email protected]>
6
-- Licensed under the WTFPL version 2
7
-- * http://sam.zoy.org/wtfpl/COPYING
8
----------------------------------------------------------------
9
-- To use this module add:
10
-- require("teardrop")
11
-- to the top of your rc.lua, and call it from a keybinding:
12
-- teardrop(prog, vert, horiz, width, height, sticky, screen)
13
--
14
-- Parameters:
15
-- prog - Program to run; "urxvt", "gmrun", "thunderbird"
16
-- vert - Vertical; "bottom", "center" or "top" (default)
17
-- horiz - Horizontal; "left", "right" or "center" (default)
18
-- width - Width in absolute pixels, or width percentage
19
-- when <= 1 (1 (100% of the screen) by default)
20
-- height - Height in absolute pixels, or height percentage
21
-- when <= 1 (0.25 (25% of the screen) by default)
22
-- sticky - Visible on all tags, false by default
23
-- screen - Screen (optional), mouse.screen by default
24
----------------------------------------------------------------
25
26
-- Grab environment
27
local pairs = pairs
28
local awful = require("awful")
29
local setmetatable = setmetatable
30
local capi = {
31
mouse = mouse,
32
client = client,
33
screen = screen
34
}
35
36
-- Teardrop: Drop-down applications manager for the awesome window manager
37
module("teardrop")
38
39
local dropdown = {}
40
41
-- Create a new window for the drop-down application when it doesn't
42
-- exist, or toggle between hidden and visible states when it does
43
function toggle(prog, vert, horiz, width, height, sticky, screen)
44
local vert = vert or "top"
45
local horiz = horiz or "center"
46
local width = width or 1
47
local height = height or 0.25
48
local sticky = sticky or false
49
local screen = screen or capi.mouse.screen
50
51
if not dropdown[prog] then
52
dropdown[prog] = {}
53
54
-- Add unmanage signal for teardrop programs
55
capi.client.add_signal("unmanage", function (c)
56
for scr, cl in pairs(dropdown[prog]) do
57
if cl == c then
58
dropdown[prog][scr] = nil
59
end
60
end
61
end)
62
end
63
64
if not dropdown[prog][screen] then
65
spawnw = function (c)
66
dropdown[prog][screen] = c
67
68
-- Teardrop clients are floaters
69
awful.client.floating.set(c, true)
70
71
-- Client geometry and placement
72
local screengeom = capi.screen[screen].workarea
73
74
if width <= 1 then width = screengeom.width * width end
75
if height <= 1 then height = screengeom.height * height end
76
77
if horiz == "left" then x = screengeom.x
78
elseif horiz == "right" then x = screengeom.width - width
79
else x = screengeom.x+(screengeom.width-width)/2 end
80
81
if vert == "bottom" then y = screengeom.height + screengeom.y - height
82
elseif vert == "center" then y = screengeom.y+(screengeom.height-height)/2
83
else y = screengeom.y - screengeom.y end
84
85
-- Client properties
86
c:geometry({ x = x, y = y, width = width, height = height })
87
c.ontop = true
88
c.above = true
89
c.skip_taskbar = true
90
if sticky then c.sticky = true end
91
if c.titlebar then awful.titlebar.remove(c) end
92
93
c:raise()
94
capi.client.focus = c
95
capi.client.remove_signal("manage", spawnw)
96
end
97
98
-- Add manage signal and spawn the program
99
capi.client.add_signal("manage", spawnw)
100
awful.util.spawn(prog, false)
101
else
102
-- Get a running client
103
c = dropdown[prog][screen]
104
105
-- Switch the client to the current workspace
106
if c:isvisible() == false then c.hidden = true
107
awful.client.movetotag(awful.tag.selected(screen), c)
108
end
109
110
-- Focus and raise if hidden
111
if c.hidden then
112
-- Make sure it is centered
113
if vert == "center" then awful.placement.center_vertical(c) end
114
if horiz == "center" then awful.placement.center_horizontal(c) end
115
c.hidden = false
116
c:raise()
117
capi.client.focus = c
118
else -- Hide and detach tags if not
119
c.hidden = true
120
local ctags = c:tags()
121
for i, t in pairs(ctags) do
122
ctags[i] = nil
123
end
124
c:tags(ctags)
125
end
126
end
127
end
128
129
setmetatable(_M, { __call = function(_, ...) return toggle(...) end })
130
131