move most of gliumwindows away from directly accessing Terminal
This commit is contained in:
1 parent
fa0ea270f4
commit
d6cb4f3ff2
7 files changed
+69
-36
No files matched your search
+10
-14
@@ -8,6 +8,7 @@ use crate::guicommon::tabs::{Tab, TabId, Tabs};
|
||||
use crate::guicommon::window::{Dimensions, TerminalWindow};
|
||||
use crate::guiloop::glutinloop::GuiEventLoop;
|
||||
use crate::guiloop::SessionTerminated;
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::opengl::render::Renderer;
|
||||
use glium;
|
||||
use glium::glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
|
||||
@@ -198,8 +199,7 @@ impl GliumTerminalWindow {
|
||||
.map(|p| p.clone().into())
|
||||
.unwrap_or_else(term::color::ColorPalette::default);
|
||||
|
||||
let terminal = tab.terminal();
|
||||
let screen = terminal.screen();
|
||||
let (physical_rows, physical_cols) = tab.renderer().physical_dimensions();
|
||||
|
||||
let metrics = fonts.default_font_metrics()?;
|
||||
let (cell_height, cell_width) = (
|
||||
@@ -207,8 +207,8 @@ impl GliumTerminalWindow {
|
||||
metrics.cell_width.ceil() as usize,
|
||||
);
|
||||
|
||||
let width = cell_width * screen.physical_cols;
|
||||
let height = cell_height * screen.physical_rows;
|
||||
let width = cell_width * physical_cols;
|
||||
let height = cell_height * physical_rows;
|
||||
|
||||
let logical_size = LogicalSize::new(width as f64, height as f64);
|
||||
eprintln!("make window with {}x{}", width, height);
|
||||
@@ -294,7 +294,7 @@ impl GliumTerminalWindow {
|
||||
|
||||
self.last_mouse_coords = position;
|
||||
let (x, y): (i32, i32) = position.into();
|
||||
tab.terminal().mouse_event(
|
||||
tab.mouse_event(
|
||||
term::MouseEvent {
|
||||
kind: MouseEventKind::Move,
|
||||
button: MouseButton::None,
|
||||
@@ -311,7 +311,7 @@ impl GliumTerminalWindow {
|
||||
// When hovering over a hyperlink, show an appropriate
|
||||
// mouse cursor to give the cue that it is clickable
|
||||
|
||||
let cursor = if tab.terminal().current_highlight().is_some() {
|
||||
let cursor = if tab.renderer().current_highlight().is_some() {
|
||||
MouseCursor::Hand
|
||||
} else {
|
||||
MouseCursor::Text
|
||||
@@ -332,7 +332,7 @@ impl GliumTerminalWindow {
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
tab.terminal().mouse_event(
|
||||
tab.mouse_event(
|
||||
term::MouseEvent {
|
||||
kind: match state {
|
||||
ElementState::Pressed => MouseEventKind::Press,
|
||||
@@ -397,7 +397,7 @@ impl GliumTerminalWindow {
|
||||
None => return Ok(()),
|
||||
};
|
||||
for _ in 0..times {
|
||||
tab.terminal().mouse_event(
|
||||
tab.mouse_event(
|
||||
term::MouseEvent {
|
||||
kind: MouseEventKind::Press,
|
||||
button,
|
||||
@@ -635,7 +635,7 @@ impl GliumTerminalWindow {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tab.terminal().key_down(key, mods, &mut *tab.writer())?
|
||||
tab.key_down(key, mods)?;
|
||||
}
|
||||
ElementState::Released => {}
|
||||
}
|
||||
@@ -687,11 +687,7 @@ impl GliumTerminalWindow {
|
||||
Some(tab) => tab,
|
||||
None => return Ok(()),
|
||||
};
|
||||
tab.terminal().key_down(
|
||||
KeyCode::Char(c),
|
||||
self.last_modifiers,
|
||||
&mut *tab.writer(),
|
||||
)?;
|
||||
tab.key_down(KeyCode::Char(c), self.last_modifiers)?;
|
||||
self.paint_if_needed()?;
|
||||
}
|
||||
return Ok(());
|
||||
|
||||
@@ -75,8 +75,7 @@ impl<H: HostHelper> HostImpl<H> {
|
||||
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.writer())?;
|
||||
tab.send_paste(&self.get_clipboard()?)?;
|
||||
return Ok(true);
|
||||
}
|
||||
if mods == (KeyModifiers::SUPER | KeyModifiers::SHIFT)
|
||||
|
||||
+30
-1
@@ -2,7 +2,7 @@ use crate::{Child, MasterPty};
|
||||
use failure::Error;
|
||||
use std::cell::{RefCell, RefMut};
|
||||
use std::rc::Rc;
|
||||
use term::Terminal;
|
||||
use term::{KeyCode, KeyModifiers, MouseEvent, Terminal, TerminalHost};
|
||||
|
||||
static TAB_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
|
||||
pub type TabId = usize;
|
||||
@@ -30,10 +30,15 @@ impl Tab {
|
||||
self.tab_id
|
||||
}
|
||||
|
||||
#[deprecated]
|
||||
pub fn terminal(&self) -> RefMut<Terminal> {
|
||||
self.terminal.borrow_mut()
|
||||
}
|
||||
|
||||
pub fn renderer(&self) -> RefMut<Terminal> {
|
||||
self.terminal.borrow_mut()
|
||||
}
|
||||
|
||||
pub fn is_dead(&self) -> bool {
|
||||
if let Ok(None) = self.process.borrow_mut().try_wait() {
|
||||
false
|
||||
@@ -42,6 +47,20 @@ impl Tab {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn advance_bytes(&self, buf: &[u8], host: &mut TerminalHost) {
|
||||
self.terminal.borrow_mut().advance_bytes(buf, host)
|
||||
}
|
||||
|
||||
pub fn mouse_event(&self, event: MouseEvent, host: &mut TerminalHost) -> Result<(), Error> {
|
||||
self.terminal.borrow_mut().mouse_event(event, host)
|
||||
}
|
||||
|
||||
pub fn key_down(&self, key: KeyCode, mods: KeyModifiers) -> Result<(), Error> {
|
||||
self.terminal
|
||||
.borrow_mut()
|
||||
.key_down(key, mods, &mut *self.pty.borrow_mut())
|
||||
}
|
||||
|
||||
pub fn resize(
|
||||
&self,
|
||||
rows: u16,
|
||||
@@ -65,6 +84,16 @@ impl Tab {
|
||||
pub fn reader(&self) -> Result<Box<std::io::Read + Send>, Error> {
|
||||
self.pty.borrow_mut().try_clone_reader()
|
||||
}
|
||||
|
||||
pub fn send_paste(&self, text: &str) -> Result<(), Error> {
|
||||
self.terminal
|
||||
.borrow_mut()
|
||||
.send_paste(text, &mut *self.pty.borrow_mut())
|
||||
}
|
||||
|
||||
pub fn get_title(&self) -> String {
|
||||
self.terminal.borrow_mut().get_title().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Tab {
|
||||
|
||||
+12
-11
@@ -1,6 +1,7 @@
|
||||
use crate::config::Config;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::guicommon::tabs::{Tab, TabId, Tabs};
|
||||
use crate::mux::renderable::Renderable;
|
||||
use crate::opengl::render::Renderer;
|
||||
use crate::opengl::textureatlas::OutOfTextureSpace;
|
||||
use crate::openpty;
|
||||
@@ -72,10 +73,7 @@ pub trait TerminalWindow {
|
||||
}
|
||||
let tab_no = self.get_tabs().get_active_idx();
|
||||
|
||||
let title = {
|
||||
let terminal = self.get_tabs().get_active().unwrap().terminal();
|
||||
terminal.get_title().to_owned()
|
||||
};
|
||||
let title = self.get_tabs().get_active().unwrap().get_title();
|
||||
|
||||
if num_tabs == 1 {
|
||||
self.set_window_title(&title).ok();
|
||||
@@ -90,7 +88,7 @@ pub trait TerminalWindow {
|
||||
Some(tab) => tab,
|
||||
None => return Ok(()),
|
||||
};
|
||||
if tab.terminal().has_dirty_lines() {
|
||||
if tab.renderer().has_dirty_lines() {
|
||||
self.paint()?;
|
||||
}
|
||||
self.update_title();
|
||||
@@ -102,7 +100,7 @@ pub trait TerminalWindow {
|
||||
|
||||
let res = {
|
||||
let (renderer, mut terminal) = self.renderer_and_terminal();
|
||||
renderer.paint(&mut target, &mut terminal)
|
||||
renderer.paint(&mut target, &mut *terminal)
|
||||
};
|
||||
|
||||
// Ensure that we finish() the target before we let the
|
||||
@@ -122,7 +120,7 @@ pub trait TerminalWindow {
|
||||
self.get_tabs_mut()
|
||||
.get_active()
|
||||
.unwrap()
|
||||
.terminal()
|
||||
.renderer()
|
||||
.make_all_lines_dirty();
|
||||
// Recursively initiate a new paint
|
||||
return self.paint();
|
||||
@@ -208,7 +206,7 @@ pub trait TerminalWindow {
|
||||
dpi_scale, font_scale
|
||||
);
|
||||
if let Some(tab) = self.get_tabs().get_active() {
|
||||
tab.terminal().make_all_lines_dirty();
|
||||
tab.renderer().make_all_lines_dirty();
|
||||
}
|
||||
fonts.change_scaling(font_scale, dpi_scale);
|
||||
|
||||
@@ -220,8 +218,11 @@ pub trait TerminalWindow {
|
||||
// If the backend supports `resize_if_not_full_screen` then we'll try
|
||||
// to resize the window to match the new cell metrics.
|
||||
let (rows, cols) = {
|
||||
let term = self.get_tabs().get_active().unwrap().terminal();
|
||||
(term.screen().physical_rows, term.screen().physical_cols)
|
||||
self.get_tabs()
|
||||
.get_active()
|
||||
.unwrap()
|
||||
.renderer()
|
||||
.physical_dimensions()
|
||||
};
|
||||
|
||||
self.advise_renderer_that_scaling_has_changed(
|
||||
@@ -240,7 +241,7 @@ pub trait TerminalWindow {
|
||||
fn tab_did_terminate(&mut self, tab_id: TabId) {
|
||||
self.get_tabs_mut().remove_by_id(tab_id);
|
||||
if let Some(active) = self.get_tabs().get_active() {
|
||||
active.terminal().make_all_lines_dirty();
|
||||
active.renderer().make_all_lines_dirty();
|
||||
self.update_title();
|
||||
}
|
||||
self.deregister_tab(tab_id).ok();
|
||||
|
||||
+2
-2
@@ -106,8 +106,8 @@ impl Mux {
|
||||
match event {
|
||||
PtyEvent::Data { tab_id, data } => {
|
||||
if let Some(tab) = self.get_tab(tab_id) {
|
||||
tab.terminal().advance_bytes(
|
||||
data,
|
||||
tab.advance_bytes(
|
||||
&data,
|
||||
&mut Host {
|
||||
writer: &mut *tab.writer(),
|
||||
},
|
||||
|
||||
@@ -18,6 +18,10 @@ pub trait Renderable {
|
||||
/// columns on this line.
|
||||
fn get_dirty_lines(&self) -> Vec<(usize, &Line, Range<usize>)>;
|
||||
|
||||
fn has_dirty_lines(&self) -> bool;
|
||||
|
||||
fn make_all_lines_dirty(&mut self);
|
||||
|
||||
/// Clear the dirty flag for all dirty lines
|
||||
fn clean_dirty_lines(&mut self);
|
||||
|
||||
@@ -42,6 +46,10 @@ impl Renderable for Terminal {
|
||||
TerminalState::clean_dirty_lines(self)
|
||||
}
|
||||
|
||||
fn make_all_lines_dirty(&mut self) {
|
||||
TerminalState::make_all_lines_dirty(self)
|
||||
}
|
||||
|
||||
fn current_highlight(&self) -> Option<Rc<Hyperlink>> {
|
||||
TerminalState::current_highlight(self)
|
||||
}
|
||||
@@ -50,4 +58,8 @@ impl Renderable for Terminal {
|
||||
let screen = self.screen();
|
||||
(screen.physical_cols, screen.physical_rows)
|
||||
}
|
||||
|
||||
fn has_dirty_lines(&self) -> bool {
|
||||
TerminalState::has_dirty_lines(self)
|
||||
}
|
||||
}
|
||||
@@ -1026,18 +1026,14 @@ impl Renderer {
|
||||
(fg_color, bg_color)
|
||||
}
|
||||
|
||||
pub fn paint(
|
||||
&mut self,
|
||||
target: &mut glium::Frame,
|
||||
term: &mut term::Terminal,
|
||||
) -> Result<(), Error> {
|
||||
pub fn paint(&mut self, target: &mut glium::Frame, term: &mut Renderable) -> Result<(), Error> {
|
||||
let background_color = self
|
||||
.palette
|
||||
.resolve_bg(term::color::ColorAttribute::Default);
|
||||
let (r, g, b, a) = background_color.to_tuple_rgba();
|
||||
target.clear_color(r, g, b, a);
|
||||
|
||||
let cursor = term.cursor_pos();
|
||||
let cursor = term.get_cursor_position();
|
||||
{
|
||||
let dirty_lines = term.get_dirty_lines();
|
||||
|
||||
|
||||
Reference in new issue
Block a user