mirror of
https://github.com/alacritty/alacritty.git
synced 2025-04-21 18:02:37 -04:00
Implement FocusIn/FocusOut reports (#589)
Implements sending FocusIn/FocusOut events, as defined at http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-FocusIn_FocusOut
This commit is contained in:
parent
81116fb8a4
commit
0321f3dcfb
4 changed files with 40 additions and 16 deletions
|
@ -302,6 +302,8 @@ pub enum Mode {
|
|||
ReportMouseClicks = 1000,
|
||||
/// ?1002
|
||||
ReportMouseMotion = 1002,
|
||||
/// ?1004
|
||||
ReportFocusInOut = 1004,
|
||||
/// ?1006
|
||||
SgrMouse = 1006,
|
||||
/// ?1049
|
||||
|
@ -325,6 +327,7 @@ impl Mode {
|
|||
25 => Mode::ShowCursor,
|
||||
1000 => Mode::ReportMouseClicks,
|
||||
1002 => Mode::ReportMouseMotion,
|
||||
1004 => Mode::ReportFocusInOut,
|
||||
1006 => Mode::SgrMouse,
|
||||
1049 => Mode::SwapScreenAndSetRestoreCursor,
|
||||
2004 => Mode::BracketedPaste,
|
||||
|
|
13
src/event.rs
13
src/event.rs
|
@ -251,14 +251,19 @@ impl<N: Notify> Processor<N> {
|
|||
*hide_cursor = false;
|
||||
processor.on_mouse_wheel(scroll_delta, touch_phase);
|
||||
},
|
||||
glutin::Event::Focused(true) |
|
||||
glutin::Event::Refresh |
|
||||
glutin::Event::Awakened => {
|
||||
processor.ctx.terminal.dirty = true;
|
||||
},
|
||||
glutin::Event::Focused(false) => {
|
||||
*hide_cursor = false;
|
||||
},
|
||||
glutin::Event::Focused(is_focused) => {
|
||||
if is_focused {
|
||||
processor.ctx.terminal.dirty = true;
|
||||
} else {
|
||||
*hide_cursor = false;
|
||||
}
|
||||
|
||||
processor.on_focus_change(is_focused);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
13
src/input.rs
13
src/input.rs
|
@ -381,6 +381,19 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn on_focus_change(&mut self, is_focused: bool) {
|
||||
if self.ctx.terminal_mode().contains(mode::FOCUS_IN_OUT) {
|
||||
let chr = if is_focused {
|
||||
"I"
|
||||
} else {
|
||||
"O"
|
||||
};
|
||||
|
||||
let msg = format!("\x1b[{}", chr);
|
||||
self.ctx.write_to_pty(msg.into_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mouse_input(&mut self, state: ElementState, button: MouseButton) {
|
||||
if let MouseButton::Left = button {
|
||||
let state = mem::replace(&mut self.ctx.mouse_mut().left_button_state, state);
|
||||
|
|
|
@ -252,18 +252,19 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
|
|||
pub mod mode {
|
||||
bitflags! {
|
||||
pub flags TermMode: u16 {
|
||||
const SHOW_CURSOR = 0b00000000001,
|
||||
const APP_CURSOR = 0b00000000010,
|
||||
const APP_KEYPAD = 0b00000000100,
|
||||
const MOUSE_REPORT_CLICK = 0b00000001000,
|
||||
const BRACKETED_PASTE = 0b00000010000,
|
||||
const SGR_MOUSE = 0b00000100000,
|
||||
const MOUSE_MOTION = 0b00001000000,
|
||||
const LINE_WRAP = 0b00010000000,
|
||||
const LINE_FEED_NEW_LINE = 0b00100000000,
|
||||
const ORIGIN = 0b01000000000,
|
||||
const INSERT = 0b10000000000,
|
||||
const ANY = 0b11111111111,
|
||||
const SHOW_CURSOR = 0b000000000001,
|
||||
const APP_CURSOR = 0b000000000010,
|
||||
const APP_KEYPAD = 0b000000000100,
|
||||
const MOUSE_REPORT_CLICK = 0b000000001000,
|
||||
const BRACKETED_PASTE = 0b000000010000,
|
||||
const SGR_MOUSE = 0b000000100000,
|
||||
const MOUSE_MOTION = 0b000001000000,
|
||||
const LINE_WRAP = 0b000010000000,
|
||||
const LINE_FEED_NEW_LINE = 0b000100000000,
|
||||
const ORIGIN = 0b001000000000,
|
||||
const INSERT = 0b010000000000,
|
||||
const FOCUS_IN_OUT = 0b100000000000,
|
||||
const ANY = 0b111111111111,
|
||||
const NONE = 0,
|
||||
}
|
||||
}
|
||||
|
@ -1631,6 +1632,7 @@ impl ansi::Handler for Term {
|
|||
ansi::Mode::CursorKeys => self.mode.insert(mode::APP_CURSOR),
|
||||
ansi::Mode::ReportMouseClicks => self.mode.insert(mode::MOUSE_REPORT_CLICK),
|
||||
ansi::Mode::ReportMouseMotion => self.mode.insert(mode::MOUSE_MOTION),
|
||||
ansi::Mode::ReportFocusInOut => self.mode.insert(mode::FOCUS_IN_OUT),
|
||||
ansi::Mode::BracketedPaste => self.mode.insert(mode::BRACKETED_PASTE),
|
||||
ansi::Mode::SgrMouse => self.mode.insert(mode::SGR_MOUSE),
|
||||
ansi::Mode::LineWrap => self.mode.insert(mode::LINE_WRAP),
|
||||
|
@ -1657,6 +1659,7 @@ impl ansi::Handler for Term {
|
|||
ansi::Mode::CursorKeys => self.mode.remove(mode::APP_CURSOR),
|
||||
ansi::Mode::ReportMouseClicks => self.mode.remove(mode::MOUSE_REPORT_CLICK),
|
||||
ansi::Mode::ReportMouseMotion => self.mode.remove(mode::MOUSE_MOTION),
|
||||
ansi::Mode::ReportFocusInOut => self.mode.remove(mode::FOCUS_IN_OUT),
|
||||
ansi::Mode::BracketedPaste => self.mode.remove(mode::BRACKETED_PASTE),
|
||||
ansi::Mode::SgrMouse => self.mode.remove(mode::SGR_MOUSE),
|
||||
ansi::Mode::LineWrap => self.mode.remove(mode::LINE_WRAP),
|
||||
|
|
Loading…
Add table
Reference in a new issue