From 8064b01c90a6d4700642154885211d958c3c1844 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 7 Jan 2024 09:52:44 -0500 Subject: [PATCH] ENH move external scripts to this repo --- {icons => assets/icons}/wifi_0.xpm | 0 {icons => assets/icons}/wifi_1.xpm | 0 {icons => assets/icons}/wifi_2.xpm | 0 {icons => assets/icons}/wifi_3.xpm | 0 {icons => assets/icons}/wifi_4.xpm | 0 {icons => assets/icons}/wifi_5.xpm | 0 {icons => assets/icons}/wifi_6.xpm | 0 {icons => assets/icons}/wifi_7.xpm | 0 {icons => assets/icons}/wifi_8.xpm | 0 {sound => assets/sound}/smb_fireball.wav | Bin {sound => assets/sound}/smb_pipe.wav | Bin {sound => assets/sound}/smb_powerup.wav | Bin bin/xmobar.hs | 3 +- lib/XMonad/Internal/Command/Desktop.hs | 2 +- package.yaml | 5 +- scripts/runtime_pkgs => runtime_pkgs | 0 scripts/screencap | 22 ++++++++ scripts/screenlock | 61 +++++++++++++++++++++++ 18 files changed, 89 insertions(+), 4 deletions(-) rename {icons => assets/icons}/wifi_0.xpm (100%) rename {icons => assets/icons}/wifi_1.xpm (100%) rename {icons => assets/icons}/wifi_2.xpm (100%) rename {icons => assets/icons}/wifi_3.xpm (100%) rename {icons => assets/icons}/wifi_4.xpm (100%) rename {icons => assets/icons}/wifi_5.xpm (100%) rename {icons => assets/icons}/wifi_6.xpm (100%) rename {icons => assets/icons}/wifi_7.xpm (100%) rename {icons => assets/icons}/wifi_8.xpm (100%) rename {sound => assets/sound}/smb_fireball.wav (100%) rename {sound => assets/sound}/smb_pipe.wav (100%) rename {sound => assets/sound}/smb_powerup.wav (100%) rename scripts/runtime_pkgs => runtime_pkgs (100%) create mode 100755 scripts/screencap create mode 100755 scripts/screenlock diff --git a/icons/wifi_0.xpm b/assets/icons/wifi_0.xpm similarity index 100% rename from icons/wifi_0.xpm rename to assets/icons/wifi_0.xpm diff --git a/icons/wifi_1.xpm b/assets/icons/wifi_1.xpm similarity index 100% rename from icons/wifi_1.xpm rename to assets/icons/wifi_1.xpm diff --git a/icons/wifi_2.xpm b/assets/icons/wifi_2.xpm similarity index 100% rename from icons/wifi_2.xpm rename to assets/icons/wifi_2.xpm diff --git a/icons/wifi_3.xpm b/assets/icons/wifi_3.xpm similarity index 100% rename from icons/wifi_3.xpm rename to assets/icons/wifi_3.xpm diff --git a/icons/wifi_4.xpm b/assets/icons/wifi_4.xpm similarity index 100% rename from icons/wifi_4.xpm rename to assets/icons/wifi_4.xpm diff --git a/icons/wifi_5.xpm b/assets/icons/wifi_5.xpm similarity index 100% rename from icons/wifi_5.xpm rename to assets/icons/wifi_5.xpm diff --git a/icons/wifi_6.xpm b/assets/icons/wifi_6.xpm similarity index 100% rename from icons/wifi_6.xpm rename to assets/icons/wifi_6.xpm diff --git a/icons/wifi_7.xpm b/assets/icons/wifi_7.xpm similarity index 100% rename from icons/wifi_7.xpm rename to assets/icons/wifi_7.xpm diff --git a/icons/wifi_8.xpm b/assets/icons/wifi_8.xpm similarity index 100% rename from icons/wifi_8.xpm rename to assets/icons/wifi_8.xpm diff --git a/sound/smb_fireball.wav b/assets/sound/smb_fireball.wav similarity index 100% rename from sound/smb_fireball.wav rename to assets/sound/smb_fireball.wav diff --git a/sound/smb_pipe.wav b/assets/sound/smb_pipe.wav similarity index 100% rename from sound/smb_pipe.wav rename to assets/sound/smb_pipe.wav diff --git a/sound/smb_powerup.wav b/assets/sound/smb_powerup.wav similarity index 100% rename from sound/smb_powerup.wav rename to assets/sound/smb_powerup.wav diff --git a/bin/xmobar.hs b/bin/xmobar.hs index 4ac7837..6b0989f 100644 --- a/bin/xmobar.hs +++ b/bin/xmobar.hs @@ -14,6 +14,7 @@ import Data.Internal.XIO import GHC.Enum (enumFrom) import Options.Applicative import RIO hiding (hFlush) +import RIO.FilePath import RIO.List import qualified RIO.NonEmpty as NE import qualified RIO.Text as T @@ -163,7 +164,7 @@ config bf ifs ios br confDir = , pickBroadest = False , persistent = True , -- store the icons with the xmonad/xmobar stack project - iconRoot = confDir ++ "/icons" + iconRoot = confDir "assets" "icons" , commands = csRunnable <$> concatRegions br } diff --git a/lib/XMonad/Internal/Command/Desktop.hs b/lib/XMonad/Internal/Command/Desktop.hs index 8dd6676..7d21b6f 100644 --- a/lib/XMonad/Internal/Command/Desktop.hs +++ b/lib/XMonad/Internal/Command/Desktop.hs @@ -206,7 +206,7 @@ runStopPlay = runMultimediaIfInstalled "stop playback" "stop" -- Volume Commands soundDir :: FilePath -soundDir = "sound" +soundDir = "assets" "sound" playSound :: MonadIO m => FilePath -> m () playSound file = do diff --git a/package.yaml b/package.yaml index 1d44bf2..2bb8ca8 100644 --- a/package.yaml +++ b/package.yaml @@ -9,9 +9,10 @@ extra-source-files: - README.md - fourmolu.yaml - make_pkgs -- icons/* +- runtime_pkgs +- assets/icons/* +- assets/sound/* - scripts/* -- sound/* default-extensions: - OverloadedStrings diff --git a/scripts/runtime_pkgs b/runtime_pkgs similarity index 100% rename from scripts/runtime_pkgs rename to runtime_pkgs diff --git a/scripts/screencap b/scripts/screencap new file mode 100755 index 0000000..fe1aa4c --- /dev/null +++ b/scripts/screencap @@ -0,0 +1,22 @@ +#! /bin/bash + +## capture a screenshot using scrot + +SS_DIR="$XDG_CACHE_HOME/screenshots" + +while getopts ":sw" opt; do + case ${opt} in + s) + scrot "$SS_DIR/desktop/%Y-%m-%d-%H:%M:%S_desktop.png" + notify-send "Screen captured" + ;; + w) + scrot -u "$SS_DIR/window/%Y-%m-%d-%H:%M:%S-\$wx\$h.png" + notify-send "Window captured" + ;; + \?) + echo "invalid option, read the code" + ;; + esac +done + diff --git a/scripts/screenlock b/scripts/screenlock new file mode 100755 index 0000000..a98af77 --- /dev/null +++ b/scripts/screenlock @@ -0,0 +1,61 @@ +#! /bin/bash + +## lock the screen using i3lock (and maybe suspend) + +## usage: screenlock [SUSPEND] + +# WORKAROUND make the date show up in the right place on 2+ monitor setups +# I want it to only show up on the primary screen, so use xrandr to get the +# dimensions and position of the primary monitor and calculate the date position +# from that +geometry=$(xrandr | sed -n 's/^.*primary \([0-9]*\)x[0-9]*+\([0-9]\)*+[0-9]* .*/\1 \2/p') +width=$(echo "$geometry" | cut -f1 -d" ") +xpos=$(echo "$geometry" | cut -f2 -d" ") +xoffset=$(("$xpos" + "$width" / 2)) +datepos="$xoffset:600" + +# lock and fork so we can suspend with the screen locked +i3lock --color=000000 \ + --pass-media-keys \ + --nofork \ + --ignore-empty-password \ + --screen=0 \ + --indicator \ + --inside-color=00000055 \ + --insidever-color=00000055 \ + --insidewrong-color=00000055 \ + --ring-color=555555ff \ + --ringwrong-color=ff3333ff \ + --ringver-color=99ceffff \ + --keyhl-color=99ceffff \ + --bshl-color=9523ffff \ + --line-color=00000000 \ + --separator-color=00000000 \ + --clock \ + --verif-color=99ceffff \ + --wrong-color=ff8282ff \ + --time-color=ffffffff \ + --time-size=72 \ + --time-str="%H:%M" \ + --date-color=ffffffff \ + --date-size=42 \ + --date-str="%b %d, %Y" \ + --date-align 0 \ + --date-pos="$datepos" \ + --wrong-size=72 \ + --verif-size=72 \ + --radius=300 \ + --ring-width=25 & + +# suspend if we want, and if this machine is currently using a battery +batpath=/sys/class/power_supply/BAT0/status + +if [ -f "$batpath" ] && \ + [ "$(cat $batpath)" == "Discharging" ] && \ + [ "$1" == "true" ]; then + systemctl suspend +fi + +# block until the screen is unlocked (since xss-lock expects the locker to exit +# only when unlocked) +wait