runraise replaces default spawning
This commit is contained in:
parent
028d866eb5
commit
673dc4e056
44
runraise.lua
Normal file
44
runraise.lua
Normal file
|
@ -0,0 +1,44 @@
|
|||
--- Spawns cmd if no client can be found matching properties
|
||||
-- If such a client can be found, pop to first tag where it is visible, and give it focus
|
||||
-- @param cmd the command to execute
|
||||
-- @param properties a table of properties to match against clients. Possible entries: any properties of the client object
|
||||
|
||||
function runraise(cmd, properties)
|
||||
local clients = client.get()
|
||||
local focused = awful.client.next(0)
|
||||
local findex = 0
|
||||
local matched_clients = {}
|
||||
local n = 0
|
||||
for i, c in pairs(clients) do
|
||||
--make an array of matched clients
|
||||
if awful.rules.match(properties, c) then
|
||||
n = n + 1
|
||||
matched_clients[n] = c
|
||||
if c == focused then
|
||||
findex = n
|
||||
end
|
||||
end
|
||||
end
|
||||
if n > 0 then
|
||||
local c = matched_clients[1]
|
||||
-- if the focused window matched switch focus to next in list
|
||||
if 0 < findex and findex < n then
|
||||
c = matched_clients[findex+1]
|
||||
end
|
||||
local ctags = c:tags()
|
||||
if table.getn(ctags) == 0 then
|
||||
-- ctags is empty, show client on current tag
|
||||
local curtag = awful.tag.selected()
|
||||
awful.client.movetotag(curtag, c)
|
||||
else
|
||||
-- Otherwise, pop to first tag client is visible on
|
||||
awful.tag.viewonly(ctags[1])
|
||||
end
|
||||
-- And then focus the client
|
||||
client.focus = c
|
||||
c:raise()
|
||||
return
|
||||
end
|
||||
awful.util.spawn(cmd)
|
||||
end
|
||||
|
Loading…
Reference in a new issue