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

57 lines
1.7 KiB
Haskell
Raw Normal View History

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
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 Data.Maybe
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
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
2020-03-18 12:17:39 -04:00
parseBody :: Body -> Maybe String
parseBody (Text s) = Just s
2020-04-01 20:17:47 -04:00
parseBody _ = Nothing
2020-03-18 12:17:39 -04:00
fmtNotifyCmd :: Note -> String
fmtNotifyCmd note =
fmtCmd "notify-send" $ getIcon note
++ getSummary note
++ getBody note
where
-- TODO add the rest of the options as needed
getSummary = (:[]) . quote . summary
getIcon n = maybe [] (\i -> ["-i", case i of { Icon s -> s; File s -> s }])
$ appImage n
getBody n = maybeToList $ (fmap quote . parseBody) =<< body n
quote s = "\"" ++ s ++ "\""