Browse files

Enable GUI support in GHCi on MacOS X.

  • Loading branch information...
1 parent fa88a6e commit e889e281ae2ad350d55f2150ff190f1e3c4e100a @HeinrichApfelmus HeinrichApfelmus committed Apr 18, 2012
View
11 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
+ performGC
+
+
+
+
View
22 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
View
6 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,

0 comments on commit e889e28

Please sign in to comment.