pub struct Keysym(pub u32);
Expand description
A keysym.
Keysyms are usually generated when a physical key is pressed. In KBVM, the process
of converting key presses to keysyms is handled by the
LookupTable
type.
A keysym represents the logical output of a key press. For example,
syms::a
- the lowercase lettera
, usually generated when pressing the physicalA
key.syms::A
- the uppercase letterA
, usually generated when pressing the physicalA
key while holding the physicalShift
key.syms::BackSpace
syms::Return
The syms
module contains pre-defined constants for all well-known
keysyms. These keysyms all have a name assigned that can be accessed by calling
Keysym::name
. This name is identical to the name of the constant (except that
constants for keysyms that start with a digit have a _
prefix).
In addition to the keysyms from the syms
module, all char
s can be encoded as
keysyms by calling Keysym::from_char
. Most of these keysyms do not have names
assigned and Keysym::name
returns None
.
§Formatting and Parsing
Keysyms can be created from strings by calling Keysym::from_str
or
Keysym::from_str_insensitive
. The keysym can be turned back into a string
by using the Display
implementation.
The Display
implementation guarantees that the output can once again be parsed
by calling Keysym::from_str
. It produces 3 kinds of outputs:
- If the keysym has a name, that name is printed.
- Otherwise, if the keysym encodes a Unicode code point, it prints
Uxxxx
wherexxxx
is the hexadecimal representation of the code point and not necessarily 4 characters long. - Otherwise, it prints
0xXXXXXXXX
whereXXXXXXXX
is simply the hexadecimal representation of theu32
.
This type additionally implements Debug
. It produces 3 kinds of outputs:
- If the keysym has a name, that name is printed.
- Otherwise, if the keysym can be converted to a char via
Keysym::char
, that char is printed withDebug::format
. - Otherwise, it prints
0xXXXXXXXX
as for theDisplay
implementation.
Tuple Fields§
§0: u32
Implementations§
Source§impl Keysym
impl Keysym
Sourcepub fn all() -> Keysyms ⓘ
pub fn all() -> Keysyms ⓘ
Returns an iterator over all well-known keysyms.
See the documentation of Keysyms
for more details.
Sourcepub fn from_char(char: char) -> Self
pub fn from_char(char: char) -> Self
Creates a keysym from a char
.
§Example
let keysym = Keysym::from_char('ァ');
assert_eq!(keysym.name().unwrap(), "kana_a");
assert_eq!(keysym.char().unwrap(), 'ァ');
Sourcepub fn name(self) -> Option<&'static str>
pub fn name(self) -> Option<&'static str>
Returns the name of the keysym if the keysym is a well-known keysym.
§Example
assert_eq!(syms::kana_a.name().unwrap(), "kana_a");
Sourcepub fn char(self) -> Option<char>
pub fn char(self) -> Option<char>
Returns the char
corresponding to this keysym.
§Example
assert_eq!(syms::kana_a.char().unwrap(), 'ァ');
Sourcepub fn from_str(name: &(impl AsRef<[u8]> + ?Sized)) -> Option<Self>
pub fn from_str(name: &(impl AsRef<[u8]> + ?Sized)) -> Option<Self>
Creates a keysym from a case-sensitive string.
§Example
assert_eq!(Keysym::from_str("kana_a").unwrap(), syms::kana_a);
Sourcepub fn from_str_insensitive(name: &(impl AsRef<[u8]> + ?Sized)) -> Option<Self>
pub fn from_str_insensitive(name: &(impl AsRef<[u8]> + ?Sized)) -> Option<Self>
Creates a keysym from a case-insensitive string.
If the well-known names of two keysyms differ only by casing, the keysym with the
larger name is returned. Here, larger is defined in terms of str::cmp
.
§Example
assert_eq!(Keysym::from_str_insensitive("A").unwrap(), syms::a);
assert_eq!(Keysym::from_str("A").unwrap(), syms::A);
Sourcepub fn to_uppercase(self) -> Self
pub fn to_uppercase(self) -> Self
Returns the uppercase variant of this keysym.
If this keysym does not have an uppercase variant or if it already uppercase,
self
is returned.
Note that some Unicode code points have uppercase variants that cannot be
represented as a single Unicode code point. In these cases this function also
returns self
. If you only about the text representation, consider first
converting to char
via Self::char
and then using the standard library
functions to do the case conversion.
§Examples
assert_eq!(syms::a.to_uppercase(), syms::A);
let u1f80 = '\u{1f80}';
assert_eq!(u1f80.to_uppercase().collect::<String>(), "\u{1f08}\u{399}");
let sym = Keysym::from_char(u1f80);
assert_eq!(sym.to_uppercase(), sym);
Sourcepub fn to_lowercase(self) -> Self
pub fn to_lowercase(self) -> Self
Returns the lowercase variant of this keysym.
If this keysym does not have an lowercase variant or if it already lowercase,
self
is returned.
The warning about Unicode code points from Self::to_uppercase
also applies to
this function.
§Examples
assert_eq!(syms::A.to_lowercase(), syms::a);
Sourcepub fn is_in_unicode_range(self) -> bool
pub fn is_in_unicode_range(self) -> bool
Returns whether this keysym is in the Unicode range.
Keysyms encode Unicode code points in the range by setting the most significant
byte to 0x01
. This function returns whether the most significant byte is 0x01
.
Note that this function does not always return true
if the keysym was created
with Self::from_char
. Many Unicode code points are represented by well-known
keysyms outside of the Unicode range.
Even if this function returns true, that does not mean that Self::char
returns
Some
. For example Keysym(0x01_ff_ff_ff).is_in_unicode_range()
returns true but
0xff_ff_ff
is not a valid Unicode code point.
§Examples
assert!(!syms::A.is_in_unicode_range());
assert!(Keysym(0x01_00_00_41).is_in_unicode_range());
Sourcepub fn is_not_in_unicode_range(self) -> bool
pub fn is_not_in_unicode_range(self) -> bool
Returns the negation of Self::is_in_unicode_range
.
Sourcepub fn is_well_known(self) -> bool
pub fn is_well_known(self) -> bool
Returns whether this keysym is well-known.
This is equivalent to Self::name
returning Some
.
§Examples
assert!(syms::A.is_well_known());
Sourcepub fn is_not_well_known(self) -> bool
pub fn is_not_well_known(self) -> bool
Returns the negation of Self::is_well_known
.
Sourcepub fn is_valid(self) -> bool
pub fn is_valid(self) -> bool
Returns whether this keysym is valid.
A keysym is valid if it is well-known or if is in the Unicode range and represents a valid Unicode code point.
§Examples
assert!(syms::A.is_valid());
assert!(!Keysym(0x01_ff_ff_ff).is_valid());
Sourcepub fn is_invalid(self) -> bool
pub fn is_invalid(self) -> bool
Returns the negation of Self::is_valid
.
Sourcepub fn is_lowercase(self) -> bool
pub fn is_lowercase(self) -> bool
Returns whether this is a lowercase keysym.
§Example
assert!(syms::a.is_lowercase());
assert!(!syms::A.is_lowercase());
assert!(!syms::Return.is_lowercase());
Sourcepub fn is_uppercase(self) -> bool
pub fn is_uppercase(self) -> bool
Returns whether this is an uppercase keysym.
§Example
assert!(syms::A.is_uppercase());
assert!(!syms::a.is_uppercase());
assert!(!syms::Return.is_uppercase());
Sourcepub fn is_keypad(self) -> bool
pub fn is_keypad(self) -> bool
Returns whether this is a keypad keysym.
§Example
assert!(syms::KP_0.is_keypad());
assert!(!syms::a.is_keypad());
Sourcepub fn is_modifier(self) -> bool
pub fn is_modifier(self) -> bool
Returns whether this is a modifier keysym.
§Example
assert!(syms::Shift_L.is_modifier());
assert!(!syms::a.is_modifier());
Trait Implementations§
Source§impl Ord for Keysym
impl Ord for Keysym
Source§impl PartialOrd for Keysym
impl PartialOrd for Keysym
impl Copy for Keysym
impl Eq for Keysym
impl StructuralPartialEq for Keysym
Auto Trait Implementations§
impl Freeze for Keysym
impl RefUnwindSafe for Keysym
impl Send for Keysym
impl Sync for Keysym
impl Unpin for Keysym
impl UnwindSafe for Keysym
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.