[awesome] add bluetooth widget (replaces blueman)
This commit is contained in:
parent
ae4a14ebde
commit
d3d7da3456
Before Width: | Height: | Size: 139 B After Width: | Height: | Size: 139 B |
Before Width: | Height: | Size: 139 B After Width: | Height: | Size: 139 B |
Before Width: | Height: | Size: 139 B After Width: | Height: | Size: 139 B |
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue