diff --git a/dot_config/bspwm/executable_bspwmrc b/dot_config/bspwm/executable_bspwmrc index ede62e0..422f0ab 100644 --- a/dot_config/bspwm/executable_bspwmrc +++ b/dot_config/bspwm/executable_bspwmrc @@ -66,6 +66,7 @@ bspc rule -a Code desktop="code" follow=on focus=on bspc rule -a Sylpheed desktop="mail" follow=off focus=off bspc rule -a thunderbird desktop="mail" follow=off focus=off bspc rule -a discord desktop="text" follow=on focus=on +bspc rule -a telegram desktop="text" follow=on focus=on bspc rule -a WebCord desktop="text" follow=on focus=on bspc rule -a Zathura state=tiled bspc rule -a Xfce4-appfinder state=floating diff --git a/dot_config/polybar/config.ini b/dot_config/polybar/config.ini index d46d94d..9fd8c9f 100644 --- a/dot_config/polybar/config.ini +++ b/dot_config/polybar/config.ini @@ -62,7 +62,7 @@ separator-foreground = ${colors.disabled} font-0 = Hack Nerd Font modules-left = bspwm xwindow -modules-right = xkeyboard pulseaudio memory-info cpu-freq wlan battery-int battery-ext date tray +modules-right = xkeyboard pulseaudio wlan battery-int battery-ext cpu-mode remaining date tray cursor-click = pointer cursor-scroll = ns-resize @@ -77,6 +77,17 @@ wm-restack = bspwm override-redirect = true +[module/cpu-mode] +type = custom/script +exec = ~/.config/polybar/power-mode.sh status +click-left = ~/.config/polybar/power-mode.sh +interval = 0 + +[module/remaining] +type = custom/script +exec = ~/.config/polybar/battery.sh +interval = 0 + ; Tray Support [module/tray] type = internal/tray @@ -236,6 +247,107 @@ animation-low-0 = "!" animation-low-1 = " " animation-low-framerate = 750 +[module/battery-time] +type = internal/battery + +full-at = 95 +low-at = 5 + +; Use the following command to list batteries and adapters: +; $ ls -1 /sys/class/power_supply/ +battery = BAT1 +adapter = AC + +poll-interval = 30 + + +; see "man date" for details on how to format the time string +; NOTE: if you want to use syntax tags here you need to use %%{...} +; Default: %H:%M:%S +time-format = %H:%M + +; Available tags: +; (default) +; +; +; +format-charging = + +; Available tags: +; (default) +; +; +; +; format-discharging = + +; Available tags: +; (default) +; +; +;format-full = +;format-full-foreground = ${colors.bat-full} + +; Format used when battery level drops to low-at +; If not defined, format-discharging is used instead. +; Available tags: +; +; +; +; +; New in version 3.6.0 +format-low = +format-low-foreground = ${colors.bat-low} + + +; Available tokens: +; %percentage% (default) - is set to 100 if full-at is reached +; %percentage_raw% +; %time% +; %consumption% (shows current charge rate in watts) +label-charging = %time% + +; Available tokens: +; %percentage% (default) - is set to 100 if full-at is reached +; %percentage_raw% +; %time% +; %consumption% (shows current discharge rate in watts) +label-discharging = %time% + +; Available tokens: +; %percentage% (default) - is set to 100 if full-at is reached +; %percentage_raw% +;label-full = FULL + +; Available tokens: +; %percentage% (default) - is set to 100 if full-at is reached +; %percentage_raw% +; %time% +; %consumption% (shows current discharge rate in watts) +; New in version 3.6.0 +label-low = %time% + +; Only applies if is used +ramp-capacity-0 =  +ramp-capacity-1 =  +ramp-capacity-2 =  +ramp-capacity-3 =  +ramp-capacity-4 =  + +; Only applies if is used +animation-charging-0 = " " +animation-charging-1 = " " +animation-charging-2 = " " +animation-charging-3 = " " +animation-charging-4 = " " +; Framerate in milliseconds +animation-charging-framerate = 750 + +; Only applies if is used +; New in version 3.6.0 +animation-low-0 = "!" +animation-low-1 = " " +animation-low-framerate = 750 + [module/battery-ext] type = internal/battery diff --git a/dot_config/polybar/executable_battery.sh b/dot_config/polybar/executable_battery.sh new file mode 100644 index 0000000..9c87640 --- /dev/null +++ b/dot_config/polybar/executable_battery.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# battery-time.sh — remaining battery time for BAT0 + BAT1 (Polybar-friendly) + +BAT_PATH="/sys/class/power_supply" +BATTERIES=(BAT0 BAT1) + +total_energy=0 +total_power=0 + +for bat in "${BATTERIES[@]}"; do + if [[ -f "$BAT_PATH/$bat/energy_now" && -f "$BAT_PATH/$bat/power_now" ]]; then + energy=$(cat "$BAT_PATH/$bat/energy_now") + power=$(cat "$BAT_PATH/$bat/power_now") + elif [[ -f "$BAT_PATH/$bat/charge_now" && -f "$BAT_PATH/$bat/current_now" ]]; then + # Convert Ah/A to Wh assuming voltage in volts (approx 1 V = 1 W/A for rough estimate) + energy=$(cat "$BAT_PATH/$bat/charge_now") + power=$(cat "$BAT_PATH/$bat/current_now") + else + continue + fi + + # Sum up + total_energy=$((total_energy + energy)) + total_power=$((total_power + power)) +done + +# Avoid division by zero +if (( total_power == 0 )); then + total_sec=0 +else + # remaining time in seconds = total stored / total draw + total_sec=$(( total_energy * 3600 / total_power )) +fi + +hours=$(( total_sec / 3600 )) +minutes=$(( (total_sec % 3600) / 60 )) + +# determine color +if (( total_sec <= 1800 )); then + color="%{F#FF0000}" # red +elif (( total_sec <= 7200 )); then + color="%{F#FFFF00}" # yellow +else + color="%{}" +fi + +# output for Polybar +echo "${color}${hours}h ${minutes}m%{F-}" + diff --git a/dot_config/polybar/executable_power-mode.sh b/dot_config/polybar/executable_power-mode.sh new file mode 100644 index 0000000..9c2f4be --- /dev/null +++ b/dot_config/polybar/executable_power-mode.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# u-mode-toggle.sh — toggle CPU modes or show current mode (Polybar-friendly + Dunstify) + +GOV_PATH="/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" +EPP_PATH="/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference" + +# --- Define modes --- +declare -A MODE_VAR # internal code name +declare -A MODE_BAR # Polybar short name +declare -A MODE_NOTIFY # Notification full name +declare -A MODE_COLOR # Polybar color + +# Internal names +MODE_VAR=( ["power"]="powersave|power" ["balanced"]="powersave|balance_power" ["performance"]="performance|performance" ) + +# Polybar short names +MODE_BAR=( ["power"]="P" ["balanced"]="B" ["performance"]="X" ) + +# Dunst notification full names +MODE_NOTIFY=( ["power"]="Power-Saving" ["balanced"]="Balanced" ["performance"]="Full-Performance" ) + +# Polybar colors +MODE_COLOR=( ["power"]="%{F#00FF00}" ["balanced"]="%{F#FFFF00}" ["performance"]="%{F#FF0000}" ) + +# --- function to determine current mode --- +get_current_mode() { + local gov=$1 + local epp=$2 + for mode in "${!MODE_VAR[@]}"; do + IFS='|' read -r m_gov m_epp <<< "${MODE_VAR[$mode]}" + if [[ "$gov" == "$m_gov" && "$epp" == "$m_epp" ]]; then + echo "$mode" + return + fi + done + echo "unknown" +} + +# --- status-only mode --- +if [[ "$1" == "status" ]]; then + gov=$(cat "$GOV_PATH") + epp=$(cat "$EPP_PATH") + mode=$(get_current_mode "$gov" "$epp") + echo "${MODE_COLOR[$mode]}${MODE_BAR[$mode]}%{F-}" + exit 0 +fi + +# --- toggle mode --- +current_gov=$(cat "$GOV_PATH") +current_epp=$(cat "$EPP_PATH") +current_mode=$(get_current_mode "$current_gov" "$current_epp") + +# determine next mode in cycle: power -> balanced -> performance -> power ... +case "$current_mode" in + "power") new_mode="balanced" ;; + "balanced") new_mode="performance" ;; + *) new_mode="power" ;; +esac + +# apply to all CPUs +IFS='|' read -r new_gov new_epp <<< "${MODE_VAR[$new_mode]}" +for cpu_dir in /sys/devices/system/cpu/cpu[0-9]*; do + echo "$new_gov" > "$cpu_dir/cpufreq/scaling_governor" + echo "$new_epp" > "$cpu_dir/cpufreq/energy_performance_preference" +done + +# --- Dunstify notification --- +dunstify \ + -u normal \ + -h string:x-dunst-stack-tag:power-mode \ + -a "CPU Mode" \ + "> ${MODE_NOTIFY[$new_mode]}" \ + "Governor: $new_gov + EPP: $new_epp" + +# --- echo for Polybar --- +echo "${MODE_COLOR[$new_mode]}${MODE_BAR[$new_mode]}%{F-}" +