summaryrefslogtreecommitdiffstats
path: root/lib
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
parent3bd9c00812d91ade512e71a9f8e0f5b8917c3fa7 (diff)
move Graphics.* & co. to lib
Diffstat (limited to 'lib')
-rw-r--r--lib/Data/Text/Encoding/Extra.hs11
-rw-r--r--lib/Foreign/C/String/Extra.hs10
-rw-r--r--lib/Graphics/X11/Extra.hs5
-rw-r--r--lib/Graphics/X11/Xlib/Atom/Extra.hs39
-rw-r--r--lib/Graphics/X11/Xlib/Display/Extra.hs20
-rw-r--r--lib/Graphics/X11/Xlib/Extra.hs7
-rw-r--r--lib/Graphics/X11/Xlib/Extras/Extra.hs14
7 files changed, 106 insertions, 0 deletions
diff --git a/lib/Data/Text/Encoding/Extra.hs b/lib/Data/Text/Encoding/Extra.hs
new file mode 100644
index 0000000..a8e6234
--- /dev/null
+++ b/lib/Data/Text/Encoding/Extra.hs
@@ -0,0 +1,11 @@
+module Data.Text.Encoding.Extra where
+
+import Data.ByteString (ByteString)
+import Data.Text (Text)
+import qualified Data.Text.Encoding as Text
+import qualified Data.Text.Encoding.Error as Text
+
+
+decodeUtf8Lenient :: ByteString -> Text
+decodeUtf8Lenient =
+ Text.decodeUtf8With Text.lenientDecode
diff --git a/lib/Foreign/C/String/Extra.hs b/lib/Foreign/C/String/Extra.hs
new file mode 100644
index 0000000..a7b6dfe
--- /dev/null
+++ b/lib/Foreign/C/String/Extra.hs
@@ -0,0 +1,10 @@
+module Foreign.C.String.Extra where
+
+import Data.Word (Word8)
+import Foreign.C.String (castCCharToChar)
+import Foreign.C.Types (CChar)
+import qualified Data.Char as Char
+
+
+castCCharToWord8 :: CChar -> Word8
+castCCharToWord8 = fromIntegral . Char.ord . castCCharToChar
diff --git a/lib/Graphics/X11/Extra.hs b/lib/Graphics/X11/Extra.hs
new file mode 100644
index 0000000..ce4cb46
--- /dev/null
+++ b/lib/Graphics/X11/Extra.hs
@@ -0,0 +1,5 @@
+module Graphics.X11.Extra
+ ( module Graphics.X11.Xlib.Extra
+ ) where
+
+import Graphics.X11.Xlib.Extra
diff --git a/lib/Graphics/X11/Xlib/Atom/Extra.hs b/lib/Graphics/X11/Xlib/Atom/Extra.hs
new file mode 100644
index 0000000..8442c48
--- /dev/null
+++ b/lib/Graphics/X11/Xlib/Atom/Extra.hs
@@ -0,0 +1,39 @@
+module Graphics.X11.Xlib.Atom.Extra where
+
+import Graphics.X11.Types (Atom)
+import Graphics.X11.Xlib.Atom (internAtom)
+import Graphics.X11.Xlib.Display.Extra (withDefaultDisplay)
+import System.IO.Unsafe (unsafePerformIO)
+
+
+unsafeInternAtom :: String -> Bool -> Atom
+unsafeInternAtom atomName onlyIfExists =
+ unsafePerformIO $ withDefaultDisplay $ \display ->
+ internAtom display atomName onlyIfExists
+
+_NET_ACTIVE_WINDOW :: Atom
+_NET_ACTIVE_WINDOW = unsafeInternAtom "_NET_ACTIVE_WINDOW" True
+
+_NET_CLIENT_LIST :: Atom
+_NET_CLIENT_LIST = unsafeInternAtom "_NET_CLIENT_LIST" True
+
+_NET_CURRENT_DESKTOP :: Atom
+_NET_CURRENT_DESKTOP = unsafeInternAtom "_NET_CURRENT_DESKTOP" True
+
+_NET_DESKTOP_NAMES :: Atom
+_NET_DESKTOP_NAMES = unsafeInternAtom "_NET_DESKTOP_NAMES" True
+
+_NET_WM_DESKTOP :: Atom
+_NET_WM_DESKTOP = unsafeInternAtom "_NET_WM_DESKTOP" True
+
+_NET_WM_NAME :: Atom
+_NET_WM_NAME = unsafeInternAtom "_NET_WM_NAME" True
+
+_WIN_WORKSPACE :: Atom
+_WIN_WORKSPACE = unsafeInternAtom "_WIN_WORKSPACE" True
+
+_WIN_WORKSPACE_NAMES :: Atom
+_WIN_WORKSPACE_NAMES = unsafeInternAtom "_WIN_WORKSPACE_NAMES" True
+
+_WM_NAME :: Atom
+_WM_NAME = unsafeInternAtom "WM_NAME" True
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
diff --git a/lib/Graphics/X11/Xlib/Extra.hs b/lib/Graphics/X11/Xlib/Extra.hs
new file mode 100644
index 0000000..c2093ab
--- /dev/null
+++ b/lib/Graphics/X11/Xlib/Extra.hs
@@ -0,0 +1,7 @@
+module Graphics.X11.Xlib.Extra
+ ( module Graphics.X11.Xlib.Atom.Extra
+ , module Graphics.X11.Xlib.Display.Extra
+ ) where
+
+import Graphics.X11.Xlib.Atom.Extra
+import Graphics.X11.Xlib.Display.Extra
diff --git a/lib/Graphics/X11/Xlib/Extras/Extra.hs b/lib/Graphics/X11/Xlib/Extras/Extra.hs
new file mode 100644
index 0000000..d88bf9d
--- /dev/null
+++ b/lib/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