mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 23:21:08 +03:00
move gui keyboard shortcut processing to guicommon
This commit is contained in:
parent
f261f079f7
commit
8f13e53ac8
@ -631,36 +631,7 @@ impl GliumTerminalWindow {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if mods == KeyModifiers::SUPER && key == KeyCode::Char('t') {
|
||||
GuiEventLoop::with_window(&self.event_loop, self.window_id(), |win| {
|
||||
win.spawn_tab().map(|_| ())
|
||||
});
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if mods == KeyModifiers::ALT
|
||||
&& (key == KeyCode::Char('\r')
|
||||
|| key == KeyCode::Char('\n')
|
||||
|| key == KeyCode::Enter)
|
||||
{
|
||||
self.host.toggle_full_screen();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if cfg!(target_os = "macos")
|
||||
&& mods == KeyModifiers::SUPER
|
||||
&& key == KeyCode::Char('c')
|
||||
{
|
||||
// Nominally copy, but that is implicit, so NOP
|
||||
return Ok(());
|
||||
}
|
||||
if (cfg!(target_os = "macos")
|
||||
&& mods == KeyModifiers::SUPER
|
||||
&& key == KeyCode::Char('v'))
|
||||
|| (mods == KeyModifiers::SHIFT && key == KeyCode::Insert)
|
||||
{
|
||||
tab.terminal()
|
||||
.send_paste(&self.host.get_clipboard()?, &mut *tab.pty())?;
|
||||
if self.host.process_gui_shortcuts(tab, mods, key)? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
use super::window::TerminalWindow;
|
||||
use crate::guicommon::tabs::Tab;
|
||||
use crate::MasterPty;
|
||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||
use failure::Error;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::rc::Rc;
|
||||
use term::{KeyCode, KeyModifiers};
|
||||
use termwiz::hyperlink::Hyperlink;
|
||||
|
||||
pub trait HostHelper {
|
||||
@ -48,6 +50,110 @@ impl<H: HostHelper> HostImpl<H> {
|
||||
// to us again until the second call to get_clipboard.
|
||||
self.get_clipboard().map(|_| ())
|
||||
}
|
||||
|
||||
pub fn process_gui_shortcuts(
|
||||
&mut self,
|
||||
tab: &Tab,
|
||||
mods: KeyModifiers,
|
||||
key: KeyCode,
|
||||
) -> Result<bool, Error> {
|
||||
if mods == KeyModifiers::SUPER && key == KeyCode::Char('t') {
|
||||
self.with_window(|win| win.spawn_tab().map(|_| ()));
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if mods == KeyModifiers::ALT
|
||||
&& (key == KeyCode::Char('\r') || key == KeyCode::Char('\n') || key == KeyCode::Enter)
|
||||
{
|
||||
self.toggle_full_screen();
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if cfg!(target_os = "macos") && mods == KeyModifiers::SUPER && key == KeyCode::Char('c') {
|
||||
// Nominally copy, but that is implicit, so NOP
|
||||
return Ok(true);
|
||||
}
|
||||
if (cfg!(target_os = "macos") && mods == KeyModifiers::SUPER && key == KeyCode::Char('v'))
|
||||
|| (mods == KeyModifiers::SHIFT && key == KeyCode::Insert)
|
||||
{
|
||||
tab.terminal()
|
||||
.send_paste(&self.get_clipboard()?, &mut *tab.pty())?;
|
||||
return Ok(true);
|
||||
}
|
||||
if mods == (KeyModifiers::SUPER | KeyModifiers::SHIFT)
|
||||
&& (key == KeyCode::Char('[') || key == KeyCode::Char('{'))
|
||||
{
|
||||
self.activate_tab_relative(-1);
|
||||
return Ok(true);
|
||||
}
|
||||
if mods == (KeyModifiers::SUPER | KeyModifiers::SHIFT)
|
||||
&& (key == KeyCode::Char(']') || key == KeyCode::Char('}'))
|
||||
{
|
||||
self.activate_tab_relative(1);
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if (mods == KeyModifiers::SUPER || mods == KeyModifiers::CTRL) && key == KeyCode::Char('-')
|
||||
{
|
||||
self.decrease_font_size();
|
||||
return Ok(true);
|
||||
}
|
||||
if (mods == KeyModifiers::SUPER || mods == KeyModifiers::CTRL) && key == KeyCode::Char('=')
|
||||
{
|
||||
self.increase_font_size();
|
||||
return Ok(true);
|
||||
}
|
||||
if (mods == KeyModifiers::SUPER || mods == KeyModifiers::CTRL) && key == KeyCode::Char('0')
|
||||
{
|
||||
self.reset_font_size();
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if mods == KeyModifiers::SUPER {
|
||||
if let KeyCode::Char(c) = key {
|
||||
if c >= '0' && c <= '9' {
|
||||
let tab_number = c as u32 - 0x30;
|
||||
// Treat 0 as 10 as that is physically right of 9 on
|
||||
// a keyboard
|
||||
let tab_number = if tab_number == 0 { 10 } else { tab_number - 1 };
|
||||
self.activate_tab(tab_number as usize);
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn activate_tab(&mut self, tab: usize) {
|
||||
self.with_window(move |win| win.activate_tab(tab))
|
||||
}
|
||||
|
||||
pub fn activate_tab_relative(&mut self, tab: isize) {
|
||||
self.with_window(move |win| win.activate_tab_relative(tab))
|
||||
}
|
||||
|
||||
pub fn increase_font_size(&mut self) {
|
||||
self.with_window(move |win| {
|
||||
let scale = win.fonts().get_font_scale();
|
||||
let dims = win.get_dimensions();
|
||||
win.scaling_changed(Some(scale * 1.1), None, dims.width, dims.height)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn decrease_font_size(&mut self) {
|
||||
self.with_window(move |win| {
|
||||
let scale = win.fonts().get_font_scale();
|
||||
let dims = win.get_dimensions();
|
||||
win.scaling_changed(Some(scale * 0.9), None, dims.width, dims.height)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn reset_font_size(&mut self) {
|
||||
self.with_window(move |win| {
|
||||
let dims = win.get_dimensions();
|
||||
win.scaling_changed(Some(1.0), None, dims.width, dims.height)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: HostHelper> Deref for HostImpl<H> {
|
||||
@ -104,34 +210,22 @@ impl<'a, H: HostHelper> term::TerminalHost for TabHost<'a, H> {
|
||||
}
|
||||
|
||||
fn activate_tab(&mut self, tab: usize) {
|
||||
self.host.with_window(move |win| win.activate_tab(tab))
|
||||
self.host.activate_tab(tab)
|
||||
}
|
||||
|
||||
fn activate_tab_relative(&mut self, tab: isize) {
|
||||
self.host
|
||||
.with_window(move |win| win.activate_tab_relative(tab))
|
||||
self.host.activate_tab_relative(tab)
|
||||
}
|
||||
|
||||
fn increase_font_size(&mut self) {
|
||||
self.host.with_window(move |win| {
|
||||
let scale = win.fonts().get_font_scale();
|
||||
let dims = win.get_dimensions();
|
||||
win.scaling_changed(Some(scale * 1.1), None, dims.width, dims.height)
|
||||
})
|
||||
self.host.increase_font_size()
|
||||
}
|
||||
|
||||
fn decrease_font_size(&mut self) {
|
||||
self.host.with_window(move |win| {
|
||||
let scale = win.fonts().get_font_scale();
|
||||
let dims = win.get_dimensions();
|
||||
win.scaling_changed(Some(scale * 0.9), None, dims.width, dims.height)
|
||||
})
|
||||
self.host.decrease_font_size()
|
||||
}
|
||||
|
||||
fn reset_font_size(&mut self) {
|
||||
self.host.with_window(move |win| {
|
||||
let dims = win.get_dimensions();
|
||||
win.scaling_changed(Some(1.0), None, dims.width, dims.height)
|
||||
})
|
||||
self.host.reset_font_size()
|
||||
}
|
||||
}
|
||||
|
@ -236,14 +236,8 @@ impl X11TerminalWindow {
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
if mods == KeyModifiers::SUPER && code == KeyCode::Char('t') {
|
||||
self.host.with_window(|win| win.spawn_tab().map(|_| ()));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if mods == KeyModifiers::SHIFT && key == KeyCode::Insert {
|
||||
tab.terminal()
|
||||
.send_paste(&self.host.get_clipboard()?, &mut *tab.pty())?;
|
||||
if self.host.process_gui_shortcuts(tab, mods, key)? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -709,60 +709,6 @@ impl TerminalState {
|
||||
|
||||
// TODO: also respect self.application_keypad
|
||||
|
||||
if mods == (KeyModifiers::SUPER | KeyModifiers::SHIFT)
|
||||
&& (key == KeyCode::Char('[') || key == KeyCode::Char('{'))
|
||||
{
|
||||
host.activate_tab_relative(-1);
|
||||
return Ok(());
|
||||
}
|
||||
if mods == (KeyModifiers::SUPER | KeyModifiers::SHIFT)
|
||||
&& (key == KeyCode::Char(']') || key == KeyCode::Char('}'))
|
||||
{
|
||||
host.activate_tab_relative(1);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if (mods == KeyModifiers::SUPER || mods == KeyModifiers::CTRL) && key == KeyCode::Char('-')
|
||||
{
|
||||
host.decrease_font_size();
|
||||
return Ok(());
|
||||
}
|
||||
if (mods == KeyModifiers::SUPER || mods == KeyModifiers::CTRL) && key == KeyCode::Char('=')
|
||||
{
|
||||
host.increase_font_size();
|
||||
return Ok(());
|
||||
}
|
||||
if (mods == KeyModifiers::SUPER || mods == KeyModifiers::CTRL) && key == KeyCode::Char('0')
|
||||
{
|
||||
host.reset_font_size();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if mods == KeyModifiers::SUPER {
|
||||
if let Char(c) = key {
|
||||
if c >= '0' && c <= '9' {
|
||||
let tab_number = c as u32 - 0x30;
|
||||
// Treat 0 as 10 as that is physically right of 9 on
|
||||
// a keyboard
|
||||
let tab_number = if tab_number == 0 { 10 } else { tab_number - 1 };
|
||||
host.activate_tab(tab_number as usize);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! paste {
|
||||
() => {{
|
||||
let clip = host.get_clipboard()?;
|
||||
if self.bracketed_paste {
|
||||
write!(buf, "\x1b[200~{}\x1b[201~", clip)?;
|
||||
} else {
|
||||
buf = clip;
|
||||
}
|
||||
buf.as_str()
|
||||
}};
|
||||
}
|
||||
|
||||
let to_send = match (key, ctrl, alt, shift, self.application_cursor_keys) {
|
||||
(Enter, _, ALT, ..) | (Char('\r'), _, ALT, ..) | (Char('\n'), _, ALT, ..) => {
|
||||
host.toggle_full_screen();
|
||||
@ -775,8 +721,6 @@ impl TerminalState {
|
||||
// Delete
|
||||
(Char('\x7f'), _, _, _, false) | (Delete, _, _, _, false) => "\x7f",
|
||||
(Char('\x7f'), ..) | (Delete, ..) => "\x1b[3~",
|
||||
(Insert, _, _, SHIFT, _) => paste!(),
|
||||
(Char('v'), ..) if mods == KeyModifiers::SUPER => paste!(),
|
||||
|
||||
(Char(c), CTRL, _, SHIFT, _) if c <= 0xff as char && c > 0x40 as char => {
|
||||
// If shift is held we have C == 0x43 and want to translate
|
||||
|
Loading…
Reference in New Issue
Block a user