summaryrefslogtreecommitdiffstats
path: root/lib/Graphics/X11/EWMH.hs
blob: 4f539add82cd136b2a7cdba0d172587f0fa67bd3 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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