aboutsummaryrefslogtreecommitdiffstats
path: root/src/Pager/Backend/Rivermonad.hs
blob: b2d63652a173b75290af51ee176a62f3eae672d3 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
-- | The pager on rivermonad (a window manager for the river Wayland
-- compositor), over its IPC socket.
module Pager.Backend.Rivermonad
    ( getScreenGeometry
    , getWorkspaces
    , viewWorkspace
    , shiftWindowToWorkspace
    ) where

import Data.Text (Text)
import Pager.Types
import qualified Data.List as List
import qualified Rivermonad.Client as Client


geometry :: Client.Rect -> Geometry
geometry r =
    Geometry
      { geometry_x = Client.rect_x r
      , geometry_y = Client.rect_y r
      , geometry_width = Client.rect_width r
      , geometry_height = Client.rect_height r
      }

getScreenGeometry :: IO Geometry
getScreenGeometry =
    geometry . Client.snapshot_screen <$> Client.getSnapshot

-- The window manager knows which window every workspace focuses, so the
-- window ids from the command line are not needed here.
getWorkspaces :: Geometry -> [Int] -> IO [Workspace]
getWorkspaces screenGeometry _focusWindows =
    map workspace . Client.snapshot_workspaces <$> Client.getSnapshot
  where
    workspace ws =
      Workspace
        { workspace_geometry = screenGeometry
        , workspace_focused = Client.workspace_focused ws
        , workspace_name = Client.workspace_name ws
        , workspace_windows =
            uncurry (<>) $
            List.partition window_focused $
            map window (Client.workspace_windows ws)
        }

    window w =
      Window
        { window_id = Client.window_id w
        , window_title = Client.window_title w
        , window_geometry = geometry (Client.window_rect w)
        , window_focused = Client.window_focused w
        -- River cannot tell the window manager yet that a window wants
        -- attention.
        , window_urgent = False
        }

viewWorkspace :: Text -> IO ()
viewWorkspace = Client.viewWorkspace

shiftWindowToWorkspace :: Int -> Text -> IO ()
shiftWindowToWorkspace = Client.shiftWindow