-
-
Notifications
You must be signed in to change notification settings - Fork 33
AwesomeWM
Stephen Bolton edited this page Jan 23, 2022
·
2 revisions
This will be a quick example of how we can wire up yubikey-touch-detector to AwesomeWM widgets. First we set up a watcher that will emit when a touch is expected and a widget that subscribes and changes its color on the events. The sky is the limit with Awesome widgets and hopefully this is a good starting point in your dotfiles.
First create the watcher that will emit the signals along with the event and context of the event.
signal: "yubikey"
event: "start" or "stop"
context: "GPG" or "U2F"
This has the only external dependency which is openbsd-netcat, which gives us the
-U
flag
local awful = require 'awful'
local naughty = require 'naughty'
-- Calling `echo` produces a newline which the awesome callback needs to process line by line
local event_stream = [[ bash -c '
nc -U $XDG_RUNTIME_DIR/yubikey-touch-detector.socket | while read -n5 cmd; do
echo $cmd
done
']]
awful.spawn.with_line_callback(event_stream, {
stdout = function(line)
local event, context
-- U2F
if line:match("U2F") then
context = "U2F"
-- started waiting
if line:match("_1") then
event = "start"
else
event = "stop"
end
-- GPG
else
context = "GPG"
-- started waiting
if line:match("_1") then
event = "start"
else
event = "stop"
end
end
awesome.emit_signal("yubikey", event, context)
end,
stderr = function(line)
naughty.notify({ title = "Yubikey Watcher Failure", text = line })
end
})
Now for the widget that subscribes to the signal and updates its background color when a touch is expected. In this example the context
arg of the signal won't get used but it is there if you'd like to incorporate it.
local wibox = require 'wibox'
local gfs = require 'gears.filesystem'
local gc = require 'gears.color'
-- SVG or PNG image works best in this example
local icon = "path/to/an/icon"
local white_icon = gc.recolor_image(icon, "#FFF")
local yellow_icon = gc.recolor_image(icon, "#FFE6B3")
local yubikey = wibox.widget {
image = white_icon,
widget = wibox.widget.imagebox,
resize = true
}
-- change the icon color when based on if a touch is expected or not
awesome.connect_signal("yubikey", function (event)
local new_icon
if event == "start" then
new_icon = yellow_icon
else
new_icon = white_icon
end
yubikey.image = new_icon
end)
return yubikey