Skip to content

Enable GUI support in GHCi by default on MacOS X #6

Merged
merged 2 commits into from Apr 20, 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
32 wxcore/src/haskell/Graphics/UI/WXCore/GHCiSupport.hs
@@ -0,0 +1,32 @@
+{-# 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
+
+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 :: IO ()
+enableGUI = alloca $ \psn -> do
+ getCurrentProcess psn
+ cgsDefaultConnection
+ cpsEnableForegroundOperation psn
+ cpsSignalAppReady psn
+ cpsSetFrontProcess psn
+
+#else
+
+enableGUI :: IO ()
+enableGUI = return ()
+
+#endif
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,
Something went wrong with that request. Please try again.