diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2021-11-29 13:11:54 -0700 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2022-10-09 12:19:45 -0600 |
| commit | 8486ce27943b1c0460bfcd6d93ed84d2b3c5afb5 (patch) | |
| tree | 52f5343a37e06d5b4d1914a7a5d00807e3f16497 | |
| parent | bc8f075ebc6ebb987a6c6a20e8a30df241197073 (diff) | |
| download | rde-8486ce27943b1c0460bfcd6d93ed84d2b3c5afb5.tar.gz rde-8486ce27943b1c0460bfcd6d93ed84d2b3c5afb5.tar.bz2 rde-8486ce27943b1c0460bfcd6d93ed84d2b3c5afb5.zip | |
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<space> keybinding to go to the toogle-cased version of the
current workspace.
| -rwxr-xr-x | extras/HOME/.local/bin/set-backlight.sh | 35 | ||||
| -rwxr-xr-x | extras/HOME/.local/bin/spotify-control | 31 | ||||
| -rw-r--r-- | extras/HOME/.xmobarrc | 10 | ||||
| -rwxr-xr-x | extras/HOME/.xmonad/xmobar-bluetooth | 2 | ||||
| -rwxr-xr-x | extras/HOME/.xmonad/xmobar-weather | 5 | ||||
| -rw-r--r-- | src/Internal/Keys.hs | 1 | ||||
| -rw-r--r-- | src/Internal/Lib.hs | 11 |
7 files changed, 82 insertions, 13 deletions
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% <fc=#a0a0a0><fn=3>%uname%</fn></fc><fc=#404040> │\ \</fc><fc=#a0a0a0> %date%</fc><fc=#404040> │ \ - \</fc>%StdinReader%}<fn=2><fc=#606060>%time%</fc></fn>\ + \</fc>%StdinReader%}\ \{ %cpu% %memory% <fc=#404040>\ \│</fc> %weather% <fc=#404040>│\ \</fc> <fc=#a0a0a0>%mpris2%</fc> <fc=#404040>│ \ - \</fc>%bluetooth%%bat% " + \</fc>%bluetooth%%bat% <fc=#404040>│</fc> <fn=2><fc=#606060>%time%</fc></fn> " , 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", "<fc=#1aa54b></fc> <fn=3><title></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 |