[awesome] add bluetooth widget (replaces blueman)

legacy
Simon Bruder 2019-06-07 14:21:32 +00:00
parent ae4a14ebde
commit d3d7da3456
No known key found for this signature in database
GPG Key ID: 6F03E0000CC5B62F
5 changed files with 49 additions and 1 deletions

View File

Before

Width:  |  Height:  |  Size: 139 B

After

Width:  |  Height:  |  Size: 139 B

View File

Before

Width:  |  Height:  |  Size: 139 B

After

Width:  |  Height:  |  Size: 139 B

View File

Before

Width:  |  Height:  |  Size: 139 B

After

Width:  |  Height:  |  Size: 139 B

View File

@ -203,6 +203,7 @@ awful.screen.connect_for_each_screen(function(s)
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
wibox.widget.systray(),
widgets.bluetooth,
widgets.netdown_icon,
widgets.netdown.widget,
widgets.netup_icon,
@ -514,7 +515,6 @@ client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_n
awful.util.spawn({"pulseaudio"})
awful.util.spawn({"nm-applet"})
awful.util.spawn({"blueman-applet"})
awful.util.spawn({"ibus-daemon", "-r", "--xim"})
awful.util.spawn({"/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1"})
awful.util.spawn_with_shell("~/bin/spawn-once pasystray")

View File

@ -1,6 +1,9 @@
local awful = require("awful")
local wibox = require("wibox")
local table = require("gears.table")
local lain = require("lain")
local helpers = require("lain.helpers")
local markup = lain.util.markup
local theme = require("theme")
@ -62,4 +65,49 @@ widgets.bat = lain.widget.bat({
end
})
widgets.bluetooth = wibox.widget.imagebox(iconsdir .. "bluetooth-on.png")
widgets.bluetooth.pass_state = function(callback)
helpers.async_with_shell("/sbin/rfkill -n -o SOFT list bluetooth|uniq", function(state)
callback(state:gsub("^%s*(.-)%s*$", "%1"))
end)
end
widgets.bluetooth.update = function()
widgets.bluetooth.pass_state(function(state)
if state == "blocked" then
widgets.bluetooth:set_image(iconsdir .. "bluetooth-off.png")
else
helpers.async_with_shell("for device in $(bluetoothctl devices|cut -d' ' -f 2);do bluetoothctl info $device|grep 'Connected: yes';done|wc -l", function(connected_devices)
if tonumber(connected_devices) > 0 then
widgets.bluetooth:set_image(iconsdir .. "bluetooth-active.png")
else
widgets.bluetooth:set_image(iconsdir .. "bluetooth-on.png")
end
end)
end
end)
end
widgets.bluetooth.toggle = function()
widgets.bluetooth.pass_state(function(state)
if state == "blocked" then
awful.spawn.spawn({ "/sbin/rfkill", "unblock", "bluetooth" })
else
awful.spawn.spawn({ "/sbin/rfkill", "block", "bluetooth" })
end
widgets.bluetooth.update()
end)
end
widgets.bluetooth:buttons(
table.join(
awful.button({ }, 1, widgets.bluetooth.toggle),
awful.button({ }, 3, function()
awful.spawn.spawn({ "blueman-manager" })
end)
)
)
helpers.newtimer("bluetooth", 10, widgets.bluetooth.update)
return widgets