From f4cdf79bd4a75e9eafe68b9a908f4cc68682b7ef Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Apr 2022 21:39:55 +0200 Subject: boom --- src/Graphics/X11/Extra.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Graphics/X11/Extra.hs (limited to 'src/Graphics/X11/Extra.hs') diff --git a/src/Graphics/X11/Extra.hs b/src/Graphics/X11/Extra.hs new file mode 100644 index 0000000..bed1ba3 --- /dev/null +++ b/src/Graphics/X11/Extra.hs @@ -0,0 +1,24 @@ +module Graphics.X11.Extra where + +import Control.Exception (bracket) +import System.Environment (getEnv) +import System.IO.Unsafe (unsafePerformIO) +import qualified Graphics.X11 as X11 + + +unsafeInternAtom :: String -> Bool -> X11.Atom +unsafeInternAtom atomName onlyIfExists = + unsafePerformIO $ withDefaultDisplay $ \display -> + X11.internAtom display atomName onlyIfExists + +defaultDisplayName :: String +defaultDisplayName = + unsafePerformIO (getEnv "DISPLAY") + +withDisplay :: String -> (X11.Display -> IO a) -> IO a +withDisplay display = + bracket (X11.openDisplay display) X11.closeDisplay + +withDefaultDisplay :: (X11.Display -> IO a) -> IO a +withDefaultDisplay = + withDisplay defaultDisplayName -- cgit v1.2.3