summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2023-02-07 03:01:37 +0100
committertv <tv@krebsco.de>2023-02-07 03:34:12 +0100
commitfe48ecd3b1cc11f176c1080539b70abac956f0a0 (patch)
tree896a7153a5dc9b861e4321a44f925e97a696648a /lib
parentf28825e471e206bcb7e6dc8e4874c2b771f7d24c (diff)
move EWMH-related stuff to Graphics.X11.EWMH
Diffstat (limited to 'lib')
-rw-r--r--lib/Graphics/X11/EWMH.hs48
-rw-r--r--lib/Graphics/X11/EWMH/Atom.hs23
-rw-r--r--lib/Graphics/X11/Xlib/Atom/Extra.hs18
3 files changed, 71 insertions, 18 deletions
diff --git a/lib/Graphics/X11/EWMH.hs b/lib/Graphics/X11/EWMH.hs
new file mode 100644
index 0000000..4f539ad
--- /dev/null
+++ b/lib/Graphics/X11/EWMH.hs
@@ -0,0 +1,48 @@
+module Graphics.X11.EWMH
+ ( module Graphics.X11.EWMH
+ , module Graphics.X11.EWMH.Atom
+ ) where
+
+import Control.Applicative ((<|>))
+import Data.Text (Text)
+import Foreign.C.Types (CLong)
+import Graphics.X11.EWMH.Atom
+import Graphics.X11.Types (Window)
+import Graphics.X11.Xlib.Atom.Extra
+import Graphics.X11.Xlib.Display (defaultRootWindow)
+import Graphics.X11.Xlib.Extras (getWindowProperty32)
+import Graphics.X11.Xlib.Extras.Extra (getWindowPropertyText)
+import Graphics.X11.Xlib.Types (Display)
+import qualified Data.Text as Text
+
+
+getActiveWindow :: Display -> IO (Maybe Window)
+getActiveWindow dpy =
+ (fmap (fromIntegral . head) <$>) $
+ getWindowProperty32 dpy _NET_ACTIVE_WINDOW w
+ where w = defaultRootWindow dpy
+
+getCurrentDesktop :: Display -> IO (Maybe CLong)
+getCurrentDesktop dpy =
+ (fmap head <$>) $
+ getWindowProperty32 dpy _NET_CURRENT_DESKTOP w <|>
+ getWindowProperty32 dpy _WIN_WORKSPACE w
+ where w = defaultRootWindow dpy
+
+getDesktopNames :: Display -> IO (Maybe [Text])
+getDesktopNames dpy = do
+ (fmap (init . Text.split (=='\NUL')) <$>) $
+ getWindowPropertyText dpy _NET_DESKTOP_NAMES w <|>
+ getWindowPropertyText dpy _WIN_WORKSPACE_NAMES w
+ where w = defaultRootWindow dpy
+
+getWindowDesktop :: Display -> Window -> IO (Maybe CLong)
+getWindowDesktop dpy w =
+ (fmap head <$>) $
+ getWindowProperty32 dpy _NET_WM_DESKTOP w <|>
+ getWindowProperty32 dpy _WIN_WORKSPACE w
+
+getWindowTitle :: Display -> Window -> IO (Maybe Text)
+getWindowTitle dpy w =
+ getWindowPropertyText dpy _NET_WM_NAME w <|>
+ getWindowPropertyText dpy _WM_NAME w
diff --git a/lib/Graphics/X11/EWMH/Atom.hs b/lib/Graphics/X11/EWMH/Atom.hs
new file mode 100644
index 0000000..71f9ff5
--- /dev/null
+++ b/lib/Graphics/X11/EWMH/Atom.hs
@@ -0,0 +1,23 @@
+module Graphics.X11.EWMH.Atom where
+
+import Graphics.X11.Types (Atom)
+import Graphics.X11.Xlib.Atom.Extra (unsafeInternAtom)
+
+
+_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
diff --git a/lib/Graphics/X11/Xlib/Atom/Extra.hs b/lib/Graphics/X11/Xlib/Atom/Extra.hs
index 8442c48..d96b54f 100644
--- a/lib/Graphics/X11/Xlib/Atom/Extra.hs
+++ b/lib/Graphics/X11/Xlib/Atom/Extra.hs
@@ -11,24 +11,6 @@ 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