Skip to content

Commit

Permalink
add ctrl +/- font size support to x11 backend
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
wez committed Feb 23, 2019
1 parent 92bb685 commit 26d7ed9
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/xwindows/xwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct Host {
pub struct TerminalWindow {
host: Host,
conn: Rc<Connection>,
fonts: Rc<FontConfiguration>,
renderer: Renderer,
width: u16,
height: u16,
Expand Down Expand Up @@ -223,6 +224,54 @@ impl<'a> term::TerminalHost for TabHost<'a> {
.map_err(|_| ())
}));
}

fn increase_font_size(&mut self) {
let events = Rc::clone(&self.host.event_loop);
let window_id = self.host.window.window.window_id;
self.host
.event_loop
.core
.spawn(futures::future::poll_fn(move || {
events
.with_window(window_id, |win| {
let scale = win.fonts.get_font_scale();
win.scaling_changed(Some(scale * 1.1))
})
.map(futures::Async::Ready)
.map_err(|_| ())
}));
}

fn decrease_font_size(&mut self) {
let events = Rc::clone(&self.host.event_loop);
let window_id = self.host.window.window.window_id;
self.host
.event_loop
.core
.spawn(futures::future::poll_fn(move || {
events
.with_window(window_id, |win| {
let scale = win.fonts.get_font_scale();
win.scaling_changed(Some(scale * 0.9))
})
.map(futures::Async::Ready)
.map_err(|_| ())
}));
}

fn reset_font_size(&mut self) {
let events = Rc::clone(&self.host.event_loop);
let window_id = self.host.window.window.window_id;
self.host
.event_loop
.core
.spawn(futures::future::poll_fn(move || {
events
.with_window(window_id, |win| win.scaling_changed(Some(1.0)))
.map(futures::Async::Ready)
.map_err(|_| ())
}));
}
}

impl TerminalWindow {
Expand Down Expand Up @@ -274,6 +323,7 @@ impl TerminalWindow {
host,
renderer,
conn: Rc::clone(&event_loop.conn),
fonts: Rc::clone(&fonts),
width,
height,
cell_height,
Expand All @@ -294,6 +344,26 @@ impl TerminalWindow {
.collect()
}

pub fn scaling_changed(&mut self, font_scale: Option<f64>) -> Result<(), Error> {
let font_scale = font_scale.unwrap_or_else(|| self.fonts.get_font_scale());
eprintln!("TerminalWindow::scaling_changed font_scale={}", font_scale);

self.fonts.change_scaling(font_scale, 1.0);

let metrics = self.fonts.default_font_metrics()?;
let (cell_height, cell_width) = (metrics.cell_height, metrics.cell_width);
self.cell_height = cell_height.ceil() as usize;
self.cell_width = cell_width.ceil() as usize;

self.renderer.scaling_changed(&self.host.window)?;

let (width, height) = (self.width, self.height);
self.width = 0;
self.height = 0;
self.resize_surfaces(width, height)?;
Ok(())
}

pub fn resize_surfaces(&mut self, width: u16, height: u16) -> Result<bool, Error> {
if width != self.width || height != self.height {
debug!("resize {},{}", width, height);
Expand Down

0 comments on commit 26d7ed9

Please sign in to comment.