ctrl|cmd +/- to manipulate font size with glutin backend

Simliar code needs to be added to the x11 backend in a follow on
commit.

Refs: https://github.com/wez/wezterm/issues/2
This commit is contained in:
Wez Furlong committed 2019-02-22 15:22:31 -08:00
1 parent 89da009dce
commit c818225a5d
4 files changed
+92 -1

No files matched your search

+19 -1
View File
@@ -109,6 +109,24 @@ impl term::TerminalHost for Host {
.request_spawn_tab(self.display.gl_window().id())
.ok();
}
fn increase_font_size(&mut self) {
self.event_loop
.request_increase_font_size(self.display.gl_window().id())
.ok();
}
fn decrease_font_size(&mut self) {
self.event_loop
.request_decrease_font_size(self.display.gl_window().id())
.ok();
}
fn reset_font_size(&mut self) {
self.event_loop
.request_reset_font_size(self.display.gl_window().id())
.ok();
}
}
pub struct TerminalWindow {
@@ -620,7 +638,7 @@ impl TerminalWindow {
/// Called in response to either the screen dpi changing,
/// or the font scaling factor changing
fn scaling_changed(&mut self, font_scale: Option<f64>) -> Result<(), Error> {
pub fn scaling_changed(&mut self, font_scale: Option<f64>) -> Result<(), Error> {
let dpi_scale = self.host.display.gl_window().get_hidpi_factor();
let font_scale = font_scale.unwrap_or_else(|| self.fonts.get_font_scale());
eprintln!(
+48
View File
@@ -71,6 +71,9 @@ struct Windows {
enum SpawnRequest {
Window,
Tab(WindowId),
FontLarger(WindowId),
FontSmaller(WindowId),
FontReset(WindowId),
}
/// The `GuiEventLoop` represents the combined gui event processor,
@@ -116,6 +119,41 @@ impl GlutinGuiSystem {
Ok(SpawnRequest::Tab(_window_id)) => {
eprintln!("Spawning tabs is not yet implemented for glutin");
}
Ok(SpawnRequest::FontLarger(window_id)) => {
let scale = fonts.get_font_scale() * 1.1;
if let Some(window) = self
.event_loop
.windows
.borrow_mut()
.by_id
.get_mut(&window_id)
{
window.scaling_changed(Some(scale)).ok();
}
}
Ok(SpawnRequest::FontSmaller(window_id)) => {
let scale = fonts.get_font_scale() * 0.9;
if let Some(window) = self
.event_loop
.windows
.borrow_mut()
.by_id
.get_mut(&window_id)
{
window.scaling_changed(Some(scale)).ok();
}
}
Ok(SpawnRequest::FontReset(window_id)) => {
if let Some(window) = self
.event_loop
.windows
.borrow_mut()
.by_id
.get_mut(&window_id)
{
window.scaling_changed(Some(1.0)).ok();
}
}
Err(TryRecvError::Empty) => return Ok(()),
Err(err) => bail!("spawn_rx disconnected {:?}", err),
}
@@ -206,6 +244,16 @@ impl GuiEventLoop {
})
}
pub fn request_increase_font_size(&self, window_id: WindowId) -> Result<(), Error> {
self.spawn_tx.send(SpawnRequest::FontLarger(window_id))
}
pub fn request_decrease_font_size(&self, window_id: WindowId) -> Result<(), Error> {
self.spawn_tx.send(SpawnRequest::FontSmaller(window_id))
}
pub fn request_reset_font_size(&self, window_id: WindowId) -> Result<(), Error> {
self.spawn_tx.send(SpawnRequest::FontReset(window_id))
}
pub fn request_spawn_window(&self) -> Result<(), Error> {
self.spawn_tx.send(SpawnRequest::Window)
}
+9
View File
@@ -36,6 +36,15 @@ pub trait TerminalHost {
/// Toggle full-screen mode
fn toggle_full_screen(&mut self) {}
/// Increase font size by one step
fn increase_font_size(&mut self) {}
/// Decrease font size by one step
fn decrease_font_size(&mut self) {}
/// Reset font size
fn reset_font_size(&mut self) {}
}
pub struct Terminal {
+16
View File
@@ -706,6 +706,22 @@ impl TerminalState {
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' {