summaryrefslogtreecommitdiffstats
path: root/src/Graphics/X11/Extra.hs
blob: bed1ba384409ab187cb4edfc3c722d78a4f9d888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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