summaryrefslogtreecommitdiffstats
path: root/lib/Graphics/X11/Xlib/Display/Extra.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2023-02-07 02:30:41 +0100
committertv <tv@krebsco.de>2023-02-07 02:30:41 +0100
commitf28825e471e206bcb7e6dc8e4874c2b771f7d24c (patch)
treec77f0bc9dd178c74f883f0c89d0ebd67366d381b /lib/Graphics/X11/Xlib/Display/Extra.hs
parent3bd9c00812d91ade512e71a9f8e0f5b8917c3fa7 (diff)
move Graphics.* & co. to lib
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