aboutsummaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/input.rs b/src/input.rs
index 2d647114..f2337d6a 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -35,6 +35,8 @@ use term::SizeInfo;
use term::mode::TermMode;
use util::fmt::Red;
+pub const FONT_SIZE_STEP: f32 = 0.5;
+
/// Processes input from glutin.
///
/// An escape sequence may be emitted in case specific keys or key combinations
@@ -64,7 +66,7 @@ pub trait ActionContext {
fn received_count(&mut self) -> &mut usize;
fn suppress_chars(&mut self) -> &mut bool;
fn last_modifiers(&mut self) -> &mut ModifiersState;
- fn change_font_size(&mut self, delta: i8);
+ fn change_font_size(&mut self, delta: f32);
fn reset_font_size(&mut self);
fn scroll(&mut self, scroll: Scroll);
}
@@ -103,15 +105,15 @@ impl<T: Eq> Binding<T> {
fn is_triggered_by(
&self,
mode: TermMode,
- mods: &ModifiersState,
+ mods: ModifiersState,
input: &T
) -> bool {
// Check input first since bindings are stored in one big list. This is
// the most likely item to fail so prioritizing it here allows more
// checks to be short circuited.
self.trigger == *input &&
- self.mode_matches(&mode) &&
- self.not_mode_matches(&mode) &&
+ self.mode_matches(mode) &&
+ self.not_mode_matches(mode) &&
self.mods_match(mods)
}
}
@@ -124,12 +126,12 @@ impl<T> Binding<T> {
}
#[inline]
- fn mode_matches(&self, mode: &TermMode) -> bool {
+ fn mode_matches(&self, mode: TermMode) -> bool {
self.mode.is_empty() || mode.intersects(self.mode)
}
#[inline]
- fn not_mode_matches(&self, mode: &TermMode) -> bool {
+ fn not_mode_matches(&self, mode: TermMode) -> bool {
self.notmode.is_empty() || !mode.intersects(self.notmode)
}
@@ -137,10 +139,10 @@ impl<T> Binding<T> {
///
/// Optimized to use single check instead of four (one per modifier)
#[inline]
- fn mods_match(&self, mods: &ModifiersState) -> bool {
- debug_assert!(4 == mem::size_of::<ModifiersState>());
+ fn mods_match(&self, mods: ModifiersState) -> bool {
+ assert_eq_size!(ModifiersState, u32);
unsafe {
- mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(mods)
+ mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(&mods)
}
}
}
@@ -243,10 +245,10 @@ impl Action {
::std::process::exit(0);
},
Action::IncreaseFontSize => {
- ctx.change_font_size(1);
+ ctx.change_font_size(FONT_SIZE_STEP);
},
Action::DecreaseFontSize => {
- ctx.change_font_size(-1);
+ ctx.change_font_size(-FONT_SIZE_STEP);
}
Action::ResetFontSize => {
ctx.reset_font_size();
@@ -507,19 +509,19 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
let mouse_modes = TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION;
// Make sure the new and deprecated setting are both allowed
- let faux_scrollback_lines = self.mouse_config
+ let faux_scrolling_lines = self.mouse_config
.faux_scrollback_lines
.unwrap_or(self.scrolling_config.faux_multiplier as usize);
if self.ctx.terminal_mode().intersects(mouse_modes) {
self.mouse_report(code, ElementState::Pressed, modifiers);
} else if self.ctx.terminal_mode().contains(TermMode::ALT_SCREEN)
- && faux_scrollback_lines > 0 && !modifiers.shift
+ && faux_scrolling_lines > 0 && !modifiers.shift
{
// Faux scrolling
let cmd = code + 1; // 64 + 1 = A, 65 + 1 = B
- let mut content = Vec::with_capacity(faux_scrollback_lines as usize * 3);
- for _ in 0..faux_scrollback_lines {
+ let mut content = Vec::with_capacity(faux_scrolling_lines as usize * 3);
+ for _ in 0..faux_scrolling_lines {
content.push(0x1b);
content.push(b'O');
content.push(cmd);
@@ -527,7 +529,8 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
self.ctx.write_to_pty(content);
} else {
for _ in 0..scroll_multiplier {
- self.ctx.scroll(Scroll::Lines(-((code as isize) * 2 - 129)));
+ // Transform the reported button codes 64 and 65 into 1 and -1 lines to scroll
+ self.ctx.scroll(Scroll::Lines(-(code as isize * 2 - 129)));
}
}
}
@@ -567,7 +570,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
return;
}
- self.process_mouse_bindings(&ModifiersState::default(), button);
+ self.process_mouse_bindings(ModifiersState::default(), button);
}
/// Process key input
@@ -577,11 +580,11 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
&mut self,
state: ElementState,
key: Option<VirtualKeyCode>,
- mods: &ModifiersState,
+ mods: ModifiersState,
) {
match (key, state) {
(Some(key), ElementState::Pressed) => {
- *self.ctx.last_modifiers() = *mods;
+ *self.ctx.last_modifiers() = mods;
*self.ctx.received_count() = 0;
*self.ctx.suppress_chars() = false;
@@ -623,7 +626,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
/// for its action to be executed.
///
/// Returns true if an action is executed.
- fn process_key_bindings(&mut self, mods: &ModifiersState, key: VirtualKeyCode) -> bool {
+ fn process_key_bindings(&mut self, mods: ModifiersState, key: VirtualKeyCode) -> bool {
for binding in self.key_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &key) {
// binding was triggered; run the action
@@ -641,7 +644,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
/// for its action to be executed.
///
/// Returns true if an action is executed.
- fn process_mouse_bindings(&mut self, mods: &ModifiersState, button: MouseButton) -> bool {
+ fn process_mouse_bindings(&mut self, mods: ModifiersState, button: MouseButton) -> bool {
for binding in self.mouse_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &button) {
// binding was triggered; run the action
@@ -741,7 +744,7 @@ mod tests {
fn last_modifiers(&mut self) -> &mut ModifiersState {
&mut self.last_modifiers
}
- fn change_font_size(&mut self, _delta: i8) {
+ fn change_font_size(&mut self, _delta: f32) {
}
fn reset_font_size(&mut self) {
}
@@ -824,9 +827,9 @@ mod tests {
#[test]
fn $name() {
if $triggers {
- assert!($binding.is_triggered_by($mode, &$mods, &KEY));
+ assert!($binding.is_triggered_by($mode, $mods, &KEY));
} else {
- assert!(!$binding.is_triggered_by($mode, &$mods, &KEY));
+ assert!(!$binding.is_triggered_by($mode, $mods, &KEY));
}
}
}