{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

A 'GI.Gdk.Structs.KeymapKey.KeymapKey' is a hardware key that can be mapped to a keyval.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Gdk.Structs.KeymapKey
    (

-- * Exported types
    KeymapKey(..)                           ,
    newZeroKeymapKey                        ,
    noKeymapKey                             ,


 -- * Properties
-- ** group #attr:group#
{- | indicates movement in a horizontal direction. Usually groups are used
  for two different languages. In group 0, a key might have two English
  characters, and in group 1 it might have two Hebrew characters. The Hebrew
  characters will be printed on the key next to the English characters.
-}
    getKeymapKeyGroup                       ,
#if ENABLE_OVERLOADING
    keymapKey_group                         ,
#endif
    setKeymapKeyGroup                       ,


-- ** keycode #attr:keycode#
{- | the hardware keycode. This is an identifying number for a
  physical key.
-}
    getKeymapKeyKeycode                     ,
#if ENABLE_OVERLOADING
    keymapKey_keycode                       ,
#endif
    setKeymapKeyKeycode                     ,


-- ** level #attr:level#
{- | indicates which symbol on the key will be used, in a vertical direction.
  So on a standard US keyboard, the key with the number “1” on it also has the
  exclamation point (\"!\") character on it. The level indicates whether to use
  the “1” or the “!” symbol. The letter keys are considered to have a lowercase
  letter at level 0, and an uppercase letter at level 1, though only the
  uppercase letter is printed.
-}
    getKeymapKeyLevel                       ,
#if ENABLE_OVERLOADING
    keymapKey_level                         ,
#endif
    setKeymapKeyLevel                       ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL


-- | Memory-managed wrapper type.
newtype KeymapKey = KeymapKey (ManagedPtr KeymapKey)
instance WrappedPtr KeymapKey where
    wrappedPtrCalloc = callocBytes 12
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 12 >=> wrapPtr KeymapKey)
    wrappedPtrFree = Just ptr_to_g_free

-- | Construct a `KeymapKey` struct initialized to zero.
newZeroKeymapKey :: MonadIO m => m KeymapKey
newZeroKeymapKey = liftIO $ wrappedPtrCalloc >>= wrapPtr KeymapKey

instance tag ~ 'AttrSet => Constructible KeymapKey tag where
    new _ attrs = do
        o <- newZeroKeymapKey
        GI.Attributes.set o attrs
        return o


-- | A convenience alias for `Nothing` :: `Maybe` `KeymapKey`.
noKeymapKey :: Maybe KeymapKey
noKeymapKey = Nothing

{- |
Get the value of the “@keycode@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' keymapKey #keycode
@
-}
getKeymapKeyKeycode :: MonadIO m => KeymapKey -> m Word32
getKeymapKeyKeycode s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Word32
    return val

{- |
Set the value of the “@keycode@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' keymapKey [ #keycode 'Data.GI.Base.Attributes.:=' value ]
@
-}
setKeymapKeyKeycode :: MonadIO m => KeymapKey -> Word32 -> m ()
setKeymapKeyKeycode s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Word32)

#if ENABLE_OVERLOADING
data KeymapKeyKeycodeFieldInfo
instance AttrInfo KeymapKeyKeycodeFieldInfo where
    type AttrAllowedOps KeymapKeyKeycodeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint KeymapKeyKeycodeFieldInfo = (~) Word32
    type AttrBaseTypeConstraint KeymapKeyKeycodeFieldInfo = (~) KeymapKey
    type AttrGetType KeymapKeyKeycodeFieldInfo = Word32
    type AttrLabel KeymapKeyKeycodeFieldInfo = "keycode"
    type AttrOrigin KeymapKeyKeycodeFieldInfo = KeymapKey
    attrGet _ = getKeymapKeyKeycode
    attrSet _ = setKeymapKeyKeycode
    attrConstruct = undefined
    attrClear _ = undefined

keymapKey_keycode :: AttrLabelProxy "keycode"
keymapKey_keycode = AttrLabelProxy

#endif


{- |
Get the value of the “@group@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' keymapKey #group
@
-}
getKeymapKeyGroup :: MonadIO m => KeymapKey -> m Int32
getKeymapKeyGroup s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 4) :: IO Int32
    return val

{- |
Set the value of the “@group@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' keymapKey [ #group 'Data.GI.Base.Attributes.:=' value ]
@
-}
setKeymapKeyGroup :: MonadIO m => KeymapKey -> Int32 -> m ()
setKeymapKeyGroup s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 4) (val :: Int32)

#if ENABLE_OVERLOADING
data KeymapKeyGroupFieldInfo
instance AttrInfo KeymapKeyGroupFieldInfo where
    type AttrAllowedOps KeymapKeyGroupFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint KeymapKeyGroupFieldInfo = (~) Int32
    type AttrBaseTypeConstraint KeymapKeyGroupFieldInfo = (~) KeymapKey
    type AttrGetType KeymapKeyGroupFieldInfo = Int32
    type AttrLabel KeymapKeyGroupFieldInfo = "group"
    type AttrOrigin KeymapKeyGroupFieldInfo = KeymapKey
    attrGet _ = getKeymapKeyGroup
    attrSet _ = setKeymapKeyGroup
    attrConstruct = undefined
    attrClear _ = undefined

keymapKey_group :: AttrLabelProxy "group"
keymapKey_group = AttrLabelProxy

#endif


{- |
Get the value of the “@level@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' keymapKey #level
@
-}
getKeymapKeyLevel :: MonadIO m => KeymapKey -> m Int32
getKeymapKeyLevel s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Int32
    return val

{- |
Set the value of the “@level@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' keymapKey [ #level 'Data.GI.Base.Attributes.:=' value ]
@
-}
setKeymapKeyLevel :: MonadIO m => KeymapKey -> Int32 -> m ()
setKeymapKeyLevel s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Int32)

#if ENABLE_OVERLOADING
data KeymapKeyLevelFieldInfo
instance AttrInfo KeymapKeyLevelFieldInfo where
    type AttrAllowedOps KeymapKeyLevelFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint KeymapKeyLevelFieldInfo = (~) Int32
    type AttrBaseTypeConstraint KeymapKeyLevelFieldInfo = (~) KeymapKey
    type AttrGetType KeymapKeyLevelFieldInfo = Int32
    type AttrLabel KeymapKeyLevelFieldInfo = "level"
    type AttrOrigin KeymapKeyLevelFieldInfo = KeymapKey
    attrGet _ = getKeymapKeyLevel
    attrSet _ = setKeymapKeyLevel
    attrConstruct = undefined
    attrClear _ = undefined

keymapKey_level :: AttrLabelProxy "level"
keymapKey_level = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList KeymapKey
type instance O.AttributeList KeymapKey = KeymapKeyAttributeList
type KeymapKeyAttributeList = ('[ '("keycode", KeymapKeyKeycodeFieldInfo), '("group", KeymapKeyGroupFieldInfo), '("level", KeymapKeyLevelFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolveKeymapKeyMethod (t :: Symbol) (o :: *) :: * where
    ResolveKeymapKeyMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveKeymapKeyMethod t KeymapKey, O.MethodInfo info KeymapKey p) => OL.IsLabel t (KeymapKey -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif