From 8486ce27943b1c0460bfcd6d93ed84d2b3c5afb5 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 29 Nov 2021 13:11:54 -0700 Subject: Add some changes. 1. Make the spotify control work for both Spotify and Spotifyd 2. Xmobar weather not break xmobar when not connected to the internet 3. Add g keybinding to go to the toogle-cased version of the current workspace. --- extras/HOME/.local/bin/set-backlight.sh | 35 +++++++++++++++++++++++++++++++++ extras/HOME/.local/bin/spotify-control | 31 ++++++++++++++++++++++------- extras/HOME/.xmobarrc | 10 +++++----- extras/HOME/.xmonad/xmobar-bluetooth | 2 +- extras/HOME/.xmonad/xmobar-weather | 5 +++++ src/Internal/Keys.hs | 1 + src/Internal/Lib.hs | 11 +++++++++++ 7 files changed, 82 insertions(+), 13 deletions(-) create mode 100755 extras/HOME/.local/bin/set-backlight.sh diff --git a/extras/HOME/.local/bin/set-backlight.sh b/extras/HOME/.local/bin/set-backlight.sh new file mode 100755 index 0000000..d0b8e3b --- /dev/null +++ b/extras/HOME/.local/bin/set-backlight.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +frac="$1" + +if [[ "$frac" == -* ]] ; then + frac=${frac//-} + t='sub' +elif [[ "$frac" == +* ]] ; then + frac=${frac//+} + t='add' +else + t='abs' +fi + +max="$(cat /sys/class/backlight/intel_backlight/max_brightness)" +to_set="$(bc <<< "$max * $frac")" +to_set=$(cut -d. -f1 <<< "$to_set") # Cut off the fractional part. + +if [[ "$t" == 'sub' ]] ; then + cur="$(cat /sys/class/backlight/intel_backlight/brightness)" + to_set=$((cur - to_set)) +elif [[ "$t" == 'add' ]] ; then + cur="$(cat /sys/class/backlight/intel_backlight/brightness)" + to_set=$((cur + to_set)) +fi + +if [ "$to_set" -gt "$max" ] ; then + to_set="$max" +fi + +if [ "$to_set" -lt 0 ] ; then + to_set=0 +fi + +echo "$to_set" | tee /sys/class/backlight/intel_backlight/brightness diff --git a/extras/HOME/.local/bin/spotify-control b/extras/HOME/.local/bin/spotify-control index e001eb6..ac921c7 100755 --- a/extras/HOME/.local/bin/spotify-control +++ b/extras/HOME/.local/bin/spotify-control @@ -6,16 +6,17 @@ then exit fi -if [ "$(pidof spotify)" = "" ] +if [ "$(pidof spotifyd)" != "" ] then - echo "Spotify is not running" - exit + target=spotifyd +else + target=spotify fi function mpris2_dbus_player_do { dbus-send \ --print-reply \ - --dest=org.mpris.MediaPlayer2.spotify \ + --dest=org.mpris.MediaPlayer2."$target" \ /org/mpris/MediaPlayer2 \ "org.mpris.MediaPlayer2.Player.$1" } @@ -23,7 +24,7 @@ function mpris2_dbus_player_do { function mpris2_dbus_get_player_property { dbus-send \ --print-reply \ - --dest=org.mpris.MediaPlayer2.spotify \ + --dest=org.mpris.MediaPlayer2."$target" \ /org/mpris/MediaPlayer2 \ org.freedesktop.DBus.Properties.Get \ string:'org.mpris.MediaPlayer2.Player' "string:$1" @@ -31,11 +32,27 @@ function mpris2_dbus_get_player_property { case $1 in "play") - mpris2_dbus_player_do PlayPause + status="$("$0" getStatus)" + if [[ "$target" == "spotifyd" ]] ; then + # Spotifyd doesn't support play/pause + if [[ "$status" == "Playing" ]] ; then + "$0" pause + else + "$0" justplay + fi + else + mpris2_dbus_player_do PlayPause + fi ;; "next") mpris2_dbus_player_do Next ;; + "pause") + mpris2_dbus_player_do Pause + ;; + "justplay") + mpris2_dbus_player_do Play + ;; "prev") mpris2_dbus_player_do Previous ;; @@ -66,7 +83,7 @@ case $1 in egrep -v ^$ ;; "getStatus") - mpris_dbus_get_player_property 'PlaybackStatus' | \ + mpris2_dbus_get_player_property 'PlaybackStatus' | \ grep 'string "[^"]*"' | \ sed 's/.*"\(.*\)"[^"]*$/\1/' ;; diff --git a/extras/HOME/.xmobarrc b/extras/HOME/.xmobarrc index a2b8a6e..8f17c72 100644 --- a/extras/HOME/.xmobarrc +++ b/extras/HOME/.xmobarrc @@ -14,8 +14,8 @@ Config , borderWidth = 2 , bgColor = "#000000" , fgColor = "white" - , alpha = 220 -- default: 255 - , position = TopSize L 100 40 + , alpha = 230 -- default: 255 + , position = TopSize L 100 50 , textOffset = -1 -- default: -1 , iconOffset = -1 -- default: -1 , lowerOnStart = True @@ -30,11 +30,11 @@ Config , template = " %logo% %uname% │\ \ %date% │ \ - \%StdinReader%}%time%\ + \%StdinReader%}\ \{ %cpu% %memory% \ \│ %weather% │\ \ %mpris2% │ \ - \%bluetooth%%bat% " + \%bluetooth%%bat% %time% " , commands = [ Run StdinReader, Run Date "%H:%M:%S" "time" 10, @@ -57,7 +57,7 @@ Config "--normal", "#88ff88", "--high", "#ff8888" ] 10, - Run Mpris2 "spotify" [ + Run Mpris2 "spotifyd" [ "-t", "</fn>", "--nastring", "<fc=#404040> </fc>"] 20, Run Com ".xmonad/xmobar-weather" [] "weather" 9000, diff --git a/extras/HOME/.xmonad/xmobar-bluetooth b/extras/HOME/.xmonad/xmobar-bluetooth index 30903e3..9b4f5cc 100755 --- a/extras/HOME/.xmonad/xmobar-bluetooth +++ b/extras/HOME/.xmonad/xmobar-bluetooth @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash cur="" diff --git a/extras/HOME/.xmonad/xmobar-weather b/extras/HOME/.xmonad/xmobar-weather index e8ce28e..6b5c409 100755 --- a/extras/HOME/.xmonad/xmobar-weather +++ b/extras/HOME/.xmonad/xmobar-weather @@ -14,6 +14,11 @@ $content = `curl "https://api.sunrise-sunset.org/json?lat=$lat&lng=$lon&formatte die "Unable to get sunrise/sunset data" unless defined $content; +if (length($content) == 0) { + printf("<fc=#404040>X</fc>"); + exit +} + $sunrise_str=$content; $sunset_str=$content; $sunrise_str =~ s#.*"sunrise":"([^"]*)".*#\1#; diff --git a/src/Internal/Keys.hs b/src/Internal/Keys.hs index 89e2cf1..2905ba0 100644 --- a/src/Internal/Keys.hs +++ b/src/Internal/Keys.hs @@ -141,6 +141,7 @@ keymap = runKeys $ do justMod $ mapNextString $ \_ str -> case str of [ch] | isAlphaNum ch -> gotoWorkspace ch + [' '] -> gotoAccompaningWorkspace _ -> return () shiftMod $ mapNextString $ \_ str -> case str of diff --git a/src/Internal/Lib.hs b/src/Internal/Lib.hs index c3bdeb9..3beb640 100644 --- a/src/Internal/Lib.hs +++ b/src/Internal/Lib.hs @@ -64,6 +64,17 @@ getHorizontallyOrderedScreens windowSet = where screens = current windowSet : visible windowSet +getCurrentWorkspace :: X WorkspaceName +getCurrentWorkspace = withWindowSet $ + \(StackSet (Screen (Workspace t _ _) _ _) _ _ _) -> do + return (head t) + +gotoAccompaningWorkspace :: X () +gotoAccompaningWorkspace = do + cur <- getCurrentWorkspace + if isUpper cur + then gotoWorkspace (toLower cur) + else gotoWorkspace (toUpper cur) gotoWorkspace :: WorkspaceName -> X () gotoWorkspace ch = do -- cgit