blob: d9c9bd70149144854f4696d0cd55ca64b6348bef (
plain) (
blame)
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
|
-- | Contains functions and thin wrappers via ffi to the wlroots API.
module Montis.Base.Foreign.WlRoots where
import Foreign (Ptr, Word32, nullPtr)
import Montis.Base.Foreign.WlRoots.Types
-- | Converts a null pointer into 'Nothing' to avoid dangling FFI handles.
guardNull :: Ptr a -> Maybe (Ptr a)
guardNull p | p == nullPtr = Nothing
guardNull p = Just p
foreign import ccall "wlr_seat_set_keyboard"
foreign_wlrSetSeatKeyboard ::
Ptr ForeignWlrSeat -> Ptr ForeignWlrInputDevice -> IO ()
-- | Binds the given input device as the active keyboard for a seat.
setSeatKeyboard :: WlrSeat -> WlrInputDevice -> IO ()
setSeatKeyboard (WlrSeat p1) (WlrInputDevice p2) =
foreign_wlrSetSeatKeyboard p1 p2
foreign import ccall "wlr_seat_get_keyboard"
foreign_wlrSeatGetKeyboard ::
Ptr ForeignWlrSeat -> IO (Ptr ForeignWlrKeyboard)
-- | Looks up the current keyboard for a seat, if one exists.
getSeatKeyboard :: WlrSeat -> IO (Maybe WlrKeyboard)
getSeatKeyboard (WlrSeat p) =
fmap WlrKeyboard . guardNull <$> foreign_wlrSeatGetKeyboard p
foreign import ccall "wlr_keyboard_get_modifiers"
foreign_wlrKeyboardGetModifiers ::
Ptr ForeignWlrKeyboard -> IO Word32
-- | Returns the current keyboard modifier mask for the keyboard.
getKeyboardModifiers :: WlrKeyboard -> IO Word32
getKeyboardModifiers (WlrKeyboard p) = foreign_wlrKeyboardGetModifiers p
foreign import ccall "wlr_seat_keyboard_notify_key"
foreign_wlrSeatKeyboardNotifyKey ::
Ptr ForeignWlrSeat -> Word32 -> Word32 -> Word32 -> IO ()
-- | Forwards a key event to the seat with time, keycode, and state.
seatKeyboardNotifyKey :: WlrSeat -> Word32 -> Word32 -> Word32 -> IO ()
seatKeyboardNotifyKey (WlrSeat p) = foreign_wlrSeatKeyboardNotifyKey p
foreign import ccall "wlr_seat_pointer_notify_button"
foreign_wlrSeatPointerNotifyButton ::
Ptr ForeignWlrSeat -> Word32 -> Word32 -> Word32 -> IO ()
-- | Forwards a pointer button event to the seat.
seatPointerNotifyButton :: WlrSeat -> Word32 -> Word32 -> Word32 -> IO ()
seatPointerNotifyButton (WlrSeat p) = foreign_wlrSeatPointerNotifyButton p
|