KeymapProtocol
public protocol KeymapProtocol : ObjectProtocol
The KeymapProtocol
protocol exposes the methods and properties of an underlying GdkKeymap
instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Keymap
.
Alternatively, use KeymapRef
as a lighweight, unowned
reference if you already have an instance you just want to use.
A GdkKeymap
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.
-
Untyped pointer to the underlying
GdkKeymap
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
keymap_ptr
Default implementationTyped pointer to the underlying
GdkKeymap
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GdkKeymap
instance.Declaration
Swift
var keymap_ptr: UnsafeMutablePointer<GdkKeymap>! { get }
-
Required Initialiser for types conforming to
KeymapProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
connect(signal:
Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
KeymapSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: KeymapSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
handler
The Swift signal handler (function or callback) to invoke on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
connect(signal:
Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
KeymapSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: KeymapSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
signalHandler
The C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
onDirectionChanged(flags:
Extension methodhandler: ) The
direction-changed
signal gets emitted when the direction of the keymap changes.Note
This represents the underlyingdirection-changed
signalDeclaration
Swift
@discardableResult @inlinable func onDirectionChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: KeymapRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
directionChanged
signal is emitted -
directionChangedSignal
Extension methodTyped
direction-changed
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var directionChangedSignal: KeymapSignalName { get }
-
onKeysChanged(flags:
Extension methodhandler: ) The
keys-changed
signal is emitted when the mapping represented bykeymap
changes.Note
This represents the underlyingkeys-changed
signalDeclaration
Swift
@discardableResult @inlinable func onKeysChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: KeymapRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
keysChanged
signal is emitted -
keysChangedSignal
Extension methodTyped
keys-changed
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var keysChangedSignal: KeymapSignalName { get }
-
onStateChanged(flags:
Extension methodhandler: ) The
state-changed
signal is emitted when the state of the keyboard changes, e.g when Caps Lock is turned on or off. Seegdk_keymap_get_caps_lock_state()
.Note
This represents the underlyingstate-changed
signalDeclaration
Swift
@discardableResult @inlinable func onStateChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: KeymapRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
stateChanged
signal is emitted -
stateChangedSignal
Extension methodTyped
state-changed
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var stateChangedSignal: KeymapSignalName { get }
-
addVirtualModifiers(state:
Extension method) 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 instate
.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.
Declaration
Swift
@inlinable func addVirtualModifiers(state: UnsafeMutablePointer<GdkModifierType>!)
-
getCapsLockState()
Extension methodReturns whether the Caps Lock modifer is locked.
Declaration
Swift
@inlinable func getCapsLockState() -> Bool
-
getDirection()
Extension methodReturns the direction of effective layout of the keymap.
Declaration
Swift
@inlinable func getDirection() -> PangoDirection
-
getEntriesForKeycode(hardwareKeycode:
Extension methodkeys: keyvals: nEntries: ) Returns the keyvals bound to
hardware_keycode
. The NthGdkKeymapKey
inkeys
is bound to the Nth keyval inkeyvals
. Free the returned arrays withg_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. Seegdk_keymap_translate_keyboard_state()
.Declaration
Swift
@inlinable func getEntriesForKeycode(hardwareKeycode: Int, keys: UnsafeMutablePointer<UnsafeMutablePointer<GdkKeymapKey>?>! = nil, keyvals: UnsafeMutablePointer<UnsafeMutablePointer<guint>?>! = nil, nEntries: UnsafeMutablePointer<gint>!) -> Bool
-
getEntriesFor(keyval:
Extension methodkeys: nKeys: ) 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.GdkEventKey
contains agroup
field that indicates the active keyboard group. The level is computed from the modifier mask. The returned array should be freed withg_free()
.Declaration
Swift
@inlinable func getEntriesFor(keyval: Int, keys: UnsafeMutablePointer<UnsafeMutablePointer<GdkKeymapKey>?>!, nKeys: UnsafeMutablePointer<gint>!) -> Bool
-
getModifierMask(intent:
Extension method) 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 thanGDK_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 bygdk_keymap_add_virtual_modifiers()
in order to contain the expected result.Declaration
Swift
@inlinable func getModifierMask(intent: GdkModifierIntent) -> ModifierType
-
getModifierState()
Extension methodReturns the current modifier state.
Declaration
Swift
@inlinable func getModifierState() -> Int
-
getNumLockState()
Extension methodReturns whether the Num Lock modifer is locked.
Declaration
Swift
@inlinable func getNumLockState() -> Bool
-
getScrollLockState()
Extension methodReturns whether the Scroll Lock modifer is locked.
Declaration
Swift
@inlinable func getScrollLockState() -> Bool
-
haveBidiLayouts()
Extension methodDetermines if keyboard layouts for both right-to-left and left-to-right languages are in use.
Declaration
Swift
@inlinable func haveBidiLayouts() -> Bool
-
lookup(key:
Extension method) 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 usegdk_keymap_translate_keyboard_state()
instead of this function, since the effective group/level may not be the same as the current keyboard state.Declaration
Swift
@inlinable func lookup<KeymapKeyT>(key: KeymapKeyT) -> Int where KeymapKeyT : KeymapKeyProtocol
-
mapVirtualModifiers(state:
Extension method) 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 instate
.This function is useful when matching key events against accelerators.
Declaration
Swift
@inlinable func mapVirtualModifiers(state: UnsafeMutablePointer<GdkModifierType>!) -> Bool
-
translateKeyboardState(hardwareKeycode:
Extension methodstate: group: keyval: effectiveGroup: level: consumedModifiers: ) Translates the contents of a
GdkEventKey
into a keyval, effective group, and level. Modifiers that affected the translation and are thus unavailable for application use are returned inconsumed_modifiers
. See Groups for an explanation of groups and levels. Theeffective_group
is the group that was actually used for the translation; some keys such as Enter are not affected by the active keyboard group. Thelevel
is derived fromstate
. For convenience,GdkEventKey
already contains the translated keyval, so this function isn’t as useful as you might think.consumed_modifiers
gives modifiers that should be masked outfromstate
when comparing this key press to a hot key. For instance, on a US keyboard, theplus
symbol is shifted, so when comparing a key press to a<Control>plus
accelerator<Shift>
should be masked out.(C Language Example):
// 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
consumed_modifiers
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 Language Example):// 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 inconsumed_modifiers
; multi-modifier combinations are returned only when actually found instate
. When you store accelerators, you should always store them with consumed modifiers removed. Store<Control>plus
, not<Control><Shift>plus
,Declaration
Swift
@inlinable func translateKeyboardState(hardwareKeycode: Int, state: ModifierType, group: Int, keyval: UnsafeMutablePointer<guint>! = nil, effectiveGroup: UnsafeMutablePointer<gint>! = nil, level: UnsafeMutablePointer<gint>! = nil, consumedModifiers: UnsafeMutablePointer<GdkModifierType>! = nil) -> Bool
-
capsLockState
Extension methodReturns whether the Caps Lock modifer is locked.
Declaration
Swift
@inlinable var capsLockState: Bool { get }
-
direction
Extension methodReturns the direction of effective layout of the keymap.
Declaration
Swift
@inlinable var direction: PangoDirection { get }
-
modifierState
Extension methodReturns the current modifier state.
Declaration
Swift
@inlinable var modifierState: Int { get }
-
numLockState
Extension methodReturns whether the Num Lock modifer is locked.
Declaration
Swift
@inlinable var numLockState: Bool { get }
-
scrollLockState
Extension methodReturns whether the Scroll Lock modifer is locked.
Declaration
Swift
@inlinable var scrollLockState: Bool { get }