summaryrefslogtreecommitdiffstats
path: root/lib/Graphics/X11/Xlib/Display/Extra.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Graphics/X11/Xlib/Display/Extra.hs')
-rw-r--r--lib/Graphics/X11/Xlib/Display/Extra.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Graphics/X11/Xlib/Display/Extra.hs b/lib/Graphics/X11/Xlib/Display/Extra.hs
new file mode 100644
index 0000000..16b1a74
--- /dev/null
+++ b/lib/Graphics/X11/Xlib/Display/Extra.hs
@@ -0,0 +1,20 @@
+module Graphics.X11.Xlib.Display.Extra where
+
+import Control.Exception (bracket)
+import System.Environment (getEnv)
+import System.IO.Unsafe (unsafePerformIO)
+import Graphics.X11.Xlib.Types (Display)
+import Graphics.X11.Xlib.Display (closeDisplay, openDisplay)
+
+
+defaultDisplayName :: String
+defaultDisplayName =
+ unsafePerformIO (getEnv "DISPLAY")
+
+withDisplay :: String -> (Display -> IO a) -> IO a
+withDisplay display =
+ bracket (openDisplay display) closeDisplay
+
+withDefaultDisplay :: (Display -> IO a) -> IO a
+withDefaultDisplay =
+ withDisplay defaultDisplayName