diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2022-03-18 21:23:28 -0600 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2022-03-18 21:23:28 -0600 |
| commit | 9118fc86df893f92a14d5ec4d82d052253a450b0 (patch) | |
| tree | ad1277c42eef73aaf6208713520b52e332fb29ab | |
| parent | d3354e4a7099bd7b70973a66b836ba4f63b60bd6 (diff) | |
| parent | a87cbc7357566b26c7dca7538d4b03da5f8b999a (diff) | |
| download | rde-9118fc86df893f92a14d5ec4d82d052253a450b0.tar.gz rde-9118fc86df893f92a14d5ec4d82d052253a450b0.tar.bz2 rde-9118fc86df893f92a14d5ec4d82d052253a450b0.zip | |
Merge branch 'v017' of josher.dev:rde into v017
| -rwxr-xr-x | extras/HOME/.local/bin/emoticon-select.sh | 3 | ||||
| -rwxr-xr-x | extras/HOME/.local/bin/library-view.sh | 7 | ||||
| -rw-r--r-- | extras/HOME/.xmobarrc | 10 | ||||
| -rw-r--r-- | extras/HOME/.xmonad/emoticons.txt | 1 | ||||
| -rwxr-xr-x | extras/HOME/.xmonad/xmobar-bluetooth | 24 | ||||
| -rwxr-xr-x | extras/HOME/.xmonad/xmobar-media | 9 | ||||
| -rwxr-xr-x | extras/HOME/.xmonad/xmobar-weather | 46 | ||||
| -rw-r--r-- | package.yaml | 1 | ||||
| -rw-r--r-- | src/Internal/Keys.hs | 158 | ||||
| -rw-r--r-- | src/Internal/Logger.hs | 36 | ||||
| -rw-r--r-- | src/Internal/Submap.hs | 46 | ||||
| -rw-r--r-- | src/Main.hs | 1 |
12 files changed, 265 insertions, 77 deletions
diff --git a/extras/HOME/.local/bin/emoticon-select.sh b/extras/HOME/.local/bin/emoticon-select.sh index e1637d1..5674e44 100755 --- a/extras/HOME/.local/bin/emoticon-select.sh +++ b/extras/HOME/.local/bin/emoticon-select.sh @@ -11,7 +11,6 @@ else fi -selection="$("${menu[@]}" < $HOME/.xmonad/emoticons.txt)" -emoticon="$(echo ${selection/*-})" +emoticon="$("${menu[@]}" < $HOME/.xmonad/emoticons.txt | sed 's#^[^-]*-\s*##')" echo "$emoticon" | xclip -selection clipboard diff --git a/extras/HOME/.local/bin/library-view.sh b/extras/HOME/.local/bin/library-view.sh index 29925a8..b2c5dd5 100755 --- a/extras/HOME/.local/bin/library-view.sh +++ b/extras/HOME/.local/bin/library-view.sh @@ -13,10 +13,9 @@ fi cd ~/Library -files=(*.pdf) - -file_with_title="$(for file in "${files[@]}" ; do - echo "$file| $(echo "$file" | sed 's#\(^\|_\|\s\)\([a-z]\)#\1\U\2#g' | tr '_' ' ' | sed 's/.[^.]*$//')" +file_with_title="$(find . -name '*.pdf' | while read file ; do + echo "$file| $(echo "$file" | sed \ + 's#\(^\|_\|\s\)\([a-z]\)#\1\U\2#g;s/\.[^.]*$//;s#^\(.*\)/\([^/]*\)$#\2 (\1)#' | tr '_' ' ')" done)" selected=$(echo "$file_with_title" | (while read file ; do diff --git a/extras/HOME/.xmobarrc b/extras/HOME/.xmobarrc index cef2154..7461de8 100644 --- a/extras/HOME/.xmobarrc +++ b/extras/HOME/.xmobarrc @@ -29,16 +29,14 @@ Config , alignSep = "}{" , template = " %logo% <fc=#a0a0a0><fn=3>%uname%</fn></fc><fc=#404040> │\ - \</fc><fc=#a0a0a0> %date%</fc><fc=#404040> │ \ \</fc>%StdinReader%}\ \{ %cpu% %memory% <fc=#404040>\ \│</fc> %weather% <fc=#404040>│\ - \</fc> <fc=#a0a0a0>%mpris2%</fc> <fc=#404040>│ \ + \</fc> <fc=#a0a0a0>%media%</fc> <fc=#404040>│ \ \</fc>%bluetooth%%bat% <fc=#404040>│</fc> <fn=2><fc=#606060>%time%</fc></fn> " , commands = [ Run StdinReader, - Run Date "%H:%M:%S" "time" 10, - Run Date "<fn=3>%m/%d</fn>" "date" 10, + Run Date "%m/%d %H:%M:%S" "time" 10, Run Cpu [ "-t", "<fn=3><fc=#000000><bar></fc></fn>", "-L", "3", @@ -57,9 +55,7 @@ Config "--normal", "#88ff88", "--high", "#ff8888" ] 10, - Run Mpris2 "spotifyd" [ - "-t", "<fc=#1aa54b></fc> <fn=3><title></fn>", - "--nastring", "<fc=#404040> </fc>"] 20, + Run Com ".xmonad/xmobar-media" [] "media" 20, Run Com ".xmonad/xmobar-weather" [] "weather" 9000, Run Com ".xmonad/xmobar-logo" [] "logo" 0, Run Com "uname" ["-r"] "uname" 0, diff --git a/extras/HOME/.xmonad/emoticons.txt b/extras/HOME/.xmonad/emoticons.txt index 65289c4..f919a81 100644 --- a/extras/HOME/.xmonad/emoticons.txt +++ b/extras/HOME/.xmonad/emoticons.txt @@ -1,5 +1,6 @@ Bear - (''')(0.0)(''') Cry - ಥ_ಥ +Cry - ಥ︵ಥ Deal with it - (•_•) ( •_•)>⌐■-■ (⌐■_■) Deal with it. - (▀̿Ĺ̯▀̿ ̿) Disapprove - ಠ_ಠ diff --git a/extras/HOME/.xmonad/xmobar-bluetooth b/extras/HOME/.xmonad/xmobar-bluetooth index 9b4f5cc..16a6d70 100755 --- a/extras/HOME/.xmonad/xmobar-bluetooth +++ b/extras/HOME/.xmonad/xmobar-bluetooth @@ -2,17 +2,21 @@ cur="" -bluetoothctl -- info | while read line ; do - key=${line%%: *} - value=${line//*: } +if [ -d /sys/class/bluetooth ] ; then - if [ "$key" == "Name" ] ; then - cur="$value" - fi + bluetoothctl -- info | while read line ; do + key=${line%%: *} + value=${line//*: } - if [ "$key" == "Connected" -a "$value" == "yes" ] ; then - exec echo "<fc=#4287f5></fc> <fc=#a0a0a0><fn=3>$cur</fn></fc> <fc=#404040>│</fc> " - fi -done + if [ "$key" == "Name" ] ; then + cur="$value" + fi + + if [ "$key" == "Connected" -a "$value" == "yes" ] ; then + exec echo "<fc=#4287f5></fc> <fc=#a0a0a0><fn=3>$cur</fn></fc> <fc=#404040>│</fc> " + fi + done + +fi exec echo "<fc=#404040></fc> <fc=#404040>│</fc> " diff --git a/extras/HOME/.xmonad/xmobar-media b/extras/HOME/.xmonad/xmobar-media new file mode 100755 index 0000000..7232900 --- /dev/null +++ b/extras/HOME/.xmonad/xmobar-media @@ -0,0 +1,9 @@ +#!/bin/bash + +title="$(spotify-control getTitle)" + +if [[ "$?" -eq 0 ]] ; then + echo "<fc=#1aa54b></fc> <fn=3>$title</fn>" +else + echo "<fc=#404040> </fc>" +fi diff --git a/extras/HOME/.xmonad/xmobar-weather b/extras/HOME/.xmonad/xmobar-weather index 6b5c409..0fee524 100755 --- a/extras/HOME/.xmonad/xmobar-weather +++ b/extras/HOME/.xmonad/xmobar-weather @@ -69,30 +69,30 @@ if ($current_str gt $sunrise_str and $current_str lt $sunset_str) { $dir=%directions{$wind_direction}; %conditions_day = ( - clear => "<fc=#ddcf04>", - sunny => "<fc=#ddcf04>", - mostly_clear => "<fc=#00a3c4>", - mostly_sunny => "<fc=#ddcf04>", - partly_sunny => "<fc=#ddcf04>", - fair => "<fc=#a0a0a0>🌑", - cloudy =>"<fc=#a0a0a0>摒", - overcast =>"<fc=#808080>", - partly_cloudy => "<fc=#a0a0a0>杖", - mostly_cloudy => "<fc=#808080>", - considerable_cloudiness => "<fc=#a0a0a0>ﭽ" ); + clear => "<fc=#ddcf04></fc>", + sunny => "<fc=#ddcf04></fc>", + mostly_clear => "<fc=#00a3c4></fc>", + mostly_sunny => "<fc=#ddcf04></fc>", + partly_sunny => "<fc=#ddcf04></fc>", + fair => "<fc=#a0a0a0>🌑</fc>", + cloudy =>"<fc=#a0a0a0>摒</fc>", + overcast =>"<fc=#808080></fc>", + partly_cloudy => "<fc=#a0a0a0>杖</fc>", + mostly_cloudy => "<fc=#808080></fc>", + considerable_cloudiness => "<fc=#a0a0a0>ﭽ</fc>" ); %conditions_night = ( - clear => "<fc=#00a3c4>", - sunny => "<fc=#00a3c4>", - mostly_clear => "<fc=#00a3c4>", - mostly_sunny => "<fc=#00a3c4>", - partly_sunny => "<fc=#00a3c4>", - fair => "<fc=#808080>🌑", - cloudy =>"<fc=#808080>摒", - overcast =>"<fc=#404040>", - partly_cloudy => "<fc=#a0a0a0>", - mostly_cloudy => "<fc=#808080>", - considerable_cloudiness => "<fc=#a0a0a0>ﭽ" ); + clear => "<fc=#00a3c4></fc>", + sunny => "<fc=#00a3c4></fc>", + mostly_clear => "<fc=#00a3c4></fc>", + mostly_sunny => "<fc=#00a3c4></fc>", + partly_sunny => "<fc=#00a3c4></fc>", + fair => "<fc=#808080>🌑</fc>", + cloudy =>"<fc=#808080>摒</fc>", + overcast =>"<fc=#404040></fc>", + partly_cloudy => "<fc=#a0a0a0></fc>", + mostly_cloudy => "<fc=#808080></fc>", + considerable_cloudiness => "<fc=#a0a0a0>ﭽ</fc>" ); if ($is_day) { $conditions = %conditions_day{$sky_conditions}; @@ -100,4 +100,4 @@ if ($is_day) { $conditions = %conditions_night{$sky_conditions}; } -printf("<fc=#a0a0a0><fn=3>$city</fn> <fn=3>$dir</fn> <fn=3>${wind_speed}</fn></fc> $conditions</fc><fn=3> <fc=#a0a0a0>%.0f°F</fc></fn>\n", $temp); +printf("<fc=#a0a0a0><fn=3>$city</fn> <fn=3>$dir</fn> <fn=3>${wind_speed}</fn></fc> $conditions<fn=3> <fc=#a0a0a0>%.0f°F</fc></fn>\n", $temp); diff --git a/package.yaml b/package.yaml index 318a3af..b07f2df 100644 --- a/package.yaml +++ b/package.yaml @@ -21,3 +21,4 @@ dependencies: - split - mtl - transformers + - monad-loops diff --git a/src/Internal/Keys.hs b/src/Internal/Keys.hs index 27315cd..195e12f 100644 --- a/src/Internal/Keys.hs +++ b/src/Internal/Keys.hs @@ -1,6 +1,7 @@ {-# LANGUAGE RankNTypes #-} module Internal.Keys (applyKeys) where +import Control.Monad.Loops (iterateWhile) import Control.Monad.Fix (fix) import Graphics.X11.ExtraTypes.XF86; import Internal.KeysM @@ -11,7 +12,7 @@ import Graphics.X11.ExtraTypes.XorgDefault import System.Process import XMonad.Util.Ungrab import XMonad.Layout.Spacing -import Data.Maybe (isJust) +import Data.Maybe (isJust, fromMaybe) import Debug.Trace import Control.Applicative import Prelude hiding ((!!)) @@ -43,15 +44,55 @@ import qualified XMonad.StackSet as W import Internal.Lib import Internal.DMenu import Internal.PassMenu +import Internal.Logger type KeyMap l = XConfig l -> Map (KeyMask, KeySym) (X ()) type ButtonsMap l = XConfig l -> Map (KeyMask, Button) (Window -> X ()) + +decreaseVolume = spawn "pactl set-sink-volume @DEFAULT_SINK@ -5%" +increaseVolume = spawn "pactl set-sink-volume @DEFAULT_SINK@ +5%" +playPause = spawn "spotify-control play" +mediaPrev = spawn "spotify-control prev" +mediaNext = spawn "spotify-control next" + + +button6 :: Button +button6 = 6 + +button7 :: Button +button7 = 7 + +button8 :: Button +button8 = 8 + +button9 :: Button +button9 = 9 + +button10 :: Button +button10 = 10 + +button11 :: Button +button11 = 11 + +button12 :: Button +button12 = 12 + +button13 :: Button +button13 = 13 + +button14 :: Button +button14 = 14 + +button15 :: Button +button15 = 15 + keymap :: KeyMap l keymap = runKeys $ do config <- getConfig - let subkeys = submap . flip runKeys config + let defaultKey key = fromMaybe (return ()) $ Map.lookup key (keymap config) + subkeys = submapDefaultWithKey defaultKey . flip runKeys config bind xK_apostrophe $ do justMod $ subkeys $ do @@ -75,7 +116,7 @@ keymap = runKeys $ do -- Button programmed on mouse rawMask shiftMask $ click >> withFocused (windows . W.sink) - shiftMod $ spawn "spotify-control play" + shiftMod playPause bind xK_F2 $ -- Button programmed on mouse @@ -90,18 +131,18 @@ keymap = runKeys $ do -- I Don't really use these, but they could be bound to something cool! bind xK_F2 $ - rawMask shiftMask $ spawn "spotify-control next" + rawMask shiftMask mediaNext bind xK_F3 $ - rawMask shiftMask $ spawn "spotify-control prev" + rawMask shiftMask mediaPrev bind xK_F10 $ do - justMod $ spawn "spotify-control play" + justMod playPause bind xK_F11 $ do - justMod $ spawn "spotify-control prev" + justMod mediaPrev bind xK_F12 $ do - justMod $ spawn "spotify-control next" + justMod mediaNext bind xK_Return $ do justMod swapMaster @@ -190,6 +231,19 @@ keymap = runKeys $ do bind xK_q $ do shiftMod $ spawn "xmonad --recompile && xmonad --restart" + + justMod $ subkeys $ do + + bind xK_q $ + (justMod -|- noMod) $ do + firstMotion@(x, y) <- nextMotion + (x', y') <- iterateWhile (==firstMotion) nextMotion + + logs $ printf "Motion: (%d, %d) (%d, %d)" x y x' y' + + if (x' - x) < 0 + then mediaPrev + else mediaNext bind xK_r $ do justMod runDMenu @@ -204,7 +258,7 @@ keymap = runKeys $ do bind xK_t $ do justMod $ spawn (terminal config) - shiftMod $ withFocused $ windows . W.sink + shiftMod $ withFocused $ windows . W.sink altMod $ spawn (terminal config ++ " -t Floating\\ Term") bind xK_v $ @@ -213,12 +267,12 @@ keymap = runKeys $ do justMod $ fix $ \recur -> subkeys $ do bind xK_h $ do justMod $ do - spawn "pactl set-sink-volume @DEFAULT_SINK@ -5%" + decreaseVolume recur bind xK_l $ do justMod $ do - spawn "pactl set-sink-volume @DEFAULT_SINK@ +5%" + increaseVolume recur bind xK_v $ do @@ -233,7 +287,7 @@ keymap = runKeys $ do bind xK_z $ do justMod $ subkeys $ do - + bind xK_g $ do (justMod -|- noMod) $ mapNextString $ \_ s -> case s of @@ -246,6 +300,9 @@ keymap = runKeys $ do str (show (map ord str)) + bind xK_t $ do + (justMod -|- noMod) $ logs "Test Log" + bind xK_n $ do (justMod -|- noMod) $ spawn (terminal config ++ " -t Notes -e notes new") @@ -268,7 +325,6 @@ keymap = runKeys $ do bind xK_v $ do (justMod -|- noMod) $ spawn "set-volume.sh" (shiftMod -|- rawMask shiftMask) $ spawn "set-volume.sh -a" - -- Double-tap Z to toggle zoom. bind xK_z $ do @@ -276,41 +332,50 @@ keymap = runKeys $ do -- Z is reserved to create sub keybindings to do various things. -- I don't really use these at the moment. - bind xK_h $ do - noMod $ spawn "spotify-control prev" - - bind xK_l $ do - noMod $ spawn "spotify-control next" + bind xK_h $ noMod mediaPrev + bind xK_j $ noMod playPause + bind xK_l $ noMod mediaNext -- Centers the current focused window. i.e. toggles the Zoom layout -- modifier. shiftMod $ sendMessage ToggleZoom + bind xF86XK_Calculator $ do + noMod $ spawn $ terminal config ++ " -t Floating\\ Term -e /usr/bin/env python3" + bind xF86XK_AudioLowerVolume $ do noMod $ spawn "pactl set-sink-volume @DEFAULT_SINK@ -1%" - justMod $ spawn "spotify-control prev" + justMod mediaPrev bind xF86XK_AudioRaiseVolume $ do noMod $ spawn "pactl set-sink-volume @DEFAULT_SINK@ +1%" - justMod $ spawn "spotify-control next" + justMod mediaNext bind xF86XK_AudioMute $ do noMod $ spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle" bind xF86XK_AudioPlay $ do - noMod $ spawn "spotify-control play" + noMod playPause bind xF86XK_AudioNext $ do - noMod $ spawn "spotify-control next" + noMod mediaNext bind xF86XK_AudioPrev $ do - noMod $ spawn "spotify-control prev" + noMod mediaPrev bind xF86XK_AudioPrev $ do - noMod $ spawn "spotify-control prev" + noMod mediaPrev mouseMap :: ButtonsMap l mouseMap = runButtons $ do + config <- getConfig + + let x button = Map.lookup button (mouseMap config) + + let defaultButtons button = fromMaybe (\w -> return ()) $ + Map.lookup button (mouseMap config) + subMouse = submapButtonsWithKey defaultButtons . flip runButtons config + bind button1 $ do justMod $ \w -> focus w >> mouseMoveWindow w >> windows W.shiftMaster @@ -320,17 +385,50 @@ mouseMap = runButtons $ do bind button3 $ do justMod $ \w -> focus w >> mouseResizeWindow w >> windows W.shiftMaster - bind (6 :: Button) $ + bind button6 $ justMod $ const (relativeWorkspaceShift prev) - bind (7 :: Button) $ + bind button7 $ justMod $ const (relativeWorkspaceShift next) - bind (8 :: Button) $ - justMod $ const $ spawn "spotify-control prev" + bind button8 $ + justMod $ const mediaPrev + + bind button9 $ + justMod $ const mediaNext + + bind button14 $ do + noMod $ subMouse $ do + + bind button13 $ do + noMod $ \_ -> click >> CopyWindow.kill1 + + bind button14 $ do + noMod $ \_ -> click >> sendMessage ToggleZoom + + let mediaButtons = [ + (button4, increaseVolume), + (button5, decreaseVolume), + (button2, playPause), + (button9, mediaNext), + (button8, mediaPrev), + (button6, mediaPrev), + (button7, mediaNext) + ] + + + let continuous :: [(Button, X ())] -> Button -> Window -> X () + continuous actions button w = do + case find ((==button) . fst) actions of + Just (_, action) -> action + Nothing -> return () + + (subMouse $ + forM_ (map fst mediaButtons) $ \b -> + bind b $ noMod $ \w -> continuous actions b w) w - bind (9 :: Button) $ - justMod $ const $ spawn "spotify-control next" + forM_ (map fst mediaButtons) $ \b -> + bind b $ noMod $ continuous mediaButtons b applyKeys :: XConfig l -> IO (XConfig l) applyKeys config = diff --git a/src/Internal/Logger.hs b/src/Internal/Logger.hs new file mode 100644 index 0000000..f1960fb --- /dev/null +++ b/src/Internal/Logger.hs @@ -0,0 +1,36 @@ +module Internal.Logger where + +import XMonad +import qualified XMonad.Util.ExtensibleState as XS +import System.IO + +data LoggerState = + LoggerState { + logHandle :: Maybe Handle + } + +instance Read LoggerState where + readsPrec i s = map (\(_, s) -> (LoggerState Nothing, s)) (readsPrec i s :: [((), String)]) + +instance Show LoggerState where + show _ = show () + +instance ExtensionClass LoggerState where + initialValue = LoggerState Nothing + +logs :: String -> X () +logs s = do + LoggerState handle' <- XS.get + + handle <- + case handle' of + Nothing -> do + handle <- io $ openFile "/tmp/xmonad.log" AppendMode + XS.put $ LoggerState (Just handle) + return handle + + Just h -> return h + + io $ do + hPutStrLn handle s + hFlush handle diff --git a/src/Internal/Submap.hs b/src/Internal/Submap.hs index cdc2f95..e5968ff 100644 --- a/src/Internal/Submap.hs +++ b/src/Internal/Submap.hs @@ -1,7 +1,14 @@ -module Internal.Submap (mapNextString, module X) where +module Internal.Submap ( + mapNextString, + submapButtonsWithKey, + nextButton, + nextMotion, + module X) where import XMonad hiding (keys) import Control.Monad.Fix (fix) +import qualified Data.Map as Map +import Data.Map (Map) import XMonad.Actions.Submap as X @@ -26,3 +33,40 @@ mapNextString fn = do io $ ungrabKeyboard d currentTime fn m str + +nextButton :: X (ButtonMask, Button) +nextButton = do + XConf { theRoot = root, display = d } <- ask + io $ grabPointer d root False buttonPressMask grabModeAsync grabModeAsync 0 0 currentTime + + ret <- io $ allocaXEvent $ \xEv -> do + maskEvent d buttonPressMask xEv + ButtonEvent { ev_button = button, ev_state = m } <- getEvent xEv + return (m, button) + + io $ ungrabPointer d currentTime + + return ret + +nextMotion :: X (Int, Int) +nextMotion = do + XConf { theRoot = root, display = d } <- ask + io $ grabPointer d root False pointerMotionMask grabModeAsync grabModeAsync 0 0 currentTime + + ret <- io $ allocaXEvent $ \xEv -> do + maskEvent d pointerMotionMask xEv + MotionEvent { ev_x = x, ev_y = y } <- getEvent xEv + return (fromIntegral x, fromIntegral y) + + io $ ungrabPointer d currentTime + + return ret + +submapButtonsWithKey :: + ((ButtonMask, Button) -> Window -> X ()) -> (Map (ButtonMask, Button) (Window -> X ())) -> Window -> X () +submapButtonsWithKey defaultAction actions window = do + arg <- nextButton + + case Map.lookup arg actions of + Nothing -> defaultAction arg window + Just fn -> fn window diff --git a/src/Main.hs b/src/Main.hs index f70496c..cda3ae2 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -13,6 +13,7 @@ import Data.Monoid import Internal.XMobarLog import Internal.Keys import Internal.Layout +import Internal.Logger import Internal.DMenu (menuCommandString) import qualified XMonad as X |