summaryrefslogtreecommitdiff
path: root/protocols/Wayland/Protocols/Core/WLOutput.hs
blob: 625ccd97f9c3959cb2efff751ed8d3e1b57adfd8 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Wayland.Protocols.Core.WLOutput
  ( Subpixel(..)
  , Transform(..)
  , Mode(..)
  , Geometry(..)
  , Request(..)
  , Event(..)
  , WLOutput(..)
  ) where

import Data.Data (Typeable)
import Data.Hashable (Hashable(..))
import Wayland.Server

newtype WLOutput = WLOutput AnyObject
  deriving (Show, Eq, Ord, Hashable)

reqRelease :: MessageDesc
reqRelease = MessageDesc { msgName         = "release"
                         , msgArguments    = []
                         , msgSince        = 3
                         , msgIsDestructor = True
                         }

evGeometry :: MessageDesc
evGeometry = MessageDesc { msgName         = "geometry"
                         , msgArguments    = [ ArgumentInt
                                             , ArgumentInt
                                             , ArgumentInt
                                             , ArgumentInt
                                             , ArgumentInt
                                             , ArgumentString NotNull
                                             , ArgumentString NotNull
                                             , ArgumentInt
                                             ]
                         , msgSince        = 1
                         , msgIsDestructor = False
                         }

evMode :: MessageDesc
evMode = MessageDesc { msgName         = "mode"
                     , msgArguments    = [ ArgumentUInt
                                         , ArgumentInt
                                         , ArgumentInt
                                         , ArgumentInt
                                         ]
                     , msgSince        = 1
                     , msgIsDestructor = False
                     }

evDone :: MessageDesc
evDone = MessageDesc { msgName         = "done"
                     , msgArguments    = []
                     , msgSince        = 2
                     , msgIsDestructor = False
                     }

evScale :: MessageDesc
evScale = MessageDesc { msgName         = "scale"
                      , msgArguments    = [ ArgumentInt ]
                      , msgSince        = 2
                      , msgIsDestructor = False
                      }

evName :: MessageDesc
evName = MessageDesc { msgName         = "name"
                     , msgArguments    = [ ArgumentString NotNull ]
                     , msgSince        = 4
                     , msgIsDestructor = False
                     }

evDescription :: MessageDesc
evDescription = MessageDesc { msgName         = "description"
                            , msgArguments    = [ ArgumentString NotNull ]
                            , msgSince        = 4
                            , msgIsDestructor = False
                            }

instance Object WLOutput where
  type ObjectEvent   WLOutput = Event
  type ObjectRequest WLOutput = Request
  toAny (WLOutput o) = o
  fromAny = WLOutput
  describeInterface _ = InterfaceDesc { ifName     = "wl_output"
                                      , ifVersion  = 4
                                      , ifRequests = [ reqRelease ]
                                      , ifEvents   = [ evGeometry
                                                     , evMode
                                                     , evDone
                                                     , evScale
                                                     , evName
                                                     , evDescription
                                                     ]
                                      }

  demarshalRequest r 0 = do
    pure (ReqRelease r)
  demarshalRequest _ _ = error "Unknown opcode."

  marshalEvent _ (EvGeometry p) = do
    marshalInt    (x p)
    marshalInt    (y p)
    marshalInt    (physicalWidth p)
    marshalInt    (physicalHeight p)
    marshalInt    (fromEnum (subpixel p))
    marshalString (make p)
    marshalString (model p)
    marshalInt    (fromEnum (transform p))
    pure 0
  marshalEvent _ (EvMode p) = do
    marshalUInt (fromBitSet (flags p))
    marshalInt  (width p)
    marshalInt  (height p)
    marshalInt  (refresh p)
    pure 1
  marshalEvent _ EvDone = do
    pure 2
  marshalEvent _ (EvScale p) = do
    marshalInt p
    pure 3
  marshalEvent _ (EvName p) = do
    marshalString p
    pure 4
  marshalEvent _ (EvDescription p) = do
    marshalString p
    pure 5

  requestSignature _ (ReqRelease _) = reqRelease

  eventSignature _ (EvGeometry _)    = evGeometry
  eventSignature _ (EvMode _)        = evMode
  eventSignature _  EvDone           = evDone
  eventSignature _ (EvScale _)       = evScale
  eventSignature _ (EvName _)        = evName
  eventSignature _ (EvDescription _) = evDescription

data Subpixel
  = SubpixelUnknown
  | SubpixelNone
  | SubpixelHorizontalRgb
  | SubpixelHorizontalBgr
  | SubpixelVerticalRgb
  | SubpixelVerticalBgr
  deriving (Show, Enum)

data Transform
  = TransformNormal
  | TransformNormal90
  | TransformNormal180
  | TransformNormal270
  | TransformFlipped
  | TransformFlipped90
  | TransformFlipped180
  | TransformFlipped270
  deriving (Show, Enum)

data ModeFlags
  = ModeFlags { current   :: Bool
              , preferred :: Bool
              }
  deriving (Show)

fromBitSet :: ModeFlags -> Word
fromBitSet _ = 0

data Mode
  = Mode { flags   :: ModeFlags
         , width   :: Int
         , height  :: Int
         , refresh :: Int
         }
  deriving (Show)

data Geometry
  = Geometry { x              :: Int
             , y              :: Int
             , physicalWidth  :: Int
             , physicalHeight :: Int
             , subpixel       :: Subpixel
             , make           :: String
             , model          :: String
             , transform      :: Transform
             }
  deriving (Show)

data Request
  = ReqRelease WLOutput
  deriving (Typeable, Show)

instance MessageClass Request
instance RequestClass Request

data Event
  = EvGeometry    Geometry
  | EvMode        Mode
  | EvScale       Int
  | EvName        String
  | EvDescription String
  | EvDone
  deriving (Typeable, Show)

instance MessageClass Event
instance EventClass Event