ktouch & discord
This commit is contained in:
@@ -1,24 +1,33 @@
|
||||
module Plugins.Audio where
|
||||
|
||||
import Xmobar
|
||||
import Xmobar.Run.Timer (doEveryTenthSeconds)
|
||||
import System.Process
|
||||
import System.Exit
|
||||
import System.IO (hClose, hGetLine)
|
||||
import Control.Concurrent
|
||||
|
||||
data Audio = Audio String Int deriving (Read, Show)
|
||||
data Audio = Audio Int deriving (Read, Show)
|
||||
|
||||
instance Exec Audio where
|
||||
alias (Audio _ _) = "audio"
|
||||
start (Audio f r) cb = if r > 0 then (doEveryTenthSeconds r (audio f cb)) else audio f cb
|
||||
alias (Audio _) = "audio"
|
||||
start (Audio r) cb = if r > 0 then go cb r else go cb 1000
|
||||
where
|
||||
go :: (String -> IO ()) -> Int -> IO ()
|
||||
go cb r = do
|
||||
response <- readProcess "/bin/sh" ["-c", "pulseaudio-ctl full-status"] ""
|
||||
let list = [w | w <- words (init response)]
|
||||
audio (head list) (list !! 1) (last list) cb
|
||||
threadDelay r
|
||||
go cb r
|
||||
|
||||
audio :: String -> (String -> IO ()) -> IO ()
|
||||
audio format cb = do
|
||||
(i,o,e,p) <- runInteractiveProcess "pulseaudio-ctl full-status" [] Nothing Nothing
|
||||
exit <- waitForProcess p
|
||||
let closeHandles = hClose o >> hClose i >> hClose e
|
||||
getL = hGetLine o
|
||||
str <- getL
|
||||
closeHandles
|
||||
cb str
|
||||
--readProcess "pulseaudio-ctl full-status" []
|
||||
audio :: String -> String -> String -> (String -> IO ()) -> IO ()
|
||||
audio vol speaker mic cb
|
||||
| speaker == "yes" = chooseMic vol "#f38ba8" "\xf466" mic cb
|
||||
| elem vol [show i | i <- [0..49]] = chooseMic vol "#a6e3a1" "\xf027" mic cb
|
||||
| otherwise = chooseMic vol "#a6e3a1" "\xf028" mic cb
|
||||
| otherwise = formatAudio vol "a" "c" "d" "e" cb
|
||||
where
|
||||
chooseMic :: String -> String -> String -> String -> (String -> IO ()) -> IO ()
|
||||
chooseMic vol speakerC speakerI mic cb
|
||||
| mic == "yes" = formatAudio vol speakerC speakerI "#f38ba8" "\xf036d" cb
|
||||
| otherwise = formatAudio vol speakerC speakerI "#a6e3a1" "\xf036c" cb
|
||||
formatAudio :: String -> String -> String -> String -> String -> (String -> IO ()) -> IO ()
|
||||
formatAudio vol speakerC speakerI micC micI cb = cb ("<fc=" ++ speakerC ++ "><fn=1>" ++ speakerI ++ "</fn></fc> " ++ vol ++ "% <fc=" ++ micC ++ "><fn=1>" ++ micI ++ "</fn></fc>")
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
packages: .
|
||||
|
||||
with-compiler: ghc-9.2.4
|
||||
|
||||
package xmobar
|
||||
flags: +all_extensions
|
||||
@@ -17,8 +17,8 @@ config =
|
||||
, fgColor = "#f5e0dc"
|
||||
, commands =
|
||||
[
|
||||
Run $ Audio "abc" 200
|
||||
--Run $ Com "/bin/sh" ["-c", "Status=$(pulseaudio-ctl full-status); Volume=$(cut -d ' ' -f 1 <<<$Status); Mute=$(cut -d ' ' -f 2 <<<$Status); Microphone=$(cut -d ' ' -f 3 <<<$Status); SpeakerColor=\"#a6e3a1\"; MicColor=\"#a6e3a1\"; if [[ $Mute == \"yes\" ]]; then Symbol=\"\xf466\"; SpeakerColor=\"#f38ba8\"; elif [[ $Volume -le 50 ]]; then Symbol=\"\xf027\"; elseSymbol=\"\xf028\"; fi; if [[ $Microphone == \"yes\" ]]; then MicOut=\"\xf036d\"; MicColor=\"#f38ba8\"; else MicOut=\"\xf036c\"; fi; echo \"<fc=$SpeakerColor><fn=1>$Symbol</fn></fc> $Volume% <fc=$MicColor><fn=1>$MicOut</fn></fc>\""] "audio" 10
|
||||
--Run $ Audio 10
|
||||
Run $ Com "/bin/sh" ["-c", "Status=$(pulseaudio-ctl full-status); Volume=$(cut -d ' ' -f 1 <<<$Status); Mute=$(cut -d ' ' -f 2 <<<$Status); Microphone=$(cut -d ' ' -f 3 <<<$Status); SpeakerColor=\"#a6e3a1\"; MicColor=\"#a6e3a1\"; if [[ $Mute == \"yes\" ]]; then Symbol=\"\xf466\"; SpeakerColor=\"#f38ba8\"; elif [[ $Volume -le 50 ]]; then Symbol=\"\xf027\"; elseSymbol=\"\xf028\"; fi; if [[ $Microphone == \"yes\" ]]; then MicOut=\"\xf036d\"; MicColor=\"#f38ba8\"; else MicOut=\"\xf036c\"; fi; echo \"<fc=$SpeakerColor><fn=1>$Symbol</fn></fc> $Volume% <fc=$MicColor><fn=1>$MicOut</fn></fc>\""] "audio" 60
|
||||
--Run $ Com "/bin/sh" ["-c", "Status=$(pulseaudio-ctl full-status);
|
||||
-- Volume=$(cut -d ' ' -f 1 <<<$Status);
|
||||
-- Mute=$(cut -d ' ' -f 2 <<<$Status);
|
||||
@@ -40,7 +40,7 @@ config =
|
||||
-- MicOut=\"\xf036d\";
|
||||
-- MicColor=\"#f38ba8\";
|
||||
-- else MicOut=\"\xf036c\";
|
||||
-- fi;
|
||||
-- fi;xmobar.Run not found
|
||||
--
|
||||
-- echo \"<fc=$SpeakerColor><fn=1>$Symbol</fn></fc> $Volume% <fc=$MicColor><fn=1>$MicOut</fn></fc>\""] "audio" 10
|
||||
--Run $ Audio
|
||||
|
||||
Reference in New Issue
Block a user