waybar: add mouse baterry indicator
This commit is contained in:
		
							parent
							
								
									910670ba0b
								
							
						
					
					
						commit
						b8cd22e425
					
				
					 7 changed files with 96 additions and 24 deletions
				
			
		| 
						 | 
					@ -10,29 +10,20 @@ if test -z "$CONTROLLER"; then
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CAPACITY=$(cat "$CONTROLLER/capacity")
 | 
					CAPACITY=$(cat "$CONTROLLER/capacity")
 | 
				
			||||||
 | 
					STATUS=$(cat "$CONTROLLER/status")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo -n ''
 | 
					echo -n ' '
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if test "$CAPACITY" -ge 90; then
 | 
					if test "$STATUS" = "Charging"; then
 | 
				
			||||||
    echo ''
 | 
					    echo -n ""
 | 
				
			||||||
elif test "$CAPACITY" -ge 90; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 80; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 70; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 60; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 50; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 40; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 30; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 20; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
elif test "$CAPACITY" -ge 10; then
 | 
					 | 
				
			||||||
    echo ''
 | 
					 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
    echo ''
 | 
					    print-battery-icon "$CAPACITY"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Add terminating newline
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Tooltip
 | 
				
			||||||
 | 
					echo -n ''
 | 
				
			||||||
 | 
					print-battery-icon "$CAPACITY"
 | 
				
			||||||
 | 
					echo " $CAPACITY%"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -137,7 +137,9 @@
 | 
				
			||||||
      libinput
 | 
					      libinput
 | 
				
			||||||
      libratbag
 | 
					      libratbag
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
    controller-battery = [ ];
 | 
					    print-battery-icon = [ ];
 | 
				
			||||||
 | 
					    controller-battery = [ print-battery-icon ];
 | 
				
			||||||
 | 
					    mouse-battery = [ print-battery-icon ];
 | 
				
			||||||
    _docker-block-external-connections = [
 | 
					    _docker-block-external-connections = [
 | 
				
			||||||
      iptables
 | 
					      iptables
 | 
				
			||||||
      gawk
 | 
					      gawk
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										39
									
								
								scripts/mouse-battery
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										39
									
								
								scripts/mouse-battery
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MODEL_NAME_FILE=$(rg --files-with-matches G502 /sys/class/power_supply/*/model_name | head -n1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if test -z "$MODEL_NAME_FILE"; then
 | 
				
			||||||
 | 
					    echo
 | 
				
			||||||
 | 
					    exit 0
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MOUSE=$(dirname "$MODEL_NAME_FILE")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if test -z "$MOUSE"; then
 | 
				
			||||||
 | 
					    echo
 | 
				
			||||||
 | 
					    exit 0
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CAPACITY=$(cat "$MOUSE/capacity")
 | 
				
			||||||
 | 
					STATUS=$(cat "$MOUSE/status")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo -n '🖱️'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if test "$STATUS" = "Charging"; then
 | 
				
			||||||
 | 
					    echo -n ""
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					    print-battery-icon "$CAPACITY"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if test "$CAPACITY" -lt 50; then
 | 
				
			||||||
 | 
					    echo -n "$CAPACITY%"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Tooltip
 | 
				
			||||||
 | 
					echo -n '🖱️'
 | 
				
			||||||
 | 
					print-battery-icon "$CAPACITY"
 | 
				
			||||||
 | 
					echo " $CAPACITY%"
 | 
				
			||||||
							
								
								
									
										33
									
								
								scripts/print-battery-icon
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										33
									
								
								scripts/print-battery-icon
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,33 @@
 | 
				
			||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if test $# -ne 1; then
 | 
				
			||||||
 | 
					    echo "Usage $0" >&2
 | 
				
			||||||
 | 
					    exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					CAPACITY="$1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if test "$CAPACITY" -ge 90; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 90; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 80; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 70; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 60; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 50; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 40; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 30; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 20; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					elif test "$CAPACITY" -ge 10; then
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					    echo -n ''
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
| 
						 | 
					@ -49,6 +49,7 @@
 | 
				
			||||||
  services.logind.extraConfig = ''
 | 
					  services.logind.extraConfig = ''
 | 
				
			||||||
    HandlePowerKey=suspend
 | 
					    HandlePowerKey=suspend
 | 
				
			||||||
  '';
 | 
					  '';
 | 
				
			||||||
 | 
					  services.upower.enable = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # This value determines the NixOS release from which the default
 | 
					  # This value determines the NixOS release from which the default
 | 
				
			||||||
  # settings for stateful data, like file locations and database versions
 | 
					  # settings for stateful data, like file locations and database versions
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,7 @@ in
 | 
				
			||||||
            "custom/playerctl"
 | 
					            "custom/playerctl"
 | 
				
			||||||
            "tray"
 | 
					            "tray"
 | 
				
			||||||
            "custom/controller-battery"
 | 
					            "custom/controller-battery"
 | 
				
			||||||
 | 
					            "custom/mouse-battery"
 | 
				
			||||||
            "custom/caffeine"
 | 
					            "custom/caffeine"
 | 
				
			||||||
            "pulseaudio"
 | 
					            "pulseaudio"
 | 
				
			||||||
            (lib.optional (osConfig.services.vpn.enable or false) "custom/vpn")
 | 
					            (lib.optional (osConfig.services.vpn.enable or false) "custom/vpn")
 | 
				
			||||||
| 
						 | 
					@ -164,7 +165,11 @@ in
 | 
				
			||||||
            format = "{}";
 | 
					            format = "{}";
 | 
				
			||||||
            exec = lib.getExe pkgs.controller-battery;
 | 
					            exec = lib.getExe pkgs.controller-battery;
 | 
				
			||||||
            interval = 1;
 | 
					            interval = 1;
 | 
				
			||||||
            tooltip = false;
 | 
					          };
 | 
				
			||||||
 | 
					          "custom/mouse-battery" = {
 | 
				
			||||||
 | 
					            format = "{}";
 | 
				
			||||||
 | 
					            exec = lib.getExe pkgs.mouse-battery;
 | 
				
			||||||
 | 
					            interval = 1;
 | 
				
			||||||
          };
 | 
					          };
 | 
				
			||||||
          "custom/caffeine" = {
 | 
					          "custom/caffeine" = {
 | 
				
			||||||
            format = "{}";
 | 
					            format = "{}";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,7 @@ window#waybar.solo {
 | 
				
			||||||
#custom-mpd,
 | 
					#custom-mpd,
 | 
				
			||||||
#custom-playerctl,
 | 
					#custom-playerctl,
 | 
				
			||||||
#custom-controller-battery,
 | 
					#custom-controller-battery,
 | 
				
			||||||
 | 
					#custom-mouse-battery,
 | 
				
			||||||
#tray,
 | 
					#tray,
 | 
				
			||||||
#clock,
 | 
					#clock,
 | 
				
			||||||
#network,
 | 
					#network,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue