From e889e281ae2ad350d55f2150ff190f1e3c4e100a Mon Sep 17 00:00:00 2001 From: Heinrich Apfelmus Date: Wed, 18 Apr 2012 22:06:18 +0200 Subject: [PATCH 1/2] Enable GUI support in GHCi on MacOS X. --- wxcore/src/haskell/Graphics/UI/WXCore.hs | 11 ++++++++-- .../haskell/Graphics/UI/WXCore/GHCiSupport.hs | 22 +++++++++++++++++++ wxcore/wxcore.cabal | 6 +++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs diff --git a/wxcore/src/haskell/Graphics/UI/WXCore.hs b/wxcore/src/haskell/Graphics/UI/WXCore.hs index 9ff924bf..334dea02 100644 --- a/wxcore/src/haskell/Graphics/UI/WXCore.hs +++ b/wxcore/src/haskell/Graphics/UI/WXCore.hs @@ -62,14 +62,21 @@ import Graphics.UI.WXCore.Layout import Graphics.UI.WXCore.Image import Graphics.UI.WXCore.OpenGL +import Graphics.UI.WXCore.GHCiSupport + -- | Start the event loop. Takes an initialisation action as argument. -- Except for 'run', the functions in the WXH library can only be called -- from this intialisation action or from event handlers, or otherwise bad -- things will happen :-) run :: IO a -> IO () run init - = do appOnInit (do wxcAppInitAllImageHandlers + = do enableGUI + appOnInit (do wxcAppInitAllImageHandlers init return ()) performGC - performGC \ No newline at end of file + performGC + + + + diff --git a/wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs b/wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs new file mode 100644 index 00000000..4c2f36bb --- /dev/null +++ b/wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs @@ -0,0 +1,22 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +module Graphics.UI.WXCore.GHCiSupport(enableGUI) where +-- GHCi support on MacOS X +-- TODO: preprocessor to make it conditional on the platform + +import Data.Int +import Foreign + +type ProcessSerialNumber = Int64 + +foreign import ccall "GetCurrentProcess" getCurrentProcess :: Ptr ProcessSerialNumber -> IO Int16 +foreign import ccall "_CGSDefaultConnection" cgsDefaultConnection :: IO () +foreign import ccall "CPSEnableForegroundOperation" cpsEnableForegroundOperation :: Ptr ProcessSerialNumber -> IO () +foreign import ccall "CPSSignalAppReady" cpsSignalAppReady :: Ptr ProcessSerialNumber -> IO () +foreign import ccall "CPSSetFrontProcess" cpsSetFrontProcess :: Ptr ProcessSerialNumber -> IO () + +enableGUI = alloca $ \psn -> do + getCurrentProcess psn + cgsDefaultConnection + cpsEnableForegroundOperation psn + cpsSignalAppReady psn + cpsSetFrontProcess psn diff --git a/wxcore/wxcore.cabal b/wxcore/wxcore.cabal index 98b8e5af..50362ebf 100644 --- a/wxcore/wxcore.cabal +++ b/wxcore/wxcore.cabal @@ -60,6 +60,12 @@ library Graphics.UI.WXCore.WxcObject Graphics.UI.WXCore.WxcTypes + other-modules: + Graphics.UI.WXCore.GHCiSupport + + frameworks: + Carbon + build-depends: bytestring, filepath, From 3a6d05e4bcc7bfe9c71e62562632f3a78df18496 Mon Sep 17 00:00:00 2001 From: Heinrich Apfelmus Date: Fri, 20 Apr 2012 14:38:10 +0200 Subject: [PATCH 2/2] Wrap GHCi support in #if darwin_HOST_OS. --- wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs b/wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs index 4c2f36bb..018ad07f 100644 --- a/wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs +++ b/wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs @@ -1,8 +1,10 @@ -{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE ForeignFunctionInterface, CPP #-} module Graphics.UI.WXCore.GHCiSupport(enableGUI) where -- GHCi support on MacOS X -- TODO: preprocessor to make it conditional on the platform +#if darwin_HOST_OS + import Data.Int import Foreign @@ -14,9 +16,17 @@ foreign import ccall "CPSEnableForegroundOperation" cpsEnableForegroundOperation foreign import ccall "CPSSignalAppReady" cpsSignalAppReady :: Ptr ProcessSerialNumber -> IO () foreign import ccall "CPSSetFrontProcess" cpsSetFrontProcess :: Ptr ProcessSerialNumber -> IO () +enableGUI :: IO () enableGUI = alloca $ \psn -> do getCurrentProcess psn cgsDefaultConnection cpsEnableForegroundOperation psn cpsSignalAppReady psn cpsSetFrontProcess psn + +#else + +enableGUI :: IO () +enableGUI = return () + +#endif \ No newline at end of file