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

67 lines
1.9 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedStrings #-}
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
2022-12-30 14:58:23 -05:00
-- Functions for formatting and sending notifications
2020-04-01 22:06:00 -04:00
--
-- 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
2022-12-30 14:58:23 -05:00
( Note (..)
, Body (..)
2020-03-18 12:17:39 -04:00
, defNote
, defNoteInfo
, defNoteError
, fmtNotifyCmd
, spawnNotify
2022-12-30 14:58:23 -05:00
)
where
2020-03-18 12:17:39 -04:00
2022-12-30 14:58:23 -05:00
import DBus.Notify
import RIO
import qualified RIO.Text as T
import XMonad.Internal.Shell
2020-03-18 12:17:39 -04:00
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
2022-12-30 14:58:23 -05:00
-- Some nice default notes
2020-04-01 22:06:00 -04:00
2020-04-01 20:17:47 -04:00
defNote :: Note
2022-12-30 14:58:23 -05:00
defNote = blankNote {summary = "\"xmonad\""}
2020-03-18 12:17:39 -04:00
2020-04-01 20:17:47 -04:00
defNoteInfo :: Note
2022-12-30 14:58:23 -05:00
defNoteInfo =
defNote
{ appImage = Just $ Icon "dialog-information-symbolic"
}
2020-03-18 12:17:39 -04:00
2020-04-01 20:17:47 -04:00
defNoteError :: Note
2022-12-30 14:58:23 -05:00
defNoteError =
defNote
{ appImage = Just $ Icon "dialog-error-symbolic"
}
2020-03-18 12:17:39 -04:00
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
2022-12-30 14:58:23 -05:00
-- Format a 'notify-send' command to be send to the shell
2020-04-01 22:06:00 -04:00
parseBody :: Body -> Maybe T.Text
parseBody (Text s) = Just $ T.pack s
2022-12-30 14:58:23 -05: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
2022-12-30 14:58:23 -05:00
getSummary = (: []) . doubleQuote . T.pack . summary
getIcon n' =
2022-12-30 14:58:23 -05:00
maybe [] (\i -> ["-i", T.pack $ case i of Icon s -> s; File s -> s]) $
appImage n'
getBody n' = maybeToList $ (fmap doubleQuote . parseBody) =<< body n'