All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 Licensed under GNU General Public License v2
4 * (c) 2016, Luke Bonham
9 local awful = require("awful")
10 local capi = { client = client }
12 local math = { floor = math.floor }
13 local string = { format = string.format }
18 local setmetatable = setmetatable
20 -- Quake-like Dropdown application spawn
23 -- If you have a rule like "awful.client.setslave" for your terminals,
24 -- ensure you use an exception for QuakeDD. Otherwise, you may
25 -- run into problems with focus.
27 function quake:display()
28 if self.followtag then self.screen = awful.screen.focused() end
30 -- First, we locate the client
33 for c in awful.client.iterate(function (c)
34 -- c.name may be changed!
35 return c.instance == self.name
36 end, nil, self.screen)
42 -- Additional matching clients, let's remove the sticky bit
43 -- which may persist between awesome restarts. We don't close
44 -- them as they may be valuable. They will just turn into
52 if not client and not self.visible then return end
55 -- The client does not exist, we spawn it
56 cmd = string.format("%s %s %s", self.app,
57 string.format(self.argname, self.name), self.extra)
58 awful.spawn(cmd, { tag = self.screen.selected_tag })
63 client.floating = true
64 client.border_width = self.border
65 client.size_hints_honor = false
66 client:geometry(self.geometry[self.screen] or self:compute_size())
68 -- Set not sticky and on top
72 client.skip_taskbar = true
74 -- Additional user settings
75 if self.settings then self.settings(client) end
81 self.last_tag = self.screen.selected_tag
82 client:tags({self.screen.selected_tag})
83 capi.client.focus = client
86 local ctags = client:tags()
87 for i, t in pairs(ctags) do
96 function quake:compute_size()
97 -- skip if we already have a geometry for this screen
98 if not self.geometry[self.screen] then
100 if not self.overlap then
101 geom = screen[self.screen].workarea
103 geom = screen[self.screen].geometry
105 local width, height = self.width, self.height
106 if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end
107 if height <= 1 then height = math.floor(geom.height * height) end
109 if self.horiz == "left" then x = geom.x
110 elseif self.horiz == "right" then x = geom.width + geom.x - width
111 else x = geom.x + (geom.width - width)/2 end
112 if self.vert == "top" then y = geom.y
113 elseif self.vert == "bottom" then y = geom.height + geom.y - height
114 else y = geom.y + (geom.height - height)/2 end
115 self.geometry[self.screen] = { x = x, y = y, width = width, height = height }
117 return self.geometry[self.screen]
120 function quake:new(config)
121 local conf = config or {}
123 conf.app = conf.app or "xterm" -- application to spawn
124 conf.name = conf.name or "QuakeDD" -- window name
125 conf.argname = conf.argname or "-name %s" -- how to specify window name
126 conf.extra = conf.extra or "" -- extra arguments
127 conf.border = conf.border or 1 -- client border width
128 conf.visible = conf.visible or false -- initially not visible
129 conf.followtag = conf.followtag or false -- spawn on currently focused screen
130 conf.overlap = conf.overlap or false -- overlap wibox
131 conf.screen = conf.screen or awful.screen.focused()
132 conf.settings = conf.settings
134 -- If width or height <= 1 this is a proportion of the workspace
135 conf.height = conf.height or 0.25 -- height
136 conf.width = conf.width or 1 -- width
137 conf.vert = conf.vert or "top" -- top, bottom or center
138 conf.horiz = conf.horiz or "left" -- left, right or center
139 conf.geometry = {} -- internal use
141 local dropdown = setmetatable(conf, { __index = quake })
143 capi.client.connect_signal("manage", function(c)
144 if c.instance == dropdown.name and c.screen == dropdown.screen then
148 capi.client.connect_signal("unmanage", function(c)
149 if c.instance == dropdown.name and c.screen == dropdown.screen then
150 dropdown.visible = false
157 function quake:toggle()
158 if self.followtag then self.screen = awful.screen.focused() end
159 local current_tag = self.screen.selected_tag
160 if current_tag and self.last_tag ~= current_tag and self.visible then
161 self:display():move_to_tag(current_tag)
163 self.visible = not self.visible
168 return setmetatable(quake, { __call = function(_, ...) return quake:new(...) end })