diff --git a/home/.config/waybar/config b/home/.config/waybar/config index c8e8fe7..359ea57 100644 --- a/home/.config/waybar/config +++ b/home/.config/waybar/config @@ -2,7 +2,7 @@ { "layer": "bottom", // Waybar at top layer "height": 22, // Waybar height - "modules-left": ["sway/workspaces", "sway/mode", "custom/playerctl"], + "modules-left": ["sway/workspaces", "sway/mode", "custom/media"], "modules-center": ["sway/window"], "modules-right": [ "idle_inhibitor", @@ -107,12 +107,12 @@ "on-scroll-up": "pamixer -ui 1 && pamixer --get-volume > $SWAYSOCK.wob", "on-scroll-down": "pamixer -ud 1 && pamixer --get-volume > $SWAYSOCK.wob" }, - "custom/playerctl": { + "custom/media": { "tooltip": false, "format": "{}", - "exec": "$HOME/Scripts/metadata.sh", - "interval": 2, - "max-length": 40, + "return-type": "json", + "exec": "$HOME/Scripts/mediaplayer.py 2>/dev/null", + "max-length": 50, "on-click": "playerctl play-pause", "on-click-right": "playerctl next", "on-scroll-up": "playerctl volume 0.05+", @@ -123,7 +123,7 @@ "format": "{} ", "exec": "yay -Qu | wc -l", "interval": 300, - "on-click": "alacritty -e yay" + "on-click": "gnome-software --mode=updates" }, "temperature": { "format": "{temperatureC}°C " diff --git a/home/.config/waybar/style.css b/home/.config/waybar/style.css index 78fcae7..7610afc 100644 --- a/home/.config/waybar/style.css +++ b/home/.config/waybar/style.css @@ -26,7 +26,7 @@ window#waybar { background: #64727D; } -#clock, #battery, #cpu, #temperature, #memory, #backlight, #network, #pulseaudio, #custom-playerctl, #custom-yay, #tray, #mode, #idle_inhibitor { +#clock, #battery, #cpu, #temperature, #memory, #backlight, #network, #pulseaudio, #custom-media, #custom-yay, #tray, #mode, #idle_inhibitor { padding: 0 10px; margin: 0 5px; } @@ -110,7 +110,7 @@ window#waybar { color: #2a5c45; } -#custom-playerctl { +#custom-media { background: #97B084; color: black; } diff --git a/home/Scripts/fzf-pass.sh b/home/Scripts/fzf-pass.sh deleted file mode 100755 index 61e512a..0000000 --- a/home/Scripts/fzf-pass.sh +++ /dev/null @@ -1 +0,0 @@ -Moved to https://git.reekynet.com/ReekyMarko/fzf-pass diff --git a/home/Scripts/mediaplayer.py b/home/Scripts/mediaplayer.py new file mode 100755 index 0000000..aa9dc61 --- /dev/null +++ b/home/Scripts/mediaplayer.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 +import argparse +import logging +import sys +import signal +import gi +import json +gi.require_version('Playerctl', '2.0') +from gi.repository import Playerctl, GLib + +logger = logging.getLogger(__name__) + + +def write_output(text, player): + logger.info('Writing output') + + output = {'text': text, + 'class': 'custom-' + player.props.player_name, + 'alt': player.props.player_name} + + sys.stdout.write(json.dumps(output) + '\n') + sys.stdout.flush() + + +def on_play(player, status, manager): + logger.info('Received new playback status') + on_metadata(player, player.props.metadata, manager) + + +def on_metadata(player, metadata, manager): + logger.info('Received new metadata') + track_info = '' + + if player.get_artist() != '' and player.get_title() != '': + track_info = '{artist} - {title}'.format(artist=player.get_artist(), + title=player.get_title()) + else: + track_info = player.get_title() + + if player.props.status == 'Playing' and track_info: + track_info = ' ' + track_info + else: + track_info = ' ' + track_info + + write_output(track_info, player) + + +def on_player_appeared(manager, player, selected_player=None): + if player is not None and (selected_player is None or player.name == selected_player): + init_player(manager, player) + else: + logger.debug("New player appeared, but it's not the selected player, skipping") + + +def on_player_vanished(manager, player): + logger.info('Player has vanished') + sys.stdout.write('\n') + sys.stdout.flush() + + +def init_player(manager, name): + logger.debug('Initialize player: {player}'.format(player=name.name)) + player = Playerctl.Player.new_from_name(name) + player.connect('playback-status', on_play, manager) + player.connect('metadata', on_metadata, manager) + manager.manage_player(player) + on_metadata(player, player.props.metadata, manager) + + +def signal_handler(sig, frame): + logger.debug('Received signal to stop, exiting') + sys.stdout.write('\n') + sys.stdout.flush() + # loop.quit() + sys.exit(0) + + +def parse_arguments(): + parser = argparse.ArgumentParser() + + # Increase verbosity with every occurence of -v + parser.add_argument('-v', '--verbose', action='count', default=0) + + # Define for which player we're listening + parser.add_argument('--player') + + return parser.parse_args() + + +def main(): + arguments = parse_arguments() + + # Initialize logging + logging.basicConfig(stream=sys.stderr, level=logging.DEBUG, + format='%(name)s %(levelname)s %(message)s') + + # Logging is set by default to WARN and higher. + # With every occurrence of -v it's lowered by one + logger.setLevel(max((3 - arguments.verbose) * 10, 0)) + + # Log the sent command line arguments + logger.debug('Arguments received {}'.format(vars(arguments))) + + manager = Playerctl.PlayerManager() + loop = GLib.MainLoop() + + manager.connect('name-appeared', lambda *args: on_player_appeared(*args, arguments.player)) + manager.connect('player-vanished', on_player_vanished) + + signal.signal(signal.SIGINT, signal_handler) + signal.signal(signal.SIGTERM, signal_handler) + + for player in manager.props.player_names: + if arguments.player is not None and arguments.player != player.name: + logger.debug('{player} is not the filtered player, skipping it' + .format(player=player.name) + ) + continue + + init_player(manager, player) + + loop.run() + + +if __name__ == '__main__': + main() diff --git a/home/Scripts/metadata.sh b/home/Scripts/metadata.sh deleted file mode 100755 index 91689b3..0000000 --- a/home/Scripts/metadata.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -ARTIST=$(playerctl metadata | grep 'xesam:artist' | cut -d' ' -f5- | sed 's/^[ \t]*//') -TITLE=$(playerctl metadata title) - -if [ -n "$ARTIST" ]; then - echo "$ARTIST - $TITLE" -else - echo "$TITLE" -fi diff --git a/home/Scripts/mpvqueue b/home/Scripts/mpvqueue index a3fe6d9..81e40f4 100755 --- a/home/Scripts/mpvqueue +++ b/home/Scripts/mpvqueue @@ -3,13 +3,7 @@ MPVPIPE=/tmp/mpvqueue.playlist notify="notify-send -i mpv -a mpv" - -# if link is a youtube playlist, clean up url -if [[ ${1} =~ /^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$ ]]; then - url="https://youtube.com/playlist?list=${1#*list=}" -else - url="$1" -fi +url="$1" # See if MPV is already running if [ -z "$(pidof mpv)" ]; then @@ -17,6 +11,9 @@ if [ -z "$(pidof mpv)" ]; then # remove fifo rm -f $MPVPIPE && mkfifo $MPVPIPE + # pause other players + playerctl pause + # start mpv /usr/bin/mpv --no-terminal --input-file="${MPVPIPE}" "$url" & disown diff --git a/home/Scripts/panextsink.sh b/home/Scripts/panextsink.sh deleted file mode 100644 index d333839..0000000 --- a/home/Scripts/panextsink.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -# Get the pid of the window that is to be moved to the next sink -pid_to_move=$(swaymsg -t get_tree | jq -r '.nodes[]?.nodes[]?.nodes[]?.nodes[]?.nodes[] | select(.focused==true).pid') - -# Assign all the sink indices into an array -sink_array=($(pacmd list-sinks | grep index | sed 's/index://' | sed 's/*//' | xargs)) - -# Get the sink inputs to prepare to be inserted into array of arrays -# The following raw string format is index sink pid\nindex sink pid -sink_inputs_raw=$(pacmd list-sink-inputs | grep -e index -e sink: -e process.id | sed 's/<[^"]*>//' | sed 's/[^0-9]*//g' | tr '\n' ' ' | xargs | sed 's/\([[:digit:]]*\) \([[:digit:]]*\) \([[:digit:]]*\) /\1 \2 \3\n/g') - -# Find the corresponding pid -sink_input_selected_pid=$(echo "$sink_inputs_raw" | grep $pid_to_move) - -# Parse the individual values from the info retrieved above -selected_input_index=$(echo $sink_input_selected_pid | awk '{print $1;}') -selected_input_sink=$(echo $sink_input_selected_pid | awk '{print $2;}') -selected_input_pid=$(echo $sink_input_selected_pid | awk '{print $3;}') - -len=${#sink_array[@]} - -for (( i=0; i<$len; i++ )); do - if [[ $selected_input_sink == "${sink_array[$i]}" ]]; then - len_idx=$((len-1)) - if (( $i == $len_idx )); then - pacmd move-sink-input $selected_input_index ${sink_array[0]} - else - pacmd move-sink-input $selected_input_index ${sink_array[$((i+1))]} - fi - fi -done diff --git a/home/Scripts/sway-launcher-desktop.sh b/home/Scripts/sway-launcher-desktop.sh deleted file mode 100755 index efcb8e2..0000000 --- a/home/Scripts/sway-launcher-desktop.sh +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/env bash -# terminal application launcher for sway, using fzf -# Based on: https://gitlab.com/FlyingWombat/my-scripts/blob/master/sway-launcher - -shopt -s nullglob -if [[ "$1" == 'describe' ]]; then - shift - if [[ $2 == 'command' ]]; then - title=$1 - readarray arr < <(whatis -l "$1" 2>/dev/null) - description="${arr[0]}" - description="${description%*-}" - else - title=$(sed -ne '/^Name=/{s/^Name=//;p;q}' "$1") - description=$(sed -ne '/^Comment=/{s/^Comment=//;p;q}' "$1") - fi - echo -e "\033[33m$title\033[0m" - echo "${description:-No description}" - exit -fi - -HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt" - -DIRS=( - /usr/share/applications - "$HOME/.local/share/applications" - /usr/local/share/applications -) - -GLYPH_COMMAND=" " -GLYPH_DESKTOP=" " - -touch "$HIST_FILE" -readarray HIST_LINES <"$HIST_FILE" -FZFPIPE=$(mktemp) -PIDFILE=$(mktemp) -trap 'rm "$FZFPIPE" "$PIDFILE"' EXIT INT - -# Append Launcher History, removing usage count -(printf '%s' "${HIST_LINES[@]#* }" >>"$FZFPIPE") & - -# Load and append Desktop entries -( - for dir in "${DIRS[@]}"; do - [[ -d "$dir" ]] || continue - awk -v pre="$GLYPH_DESKTOP" -F= ' - BEGINFILE{application=0;block="";a=0} - /^\[Desktop Entry\]/{block="entry"} - /^Type=Application/{application=1} - /^\[Desktop Action/{ - sub("^\\[Desktop Action ", ""); - sub("\\]$", ""); - block="action"; - a++; - actions[a,"key"]=$0 - } - /^Name=/{ - if(block=="action") { - actions[a,"name"]=$2; - } else { - name=$2 - } - } - ENDFILE{ - if (application){ - print FILENAME "\034desktop\034\033[33m" pre name "\033[0m"; - if (a>0) - for (i=1; i<=a; i++) - print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"] - } - }' \ - "$dir/"*.desktop >"$FZFPIPE" - # the empty stdin is needed in case no *.desktop files - done -) & - -# Load and append command list -( - IFS=: - read -ra path <<<"$PATH" - for dir in "${path[@]}"; do - printf '%s\n' "$dir/"* | - awk -F / -v pre="$GLYPH_COMMAND" '{print $NF "\034command\034\033[31m" pre "\033[0m" $NF;}' - done | sort -u >>"$FZFPIPE" -) & - -COMMAND_STR=$( - ( - tail -n +0 -f "$FZFPIPE" & - echo $! >"$PIDFILE" - ) | - fzf +s -x -d '\034' --nth ..3 --with-nth 3 \ - --preview "$0 describe {1} {2}" \ - --preview-window=up:3:wrap --ansi - kill -9 "$(<"$PIDFILE")" | tail -n1 -) || exit 1 - -[ -z "$COMMAND_STR" ] && exit 1 - -# update history -for i in "${!HIST_LINES[@]}"; do - if [[ "${HIST_LINES[i]}" == *" $COMMAND_STR"$'\n' ]]; then - HIST_COUNT=${HIST_LINES[i]%% *} - HIST_LINES[$i]="$((HIST_COUNT + 1)) $COMMAND_STR"$'\n' - match=1 - break - fi -done -if ! ((match)); then - HIST_LINES+=("1 $COMMAND_STR"$'\n') -fi - -printf '%s' "${HIST_LINES[@]}" | sort -nr >"$HIST_FILE" - -command='echo "nope"' -# shellcheck disable=SC2086 -readarray -d $'\034' -t PARAMS <<<${COMMAND_STR} -# COMMAND_STR is "\034" -case ${PARAMS[1]} in -desktop) - # Define the search pattern that specifies the block to search for within the .desktop file - PATTERN="^\\\\[Desktop Entry\\\\]" - if [[ -n ${PARAMS[3]} ]]; then - PATTERN="^\\\\[Desktop Action ${PARAMS[3]%?}\\\\]" - fi - # 1. We see a line starting [Desktop, but we're already searching: deactivate search again - # 2. We see the specified pattern: start search - # 3. We see an Exec= line during search: remove field codes and set variable - # 3. We see a Path= line during search: set variable - # 4. Finally, build command line - command=$(awk -v pattern="${PATTERN}" -F= ' - BEGIN{a=0;exec=0; path=0} - /^\[Desktop/{ - if(a){ - a=0 - } - } - $0 ~ pattern{ - a=1 - } - /^Exec=/{ - if(a && !exec){ - sub("^Exec=", ""); - gsub(" ?%[cDdFfikmNnUuv]", ""); - exec=$0; - } - } - /^Path=/{ - if(a && !path){ - path=$2 - } - } - - END{ - if(path){ - print "cd " path " &&" - } - print exec - }' "${PARAMS[0]}") - ;; -command) - command="${PARAMS[0]}" - ;; -esac -swaymsg -t command exec "$command" diff --git a/home/Scripts/swayidle.sh b/home/Scripts/swayidle.sh index 87ad899..bc85114 100755 --- a/home/Scripts/swayidle.sh +++ b/home/Scripts/swayidle.sh @@ -1,13 +1,13 @@ #!/bin/bash swaylock="$HOME/Scripts/swaylock.sh" -dimscreen="$HOME/Scripts/dim-screen.sh" screenon="swaymsg 'output * dpms on'" screenoff="swaymsg 'output * dpms off'" swayidle \ lock "$swaylock" \ + unlock "pkill -9 swaylock" \ timeout 300 "lqsd -d" \ resume "lqsd -r" \ - timeout 600 "loginctl lock-session $(loginctl show-user $USER -p Sessions | cut -d'=' -f2); sleep 0.5; $screenoff" \ + timeout 600 "loginctl lock-session" \ + timeout 610 "$screenoff" \ resume "$screenon; lqsd -r" \ - before-sleep "playerctl pause; loginctl lock-session $(loginctl show-user $USER -p Sessions | cut -d'=' -f2)" \ - unlock "pkill -9 swaylock" + before-sleep "playerctl pause; loginctl lock-session)" diff --git a/home/Scripts/switchlayout.sh b/home/Scripts/switchlayout.sh deleted file mode 100755 index 66fa835..0000000 --- a/home/Scripts/switchlayout.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -curLayout=$(setxkbmap -query | grep layout | sed 's/layout: //g') - -if [ $curLayout == "eu" ]; then - setxkbmap dvorak -else - setxkbmap eu -fi