2022-12-26 14:45:49 -05:00
|
|
|
{-# 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
|
2021-06-20 13:55:31 -04:00
|
|
|
, 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
|
|
|
|
2022-12-29 14:49:06 -05:00
|
|
|
import RIO
|
|
|
|
import qualified RIO.Text as T
|
2022-12-26 14:45:49 -05:00
|
|
|
|
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
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
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
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
fmtNotifyCmd :: Note -> T.Text
|
2021-06-20 13:55:31 -04:00
|
|
|
fmtNotifyCmd = fmtCmd "notify-send" . fmtNotifyArgs
|
|
|
|
|
|
|
|
spawnNotify :: MonadIO m => Note -> m ()
|
|
|
|
spawnNotify = spawnCmd "notify-send" . fmtNotifyArgs
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
fmtNotifyArgs :: Note -> [T.Text]
|
2021-06-20 13:55:31 -04:00
|
|
|
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
|
2022-12-26 14:45:49 -05:00
|
|
|
getSummary = (:[]) . doubleQuote . T.pack . summary
|
|
|
|
getIcon n' =
|
|
|
|
maybe [] (\i -> ["-i", T.pack $ case i of { Icon s -> s; File s -> s }])
|
2021-06-20 13:55:31 -04:00
|
|
|
$ appImage n'
|
|
|
|
getBody n' = maybeToList $ (fmap doubleQuote . parseBody) =<< body n'
|