#!/usr/bin/bash
# ABOUTME: Waybar module that outputs the active power profile as JSON.
# ABOUTME: Referenced by the Waybar custom/cpugov config.

# The ppd profile, not scaling_governor: under amd-pstate in active mode the governor
# stays where the driver put it and says nothing about the profile the user picked.
CPU_GOV=$(powerprofilesctl get 2>/dev/null)

case $CPU_GOV in
  performance)
    CPU_GOV_SHORT=󰓅
    ;;
  balanced)
    CPU_GOV_SHORT=󰾅
    ;;
  power-saver)
    CPU_GOV_SHORT=󰌪
    ;;
  *)
    CPU_GOV_SHORT="?"
    ;;
esac

case $CPU_GOV in
  performance) CPU_GOV_FULL="Performance" ;;
  balanced) CPU_GOV_FULL="Balanced" ;;
  power-saver) CPU_GOV_FULL="Powersave" ;;
  *) CPU_GOV_FULL="Unknown" ;;
esac

jq --compact-output -n \
  --arg text "$CPU_GOV_SHORT" \
  --arg alt "$CPU_GOV_FULL" \
  --arg tooltip "CPU Mode: $CPU_GOV_FULL" \
  --arg class "cpugov" \
  '{text: $text, alt: $alt, tooltip: $tooltip, class: $class}'
