From 4b91be7b57ded48f0f22a827ed22ba526f7972de Mon Sep 17 00:00:00 2001
From: Christian Colglazier <christian@cacolglazier.com>
Date: Sat, 24 Oct 2020 11:56:28 -0400
Subject: [PATCH] Battery percentage

---
 i3/shared.conf               |  5 +++++
 polybar/config               | 42 ++++++++++++++----------------------
 scripts/get-mouse-battery.sh | 11 ++++++++++
 3 files changed, 32 insertions(+), 26 deletions(-)
 create mode 100755 scripts/get-mouse-battery.sh

diff --git a/i3/shared.conf b/i3/shared.conf
index cabea44..06452a1 100644
--- a/i3/shared.conf
+++ b/i3/shared.conf
@@ -72,6 +72,11 @@ bindsym $mod+space focus mode_toggle
 # focus the parent container
 bindsym $mod+a focus parent
 
+# media controls
+bindsym Ctrl+Left exec playerctl previous
+bindsym Ctrl+Down exec playerctl play-pause
+bindsym Ctrl+Right exec playerctl next
+
 # Gaps
 set $inner 16
 set $outer 0
diff --git a/polybar/config b/polybar/config
index dd1878f..b94c6bd 100644
--- a/polybar/config
+++ b/polybar/config
@@ -37,7 +37,7 @@ font-5 = Font Awesome 5 Free Solid:pixelsize=70;3
 
 modules-left = i3
 modules-center = xwindow
-modules-right = backlight volume network battery date
+modules-right = backlight volume network battery mouse-battery date
 
 tray-position = right
 tray-padding = 2
@@ -47,42 +47,26 @@ type = internal/xwindow
 label = %title:0:80:...%
 format-background = ${colors.black}
 
-[module/bspwm]
-type = internal/bspwm
-
-label-focused = %index%
-label-focused-background = ${colors.blue}
-label-focused-underline= ${colors.pink}
-label-focused-padding = 2
-
-label-occupied = %index%
-label-occupied-padding = 2
-
-label-urgent = %index%!
-label-urgent-background = ${colors.alert}
-label-urgent-padding = 2
-
-label-empty = %index%
-label-empty-foreground = ${colors.foreground-alt}
-label-empty-padding = 2
-
 [module/i3]
 type = internal/i3
 format = <label-state> <label-mode>
 index-sort = true
 wrapping-scroll = false
 
+strip-wsnumbers = true
+fuzzy-match = true
+
 label-mode-padding = 2
 label-mode-foreground = #000
 label-mode-background = ${colors.pink}
 
 label-focused = %index%
-label-focused-background = ${module/bspwm.label-focused-background}
-label-focused-underline = ${module/bspwm.label-focused-underline}
-label-focused-padding = ${module/bspwm.label-focused-padding}
+label-focused-background = ${colors.blue}
+label-focused-underline = ${colors.pink}
+label-focused-padding = 2
 
 label-unfocused = %index%
-label-unfocused-padding = ${module/bspwm.label-occupied-padding}
+label-unfocused-padding = 2
 
 label-visible = %index%
 label-visible-background = ${self.label-focused-background}
@@ -90,8 +74,8 @@ label-visible-underline = ${self.label-focused-background}
 label-visible-padding = ${self.label-focused-padding}
 
 label-urgent = %index%!
-label-urgent-background = ${module/bspwm.label-urgent-background}
-label-urgent-padding = ${module/bspwm.label-urgent-padding}
+label-urgent-background = ${colors.alert}
+label-urgent-padding = 2
 
 [module/date]
 type = internal/date
@@ -192,6 +176,12 @@ label-connected-underline = ${colors.blue}
 label-disconnected = 
 label-disconnected-underline = ${colors.pink}
 
+[module/mouse-battery]
+type = custom/script
+exec = ~/.config/scripts/get-mouse-battery.sh
+label = %output%
+interval = 60
+
 [settings]
 screenchange-reload = true
 ;compositing-background = xor
diff --git a/scripts/get-mouse-battery.sh b/scripts/get-mouse-battery.sh
new file mode 100755
index 0000000..63767e4
--- /dev/null
+++ b/scripts/get-mouse-battery.sh
@@ -0,0 +1,11 @@
+#! /bin/bash
+
+mouseState=$(upower -i /org/freedesktop/UPower/devices/mouse_hidpp_battery_0)
+batteryPercentage=$(echo $mouseState | grep percentage | grep -Po '\d+%')
+charging=$(echo $mouseState | grep 'state: charging')
+
+if [ ! -z "$charging" ]; then
+    echo Charging
+else
+    echo $batteryPercentage
+fi