summaryrefslogtreecommitdiffstats
path: root/.config/awesome/ext.lua
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-10-03 02:47:17 +0200
committerGravatar Tom Willemsen2012-10-03 02:47:17 +0200
commitb4e8c45e18cec74210e8d3d5c0d46ebcc41e5024 (patch)
tree263d4290d65a86a07db692e5e6098d5e08a25fc8 /.config/awesome/ext.lua
parentdf6be906492b103c56b12917874a7a2b3ae911ee (diff)
downloaddotfiles-b4e8c45e18cec74210e8d3d5c0d46ebcc41e5024.tar.gz
dotfiles-b4e8c45e18cec74210e8d3d5c0d46ebcc41e5024.zip
.config/awesome/rc.lua
Diffstat (limited to '.config/awesome/ext.lua')
-rw-r--r--.config/awesome/ext.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/.config/awesome/ext.lua b/.config/awesome/ext.lua
new file mode 100644
index 0000000..d564867
--- /dev/null
+++ b/.config/awesome/ext.lua
@@ -0,0 +1,67 @@
+local client=client
+local awful=awful
+local pairs=pairs
+local table=table
+
+module("ext")
+
+-- Returns true if all pairs in table1 are present in table2
+function match(table1, table2)
+ for k, v in pairs(table1) do
+ if table[k] ~= v and not table2[k]:find(v) then
+ return false
+ end
+ end
+
+ return true
+end
+
+--- 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
+function run_or_raise(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 match(properties, c) then
+ n = n + 1
+ matched_clients[n] = c
+
+ if n == 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()
+ awful.screen.focus(c.screen)
+ return
+ end
+ awful.util.spawn(cmd)
+end