[]Struct gdk::Keymap

pub struct Keymap(_, _);

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.

Implementations

impl Keymap[src]

pub fn get_caps_lock_state(&self) -> bool[src]

Returns whether the Caps Lock modifer is locked.

Returns

true if Caps Lock is on

pub fn get_direction(&self) -> Direction[src]

Returns the direction of effective layout of the keymap.

Returns

pango::Direction::Ltr or pango::Direction::Rtl if it can determine the direction. pango::Direction::Neutral otherwise.

pub fn get_modifier_mask(&self, intent: ModifierIntent) -> ModifierType[src]

Returns the modifier mask the self’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 ModifierType::Mod1Mask rather than ModifierType::MetaMask if the backend maps MOD1 to META), so there are use cases where the return value of this function has to be transformed by Keymap::add_virtual_modifiers in order to contain the expected result.

intent

the use case for the modifier mask

Returns

the modifier mask used for intent.

pub fn get_modifier_state(&self) -> u32[src]

Returns the current modifier state.

Returns

the current modifier state.

pub fn get_num_lock_state(&self) -> bool[src]

Returns whether the Num Lock modifer is locked.

Returns

true if Num Lock is on

pub fn get_scroll_lock_state(&self) -> bool[src]

Returns whether the Scroll Lock modifer is locked.

Feature: v3_18

Returns

true if Scroll Lock is on

pub fn have_bidi_layouts(&self) -> bool[src]

Determines if keyboard layouts for both right-to-left and left-to-right languages are in use.

Returns

true if there are layouts in both directions, false otherwise

pub fn lookup_key(&self, key: &KeymapKey) -> u32[src]

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 Keymap::translate_keyboard_state instead of this function, since the effective group/level may not be the same as the current keyboard state.

key

a KeymapKey with keycode, group, and level initialized

Returns

a keyval, or 0 if none was mapped to the given key

pub fn translate_keyboard_state(
    &self,
    hardware_keycode: u32,
    state: ModifierType,
    group: i32
) -> Option<(u32, i32, i32, ModifierType)>
[src]

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 consumed_modifiers. See [Groups][key-group-explanation] for an explanation of groups and levels. The effective_group 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.

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

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

// 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 consumed_modifiers; 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,

hardware_keycode

a keycode

state

a modifier state

group

active keyboard group

keyval

return location for keyval, or None

effective_group

return location for effective group, or None

level

return location for level, or None

consumed_modifiers

return location for modifiers that were used to determine the group or level, or None

Returns

true if there was a keyval bound to the keycode/state/group

pub fn get_default() -> Option<Keymap>[src]

Returns the Keymap attached to the default display.

Deprecated since 3.22

Use Keymap::get_for_display instead

Returns

the Keymap attached to the default display.

pub fn get_for_display(display: &Display) -> Option<Keymap>[src]

Returns the Keymap attached to display.

display

the Display.

Returns

the Keymap attached to display.

pub fn connect_direction_changed<F: Fn(&Keymap) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

The ::direction-changed signal gets emitted when the direction of the keymap changes.

pub fn connect_keys_changed<F: Fn(&Keymap) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

The ::keys-changed signal is emitted when the mapping represented by keymap changes.

pub fn connect_state_changed<F: Fn(&Keymap) + 'static>(
    &self,
    f: F
) -> SignalHandlerId
[src]

The ::state-changed signal is emitted when the state of the keyboard changes, e.g when Caps Lock is turned on or off. See Keymap::get_caps_lock_state.

impl Keymap[src]

pub fn get_entries_for_keycode(
    &self,
    hardware_keycode: u32
) -> Vec<(KeymapKey, u32)>
[src]

Returns the keyvals bound to hardware_keycode. The Nth KeymapKey in keys is bound to the Nth keyval in keyvals. Free the returned arrays with g_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 Keymap::translate_keyboard_state.

hardware_keycode

a keycode

keys

return location for array of KeymapKey, or None

keyvals

return location for array of keyvals, or None

n_entries

length of keys and keyvals

Returns

true if there were any entries

pub fn get_entries_for_keyval(&self, keyval: u32) -> Vec<KeymapKey>[src]

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

keyval

a keyval, such as GDK_KEY_a, GDK_KEY_Up, GDK_KEY_Return, etc.

keys

return location for an array of KeymapKey

n_keys

return location for number of elements in returned array

Returns

true if keys were found and returned

pub fn add_virtual_modifiers(&self, state: &mut ModifierType)[src]

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.

state

pointer to the modifier mask to change

pub fn map_virtual_modifiers(&self, state: &mut ModifierType) -> bool[src]

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.

state

pointer to the modifier state to map

Returns

false if two virtual modifiers were mapped to the same non-virtual modifier. Note that false is also returned if a virtual modifier is mapped to a non-virtual modifier that was already set in state.

Trait Implementations

impl Clone for Keymap

impl Debug for Keymap

impl Display for Keymap[src]

impl Eq for Keymap

impl Hash for Keymap

impl Ord for Keymap

impl<T: ObjectType> PartialEq<T> for Keymap

impl<T: ObjectType> PartialOrd<T> for Keymap

impl StaticType for Keymap

Auto Trait Implementations

impl RefUnwindSafe for Keymap

impl !Send for Keymap

impl !Sync for Keymap

impl Unpin for Keymap

impl UnwindSafe for Keymap

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.