summaryrefslogtreecommitdiff
path: root/Presence/ConsoleWriter.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-03-16 14:04:14 -0400
committerjoe <joe@jerkface.net>2014-03-16 14:04:14 -0400
commitfe3087cc86552fdccac5b90d49d998611a493a45 (patch)
tree092c07e4754bed7013a4c0adb1db28ccba1d3cef /Presence/ConsoleWriter.hs
parent0658b76ea0874d0ea789659effed102002486d01 (diff)
Deliver messages to X via notify-send.
Diffstat (limited to 'Presence/ConsoleWriter.hs')
-rw-r--r--Presence/ConsoleWriter.hs28
1 files changed, 24 insertions, 4 deletions
diff --git a/Presence/ConsoleWriter.hs b/Presence/ConsoleWriter.hs
index 2024131b..d75dfec0 100644
--- a/Presence/ConsoleWriter.hs
+++ b/Presence/ConsoleWriter.hs
@@ -16,6 +16,11 @@ import Data.Monoid
16import Data.Char 16import Data.Char
17import Data.Maybe 17import Data.Maybe
18import System.Environment 18import System.Environment
19import System.Process ( rawSystem )
20import System.Exit ( ExitCode(ExitSuccess) )
21import System.Posix.Env ( setEnv )
22import System.Posix.Process ( forkProcess, exitImmediately )
23import System.Posix.User ( setUserID, getUserEntryForName, userID )
19import System.Posix.Files ( getFileStatus, fileMode ) 24import System.Posix.Files ( getFileStatus, fileMode )
20import System.INotify ( initINotify, EventVariety(Modify), addWatch ) 25import System.INotify ( initINotify, EventVariety(Modify), addWatch )
21import Data.Word ( Word8 ) 26import Data.Word ( Word8 )
@@ -32,7 +37,8 @@ import qualified Network.BSD as BSD
32import UTmp ( users2, utmp_file, UtmpRecord(..), UT_Type(..) ) 37import UTmp ( users2, utmp_file, UtmpRecord(..), UT_Type(..) )
33import FGConsole ( monitorTTY ) 38import FGConsole ( monitorTTY )
34import XMPPServer ( Stanza, makePresenceStanza, JabberShow(..), stanzaType 39import XMPPServer ( Stanza, makePresenceStanza, JabberShow(..), stanzaType
35 , LangSpecificMessage(..), msgLangMap, cloneStanza ) 40 , LangSpecificMessage(..), msgLangMap, cloneStanza, stanzaFrom )
41import ControlMaybe ( handleIO_ )
36import ClientState 42import ClientState
37 43
38data ConsoleWriter = ConsoleWriter 44data ConsoleWriter = ConsoleWriter
@@ -197,6 +203,7 @@ readEnvFile var file = fmap parse $ readFile file
197 203
198writeActiveTTY :: ConsoleWriter -> Stanza -> IO Bool 204writeActiveTTY :: ConsoleWriter -> Stanza -> IO Bool
199writeActiveTTY cw msg = do 205writeActiveTTY cw msg = do
206 putStrLn $ "writeActiveTTY"
200 (tty, mbu) <- atomically $ do 207 (tty, mbu) <- atomically $ do
201 num <- readTVar $ csActiveTTY cw 208 num <- readTVar $ csActiveTTY cw
202 utmp <- readTVar $ csUtmp cw 209 utmp <- readTVar $ csUtmp cw
@@ -212,9 +219,22 @@ writeActiveTTY cw msg = do
212 _ -> deliverTerminalMessage cw tty utmp msg 219 _ -> deliverTerminalMessage cw tty utmp msg
213 220
214deliverGUIMessage cw tty utmp msg = do 221deliverGUIMessage cw tty utmp msg = do
215 -- TODO: deliver to active x (notify-send of libnotify package) 222 text <- do
216 -- chpst seems neccessary for notify-send to work 223 t <- messageText msg
217 return False 224 return $ Text.unpack
225 $ case stanzaFrom msg of
226 Just from -> from <> ": " <> t
227 Nothing -> t
228 putStrLn $ "deliverGUI: " ++ text
229 handleIO_ (return False) $ do
230 uentry <- getUserEntryForName (Text.unpack $ utmpUser utmp)
231 let display = Text.unpack $ utmpHost utmp
232 pid <- forkProcess $ do
233 setUserID (userID uentry)
234 setEnv "DISPLAY" display True
235 rawSystem "/usr/bin/notify-send" [text]
236 exitImmediately ExitSuccess
237 return True
218 238
219deliverTerminalMessage cw tty utmp msg = do 239deliverTerminalMessage cw tty utmp msg = do
220 mode <- fmap fileMode (getFileStatus $ Text.unpack tty) 240 mode <- fmap fileMode (getFileStatus $ Text.unpack tty)