Use flag to determine when terminal needs update, only update once before draw
This commit is contained in:
parent
bb0d11180d
commit
556c32e33f
3 changed files with 22 additions and 4 deletions
|
|
@ -666,7 +666,7 @@ impl Application for App {
|
||||||
TermEvent::MouseCursorDirty | TermEvent::Wakeup => {
|
TermEvent::MouseCursorDirty | TermEvent::Wakeup => {
|
||||||
if let Some(terminal) = self.tab_model.data::<Mutex<Terminal>>(entity) {
|
if let Some(terminal) = self.tab_model.data::<Mutex<Terminal>>(entity) {
|
||||||
let mut terminal = terminal.lock().unwrap();
|
let mut terminal = terminal.lock().unwrap();
|
||||||
terminal.update();
|
terminal.needs_update = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ pub struct Terminal {
|
||||||
colors: Colors,
|
colors: Colors,
|
||||||
notifier: Notifier,
|
notifier: Notifier,
|
||||||
pub context_menu: Option<cosmic::iced::Point>,
|
pub context_menu: Option<cosmic::iced::Point>,
|
||||||
|
pub needs_update: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Terminal {
|
impl Terminal {
|
||||||
|
|
@ -182,6 +183,7 @@ impl Terminal {
|
||||||
term,
|
term,
|
||||||
notifier,
|
notifier,
|
||||||
context_menu: None,
|
context_menu: None,
|
||||||
|
needs_update: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,22 @@ where
|
||||||
let limits = limits.width(Length::Fill).height(Length::Fill);
|
let limits = limits.width(Length::Fill).height(Length::Fill);
|
||||||
|
|
||||||
let mut terminal = self.terminal.lock().unwrap();
|
let mut terminal = self.terminal.lock().unwrap();
|
||||||
|
|
||||||
//TODO: set size?
|
//TODO: set size?
|
||||||
|
|
||||||
|
// Update if needed
|
||||||
|
if terminal.needs_update {
|
||||||
|
terminal.update();
|
||||||
|
terminal.needs_update = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure terminal is shaped
|
||||||
terminal.with_buffer_mut(|buffer| {
|
terminal.with_buffer_mut(|buffer| {
|
||||||
let mut font_system = font_system().write().unwrap();
|
let mut font_system = font_system().write().unwrap();
|
||||||
buffer.shape_until_scroll(font_system.raw(), true);
|
buffer.shape_until_scroll(font_system.raw(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Calculate layout lines
|
||||||
terminal.with_buffer(|buffer| {
|
terminal.with_buffer(|buffer| {
|
||||||
let mut layout_lines = 0;
|
let mut layout_lines = 0;
|
||||||
for line in buffer.lines.iter() {
|
for line in buffer.lines.iter() {
|
||||||
|
|
@ -182,8 +192,6 @@ where
|
||||||
|
|
||||||
let state = tree.state.downcast_ref::<State>();
|
let state = tree.state.downcast_ref::<State>();
|
||||||
|
|
||||||
let mut terminal = self.terminal.lock().unwrap();
|
|
||||||
|
|
||||||
//TODO: make this configurable
|
//TODO: make this configurable
|
||||||
let scrollbar_w = 8.0;
|
let scrollbar_w = 8.0;
|
||||||
|
|
||||||
|
|
@ -200,9 +208,17 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut terminal = self.terminal.lock().unwrap();
|
||||||
|
|
||||||
// Ensure terminal is the right size
|
// Ensure terminal is the right size
|
||||||
terminal.resize(view_w as u32, view_h as u32);
|
terminal.resize(view_w as u32, view_h as u32);
|
||||||
|
|
||||||
|
// Update if needed
|
||||||
|
if terminal.needs_update {
|
||||||
|
terminal.update();
|
||||||
|
terminal.needs_update = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure terminal is shaped
|
// Ensure terminal is shaped
|
||||||
terminal.with_buffer_mut(|buffer| {
|
terminal.with_buffer_mut(|buffer| {
|
||||||
let mut font_system = font_system().write().unwrap();
|
let mut font_system = font_system().write().unwrap();
|
||||||
|
|
@ -337,7 +353,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
let duration = instant.elapsed();
|
let duration = instant.elapsed();
|
||||||
log::debug!("redraw {}, {}: {:?}", view_w, view_h, duration);
|
log::trace!("redraw {}, {}: {:?}", view_w, view_h, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
fn on_event(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue