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
31 -- First, we locate the client
34 for c in awful.client.iterate(function (c)
35 -- c.name may be changed!
36 return c.instance == self.name
37 end, nil, self.screen)
43 -- Additional matching clients, let's remove the sticky bit
44 -- which may persist between awesome restarts. We don't close
45 -- them as they may be valuable. They will just turn into
53 if not client and not self.visible then return end
56 -- The client does not exist, we spawn it
57 cmd = string.format("%s %s %s", self.app,
58 string.format(self.argname, self.name), self.extra)
59 awful.spawn(cmd, { tag = self.screen.selected_tag })
64 client.floating = true
65 client.border_width = self.border
66 client.size_hints_honor = false
67 client:geometry(self:compute_size())
69 -- Set not sticky and on top
73 client.skip_taskbar = true
75 -- Additional user settings
76 if self.settings then self.settings(client) end
82 self.last_tag = self.screen.selected_tag
83 client:tags({self.screen.selected_tag})
84 capi.client.focus = client
87 local ctags = client:tags()
88 for i, t in pairs(ctags) do
97 function quake:compute_size()
98 -- skip if we already have a geometry for this screen
99 if not self.geometry[self.screen] then
101 if not self.overlap then
102 geom = screen[self.screen].workarea
104 geom = screen[self.screen].geometry
106 local width, height = self.width, self.height
107 if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end
108 if height <= 1 then height = math.floor(geom.height * height) end
110 if self.horiz == "left" then x = geom.x
111 elseif self.horiz == "right" then x = geom.width + geom.x - width
112 else x = geom.x + (geom.width - width)/2 end
113 if self.vert == "top" then y = geom.y
114 elseif self.vert == "bottom" then y = geom.height + geom.y - height
115 else y = geom.y + (geom.height - height)/2 end
116 self.geometry[self.screen] = { x = x, y = y, width = width, height = height }
118 return self.geometry[self.screen]
121 function quake:new(config)
122 local conf = config or {}
124 conf.app = conf.app or "xterm" -- application to spawn
125 conf.name = conf.name or "QuakeDD" -- window name
126 conf.argname = conf.argname or "-name %s" -- how to specify window name
127 conf.extra = conf.extra or "" -- extra arguments
128 conf.border = conf.border or 1 -- client border width
129 conf.visible = conf.visible or false -- initially not visible
130 conf.followtag = conf.followtag or false -- spawn on currently focused screen
131 conf.overlap = conf.overlap or false -- overlap wibox
132 conf.screen = conf.screen or awful.screen.focused()
133 conf.settings = conf.settings
135 -- If width or height <= 1 this is a proportion of the workspace
136 conf.height = conf.height or 0.25 -- height
137 conf.width = conf.width or 1 -- width
138 conf.vert = conf.vert or "top" -- top, bottom or center
139 conf.horiz = conf.horiz or "left" -- left, right or center
140 conf.geometry = {} -- internal use
142 local dropdown = setmetatable(conf, { __index = quake })
144 capi.client.connect_signal("manage", function(c)
145 if c.instance == dropdown.name and c.screen == dropdown.screen then
149 capi.client.connect_signal("unmanage", function(c)
150 if c.instance == dropdown.name and c.screen == dropdown.screen then
151 dropdown.visible = false
158 function quake:toggle()
159 if self.followtag then self.screen = awful.screen.focused() end
160 local current_tag = self.screen.selected_tag
161 if current_tag and self.last_tag ~= current_tag and self.visible then
162 self:display():move_to_tag(current_tag)
164 self.visible = not self.visible
169 return setmetatable(quake, { __call = function(_, ...) return quake:new(...) end })