This commit allows distinguishing between left and right alt modifiers at the window layer. So far only macos provides this additional information. Expand the logic that decides whether Alt should emit the composed key or act as the raw key with the Alt modifier flag set so that we can set that behavior separately for the left and right modifiers on systems that support it, and use the existing config for systems that don't support it. The default settings for these flags is that Left Alt will send the uncomposed key + Alt modifier while the Right Alt will behave more like AltGr (which is typically on the RHS of the keyboard) and send the composed key. This gives more flexibility by default and hopefully matches expectations a bit better. refs: https://github.com/wez/wezterm/issues/216
158 lines
3.4 KiB
Rust
158 lines
3.4 KiB
Rust
use bitflags::*;
|
|
|
|
/// Which key is pressed. Not all of these are probable to appear
|
|
/// on most systems. A lot of this list is @wez trawling docs and
|
|
/// making an entry for things that might be possible in this first pass.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum KeyCode {
|
|
/// The decoded unicode character
|
|
Char(char),
|
|
Composed(String),
|
|
|
|
Hyper,
|
|
Super,
|
|
Meta,
|
|
|
|
/// Ctrl-break on windows
|
|
Cancel,
|
|
// There is no `Backspace`; use `Char('\u{8}') instead
|
|
|
|
// There is no `Tab`; use `Char('\t')` instead
|
|
Clear,
|
|
// There is no `Enter`; use `Char('\r')` instead
|
|
Shift,
|
|
// There is no `Escape`; use `Char('\u{1b}') instead
|
|
LeftShift,
|
|
RightShift,
|
|
Control,
|
|
LeftControl,
|
|
RightControl,
|
|
Alt,
|
|
LeftAlt,
|
|
RightAlt,
|
|
Pause,
|
|
CapsLock,
|
|
PageUp,
|
|
PageDown,
|
|
End,
|
|
Home,
|
|
LeftArrow,
|
|
RightArrow,
|
|
UpArrow,
|
|
DownArrow,
|
|
Select,
|
|
Print,
|
|
Execute,
|
|
PrintScreen,
|
|
Insert,
|
|
// There is no `Delete`; use `Char('\u{7f}')` instead
|
|
Help,
|
|
LeftWindows,
|
|
RightWindows,
|
|
Applications,
|
|
Sleep,
|
|
/// Numeric keypad digits 0-9
|
|
Numpad(u8),
|
|
Multiply,
|
|
Add,
|
|
Separator,
|
|
Subtract,
|
|
Decimal,
|
|
Divide,
|
|
/// F1-F24 are possible
|
|
Function(u8),
|
|
NumLock,
|
|
ScrollLock,
|
|
BrowserBack,
|
|
BrowserForward,
|
|
BrowserRefresh,
|
|
BrowserStop,
|
|
BrowserSearch,
|
|
BrowserFavorites,
|
|
BrowserHome,
|
|
VolumeMute,
|
|
VolumeDown,
|
|
VolumeUp,
|
|
MediaNextTrack,
|
|
MediaPrevTrack,
|
|
MediaStop,
|
|
MediaPlayPause,
|
|
ApplicationLeftArrow,
|
|
ApplicationRightArrow,
|
|
ApplicationUpArrow,
|
|
ApplicationDownArrow,
|
|
}
|
|
|
|
bitflags! {
|
|
#[derive(Default)]
|
|
pub struct Modifiers: u8 {
|
|
const NONE = 0;
|
|
const SHIFT = 1<<1;
|
|
const ALT = 1<<2;
|
|
const CTRL = 1<<3;
|
|
const SUPER = 1<<4;
|
|
const LEFT_ALT = 1<<5;
|
|
const RIGHT_ALT = 1<<6;
|
|
}
|
|
}
|
|
bitflags! {
|
|
#[derive(Default)]
|
|
pub struct MouseButtons: u8 {
|
|
const NONE = 0;
|
|
#[allow(clippy::identity_op)]
|
|
const LEFT = 1<<0;
|
|
const RIGHT = 1<<1;
|
|
const MIDDLE = 1<<2;
|
|
const X1 = 1<<3;
|
|
const X2 = 1<<4;
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum MousePress {
|
|
Left,
|
|
Right,
|
|
Middle,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum MouseEventKind {
|
|
Move,
|
|
Press(MousePress),
|
|
Release(MousePress),
|
|
VertWheel(i16),
|
|
HorzWheel(i16),
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct MouseEvent {
|
|
pub kind: MouseEventKind,
|
|
/// Coordinates of the mouse relative to the top left of the window
|
|
pub coords: crate::Point,
|
|
/// The mouse position in screen coordinates
|
|
pub screen_coords: crate::ScreenPoint,
|
|
pub mouse_buttons: MouseButtons,
|
|
pub modifiers: Modifiers,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct KeyEvent {
|
|
/// Which key was pressed.
|
|
/// This is the potentially processed/composed version
|
|
/// of the input.
|
|
pub key: KeyCode,
|
|
/// Which modifiers are down
|
|
pub modifiers: Modifiers,
|
|
|
|
/// The raw unprocessed key press if it was different from
|
|
/// the processed/composed version
|
|
pub raw_key: Option<KeyCode>,
|
|
pub raw_modifiers: Modifiers,
|
|
|
|
/// How many times this key repeats
|
|
pub repeat_count: u16,
|
|
|
|
/// If true, this is a key down rather than a key up event
|
|
pub key_is_down: bool,
|
|
}
|