Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
A Keymap
defines the translation from keyboard state
(including a hardware key, a modifier mask, and active keyboard group)
to a keyval. This translation has two phases. The first phase is
to determine the effective keyboard group and level for the keyboard
state; the second phase is to look up the keycode/group/level triplet
in the keymap and see what keyval it corresponds to.
- newtype Keymap = Keymap (ManagedPtr Keymap)
- class GObject o => IsKeymap o
- toKeymap :: IsKeymap o => o -> IO Keymap
- noKeymap :: Maybe Keymap
- data KeymapAddVirtualModifiersMethodInfo
- keymapAddVirtualModifiers :: (HasCallStack, MonadIO m, IsKeymap a) => a -> [ModifierType] -> m [ModifierType]
- data KeymapGetCapsLockStateMethodInfo
- keymapGetCapsLockState :: (HasCallStack, MonadIO m, IsKeymap a) => a -> m Bool
- keymapGetDefault :: (HasCallStack, MonadIO m) => m Keymap
- data KeymapGetDirectionMethodInfo
- keymapGetDirection :: (HasCallStack, MonadIO m, IsKeymap a) => a -> m Direction
- data KeymapGetEntriesForKeycodeMethodInfo
- keymapGetEntriesForKeycode :: (HasCallStack, MonadIO m, IsKeymap a) => a -> Word32 -> m (Bool, [KeymapKey], [Word32])
- data KeymapGetEntriesForKeyvalMethodInfo
- keymapGetEntriesForKeyval :: (HasCallStack, MonadIO m, IsKeymap a) => a -> Word32 -> m (Bool, [KeymapKey])
- keymapGetForDisplay :: (HasCallStack, MonadIO m, IsDisplay a) => a -> m Keymap
- data KeymapGetModifierMaskMethodInfo
- keymapGetModifierMask :: (HasCallStack, MonadIO m, IsKeymap a) => a -> ModifierIntent -> m [ModifierType]
- data KeymapGetModifierStateMethodInfo
- keymapGetModifierState :: (HasCallStack, MonadIO m, IsKeymap a) => a -> m Word32
- data KeymapGetNumLockStateMethodInfo
- keymapGetNumLockState :: (HasCallStack, MonadIO m, IsKeymap a) => a -> m Bool
- data KeymapGetScrollLockStateMethodInfo
- keymapGetScrollLockState :: (HasCallStack, MonadIO m, IsKeymap a) => a -> m Bool
- data KeymapHaveBidiLayoutsMethodInfo
- keymapHaveBidiLayouts :: (HasCallStack, MonadIO m, IsKeymap a) => a -> m Bool
- data KeymapLookupKeyMethodInfo
- keymapLookupKey :: (HasCallStack, MonadIO m, IsKeymap a) => a -> KeymapKey -> m Word32
- data KeymapMapVirtualModifiersMethodInfo
- keymapMapVirtualModifiers :: (HasCallStack, MonadIO m, IsKeymap a) => a -> [ModifierType] -> m (Bool, [ModifierType])
- data KeymapTranslateKeyboardStateMethodInfo
- keymapTranslateKeyboardState :: (HasCallStack, MonadIO m, IsKeymap a) => a -> Word32 -> [ModifierType] -> Int32 -> m (Bool, Word32, Int32, Int32, [ModifierType])
- type C_KeymapDirectionChangedCallback = Ptr () -> Ptr () -> IO ()
- type KeymapDirectionChangedCallback = IO ()
- data KeymapDirectionChangedSignalInfo
- afterKeymapDirectionChanged :: (GObject a, MonadIO m) => a -> KeymapDirectionChangedCallback -> m SignalHandlerId
- genClosure_KeymapDirectionChanged :: KeymapDirectionChangedCallback -> IO Closure
- mk_KeymapDirectionChangedCallback :: C_KeymapDirectionChangedCallback -> IO (FunPtr C_KeymapDirectionChangedCallback)
- noKeymapDirectionChangedCallback :: Maybe KeymapDirectionChangedCallback
- onKeymapDirectionChanged :: (GObject a, MonadIO m) => a -> KeymapDirectionChangedCallback -> m SignalHandlerId
- wrap_KeymapDirectionChangedCallback :: KeymapDirectionChangedCallback -> Ptr () -> Ptr () -> IO ()
- type C_KeymapKeysChangedCallback = Ptr () -> Ptr () -> IO ()
- type KeymapKeysChangedCallback = IO ()
- data KeymapKeysChangedSignalInfo
- afterKeymapKeysChanged :: (GObject a, MonadIO m) => a -> KeymapKeysChangedCallback -> m SignalHandlerId
- genClosure_KeymapKeysChanged :: KeymapKeysChangedCallback -> IO Closure
- mk_KeymapKeysChangedCallback :: C_KeymapKeysChangedCallback -> IO (FunPtr C_KeymapKeysChangedCallback)
- noKeymapKeysChangedCallback :: Maybe KeymapKeysChangedCallback
- onKeymapKeysChanged :: (GObject a, MonadIO m) => a -> KeymapKeysChangedCallback -> m SignalHandlerId
- wrap_KeymapKeysChangedCallback :: KeymapKeysChangedCallback -> Ptr () -> Ptr () -> IO ()
- type C_KeymapStateChangedCallback = Ptr () -> Ptr () -> IO ()
- type KeymapStateChangedCallback = IO ()
- data KeymapStateChangedSignalInfo
- afterKeymapStateChanged :: (GObject a, MonadIO m) => a -> KeymapStateChangedCallback -> m SignalHandlerId
- genClosure_KeymapStateChanged :: KeymapStateChangedCallback -> IO Closure
- mk_KeymapStateChangedCallback :: C_KeymapStateChangedCallback -> IO (FunPtr C_KeymapStateChangedCallback)
- noKeymapStateChangedCallback :: Maybe KeymapStateChangedCallback
- onKeymapStateChanged :: (GObject a, MonadIO m) => a -> KeymapStateChangedCallback -> m SignalHandlerId
- wrap_KeymapStateChangedCallback :: KeymapStateChangedCallback -> Ptr () -> Ptr () -> IO ()
Exported types
GObject Keymap Source # | |
IsObject Keymap Source # | |
IsKeymap Keymap Source # | |
((~) * info (ResolveKeymapMethod t Keymap), MethodInfo * info Keymap p) => IsLabel t (Keymap -> p) Source # | |
((~) * info (ResolveKeymapMethod t Keymap), MethodInfo * info Keymap p) => IsLabelProxy t (Keymap -> p) Source # | |
HasAttributeList * Keymap Source # | |
type AttributeList Keymap Source # | |
type SignalList Keymap Source # | |
Methods
addVirtualModifiers
data KeymapAddVirtualModifiersMethodInfo Source #
((~) * signature ([ModifierType] -> m [ModifierType]), MonadIO m, IsKeymap a) => MethodInfo * KeymapAddVirtualModifiersMethodInfo a signature Source # | |
keymapAddVirtualModifiers Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> [ModifierType] |
|
-> m [ModifierType] |
Maps the non-virtual modifiers (i.e Mod2, Mod3, ...) which are set
in state
to the virtual modifiers (i.e. Super, Hyper and Meta) and
set the corresponding bits in state
.
GDK already does this before delivering key events, but for compatibility reasons, it only sets the first virtual modifier it finds, whereas this function sets all matching virtual modifiers.
This function is useful when matching key events against accelerators.
Since: 2.20
getCapsLockState
data KeymapGetCapsLockStateMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsKeymap a) => MethodInfo * KeymapGetCapsLockStateMethodInfo a signature Source # | |
keymapGetCapsLockState Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> m Bool | Returns: |
Returns whether the Caps Lock modifer is locked.
Since: 2.16
getDefault
:: (HasCallStack, MonadIO m) | |
=> m Keymap | Returns: the |
Returns the Keymap
attached to the default display.
getDirection
data KeymapGetDirectionMethodInfo Source #
((~) * signature (m Direction), MonadIO m, IsKeymap a) => MethodInfo * KeymapGetDirectionMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> m Direction | Returns: |
Returns the direction of effective layout of the keymap.
getEntriesForKeycode
keymapGetEntriesForKeycode Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> Word32 |
|
-> m (Bool, [KeymapKey], [Word32]) | Returns: |
Returns the keyvals bound to hardwareKeycode
.
The Nth KeymapKey
in keys
is bound to the Nth
keyval in keyvals
. Free the returned arrays with free
.
When a keycode is pressed by the user, the keyval from
this list of entries is selected by considering the effective
keyboard group and level. See keymapTranslateKeyboardState
.
getEntriesForKeyval
keymapGetEntriesForKeyval Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> Word32 |
|
-> m (Bool, [KeymapKey]) | Returns: |
Obtains a list of keycode/group/level combinations that will
generate keyval
. Groups and levels are two kinds of keyboard mode;
in general, the level determines whether the top or bottom symbol
on a key is used, and the group determines whether the left or
right symbol is used. On US keyboards, the shift key changes the
keyboard level, and there are no groups. A group switch key might
convert a keyboard between Hebrew to English modes, for example.
EventKey
contains a group
field that indicates the active
keyboard group. The level is computed from the modifier mask.
The returned array should be freed
with free
.
getForDisplay
:: (HasCallStack, MonadIO m, IsDisplay a) | |
=> a |
|
-> m Keymap | Returns: the |
Returns the Keymap
attached to display
.
Since: 2.2
getModifierMask
data KeymapGetModifierMaskMethodInfo Source #
((~) * signature (ModifierIntent -> m [ModifierType]), MonadIO m, IsKeymap a) => MethodInfo * KeymapGetModifierMaskMethodInfo a signature Source # | |
keymapGetModifierMask Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> ModifierIntent |
|
-> m [ModifierType] | Returns: the modifier mask used for |
Returns the modifier mask the keymap
’s windowing system backend
uses for a particular purpose.
Note that this function always returns real hardware modifiers, not
virtual ones (e.g. it will return GDK_MOD1_MASK
rather than
GDK_META_MASK
if the backend maps MOD1 to META), so there are use
cases where the return value of this function has to be transformed
by keymapAddVirtualModifiers
in order to contain the
expected result.
Since: 3.4
getModifierState
data KeymapGetModifierStateMethodInfo Source #
((~) * signature (m Word32), MonadIO m, IsKeymap a) => MethodInfo * KeymapGetModifierStateMethodInfo a signature Source # | |
keymapGetModifierState Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> m Word32 | Returns: the current modifier state. |
Returns the current modifier state.
Since: 3.4
getNumLockState
data KeymapGetNumLockStateMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsKeymap a) => MethodInfo * KeymapGetNumLockStateMethodInfo a signature Source # | |
keymapGetNumLockState Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> m Bool | Returns: |
Returns whether the Num Lock modifer is locked.
Since: 3.0
getScrollLockState
data KeymapGetScrollLockStateMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsKeymap a) => MethodInfo * KeymapGetScrollLockStateMethodInfo a signature Source # | |
keymapGetScrollLockState Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> m Bool | Returns: |
Returns whether the Scroll Lock modifer is locked.
Since: 3.18
haveBidiLayouts
data KeymapHaveBidiLayoutsMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsKeymap a) => MethodInfo * KeymapHaveBidiLayoutsMethodInfo a signature Source # | |
keymapHaveBidiLayouts Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> m Bool | Returns: |
Determines if keyboard layouts for both right-to-left and left-to-right languages are in use.
Since: 2.12
lookupKey
data KeymapLookupKeyMethodInfo Source #
((~) * signature (KeymapKey -> m Word32), MonadIO m, IsKeymap a) => MethodInfo * KeymapLookupKeyMethodInfo a signature Source # | |
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> KeymapKey |
|
-> m Word32 | Returns: a keyval, or 0 if none was mapped to the given |
Looks up the keyval mapped to a keycode/group/level triplet.
If no keyval is bound to key
, returns 0. For normal user input,
you want to use keymapTranslateKeyboardState
instead of
this function, since the effective group/level may not be
the same as the current keyboard state.
mapVirtualModifiers
data KeymapMapVirtualModifiersMethodInfo Source #
((~) * signature ([ModifierType] -> m (Bool, [ModifierType])), MonadIO m, IsKeymap a) => MethodInfo * KeymapMapVirtualModifiersMethodInfo a signature Source # | |
keymapMapVirtualModifiers Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> [ModifierType] |
|
-> m (Bool, [ModifierType]) | Returns: |
Maps the virtual modifiers (i.e. Super, Hyper and Meta) which
are set in state
to their non-virtual counterparts (i.e. Mod2,
Mod3,...) and set the corresponding bits in state
.
This function is useful when matching key events against accelerators.
Since: 2.20
translateKeyboardState
data KeymapTranslateKeyboardStateMethodInfo Source #
((~) * signature (Word32 -> [ModifierType] -> Int32 -> m (Bool, Word32, Int32, Int32, [ModifierType])), MonadIO m, IsKeymap a) => MethodInfo * KeymapTranslateKeyboardStateMethodInfo a signature Source # | |
keymapTranslateKeyboardState Source #
:: (HasCallStack, MonadIO m, IsKeymap a) | |
=> a |
|
-> Word32 |
|
-> [ModifierType] |
|
-> Int32 |
|
-> m (Bool, Word32, Int32, Int32, [ModifierType]) | Returns: |
Translates the contents of a EventKey
into a keyval, effective
group, and level. Modifiers that affected the translation and
are thus unavailable for application use are returned in
consumedModifiers
.
See [Groups][key-group-explanation] for an explanation of
groups and levels. The effectiveGroup
is the group that was
actually used for the translation; some keys such as Enter are not
affected by the active keyboard group. The level
is derived from
state
. For convenience, EventKey
already contains the translated
keyval, so this function isn’t as useful as you might think.
consumedModifiers
gives modifiers that should be masked outfrom state
when comparing this key press to a hot key. For instance, on a US keyboard,
the plus
symbol is shifted, so when comparing a key press to a
<Control>plus
accelerator <Shift>
should be masked out.
C code
// We want to ignore irrelevant modifiers like ScrollLock #define ALL_ACCELS_MASK (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK) gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode, event->state, event->group, &keyval, NULL, NULL, &consumed); if (keyval == GDK_PLUS && (event->state & ~consumed & ALL_ACCELS_MASK) == GDK_CONTROL_MASK) // Control was pressed
An older interpretation consumedModifiers
was that it contained
all modifiers that might affect the translation of the key;
this allowed accelerators to be stored with irrelevant consumed
modifiers, by doing:
C code
// XXX Don’t do this XXX if (keyval == accel_keyval && (event->state & ~consumed & ALL_ACCELS_MASK) == (accel_mods & ~consumed)) // Accelerator was pressed
However, this did not work if multi-modifier combinations were
used in the keymap, since, for instance, <Control>
would be
masked out even if only <Control><Alt>
was used in the keymap.
To support this usage as well as well as possible, all single
modifier combinations that could affect the key for any combination
of modifiers will be returned in consumedModifiers
; multi-modifier
combinations are returned only when actually found in state
. When
you store accelerators, you should always store them with consumed
modifiers removed. Store <Control>plus
, not <Control><Shift>plus
,
Signals
directionChanged
type KeymapDirectionChangedCallback = IO () Source #
afterKeymapDirectionChanged :: (GObject a, MonadIO m) => a -> KeymapDirectionChangedCallback -> m SignalHandlerId Source #
mk_KeymapDirectionChangedCallback :: C_KeymapDirectionChangedCallback -> IO (FunPtr C_KeymapDirectionChangedCallback) Source #
onKeymapDirectionChanged :: (GObject a, MonadIO m) => a -> KeymapDirectionChangedCallback -> m SignalHandlerId Source #
wrap_KeymapDirectionChangedCallback :: KeymapDirectionChangedCallback -> Ptr () -> Ptr () -> IO () Source #
keysChanged
type KeymapKeysChangedCallback = IO () Source #
afterKeymapKeysChanged :: (GObject a, MonadIO m) => a -> KeymapKeysChangedCallback -> m SignalHandlerId Source #
mk_KeymapKeysChangedCallback :: C_KeymapKeysChangedCallback -> IO (FunPtr C_KeymapKeysChangedCallback) Source #
onKeymapKeysChanged :: (GObject a, MonadIO m) => a -> KeymapKeysChangedCallback -> m SignalHandlerId Source #
wrap_KeymapKeysChangedCallback :: KeymapKeysChangedCallback -> Ptr () -> Ptr () -> IO () Source #
stateChanged
type KeymapStateChangedCallback = IO () Source #
afterKeymapStateChanged :: (GObject a, MonadIO m) => a -> KeymapStateChangedCallback -> m SignalHandlerId Source #
mk_KeymapStateChangedCallback :: C_KeymapStateChangedCallback -> IO (FunPtr C_KeymapStateChangedCallback) Source #
onKeymapStateChanged :: (GObject a, MonadIO m) => a -> KeymapStateChangedCallback -> m SignalHandlerId Source #
wrap_KeymapStateChangedCallback :: KeymapStateChangedCallback -> Ptr () -> Ptr () -> IO () Source #