added waybar config
This commit is contained in:
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
## TODO: proper clean up, get or info?
|
||||
|
||||
|
||||
battery_level=$(solaar show | grep "Battery: " | awk '{print $2}' | head -n1 | tr -d -c 0-9)
|
||||
[[ "$battery_level" -gt 50 ]] && exit
|
||||
echo "$battery_level"%
|
||||
|
||||
|
||||
#round() {
|
||||
# printf "%.${2:-0}f" "$1"
|
||||
#}
|
||||
|
||||
#temp_cpu=$(echo "$(sensors | grep Tctl | awk '{print $2}' | cut -c 2-3)")
|
||||
## temp_liquid=$(echo "$(liquidctl status | grep 'Liquid' | awk '{print $4}')°C")
|
||||
## rpm_fan=$(echo "$(liquidctl status | grep 'Fan' | awk '{print $4}')RPM")
|
||||
## rpm_pump=$(echo "$(liquidctl status | grep 'Pump' | awk '{print $4}')RPM")
|
||||
#power_core=$(echo "$(sensors | grep SVI2_P_Core | awk '{print $2}')")
|
||||
#power_soc=$(echo "$(sensors | grep SVI2_P_SoC | awk '{print $2}')")
|
||||
#power_package=$(echo "$power_core + $power_soc" | bc)
|
||||
#power_package="$(round $power_package 0) W"
|
||||
##usage=$(echo "$(grep 'cpu ' /proc/stat | awk '{cpu_usage=($2+$4)*100/($2+$4+$5)} END {printf "%0.2f%", cpu_usage}')")
|
||||
|
||||
##deprecated:
|
||||
##clock=$(lscpu | grep 'CPU MHz' | awk '{ print $3 }' | head -c4)
|
||||
|
||||
## clock=$(echo "$(cat /proc/cpuinfo | grep MHz | sort -r | head -n1 | awk '{ print $4 }' | cut -c-4)"Mhz)
|
||||
#clock=$(cat /proc/cpuinfo | grep MHz | sort -r | head -n1 | awk '{ print $4 }' | cut -c-4)
|
||||
|
||||
##divide clock in Mhz by 1000 for Ghz
|
||||
## clock_ghz=$( echo "scale=1; $clock/1000" | bc -l )
|
||||
#clock_ghz="$( echo "scale=1; $clock/1000" | bc -l | sed 's/\./,/g' )G"
|
||||
|
||||
## Get number of cores
|
||||
#CORECOUNT=$(grep -c ^processor /proc/cpuinfo)
|
||||
## Use top, skip the first 7 rows, count the sum of the values
|
||||
## in column 9 - the CPU column, do some simple rounding at the end
|
||||
#usage=$(top -bn 1 | awk -v n=$CORECOUNT 'NR > 7 { s += $9 } END { print int(s / n + .5); }')
|
||||
|
||||
|
||||
## echo "CPU $usage% CORE $temp_cpu LIQUID $temp_liquid FAN $rpm_fan PUMP $rpm_pump $clock Mhz $power_package"
|
||||
## echo "CPU $usage% $temp_cpu $clock $power_package"
|
||||
#[[ "$temp_cpu" -gt 50 || %usage -gt 33 ]] && echo "$usage% $power_package" || && exit
|
||||
|
||||
#echo "$usage% $temp_cpu°C $clock_ghz $power_package"
|
||||
|
||||
##
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
round() {
|
||||
printf "%.${2:-0}f" "$1"
|
||||
}
|
||||
|
||||
temp_cpu=$(echo "$(sensors | grep Tctl | awk '{print $2}' | cut -c 2-3)")
|
||||
# temp_liquid=$(echo "$(liquidctl status | grep 'Liquid' | awk '{print $4}')°C")
|
||||
# rpm_fan=$(echo "$(liquidctl status | grep 'Fan' | awk '{print $4}')RPM")
|
||||
# rpm_pump=$(echo "$(liquidctl status | grep 'Pump' | awk '{print $4}')RPM")
|
||||
power_core=$(echo "$(sensors | grep SVI2_P_Core | awk '{print $2}')")
|
||||
power_soc=$(echo "$(sensors | grep SVI2_P_SoC | awk '{print $2}')")
|
||||
power_package=$(echo "$power_core + $power_soc" | bc)
|
||||
power_package="$(round $power_package 0)W"
|
||||
#usage=$(echo "$(grep 'cpu ' /proc/stat | awk '{cpu_usage=($2+$4)*100/($2+$4+$5)} END {printf "%0.2f%", cpu_usage}')")
|
||||
|
||||
temp_liquid=$(echo "$(sensors | grep 'Coolant' | awk '{print $2}' | cut -c 2-)")
|
||||
temp_liquid=$(round $temp_liquid 0)
|
||||
|
||||
rpm_fan=$(echo "$(sensors | grep 'Fan' | awk '{print $2}')RPM")
|
||||
# rpm_fan=$(echo "$(liquidctl status | grep 'Fan' | awk '{print $4}')RPM")
|
||||
rpm_pump=$(echo "$(sensors | grep 'Pump' | awk '{print $2}')RPM")
|
||||
|
||||
#deprecated:
|
||||
#clock=$(lscpu | grep 'CPU MHz' | awk '{ print $3 }' | head -c4)
|
||||
|
||||
# clock=$(echo "$(cat /proc/cpuinfo | grep MHz | sort -r | head -n1 | awk '{ print $4 }' | cut -c-4)"Mhz)
|
||||
clock=$(cat /proc/cpuinfo | grep MHz | sort -r | head -n1 | awk '{ print $4 }' | cut -c-4)
|
||||
|
||||
#divide clock in Mhz by 1000 for Ghz
|
||||
# clock_ghz=$( echo "scale=1; $clock/1000" | bc -l )
|
||||
clock_ghz="$( echo "scale=1; $clock/1000" | bc -l | sed 's/\./,/g' )GHz"
|
||||
|
||||
# Get number of cores
|
||||
CORECOUNT=$(grep -c ^processor /proc/cpuinfo)
|
||||
# Use top, skip the first 7 rows, count the sum of the values
|
||||
# in column 9 - the CPU column, do some simple rounding at the end
|
||||
usage=$(top -bn 1 | awk -v n=$CORECOUNT 'NR > 7 { s += $9 } END { print int(s / n + .5); }')
|
||||
|
||||
|
||||
# echo "CPU $usage% CORE $temp_cpu LIQUID $temp_liquid FAN $rpm_fan PUMP $rpm_pump $clock Mhz $power_package"
|
||||
# echo "CPU $usage% $temp_cpu $clock $power_package"
|
||||
# [[ "$temp_cpu" -gt 50 || %usage -gt 33 ]] && echo "$usage% $power_package" && exit
|
||||
# [[ "$temp_cpu" -gt 50 || %usage -gt 33 ]] && echo "$usage% $power_package" || && exit
|
||||
|
||||
# [[ "$temp_liquid" -gt 35 ]] && echo "$usage% $temp_cpu°C $temp_liquid°C $power_package" && exit || echo "$usage% $temp_cpu°C $power_package"
|
||||
|
||||
[[ "$temp_liquid" -gt 38 ]] && echo "$usage% $temp_cpu°C $temp_liquid°C $power_package" && exit || echo "$usage% $power_package"
|
||||
echo "$usage% $temp_cpu°C $temp_liquid°C $rpm_fan $clock_ghz $power_package"
|
||||
|
||||
#
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
# curtesy of:
|
||||
#https://github.com/Alexays/Waybar/wiki/Module:-Custom
|
||||
|
||||
COUNT=$(dunstctl count waiting)
|
||||
ENABLED=""
|
||||
DISABLED=""
|
||||
if [ $COUNT != 0 ]; then DISABLED=" $COUNT"; fi
|
||||
if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED"; else echo "$DISABLED"; fi
|
||||
# if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED "; else echo "$DISABLED "; fi
|
||||
# if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED "; else echo "$DISABLED "; fi
|
||||
# if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED | "; else echo "$DISABLED "; fi
|
||||
# if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED | "; else echo "$DISABLED "; fi
|
||||
# if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED X "; else echo "$DISABLED "; fi
|
||||
# if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED "; else echo "$DISABLED "; fi
|
||||
# if dunstctl is-paused | grep -q "false" ; then echo "$ENABLED "; else echo "$DISABLED "; fi
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
|
||||
# version 2
|
||||
# written by fennek182
|
||||
# for personal use
|
||||
# waybar module to display gpu usage - for all gpus using mesa (intel)
|
||||
|
||||
|
||||
round() {
|
||||
number="$(echo $1 | sed 's/\./,/')"
|
||||
printf "%.${2:-0}f" "$number"
|
||||
}
|
||||
|
||||
gpu_usage=$(cat /sys/class/drm/card1/device/gpu_busy_percent)
|
||||
gpu_temp_core=$(sensors | grep "edge" | awk '{ print $2 }' | cut -c 2-3) #edge temp, there's also junction and mem
|
||||
gpu_temp_hotspot=$(sensors | grep "junction" | awk '{ print $2 }' | cut -c 2-3) #edge temp, there's also junction and mem
|
||||
gpu_temp_mem=$(sensors | grep "mem" | awk '{ print $2 }' | cut -c 2-3) #edge temp, there's also junction and mem
|
||||
gpu_clock=$(cat /sys/class/drm/card1/device/pp_dpm_sclk | grep "*" | awk '{ print $2 }')
|
||||
gpu_power=$(sensors | grep "PPT" | awk '{ print $2 }')
|
||||
gpu_power=$(echo "${gpu_power%%.*}")
|
||||
# gpu_power=$(sensors | grep "PPT" | awk '{ print $2 }' | head -c2)
|
||||
fan_current_rpm=$(sensors | grep "fan1" | awk '{ print $2 }')
|
||||
fan_max_rpm=$(sensors | grep "fan1" | awk '{ print $10 }')
|
||||
fan_duty=$(echo "$(awk "BEGIN { print "$fan_current_rpm/$fan_max_rpm*100" }" | head -c2 )")
|
||||
# vram_size=$(nvidia-smi -q | grep 'Total' | head -n1 | awk '{print int($3/1000)}')
|
||||
vram_size=20
|
||||
vram_used=$(cat /sys/class/drm/card1/device/mem_info_vram_used)
|
||||
# vram_used=$(echo $vram_used | sed 's/G//')
|
||||
|
||||
vram_used_percentage=$(echo "$(awk "BEGIN { print "$vram_used/21474836480*100" }" | cut -c1-4 )")
|
||||
vram_used_percentage=$(round $vram_used_percentage 0)
|
||||
|
||||
# todo: use MB and TB insted of MiB and GiB and hide the G if it's >= 1 GB
|
||||
|
||||
# auto format to human readable file size unit
|
||||
vram_used=$(printf %s\\n $vram_used | numfmt --to=si | sed 's/G*//g')
|
||||
# vram_used=$(printf %s\\n $vram_used | numfmt --to=iec-i | sed 's/.$//')
|
||||
|
||||
# make usage human readable
|
||||
# vram_used_mib=$(echo "$(awk "BEGIN { print "$vram_used/1024/1024" }" | head -c4)")
|
||||
|
||||
# when the usage in MiB is greater than 999MBiB, so over 1G
|
||||
# if [ ${#vram_used/1024/1024} -gt 1000 ]; then
|
||||
# vram_used=$(echo "$(awk "BEGIN { print "$vram_used/1024/1024/1024" }")G")
|
||||
# else
|
||||
# vram_used=$(echo "$(awk "BEGIN { print "$vram_used/1024/1024" }" | head -c3 )M")
|
||||
# fi
|
||||
|
||||
|
||||
#echo "GPU "$gpu_usage"% $gpu_temp°C "$gpu_clock"MHz "$gpu_power"W FAN "$fan_duty"% VRAM "$vram_used_percentage"% $vram_used" / "$vram_size"G
|
||||
|
||||
|
||||
# hide core clock and vram usage if gpu usage is below 50%
|
||||
# [[ $fan_duty == "0" ]] && echo ""$gpu_usage"% $gpu_temp_core°C "$gpu_power"W "$fan_duty"%"
|
||||
|
||||
# [[ $gpu_usage -lt 51 ]] && echo "$usage% $power_package"
|
||||
# [[ $gpu_usage -lt "51" ]] && echo ""$gpu_usage"% $gpu_temp_core°C "$gpu_power"W"
|
||||
|
||||
# when called from terminal, show the info and exit
|
||||
# TODO: make this properly check if run from terminal
|
||||
|
||||
[[ "$1" == "-a" ]] && echo ""$gpu_usage"% C: $gpu_temp_core°C H: $gpu_temp_hotspot°C M: $gpu_temp_mem°C "$gpu_clock" "$gpu_power"W "$fan_duty"% "$fan_current_rpm"RPM "$vram_used_percentage"% $vram_used"/"$vram_size"GB && exit
|
||||
|
||||
[[ $gpu_temp_core -lt "65" ]] && [[ $gpu_usage -lt "51" ]] && echo ""$gpu_usage"% "$gpu_power"W"
|
||||
[[ $gpu_temp_core -gt "66" ]] && echo ""$gpu_usage"% $gpu_temp_core °C "$gpu_power"W"
|
||||
|
||||
# [[ $gpu_usage -lt "51" ]] && echo ""$gpu_usage"% $gpu_temp_core°C "$gpu_power"W"
|
||||
# [[ $gpu_usage -lt "50" ]] && echo ""$gpu_usage"% $gpu_temp°C "$gpu_power"W "$fan_duty"%"
|
||||
# [[ $gpu_usage -lt "50" ]] && echo ""$gpu_usage"% $gpu_temp°C "$gpu_power"W "$fan_duty"% "$fan_current_rpm"RPM"
|
||||
|
||||
# echo "GPU "$gpu_usage"% $gpu_temp°C "$gpu_clock"MHz "$gpu_power"W FAN "$fan_duty"% VRAM "$vram_used_percentage"% $vram_used"/"$vram_size"G
|
||||
# echo ""$gpu_usage"% $gpu_temp°C "$gpu_clock"MHz "$gpu_power"W FAN "$fan_duty"% VRAM "$vram_used_percentage"% $vram_used"/"$vram_size"G
|
||||
# echo ""$gpu_usage"% $gpu_temp_core°C "$gpu_clock" "$gpu_power"W "$fan_duty"% "$fan_current_rpm"RPM "$vram_used_percentage"% $vram_used"/"$vram_size"G
|
||||
|
||||
# older output with more withspace for the temps - used until 2026-05-04:
|
||||
# echo ""$gpu_usage"% C: $gpu_temp_core°C H: $gpu_temp_hotspot°C M: $gpu_temp_mem°C "$gpu_clock" "$gpu_power"W "$fan_duty"% "$fan_current_rpm"RPM "$vram_used_percentage"% $vram_used"/"$vram_size"GB
|
||||
echo ""$gpu_usage"% C/H/M: $gpu_temp_core/$gpu_temp_hotspot/$gpu_temp_mem°C "$gpu_clock" "$gpu_power"W "$fan_duty"% "$fan_current_rpm"RPM "$vram_used_percentage"% $vram_used"GB
|
||||
|
||||
#
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
gpu_usage=$(nvidia-smi -q | grep 'Gpu' | awk '{ print $3 }')
|
||||
gpu_temp=$(nvidia-smi -q | grep 'GPU Current Temp' | awk '{ print $5 }')
|
||||
gpu_clock=$(nvidia-smi -q | grep 'Graphics' | head -n1 | awk '{ print $3 }')
|
||||
gpu_power=$(nvidia-smi -q | grep 'Power Draw' | awk '{ print $4 }' | awk -F. '{ print $1 }')
|
||||
fan_duty=$(nvidia-smi -q | grep 'Fan Speed' | awk '{ print $4 }')
|
||||
|
||||
vram_used=$(nvidia-smi -q | grep 'Used' | head -n1 | awk '{print $3}' | head -c4 | sed -r 's/[.]+/,/g')
|
||||
|
||||
# make usage human readable
|
||||
# when the usage in MiB is greater than 3 charaters, so over 1G
|
||||
if [ ${#vram_used} -gt 3 ]; then
|
||||
vram_used=$(echo "$(awk "BEGIN { print "$vram_used/1024" }" | head -c4)G")
|
||||
else
|
||||
vram_used=$(echo "$vram_used"M)
|
||||
fi
|
||||
|
||||
vram_used_percentage=$(nvidia-smi -q | grep 'Memory' | sed '3q;d' | awk '{print $3}')
|
||||
vram_size=$(nvidia-smi -q | grep 'Total' | head -n1 | awk '{print int($3/1000)}')
|
||||
|
||||
#echo "GPU "$gpu_usage"% $gpu_temp°C "$gpu_clock"MHz "$gpu_power"W FAN "$fan_duty"% VRAM "$vram_used_percentage"% $vram_used" / "$vram_size"G
|
||||
|
||||
# echo "GPU "$gpu_usage"% $gpu_temp°C "$gpu_clock"MHz "$gpu_power"W FAN "$fan_duty"% VRAM "$vram_used_percentage"% $vram_used"/"$vram_size"G
|
||||
# echo ""$gpu_usage"% $gpu_temp°C "$gpu_clock"MHz "$gpu_power"W FAN "$fan_duty"% VRAM "$vram_used_percentage"% $vram_used"/"$vram_size"G
|
||||
echo ""$gpu_usage"% $gpu_temp°C "$gpu_clock"MHz "$gpu_power"W "$fan_duty"% "$vram_used_percentage"% $vram_used"/"$vram_size"G
|
||||
|
||||
#
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
|
||||
: "${XDG_RUNTIME_DIR:?Environment variable XDG_RUNTIME_DIR not set}"
|
||||
: "${HYPRLAND_INSTANCE_SIGNATURE:?Environment variable HYPRLAND_INSTANCE_SIGNATURE not set}"
|
||||
|
||||
handle() {
|
||||
case "$1" in
|
||||
workspace* | focusedmon* | openwindow* | closewindow* | movewindow* | activewindow*)
|
||||
update_active_clients
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
update_active_clients() {
|
||||
# active_clients=$(hyprctl activeworkspace -j | jq -r .windows)
|
||||
# echo "$active_clients"
|
||||
clients=$(hyprctl clients -j | grep address | awk '{print $2}' | sed "s/\"//"| cut -c -14)
|
||||
active_window=$(hyprctl -j activewindow | jq -r '.address')
|
||||
|
||||
|
||||
while IFS= read -r line; do
|
||||
hyprctl dispatch setprop address:$line bordersize 1
|
||||
done <<< "$clients"
|
||||
|
||||
# echo $active_window
|
||||
hyprctl dispatch setprop address:$active_window bordersize 2
|
||||
}
|
||||
|
||||
# Initial update
|
||||
update_active_clients
|
||||
|
||||
# Listen to events and handle them
|
||||
socat -U - UNIX-CONNECT:"$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while IFS= read -r line; do
|
||||
handle "$line"
|
||||
done
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
round() {
|
||||
printf "%.${2:-0}f" "$1"
|
||||
}
|
||||
|
||||
temp_liquid=$(echo "$(sensors | grep 'Coolant' | awk '{print $2}' | cut -c 2-)")
|
||||
temp_liquid=$(round $temp_liquid 0)°C
|
||||
|
||||
# temp_liquid=$(echo "$(liquidctl status | grep 'Liquid' | awk '{print $4}')°C")
|
||||
|
||||
rpm_fan=$(echo "$(sensors | grep 'Fan' | awk '{print $2}')RPM")
|
||||
# rpm_fan=$(echo "$(liquidctl status | grep 'Fan' | awk '{print $4}')RPM")
|
||||
rpm_pump=$(echo "$(sensors | grep 'Pump' | awk '{print $2}')RPM")
|
||||
# rpm_pump=$(echo "$(liquidctl status | grep 'Pump' | awk '{print $4}')RPM")
|
||||
|
||||
# echo "LIQUID $temp_liquid FAN $rpm_fan PUMP $rpm_pump"
|
||||
# echo "KRAKEN $temp_liquid FAN $rpm_fan PUMP $rpm_pump"
|
||||
# echo "$temp_liquid $rpm_fan $rpm_pump"
|
||||
|
||||
[[ "$rpm_fan" =~ ^4* || "$rpm_fan" =~ ^5* ]] && echo "" && exit
|
||||
|
||||
echo "$temp_liquid $rpm_fan"
|
||||
|
||||
#
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
usage=$(echo "$(free -h --si | awk '/^Speicher:/ {print $3 "/" $2}')" | sed 's/G//')GB
|
||||
usage_short=$(echo "$(free -h --si | awk '/^Speicher:/ {print $3}')" | sed 's/G//')GB
|
||||
# usage=$(echo "$(free -h --si | awk '/^Speicher:/ {print $3 "/" $2}')")
|
||||
|
||||
percentage=$(echo "$(free --si | awk '/^Speicher:/ {print int($3/$2 * 100.0)}')%")
|
||||
# echo "RAM $percentage $usage"
|
||||
|
||||
# [[ "$percentage" -lt 33 || "$temp_cpu" =~ ^4* || $usage -lt 33 ]] && exit
|
||||
|
||||
# echo "$percentage $usage_short"
|
||||
|
||||
echo "$percentage"
|
||||
echo "$percentage $usage"
|
||||
#[[ "$temp_cpu" =~ ^3* || "$temp_cpu" =~ ^4* ]] && echo "$usage% $power_package"
|
||||
|
||||
|
||||
#
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
root=$(df -h / | grep '/dev/nvme0' | awk '{ print $4 }')
|
||||
root_percentage=$(df -h / | grep '/dev/nvme0' | awk '{ print $5 }')
|
||||
data=$(df -h /mnt/data | grep '/dev/nvme1' | awk '{ print $4 }')
|
||||
data_percentage=$(df -h /mnt/data | grep '/dev/nvme1' | awk '{ print $5 }')
|
||||
|
||||
echo "ROOT $root_percentage $root DATA $data_percentage $data"
|
||||
Executable
+275
@@ -0,0 +1,275 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
import traceback
|
||||
|
||||
import psutil
|
||||
from gi.repository import GLib
|
||||
from pydbus import SessionBus
|
||||
|
||||
MPRIS_PLAYER_OBJ_PATH = '/org/mpris/MediaPlayer2'
|
||||
MPRIS_PLAYER_IFACE = 'org.mpris.MediaPlayer2.Player'
|
||||
KNOWN_SERVICES = [
|
||||
'org.mpris.MediaPlayer2.mpv',
|
||||
'org.kde.plasma.browser_integration'
|
||||
]
|
||||
KNOWN_BROWSER_MAP = {
|
||||
'mozilla': 'Firefox',
|
||||
'chromium': 'Chromium',
|
||||
'chrome': 'Google Chrome'
|
||||
}
|
||||
|
||||
|
||||
class Player:
|
||||
def __init__(self, bus, owner_name):
|
||||
self._bus = bus
|
||||
self.owner_name = owner_name
|
||||
self.owner_process = self._get_owner_process()
|
||||
self._obj = self._bus.get(owner_name, MPRIS_PLAYER_OBJ_PATH)
|
||||
|
||||
def _get_owner_process(self):
|
||||
obj = self._bus.get('org.freedesktop.DBus', '/org/freedesktop/DBus')
|
||||
pid = obj.GetConnectionUnixProcessID(self.owner_name)
|
||||
if pid is None:
|
||||
return None
|
||||
|
||||
return psutil.Process(pid)
|
||||
|
||||
@staticmethod
|
||||
def _identify_browser_by_cmdline(cmdline):
|
||||
for fragment, browser in KNOWN_BROWSER_MAP.items():
|
||||
if fragment in cmdline:
|
||||
return browser
|
||||
return None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
name = self.owner_process.name()
|
||||
if name == 'plasma-browser-integration-host':
|
||||
cmdline = ' '.join(self.owner_process.cmdline())
|
||||
return self._identify_browser_by_cmdline(cmdline)
|
||||
return name
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
return self._obj.PlaybackStatus.lower()
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return self._obj.Metadata.get('xesam:title')
|
||||
|
||||
@property
|
||||
def album(self):
|
||||
return self._obj.Metadata.get('xesam:album')
|
||||
|
||||
@property
|
||||
def artist(self):
|
||||
artists = self._obj.Metadata.get('xesam:artist')
|
||||
return ', '.join(artists) if isinstance(artists, list) else artists
|
||||
|
||||
def playpause(self):
|
||||
if self._obj.CanPlay or self._obj.CanPause:
|
||||
self._obj.PlayPause()
|
||||
|
||||
def play(self):
|
||||
if self._obj.CanPlay:
|
||||
self._obj.Play()
|
||||
|
||||
def pause(self):
|
||||
if self._obj.CanPause:
|
||||
self._obj.Pause()
|
||||
|
||||
def previous(self):
|
||||
if self._obj.CanGoPrevious:
|
||||
self._obj.Previous()
|
||||
|
||||
def next(self):
|
||||
if self._obj.CanGoNext:
|
||||
self._obj.Next()
|
||||
|
||||
|
||||
class MediaWatcher:
|
||||
def __init__(self, bus, do_print_status=False):
|
||||
self._bus = bus
|
||||
|
||||
self._owner_to_player = self._find_players()
|
||||
self.player = self._find_active_player()
|
||||
|
||||
if do_print_status:
|
||||
self.status_builder = MediaWatcherStatusBuilder(self)
|
||||
self.status_builder.print_status()
|
||||
else:
|
||||
self.status_builder = None
|
||||
|
||||
def __enter__(self):
|
||||
self._subscription = self._bus.subscribe(
|
||||
iface='org.freedesktop.DBus.Properties',
|
||||
signal='PropertiesChanged',
|
||||
object=MPRIS_PLAYER_OBJ_PATH,
|
||||
arg0=MPRIS_PLAYER_IFACE,
|
||||
signal_fired=self._mpris_signal_handler,
|
||||
)
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, tb):
|
||||
if exc_type is not None:
|
||||
traceback.print_exception(exc_type, exc_value, tb)
|
||||
self._subscription.unsubscribe()
|
||||
|
||||
def _find_players(self):
|
||||
owner_to_player = {}
|
||||
for service in KNOWN_SERVICES:
|
||||
try:
|
||||
owner_name = self._bus.dbus.GetNameOwner(service)
|
||||
except GLib.Error:
|
||||
continue
|
||||
owner_to_player[owner_name] = Player(bus=self._bus, owner_name=owner_name)
|
||||
return owner_to_player
|
||||
|
||||
def _group_players_by_status(self):
|
||||
status_to_players = {}
|
||||
for player in self._owner_to_player.values():
|
||||
if player.status in status_to_players:
|
||||
status_to_players[player.status].append(player)
|
||||
else:
|
||||
status_to_players[player.status] = [player]
|
||||
return status_to_players
|
||||
|
||||
def _find_active_player(self):
|
||||
players_by_status = self._group_players_by_status()
|
||||
|
||||
if players_by_status.get('playing'):
|
||||
players_by_status['playing'].sort(key=lambda x: x.owner_process.create_time(), reverse=True)
|
||||
return players_by_status['playing'][0]
|
||||
elif players_by_status.get('paused'):
|
||||
return players_by_status['paused'][0]
|
||||
elif players_by_status.get('stopped'):
|
||||
return players_by_status['stopped'][0]
|
||||
|
||||
return None
|
||||
|
||||
def _mpris_signal_handler(self, sender_name, *_):
|
||||
if sender_name not in self._owner_to_player:
|
||||
self._owner_to_player[sender_name] = Player(bus=self._bus, owner_name=sender_name)
|
||||
|
||||
self.player = self._find_active_player()
|
||||
|
||||
if self.status_builder:
|
||||
self.status_builder.print_status()
|
||||
|
||||
|
||||
class MediaWatcherStatusBuilder:
|
||||
def __init__(self, watcher):
|
||||
self.watcher = watcher
|
||||
|
||||
def _build_tooltip(self):
|
||||
tooltip = []
|
||||
player = self.watcher.player
|
||||
|
||||
if player.status in ['playing', 'paused']:
|
||||
tooltip.append(player.status.title() + ':')
|
||||
if player.title:
|
||||
tooltip.append(player.title)
|
||||
if player.album:
|
||||
tooltip.append(player.album)
|
||||
if player.artist:
|
||||
tooltip.append(player.artist)
|
||||
if player.name:
|
||||
tooltip.append('(' + player.name + ')')
|
||||
|
||||
return '\n'.join(tooltip) if tooltip else None
|
||||
|
||||
def _build_text(self, max_width, title_to_artist_ratio=2 / 3, separator=' - ', placeholder='…'):
|
||||
max_width = max_width - len(separator)
|
||||
player = self.watcher.player
|
||||
|
||||
if player.title and player.artist:
|
||||
title_width = math.floor(max_width * title_to_artist_ratio)
|
||||
artist_width = max_width - title_width
|
||||
elif player.title and not player.artist:
|
||||
title_width = max_width
|
||||
artist_width = 0
|
||||
elif player.artist and not player.title:
|
||||
title_width = 0
|
||||
artist_width = max_width
|
||||
else:
|
||||
return None
|
||||
|
||||
short_title = (
|
||||
None if title_width == 0 else textwrap.shorten(player.title, width=title_width, placeholder=placeholder)
|
||||
)
|
||||
short_artist = (
|
||||
None if artist_width == 0 else textwrap.shorten(player.artist, width=artist_width, placeholder=placeholder)
|
||||
)
|
||||
|
||||
if short_title and short_artist:
|
||||
return separator.join((short_title, short_artist))
|
||||
elif short_title and not short_artist:
|
||||
return short_title
|
||||
elif short_artist and not short_title:
|
||||
return short_artist
|
||||
|
||||
def _build_classes(self):
|
||||
classes = []
|
||||
player = self.watcher.player
|
||||
|
||||
if player.status in ['playing', 'paused']:
|
||||
classes.append(player.status)
|
||||
else:
|
||||
classes.append('stopped')
|
||||
|
||||
return classes
|
||||
|
||||
def build_status(self):
|
||||
return json.dumps(
|
||||
{'tooltip': self._build_tooltip(), 'text': self._build_text(max_width=80), 'class': self._build_classes()}
|
||||
)
|
||||
|
||||
def print_status(self):
|
||||
print(self.build_status())
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def print_usage():
|
||||
name = os.path.basename(sys.argv[0])
|
||||
print('Usage:\n\t{} (status|playpause|previous|next)\n'.format(name))
|
||||
|
||||
|
||||
def main():
|
||||
bus = SessionBus()
|
||||
loop = GLib.MainLoop()
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
arg = sys.argv[1]
|
||||
else:
|
||||
print_usage()
|
||||
return
|
||||
|
||||
with MediaWatcher(bus, do_print_status=(arg == 'status')) as media_watcher:
|
||||
if arg == 'status':
|
||||
while True:
|
||||
try:
|
||||
loop.run()
|
||||
except GLib.Error:
|
||||
pass
|
||||
elif arg == 'playpause':
|
||||
media_watcher.player.playpause()
|
||||
elif arg == 'play':
|
||||
media_watcher.player.play()
|
||||
elif arg == 'pause':
|
||||
media_watcher.player.pause()
|
||||
elif arg == 'previous':
|
||||
media_watcher.player.previous()
|
||||
elif arg == 'next':
|
||||
media_watcher.player.next()
|
||||
else:
|
||||
print_usage()
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
sunrise=$(wlsunset_info --sunrise)
|
||||
sunset=$(wlsunset_info --sunset)
|
||||
|
||||
# sleep .1
|
||||
|
||||
if pgrep -x "wlsunset" > /dev/null
|
||||
then
|
||||
state="an"
|
||||
else
|
||||
state="aus"
|
||||
fi
|
||||
|
||||
# check if temperature is set, so blue light filter is active
|
||||
# if there's a line in the logs, than it's active
|
||||
# example line:
|
||||
# setting temperature on output '49' to 4771 K
|
||||
|
||||
[[ $sunrise == "" ]] && echo "" && echo "6500K" && exit
|
||||
[[ $state == "aus" ]] && echo "" && echo "$sunrise - $sunset - 6500K" && exit
|
||||
|
||||
|
||||
# todo: if temperature is below 6500K
|
||||
|
||||
|
||||
[[ $state == "an" ]] && \
|
||||
temperature=$(cat /tmp/wlsunset.log | awk '/temperature/ {print $4}' | tail -n1) && \
|
||||
[[ $temperature == "" ]] && echo "" && exit || echo "" && echo "$sunrise - $sunset - $temperature"K # echo " "
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# ⏾
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
Reference in New Issue
Block a user