summaryrefslogtreecommitdiffstats
path: root/src/Graphics/X11
diff options
context:
space:
mode:
Diffstat (limited to 'src/Graphics/X11')
-rw-r--r--src/Graphics/X11/Extra.hs24
-rw-r--r--src/Graphics/X11/Xlib/Extras/Extra.hs14
2 files changed, 38 insertions, 0 deletions
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
diff --git a/src/Graphics/X11/Xlib/Extras/Extra.hs b/src/Graphics/X11/Xlib/Extras/Extra.hs
new file mode 100644
index 0000000..d88bf9d
--- /dev/null
+++ b/src/Graphics/X11/Xlib/Extras/Extra.hs
@@ -0,0 +1,14 @@
+module Graphics.X11.Xlib.Extras.Extra where
+
+import Data.Text (Text)
+import Foreign.C.String.Extra (castCCharToWord8)
+import qualified Data.ByteString as ByteString
+import qualified Data.Text.Encoding.Extra as Text
+import qualified Graphics.X11 as X11
+import qualified Graphics.X11.Xlib.Extras as X11
+
+
+getWindowPropertyText :: X11.Display -> X11.Atom -> X11.Window -> IO (Maybe Text)
+getWindowPropertyText d a w =
+ fmap (Text.decodeUtf8Lenient . ByteString.pack . map castCCharToWord8) <$>
+ X11.getWindowProperty8 d a w