Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 2 commits into from

2 participants

@HeinrichApfelmus

This patch bakes the old EnableGUI.hs solution right into the wxcore package. This works because GHC packages may reference external libraries that GHCi will link in.

Note: The new GHCiSupport.hs module probably needs to be wrapped in #ifdefs.

Note: People need to be reminded to use the ghci -fno-ghci-sandbox flag if they want to use wx from GHCi.

This patch does not address the issue that wx is prone to crashes when used twice from GHCi.

@jodonoghue
Owner

I have created a branch on my local build (GHCI_FIX_BRANCH) which pulls this. I would prefer not to put it into master until the conditional compilation has been sorted out, as it will break Windows and Linux as it stands.

I will pull into mainline once we have something which works for all platforms - I agree that this is a good idea.

@HeinrichApfelmus

Ok. I have found the relevant CPP macro and wrapped everything in the appropriate #if .

@jodonoghue jodonoghue merged commit 3a6d05e into jodonoghue:master
@jodonoghue
Owner

Thanks so much for this. Pulled into master now, along with a partial fix for the TextCtrl behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 18, 2012
  1. @HeinrichApfelmus
Commits on Apr 20, 2012
  1. @HeinrichApfelmus
This page is out of date. Refresh to see the latest.
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.