|
| 1 | +--Simple lua OS examples by Paul Hedderly |
| 2 | +-- PREREQUISITES: |
| 3 | +-- luarocks install luasocket # optional if you will use your own connectors (see below) |
| 4 | +-- luarocks install luabitop # you don't need this for lua 5.3 |
| 5 | +-- luarocks install luasec # you don't need this if you don't want to use SSL connections |
| 6 | +-- luarocks install luamqtt |
| 7 | + |
| 8 | +-- Example - A lot of these will depend on other configs and will need to be localised |
| 9 | +-- [lua i3msg] |
| 10 | +-- script = confgs/i3msg.lua |
| 11 | +-- default-handler = i3msg |
| 12 | +-- |
| 13 | +-- nanomap.{1..10} > i3msg.workspace.{1..10} -- Jump to i3 workspace |
| 14 | +-- nanomap.10 > i3msg.muteall |
| 15 | +-- nanomap.11 > i3msg.run.pasink |
| 16 | +-- nanomap.12 > i3msg.showhide.retext |
| 17 | +-- nanomap.13 > i3msg.showhide.paprefs |
| 18 | +-- nanomap.14 > i3msg.showhide.pavucontrol |
| 19 | +-- nanomap.15 > i3msg.showhide.keepassxc |
| 20 | +-- nanomap.16 > i3msg.showhide.microsoft teams - insiders |
| 21 | + |
| 22 | +-- trackpad.gestureoo852 > i3msg.macro.volup -- see my trackpad.lua example |
| 23 | +-- trackpad.gestureoo25> i3msg.macro.voldown |
| 24 | + |
| 25 | +function i3msg(v) -- Use a default function - then you can use any input channel name |
| 26 | + |
| 27 | + m=0.31 |
| 28 | + M=0.99 |
| 29 | + A = - M*m^2 / (M^2 - 2*m*M) |
| 30 | + B = M*m^2 / (M^2 - 2*m*M) |
| 31 | + C = math.log((M - m)^2 / m^2) |
| 32 | + inchan=input_channel() |
| 33 | + first=inchan:gsub("%..*","") |
| 34 | + last=inchan:gsub('^.-%.',"") |
| 35 | + |
| 36 | + if (v==0) then return; end -- Here were do not care that the control was released |
| 37 | + |
| 38 | + if (inchan == "macro.myadminpass") then |
| 39 | + os.execute("/home/user/bin/macroscripttotypemyadminpassword") |
| 40 | + |
| 41 | + elseif (first == "workspace") then |
| 42 | + -- print("i3-msg workspace number "..last) |
| 43 | + os.execute("i3-msg workspace number "..last) |
| 44 | + |
| 45 | + elseif (first=="showhide") then |
| 46 | + os.execute("i3-msg '[instance=\""..last.."\"] scratchpad show;'") |
| 47 | + |
| 48 | + elseif (inchan=="macro.volup") then |
| 49 | + os.execute("pactl set-sink-volume 0 +5%") |
| 50 | + |
| 51 | + elseif (inchan=="macro.voldown") then |
| 52 | + os.execute("pactl set-sink-volume 0 -10%") |
| 53 | + |
| 54 | + elseif (first=="sinkvol") then |
| 55 | + os.execute("pactl set-sink-volume "..last.." "..math.floor(100*(A+B*math.exp(C*v))).."%") |
| 56 | + |
| 57 | + elseif (first=="vol") then |
| 58 | + os.execute("pactl set-sink-volume "..last.." "..v) |
| 59 | + |
| 60 | + elseif (first=="srcvol") then |
| 61 | + os.execute("pactl set-source-volume "..last.." "..math.floor(100*(A+B*math.exp(C*v))).."%") |
| 62 | + |
| 63 | + elseif (first=="dsink") then |
| 64 | + os.execute("pactl set-default-sink "..last) |
| 65 | + |
| 66 | + elseif (first=="dsrc") then |
| 67 | + os.execute("pactl set-default-source "..last) |
| 68 | + |
| 69 | + elseif (first=="muteall") then |
| 70 | + os.execute("~/bin/muteall") |
| 71 | + |
| 72 | + else |
| 73 | + print("i3msg-notfound:"..first.." L:"..last.." v:"..v) |
| 74 | + end |
| 75 | +end |
0 commit comments