----------------------------------------------------------------1-- Drop-down applications manager for the awesome window manager2----------------------------------------------------------------3-- Coded by: Lucas de Vries <[email protected]>4-- Hacked by: Adrian C. <[email protected]>5-- Licensed under the WTFPL version 26-- * http://sam.zoy.org/wtfpl/COPYING7----------------------------------------------------------------8-- To use this module add:9-- require("teardrop")10-- to the top of your rc.lua, and call it from a keybinding:11-- teardrop(prog, vert, horiz, width, height, sticky, screen)12--13-- Parameters:14-- prog - Program to run; "urxvt", "gmrun", "thunderbird"15-- vert - Vertical; "bottom", "center" or "top" (default)16-- horiz - Horizontal; "left", "right" or "center" (default)17-- width - Width in absolute pixels, or width percentage18-- when <= 1 (1 (100% of the screen) by default)19-- height - Height in absolute pixels, or height percentage20-- when <= 1 (0.25 (25% of the screen) by default)21-- sticky - Visible on all tags, false by default22-- screen - Screen (optional), mouse.screen by default23----------------------------------------------------------------2425-- Grab environment26local pairs = pairs27local awful = require("awful")28local setmetatable = setmetatable29local capi = {30mouse = mouse,31client = client,32screen = screen33}3435-- Teardrop: Drop-down applications manager for the awesome window manager36module("teardrop")3738local dropdown = {}3940-- Create a new window for the drop-down application when it doesn't41-- exist, or toggle between hidden and visible states when it does42function toggle(prog, vert, horiz, width, height, sticky, screen)43local vert = vert or "top"44local horiz = horiz or "center"45local width = width or 146local height = height or 0.2547local sticky = sticky or false48local screen = screen or capi.mouse.screen4950if not dropdown[prog] then51dropdown[prog] = {}5253-- Add unmanage signal for teardrop programs54capi.client.add_signal("unmanage", function (c)55for scr, cl in pairs(dropdown[prog]) do56if cl == c then57dropdown[prog][scr] = nil58end59end60end)61end6263if not dropdown[prog][screen] then64spawnw = function (c)65dropdown[prog][screen] = c6667-- Teardrop clients are floaters68awful.client.floating.set(c, true)6970-- Client geometry and placement71local screengeom = capi.screen[screen].workarea7273if width <= 1 then width = screengeom.width * width end74if height <= 1 then height = screengeom.height * height end7576if horiz == "left" then x = screengeom.x77elseif horiz == "right" then x = screengeom.width - width78else x = screengeom.x+(screengeom.width-width)/2 end7980if vert == "bottom" then y = screengeom.height + screengeom.y - height81elseif vert == "center" then y = screengeom.y+(screengeom.height-height)/282else y = screengeom.y - screengeom.y end8384-- Client properties85c:geometry({ x = x, y = y, width = width, height = height })86c.ontop = true87c.above = true88c.skip_taskbar = true89if sticky then c.sticky = true end90if c.titlebar then awful.titlebar.remove(c) end9192c:raise()93capi.client.focus = c94capi.client.remove_signal("manage", spawnw)95end9697-- Add manage signal and spawn the program98capi.client.add_signal("manage", spawnw)99awful.util.spawn(prog, false)100else101-- Get a running client102c = dropdown[prog][screen]103104-- Switch the client to the current workspace105if c:isvisible() == false then c.hidden = true106awful.client.movetotag(awful.tag.selected(screen), c)107end108109-- Focus and raise if hidden110if c.hidden then111-- Make sure it is centered112if vert == "center" then awful.placement.center_vertical(c) end113if horiz == "center" then awful.placement.center_horizontal(c) end114c.hidden = false115c:raise()116capi.client.focus = c117else -- Hide and detach tags if not118c.hidden = true119local ctags = c:tags()120for i, t in pairs(ctags) do121ctags[i] = nil122end123c:tags(ctags)124end125end126end127128setmetatable(_M, { __call = function(_, ...) return toggle(...) end })129130131