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.
4 Licensed under GNU General Public License v2
5 * (c) 2016, Luke Bonham
10 local awful = require("awful")
11 local capi = { client = client }
13 local math = { floor = math.floor }
14 local string = { format = string.format }
19 local setmetatable = setmetatable
21 -- Quake-like Dropdown application spawn
24 -- If you have a rule like "awful.client.setslave" for your terminals,
25 -- ensure you use an exception for QuakeDD. Otherwise, you may
26 -- run into problems with focus.
28 function quake:display()
29 if self.followtag then self.screen = awful.screen.focused() end
30 local toscan = self.screen
31 if self.onlyone then toscan = nil end
33 -- First, we locate the client
36 for c in awful.client.iterate(function (c)
37 -- c.name may be changed!
38 return c.instance == self.name
45 -- Additional matching clients, let's remove the sticky bit
46 -- which may persist between awesome restarts. We don't close
47 -- them as they may be valuable. They will just turn into
55 if not client and not self.visible then return end
58 -- The client does not exist, we spawn it
59 cmd = string.format("%s %s %s", self.app,
60 string.format(self.argname, self.name), self.extra)
61 awful.spawn(cmd, { tag = self.screen.selected_tag })
66 client.floating = true
67 client.border_width = self.border
68 client.size_hints_honor = false
69 client:geometry(self:compute_size())
71 -- Set not sticky and on top
75 client.skip_taskbar = true
77 -- Additional user settings
78 if self.settings then self.settings(client) end
84 self.last_tag = self.screen.selected_tag
85 client:tags({self.screen.selected_tag})
86 capi.client.focus = client
89 local ctags = client:tags()
90 for i, t in pairs(ctags) do
99 function quake:compute_size()
100 -- skip if we already have a geometry for this screen
101 if not self.geometry[self.screen] then
103 if not self.overlap then
104 geom = screen[self.screen].workarea
106 geom = screen[self.screen].geometry
108 local width, height = self.width, self.height
109 if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end
110 if height <= 1 then height = math.floor(geom.height * height) end
112 if self.horiz == "left" then x = geom.x
113 elseif self.horiz == "right" then x = geom.width + geom.x - width
114 else x = geom.x + (geom.width - width)/2 end
115 if self.vert == "top" then y = geom.y
116 elseif self.vert == "bottom" then y = geom.height + geom.y - height
117 else y = geom.y + (geom.height - height)/2 end
118 self.geometry[self.screen] = { x = x, y = y, width = width, height = height }
120 return self.geometry[self.screen]
123 function quake:new(config)
124 local conf = config or {}
126 conf.app = conf.app or "xterm" -- application to spawn
127 conf.name = conf.name or "QuakeDD" -- window name
128 conf.argname = conf.argname or "-name %s" -- how to specify window name
129 conf.extra = conf.extra or "" -- extra arguments
130 conf.border = conf.border or 1 -- client border width
131 conf.visible = conf.visible or false -- initially not visible
132 conf.followtag = conf.followtag or false -- spawn on currently focused screen
133 conf.onlyone = conf.onlyone or false -- one instance for all screens
134 conf.overlap = conf.overlap or false -- overlap wibox
135 conf.screen = conf.screen or awful.screen.focused()
136 conf.settings = conf.settings
138 -- If width or height <= 1 this is a proportion of the workspace
139 conf.height = conf.height or 0.25 -- height
140 conf.width = conf.width or 1 -- width
141 conf.vert = conf.vert or "top" -- top, bottom or center
142 conf.horiz = conf.horiz or "left" -- left, right or center
143 conf.geometry = {} -- internal use
145 local dropdown = setmetatable(conf, { __index = quake })
147 capi.client.connect_signal("manage", function(c)
148 if c.instance == dropdown.name and c.screen == dropdown.screen then
152 capi.client.connect_signal("unmanage", function(c)
153 if c.instance == dropdown.name and c.screen == dropdown.screen then
154 dropdown.visible = false
161 function quake:toggle()
162 if self.followtag then self.screen = awful.screen.focused() end
163 local current_tag = self.screen.selected_tag
164 if current_tag and self.last_tag ~= current_tag and self.visible then
165 self:display():move_to_tag(current_tag)
167 self.visible = not self.visible
172 return setmetatable(quake, { __call = function(_, ...) return quake:new(...) end })