1 -------------------------------------------------------------------
2 -- Drop-down applications manager for the awesome window manager
3 -------------------------------------------------------------------
4 -- Coded by: * Lucas de Vries <lucas@glacicle.com>
5 -- Hacked by: * Adrian C. (anrxc) <anrxc@sysphere.org>
6 -- Licensed under the WTFPL version 2
7 -- * http://sam.zoy.org/wtfpl/COPYING
8 -------------------------------------------------------------------
9 -- To use this module add:
11 -- to the top of your rc.lua, and call it from a keybinding:
12 -- scratch.drop(prog, vert, horiz, width, height, sticky, screen)
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 -------------------------------------------------------------------
28 local awful = require("awful")
29 local setmetatable = setmetatable
36 -- Scratchdrop: drop-down applications manager for the awesome window manager
37 module("scratch.drop")
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)
45 horiz = horiz or "center"
47 height = height or 0.25
48 sticky = sticky or false
49 screen = screen or capi.mouse.screen
51 if not dropdown[prog] then
54 -- Add unmanage signal for scratchdrop programs
55 capi.client.add_signal("unmanage", function (c)
56 for scr, cl in pairs(dropdown[prog]) do
58 dropdown[prog][scr] = nil
64 if not dropdown[prog][screen] then
66 dropdown[prog][screen] = c
68 -- Scratchdrop clients are floaters
69 awful.client.floating.set(c, true)
71 -- Client geometry and placement
72 local screengeom = capi.screen[screen].workarea
74 if width <= 1 then width = screengeom.width * width end
75 if height <= 1 then height = screengeom.height * height end
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
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
86 c:geometry({ x = x, y = y, width = width, height = height })
90 if sticky then c.sticky = true end
91 if c.titlebar then awful.titlebar.remove(c) end
95 capi.client.remove_signal("manage", spawnw)
98 -- Add manage signal and spawn the program
99 capi.client.add_signal("manage", spawnw)
100 awful.util.spawn(prog, false)
102 -- Get a running client
103 c = dropdown[prog][screen]
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)
110 -- Focus and raise if hidden
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
117 capi.client.focus = c
118 else -- Hide and detach tags if not
120 local ctags = c:tags()
121 for i, t in pairs(ctags) do
129 setmetatable(_M, { __call = function(_, ...) return toggle(...) end })