mirror of
https://github.com/wez/wezterm.git
synced 2024-11-28 01:06:37 +03:00
move window/tab/fullscreen related to TerminalHost
This commit is contained in:
parent
9affe0ea30
commit
88473e5a09
@ -28,6 +28,10 @@ struct Host {
|
||||
display: glium::Display,
|
||||
pty: MasterPty,
|
||||
clipboard: Clipboard,
|
||||
window_position: Option<(i32, i32)>,
|
||||
/// is is_some, holds position to be restored after exiting
|
||||
/// fullscreen mode.
|
||||
is_fullscreen: Option<(i32, i32)>,
|
||||
}
|
||||
|
||||
impl term::TerminalHost for Host {
|
||||
@ -54,6 +58,37 @@ impl term::TerminalHost for Host {
|
||||
fn set_title(&mut self, title: &str) {
|
||||
self.display.gl_window().set_title(title);
|
||||
}
|
||||
|
||||
fn toggle_full_screen(&mut self) {
|
||||
let window = self.display.gl_window();
|
||||
let pos = self.is_fullscreen.take();
|
||||
if let Some((x, y)) = pos {
|
||||
window.set_fullscreen(None);
|
||||
window.set_position(x, y);
|
||||
} else {
|
||||
// We use our own idea of the position because get_position()
|
||||
// appears to only return the initial position of the window
|
||||
// on Linux.
|
||||
self.is_fullscreen = self.window_position.take();
|
||||
window.set_fullscreen(Some(window.get_current_monitor()));
|
||||
}
|
||||
}
|
||||
|
||||
fn new_window(&mut self) {
|
||||
/*
|
||||
println!("open a new one!");
|
||||
let event_loop = Rc::clone(&self.event_loop);
|
||||
let config = Rc::clone(&self.config);
|
||||
let fonts = Rc::clone(&self.renderer.fonts);
|
||||
self.event_loop
|
||||
.core
|
||||
.spawn(futures::future::poll_fn(move || {
|
||||
spawn_window(&event_loop, None, &config, &fonts)
|
||||
.map(futures::Async::Ready)
|
||||
.map_err(|_| ())
|
||||
}));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TerminalWindow {
|
||||
@ -69,10 +104,6 @@ pub struct TerminalWindow {
|
||||
process: Child,
|
||||
last_mouse_coords: (f64, f64),
|
||||
last_modifiers: KeyModifiers,
|
||||
window_position: Option<(i32, i32)>,
|
||||
/// is is_some, holds position to be restored after exiting
|
||||
/// fullscreen mode.
|
||||
is_fullscreen: Option<(i32, i32)>,
|
||||
}
|
||||
|
||||
impl TerminalWindow {
|
||||
@ -112,15 +143,17 @@ impl TerminalWindow {
|
||||
let display = glium::Display::new(window, context, &*event_loop.event_loop.borrow_mut())
|
||||
.map_err(|e| format_err!("{:?}", e))?;
|
||||
let window_id = display.gl_window().id();
|
||||
let window_position = display.gl_window().get_position();
|
||||
|
||||
let host = Host {
|
||||
display,
|
||||
pty,
|
||||
clipboard: Clipboard::new(event_loop.paster.clone(), window_id)?,
|
||||
window_position,
|
||||
is_fullscreen: None,
|
||||
};
|
||||
|
||||
host.display.gl_window().set_cursor(MouseCursor::Text);
|
||||
let window_position = host.display.gl_window().get_position();
|
||||
|
||||
let renderer = Renderer::new(&host.display, width, height, fonts, palette)?;
|
||||
let cell_height = cell_height.ceil() as usize;
|
||||
@ -139,8 +172,6 @@ impl TerminalWindow {
|
||||
process,
|
||||
last_mouse_coords: (0.0, 0.0),
|
||||
last_modifiers: Default::default(),
|
||||
window_position,
|
||||
is_fullscreen: None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -508,37 +539,8 @@ impl TerminalWindow {
|
||||
event: WindowEvent::ReceivedCharacter(c),
|
||||
..
|
||||
} => {
|
||||
// Primitive Alt-Enter fullscreen shortcut
|
||||
if c == '\r' && self.last_modifiers.contains(KeyModifiers::ALT) {
|
||||
let window = self.host.display.gl_window();
|
||||
let pos = self.is_fullscreen.take();
|
||||
if let Some((x, y)) = pos {
|
||||
window.set_fullscreen(None);
|
||||
window.set_position(x, y);
|
||||
} else {
|
||||
// We use our own idea of the position because get_position()
|
||||
// appears to only return the initial position of the window
|
||||
// on Linux.
|
||||
self.is_fullscreen = self.window_position.take();
|
||||
window.set_fullscreen(Some(window.get_current_monitor()));
|
||||
}
|
||||
} else if c == 'y' && self.last_modifiers.contains(KeyModifiers::SUPER) {
|
||||
// CMD-y to open a new window
|
||||
println!("open a new one!");
|
||||
let event_loop = Rc::clone(&self.event_loop);
|
||||
let config = Rc::clone(&self.config);
|
||||
let fonts = Rc::clone(&self.renderer.fonts);
|
||||
self.event_loop
|
||||
.core
|
||||
.spawn(futures::future::poll_fn(move || {
|
||||
spawn_window(&event_loop, None, &config, &fonts)
|
||||
.map(futures::Async::Ready)
|
||||
.map_err(|_| ())
|
||||
}));
|
||||
} else {
|
||||
self.terminal
|
||||
.key_down(KeyCode::Char(c), self.last_modifiers, &mut self.host)?;
|
||||
}
|
||||
self.terminal
|
||||
.key_down(KeyCode::Char(c), self.last_modifiers, &mut self.host)?;
|
||||
self.paint_if_needed()?;
|
||||
}
|
||||
Event::WindowEvent {
|
||||
|
@ -25,13 +25,14 @@ struct Host {
|
||||
pty: MasterPty,
|
||||
timestamp: xcb::xproto::Timestamp,
|
||||
clipboard: Clipboard,
|
||||
event_loop: Rc<GuiEventLoop>,
|
||||
fonts: Rc<FontConfiguration>,
|
||||
config: Rc<Config>,
|
||||
}
|
||||
|
||||
pub struct TerminalWindow {
|
||||
host: Host,
|
||||
conn: Rc<Connection>,
|
||||
event_loop: Rc<GuiEventLoop>,
|
||||
config: Rc<Config>,
|
||||
renderer: Renderer,
|
||||
width: u16,
|
||||
height: u16,
|
||||
@ -67,6 +68,19 @@ impl term::TerminalHost for Host {
|
||||
fn set_title(&mut self, title: &str) {
|
||||
self.window.set_title(title);
|
||||
}
|
||||
|
||||
fn new_window(&mut self) {
|
||||
let event_loop = Rc::clone(&self.event_loop);
|
||||
let config = Rc::clone(&self.config);
|
||||
let fonts = Rc::clone(&self.fonts);
|
||||
self.event_loop
|
||||
.core
|
||||
.spawn(futures::future::poll_fn(move || {
|
||||
spawn_window(&event_loop, None, &config, &fonts)
|
||||
.map(futures::Async::Ready)
|
||||
.map_err(|_| ())
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl TerminalWindow {
|
||||
@ -104,6 +118,9 @@ impl TerminalWindow {
|
||||
pty,
|
||||
timestamp: 0,
|
||||
clipboard: Clipboard::new(event_loop.paster.clone(), window_id)?,
|
||||
event_loop: Rc::clone(event_loop),
|
||||
config: Rc::clone(config),
|
||||
fonts: Rc::clone(fonts),
|
||||
};
|
||||
|
||||
let renderer = Renderer::new(&host.window, width, height, fonts, palette)?;
|
||||
@ -116,8 +133,6 @@ impl TerminalWindow {
|
||||
host,
|
||||
renderer,
|
||||
conn: Rc::clone(&event_loop.conn),
|
||||
event_loop: Rc::clone(event_loop),
|
||||
config: Rc::clone(config),
|
||||
width,
|
||||
height,
|
||||
cell_height,
|
||||
@ -259,23 +274,6 @@ impl TerminalWindow {
|
||||
let key_press: &xcb::KeyPressEvent = unsafe { xcb::cast_event(event) };
|
||||
self.host.timestamp = key_press.time();
|
||||
let (code, mods) = self.decode_key(key_press);
|
||||
|
||||
if code == KeyCode::Char('y') && mods == KeyModifiers::SUPER {
|
||||
println!("open a new one!");
|
||||
let event_loop = Rc::clone(&self.event_loop);
|
||||
let config = Rc::clone(&self.config);
|
||||
let fonts = Rc::clone(&self.renderer.fonts);
|
||||
self.event_loop
|
||||
.core
|
||||
.spawn(futures::future::poll_fn(move || {
|
||||
spawn_window(&event_loop, None, &config, &fonts)
|
||||
.map(futures::Async::Ready)
|
||||
.map_err(|_| ())
|
||||
}));
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.terminal.key_down(code, mods, &mut self.host)?;
|
||||
}
|
||||
xcb::KEY_RELEASE => {
|
||||
|
@ -19,6 +19,15 @@ pub trait TerminalHost {
|
||||
|
||||
/// Called when a URL is clicked
|
||||
fn click_link(&mut self, link: &Rc<Hyperlink>);
|
||||
|
||||
/// Create a new Window
|
||||
fn new_window(&mut self) {}
|
||||
|
||||
/// Create a new tab in the current window
|
||||
fn new_tab(&mut self) {}
|
||||
|
||||
/// Toggle full-screen mode
|
||||
fn toggle_full_screen(&mut self) {}
|
||||
}
|
||||
|
||||
pub struct Terminal {
|
||||
|
@ -610,7 +610,22 @@ impl TerminalState {
|
||||
|
||||
// TODO: also respect self.application_keypad
|
||||
|
||||
// TODO: I don't really like this key assignment, but for the sake of
|
||||
// testing, I'm just jamming something in.
|
||||
if mods == KeyModifiers::SUPER && key == KeyCode::Char('y') {
|
||||
host.new_window();
|
||||
return Ok(());
|
||||
}
|
||||
if mods == KeyModifiers::SUPER && key == KeyCode::Char('t') {
|
||||
host.new_tab();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let to_send = match (key, ctrl, alt, shift, self.application_cursor_keys) {
|
||||
(Char('\n'), _, ALT, ..) => {
|
||||
host.toggle_full_screen();
|
||||
return Ok(());
|
||||
}
|
||||
// Delete
|
||||
(Char('\x7f'), ..) => "\x1b[3~",
|
||||
(Char(c), CTRL, _, SHIFT, _) if c <= 0xff as char && c > 0x40 as char => {
|
||||
|
Loading…
Reference in New Issue
Block a user