From d3d7da3456c7483116825e42f95accbf08380a2d Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 7 Jun 2019 14:21:32 +0000 Subject: [PATCH] [awesome] add bluetooth widget (replaces blueman) --- .../awesome/icons/bluetooth-active.png} | Bin .../awesome/icons/bluetooth-off.png} | Bin .../awesome/icons/bluetooth-on.png} | Bin home/.config/awesome/rc.lua | 2 +- home/.config/awesome/widgets.lua | 48 ++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) rename home/{.local/share/icons/hicolor/16x16/status/blueman-active.png => .config/awesome/icons/bluetooth-active.png} (100%) rename home/{.local/share/icons/hicolor/16x16/status/blueman-disabled.png => .config/awesome/icons/bluetooth-off.png} (100%) rename home/{.local/share/icons/hicolor/16x16/status/blueman-tray.png => .config/awesome/icons/bluetooth-on.png} (100%) diff --git a/home/.local/share/icons/hicolor/16x16/status/blueman-active.png b/home/.config/awesome/icons/bluetooth-active.png similarity index 100% rename from home/.local/share/icons/hicolor/16x16/status/blueman-active.png rename to home/.config/awesome/icons/bluetooth-active.png diff --git a/home/.local/share/icons/hicolor/16x16/status/blueman-disabled.png b/home/.config/awesome/icons/bluetooth-off.png similarity index 100% rename from home/.local/share/icons/hicolor/16x16/status/blueman-disabled.png rename to home/.config/awesome/icons/bluetooth-off.png diff --git a/home/.local/share/icons/hicolor/16x16/status/blueman-tray.png b/home/.config/awesome/icons/bluetooth-on.png similarity index 100% rename from home/.local/share/icons/hicolor/16x16/status/blueman-tray.png rename to home/.config/awesome/icons/bluetooth-on.png diff --git a/home/.config/awesome/rc.lua b/home/.config/awesome/rc.lua index ef80703..8115dc4 100644 --- a/home/.config/awesome/rc.lua +++ b/home/.config/awesome/rc.lua @@ -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") diff --git a/home/.config/awesome/widgets.lua b/home/.config/awesome/widgets.lua index d129dd7..3214402 100644 --- a/home/.config/awesome/widgets.lua +++ b/home/.config/awesome/widgets.lua @@ -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