xmonad-config/lib/XMonad/Internal/Notify.hs

64 lines
1.9 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedStrings #-}
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Functions for formatting and sending notifications
--
-- NOTE I use the DBus.Notify lib even though I don't actually use the DBus for
-- notifications (just formation them into 'notify-send' commands and spawn a
-- shell since that works more consistently with my current commands). If I ever
-- decide to switch to using the DBus it will be easy.
2020-04-01 20:17:47 -04:00
module XMonad.Internal.Notify
2020-03-18 12:17:39 -04:00
( Note(..)
, Body(..)
, defNote
, defNoteInfo
, defNoteError
, fmtNotifyCmd
, spawnNotify
2020-04-01 20:17:47 -04:00
) where
2020-03-18 12:17:39 -04:00
2020-04-01 20:17:47 -04:00
import DBus.Notify
2020-03-18 12:17:39 -04:00
import RIO
import qualified RIO.Text as T
2020-04-01 20:17:47 -04:00
import XMonad.Internal.Shell
2020-03-18 12:17:39 -04:00
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Some nice default notes
2020-04-01 20:17:47 -04:00
defNote :: Note
2020-03-18 12:17:39 -04:00
defNote = blankNote { summary = "\"xmonad\"" }
2020-04-01 20:17:47 -04:00
defNoteInfo :: Note
2020-03-18 12:17:39 -04:00
defNoteInfo = defNote
{ appImage = Just $ Icon "dialog-information-symbolic" }
2020-04-01 20:17:47 -04:00
defNoteError :: Note
2020-03-18 12:17:39 -04:00
defNoteError = defNote
{ appImage = Just $ Icon "dialog-error-symbolic" }
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Format a 'notify-send' command to be send to the shell
parseBody :: Body -> Maybe T.Text
parseBody (Text s) = Just $ T.pack s
2020-04-01 20:17:47 -04:00
parseBody _ = Nothing
2020-03-18 12:17:39 -04:00
fmtNotifyCmd :: Note -> T.Text
fmtNotifyCmd = fmtCmd "notify-send" . fmtNotifyArgs
spawnNotify :: MonadIO m => Note -> m ()
spawnNotify = spawnCmd "notify-send" . fmtNotifyArgs
fmtNotifyArgs :: Note -> [T.Text]
fmtNotifyArgs n = getIcon n ++ getSummary n ++ getBody n
2020-03-18 12:17:39 -04:00
where
-- TODO add the rest of the options as needed
getSummary = (:[]) . doubleQuote . T.pack . summary
getIcon n' =
maybe [] (\i -> ["-i", T.pack $ case i of { Icon s -> s; File s -> s }])
$ appImage n'
getBody n' = maybeToList $ (fmap doubleQuote . parseBody) =<< body n'