aboutsummaryrefslogtreecommitdiff
path: root/src/tty.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-12-10 22:44:13 -0800
committerJoe Wilm <joe@jwilm.com>2016-12-11 20:23:41 -0800
commited0b1cfff04903fe26f586340e036c38bbf30b33 (patch)
treeeb4eb3545bee57ed401cb7727c9dc3f106fabe3b /src/tty.rs
parentbbd8ddbfc055e85f8810285e71fd227cdd418221 (diff)
downloadalacritty-ed0b1cfff04903fe26f586340e036c38bbf30b33.tar.gz
alacritty-ed0b1cfff04903fe26f586340e036c38bbf30b33.zip
Display manages window, renderer, rasterizer
This is part of an ongoing decoupling effort across the codebase and tidying effort in main.rs. Everything to do with showing the window with a grid of characters is now managed by the `Display` type. It owns the window, the font rasterizer, and the renderer. The only info needed from it are dimensions of characters and the window itself for sizing the terminal properly. Additionally, the I/O loop has access to wake it up when new data arrives.
Diffstat (limited to 'src/tty.rs')
-rw-r--r--src/tty.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/tty.rs b/src/tty.rs
index fddb4d99..7071bad3 100644
--- a/src/tty.rs
+++ b/src/tty.rs
@@ -23,8 +23,6 @@ use std::ptr;
use libc::{self, winsize, c_int, pid_t, WNOHANG, WIFEXITED, WEXITSTATUS, SIGCHLD};
-use index::{Line, Column};
-
/// Process ID of child process
///
/// Necessary to put this in static storage for `sigchld` to have access
@@ -238,8 +236,10 @@ fn execsh() -> ! {
}
/// Create a new tty and return a handle to interact with it.
-pub fn new(lines: Line, cols: Column) -> Pty {
- let (master, slave) = openpty(lines.0 as _, cols.0 as _);
+pub fn new<T: ToWinsize>(size: T) -> Pty {
+ let win = size.to_winsize();
+
+ let (master, slave) = openpty(win.ws_row as _, win.ws_col as _);
match fork() {
Relation::Child => {
@@ -282,7 +282,9 @@ pub fn new(lines: Line, cols: Column) -> Pty {
set_nonblocking(master);
}
- Pty { fd: master }
+ let pty = Pty { fd: master };
+ pty.resize(size);
+ pty
}
}
}
@@ -301,15 +303,12 @@ impl Pty {
}
}
- pub fn resize(&self, lines: Line, cols: Column, px_x: usize, px_y: usize) {
- let lines = lines.0;
- let cols = cols.0;
- let win = winsize {
- ws_row: lines as libc::c_ushort,
- ws_col: cols as libc::c_ushort,
- ws_xpixel: px_x as libc::c_ushort,
- ws_ypixel: px_y as libc::c_ushort,
- };
+ /// Resize the pty
+ ///
+ /// Tells the kernel that the window size changed with the new pixel
+ /// dimensions and line/column counts.
+ pub fn resize<T: ToWinsize>(&self, size: T) {
+ let win = size.to_winsize();
let res = unsafe {
libc::ioctl(self.fd, libc::TIOCSWINSZ, &win as *const _)
@@ -321,6 +320,12 @@ impl Pty {
}
}
+/// Types that can produce a `libc::winsize`
+pub trait ToWinsize {
+ /// Get a `libc::winsize`
+ fn to_winsize(&self) -> winsize;
+}
+
unsafe fn set_nonblocking(fd: c_int) {
use libc::{fcntl, F_SETFL, F_GETFL, O_NONBLOCK};