diff options
Diffstat (limited to 'waybar/custom_modules')
-rwxr-xr-x | waybar/custom_modules/cpugovernor.sh | 16 | ||||
-rwxr-xr-x | waybar/custom_modules/custom-gpu-lite.sh | 8 | ||||
-rwxr-xr-x | waybar/custom_modules/custom-gpu.sh | 12 | ||||
-rwxr-xr-x | waybar/custom_modules/custom-kdeconnect.sh | 85 | ||||
-rwxr-xr-x | waybar/custom_modules/media-player-status.py | 123 |
5 files changed, 244 insertions, 0 deletions
diff --git a/waybar/custom_modules/cpugovernor.sh b/waybar/custom_modules/cpugovernor.sh new file mode 100755 index 0000000..2f75469 --- /dev/null +++ b/waybar/custom_modules/cpugovernor.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +GOVERNOR=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) + +if [ $GOVERNOR = performance ]; then + echo '{"text": "perf", "alt": "perf", "class": "performance", "tooltip": "<b>Governor</b> Performance"}' + if [[ $1 = switch ]]; then + sudo cpupower frequency-set -g ondemand;pkill -RTMIN+8 waybar; + fi + #echo '' +elif [ $GOVERNOR = ondemand ]; then + echo '{"text": "ondemand", "alt": "ondemand", "class": "ondemand", "tooltip": "<b>Governor</b> On Demand"}' + if [[ $1 = switch ]]; then + sudo cpupower frequency-set -g performance;pkill -RTMIN+8 waybar; + fi +fi
\ No newline at end of file diff --git a/waybar/custom_modules/custom-gpu-lite.sh b/waybar/custom_modules/custom-gpu-lite.sh new file mode 100755 index 0000000..d2821c1 --- /dev/null +++ b/waybar/custom_modules/custom-gpu-lite.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +raw_temp=$(cat /sys/class/drm/card0/device/hwmon/hwmon5/temp1_input) +temperature=$(($raw_temp/1000)) +deviceinfo=$(glxinfo -B | grep 'Device:' | sed 's/^.*: //') +driverinfo=$(glxinfo -B | grep "OpenGL version") + +echo '{"text": " '$temperature'°C", "class": "custom-gpu", "tooltip": "<b>'$deviceinfo'</b>\n'$driverinfo'"}'
\ No newline at end of file diff --git a/waybar/custom_modules/custom-gpu.sh b/waybar/custom_modules/custom-gpu.sh new file mode 100755 index 0000000..e87374d --- /dev/null +++ b/waybar/custom_modules/custom-gpu.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +raw_clock=$(cat /sys/class/drm/card0/device/pp_dpm_sclk | egrep -o '[0-9]{0,4}Mhz \W' | sed "s/Mhz \*//") +clock=$(echo "scale=1;$raw_clock/1000" | bc | sed -e 's/^-\./-0./' -e 's/^\./0./') + +raw_temp=$(cat /sys/class/drm/card0/device/hwmon/hwmon5/temp1_input) +temperature=$(($raw_temp/1000)) +busypercent=$(cat /sys/class/hwmon/hwmon5/device/gpu_busy_percent) +deviceinfo=$(glxinfo -B | grep 'Device:' | sed 's/^.*: //') +driverinfo=$(glxinfo -B | grep "OpenGL version") + +echo '{"text": "'$clock'GHz | '$temperature'°C <span color=\"darkgray\">| '$busypercent'%</span>", "class": "custom-gpu", "tooltip": "<b>'$deviceinfo'</b>\n'$driverinfo'"}'
\ No newline at end of file diff --git a/waybar/custom_modules/custom-kdeconnect.sh b/waybar/custom_modules/custom-kdeconnect.sh new file mode 100755 index 0000000..5b2c3a8 --- /dev/null +++ b/waybar/custom_modules/custom-kdeconnect.sh @@ -0,0 +1,85 @@ +# +# Shamefully massacred from haideralipunjabi's polybar-kdeconnect +# (https://github.com/haideralipunjabi/polybar-kdeconnect/) +# + +# Color Settings of Icon shown in Waybar +COLOR_DISCONNECTED='#655b53' # Device Disconnected +COLOR_BATTERY_90='#ebdbb2' # Battery >= 90 +COLOR_BATTERY_80='#a89985' # Battery >= 80 +COLOR_BATTERY_70='#448488' # Battery >= 70 +COLOR_BATTERY_60='#83a597' # Battery >= 60 +COLOR_BATTERY_50='#b16185' # Battery >= 50 +COLOR_BATTERY_LOW='#BF616A' # Battery < 50 + +# Icons shown in Polybar +ICON_SMARTPHONE='' +ICON_TABLET='' + +devices="" + +get_icon () { + if [ "$2" = "tablet" ] + then + icon=$ICON_TABLET + else + icon=$ICON_SMARTPHONE + fi + case $1 in + "-1") ICON="<span foreground=\"$COLOR_DISCONNECTED\">$icon</span>" ;; + "-2") ICON="<span foreground=\"$COLOR_NEWDEVICE\">$icon</span>" ;; + 5*) ICON="<span foreground=\"$COLOR_BATTERY_50\">$icon</span>" ;; + 6*) ICON="<span foreground=\"$COLOR_BATTERY_60\">$icon</span>" ;; + 7*) ICON="<span foreground=\"$COLOR_BATTERY_70\">$icon</span>" ;; + 8*) ICON="<span foreground=\"$COLOR_BATTERY_80\">$icon</span>" ;; + 9*|100) ICON="<span foreground=\"$COLOR_BATTERY_90\">$icon</span>" ;; + *) ICON="<span foreground=\"$COLOR_BATTERY_LOW\">$icon</span>" ;; + esac + echo $ICON +} + +get_status() { + for device in $(qdbus --literal org.kde.kdeconnect /modules/kdeconnect org.kde.kdeconnect.daemon.devices); do + deviceid=$(echo "$device" | awk -F'["|"]' '{print $2}') + isreach="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isReachable)" + istrust="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isTrusted)" + if [ "$isreach" = "true" ] && [ "$istrust" = "true" ] + then + battery="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid/battery" org.kde.kdeconnect.device.battery.charge)%" + icon=$(get_icon "$battery" "$devicetype") + devices+="$battery $icon" + elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ] + then + devices+="$(get_icon -1 "$devicetype")" + fi + done + + echo $devices +} + +send_ring() { + for device in $(qdbus --literal org.kde.kdeconnect /modules/kdeconnect org.kde.kdeconnect.daemon.devices); do + deviceid=$(echo "$device" | awk -F'["|"]' '{print $2}') + isreach="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isReachable)" + istrust="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isTrusted)" + if [ "$isreach" = "true" ] && [ "$istrust" = "true" ] + then + $(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid/findmyphone" org.kde.kdeconnect.device.findmyphone.ring) + fi + done + + echo $devices +} + + +option="${1}" + case "${option}" in + ring) send_ring + ;; + battery) get_status + ;; + *) echo "Use with ./custom-kdeconnect.sh battery or ring" + ;; + esac + +exit 0
\ No newline at end of file diff --git a/waybar/custom_modules/media-player-status.py b/waybar/custom_modules/media-player-status.py new file mode 100755 index 0000000..df348c7 --- /dev/null +++ b/waybar/custom_modules/media-player-status.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python + +import html +import json +import gi +import sys +gi.require_version('Playerctl', '2.0') +from gi.repository import Playerctl, GLib # noqa: E402 + +ARTIST = 'xesam:artist' +TITLE = 'xesam:title' +ICONS = { + 'spotify': '阮 ', + 'ncspot': '阮 ', + 'vlc': '嗢 ', + 'firefox': ' ', + 'default': '契 ', + 'paused': ' ' +} + +last_status = None + + +def find_active_player(manager, vanished_player): + for player in manager.props.players: + if player == vanished_player: + continue + if player.props.playback_status != Playerctl.PlaybackStatus.STOPPED: + return player + return None + + +def get_status(manager, vanished_player): + player = find_active_player(manager, vanished_player) + if player is None: + return '', '', 'stopped' + name = player.props.player_name + metadata = player.props.metadata + title = metadata[TITLE] if TITLE in metadata.keys() else None + artist = metadata[ARTIST][0] if ARTIST in metadata.keys() else None + if name == 'firefox' and title == 'Firefox' and artist == 'Mozilla': + title = None + artist = None + if player.props.playback_status == Playerctl.PlaybackStatus.PAUSED: + css_class = 'paused' + else: + css_class = 'playing' + if title is None and artist is None: + if css_class == 'paused': + icon = ICONS['paused'] + else: + icon = ICONS['default'] + app_icon = ICONS.get(name, None) + if app_icon is None: + label = icon + else: + label = f'{icon} {app_icon}' + return label, f'{name.title()}: {css_class.title()}', css_class + if css_class == 'paused': + icon = ICONS['paused'] + else: + # Added override for icon + #icon = ICONS.get(name, ICONS['default']) + icon = ICONS['default'] + if title is None or title == '': + song = artist or name.title() + elif artist is None or artist == '': + song = f'{title}' + else: + song = f'{artist} – {title}' + html_song = html.escape(song) + return f'{icon} {html_song}', f'{name.title()}: {song}', css_class + + +def print_status(manager, vanished_player=None): + text, tooltip, css_class = get_status(manager, vanished_player) + status = json.dumps({'text': text, 'tooltip': tooltip, 'class': css_class}) + global last_status + if last_status != status: + print(status) + sys.stdout.flush() + last_status = status + + +def on_playback_status(player, status, manager): + manager.move_player_to_top(player) + print_status(manager) + + +def on_metadata(player, metadata, manager): + manager.move_player_to_top(player) + print_status(manager) + + +def init_player(manager, name): + player = Playerctl.Player.new_from_name(name) + player.connect('playback-status', on_playback_status, manager) + player.connect('metadata', on_metadata, manager) + manager.manage_player(player) + + +def on_name_appeared(manager, name, _): + init_player(manager, name) + print_status(manager) + + +def on_player_vanished(manager, player, _): + print_status(manager, player) + + +def init_manager(): + manager = Playerctl.PlayerManager() + manager.connect('name-appeared', on_name_appeared, manager) + manager.connect('player-vanished', on_player_vanished, manager) + for name in manager.props.player_names: + init_player(manager, name) + print_status(manager) + + +if __name__ == '__main__': + init_manager() + main = GLib.MainLoop() + main.run() |