summaryrefslogtreecommitdiff
path: root/utils.lua
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2016-12-25 12:03:06 +0100
committerAnton Khirnov <anton@khirnov.net>2016-12-25 12:03:06 +0100
commite8bb1f4a1844f07fc2f6973f2e7b400f2ddf2f3d (patch)
tree73e0028d455fef267c5c8a46c32a45430af9683c /utils.lua
Initial commit.
Diffstat (limited to 'utils.lua')
-rw-r--r--utils.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/utils.lua b/utils.lua
new file mode 100644
index 0000000..1df9690
--- /dev/null
+++ b/utils.lua
@@ -0,0 +1,42 @@
+local M = {}
+
+local awful = require("awful")
+
+-- mapping from logical screen indices to indices corresponding to their
+-- physical layout
+local function map_screen_physical(n)
+ local function screen_cmp(s1, s2)
+ return s1[2].geometry.x < s2[2].geometry.x
+ end
+
+ local screens = {}
+ for s = 1, screen.count() do
+ screens[s] = {s, screen[s]}
+ end
+
+ table.sort(screens, screen_cmp)
+
+ if screens[n] ~= nil then
+ return screens[n][1]
+ end
+ return nil
+end
+
+local function screen_focus_physical(n)
+ local idx_logical = map_screen_physical(n)
+ if idx_logical then
+ awful.screen.focus(idx_logical)
+ end
+end
+
+function M.screen_focus_physical(n) screen_focus_physical(n) end
+
+-- audio control functions
+local function vol_control(n)
+ local cmd = string.format("amixer -q set Master %d%%", math.abs(n)) .. (n < 0 and "-" or "+")
+ awful.util.spawn(cmd)
+end
+
+function M.vol_control(n) vol_control(n) end
+
+return M