-- | 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