[Linux] Don't do anything in rofi_select_input if nothing selected

This commit is contained in:
Ivan Malison 2017-03-30 11:36:44 -07:00
parent a5e55df922
commit fb24509e21
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8

View File

@ -16,11 +16,14 @@ main = do
matches = catMaybes $ matchRegex sinkRegex <$> sinkInfos
entries = map buildEntry matches
rofiText = intercalate "\n" entries
selection <- snd <$> shellStrict "rofi -dmenu -i" (select $ map fromString entries)
(exitCode, selection) <- shellStrict "rofi -dmenu -i" (select $ map fromString entries)
case exitCode of
ExitSuccess -> do
let selectedSink = head $ splitOn " " $ unpack selection
mapM_ (setMuteAction "1" . head) matches
setMuteAction "0" selectedSink
return ()
ExitFailure _ -> return ()
where getSinkText = snd <$> shellStrict "pactl list sink-inputs" empty
sinkRegex = mkRegexWithOpts "Input .([0-9]*).*?application.name =([^\n]*)" False True
buildEntry (num:name:_) = let app = (filter (not . (`elem` ("\"" :: String))) name) in printf "%s - %s" num $ trim app