diff options
author | Joe Wilm <joe@jwilm.com> | 2016-06-09 20:39:40 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-06-14 07:39:06 -0700 |
commit | bd8bd26c8bd6f9dfc988e222b57a71cf94902c4d (patch) | |
tree | 5e7211ac03e5481b8fb8b89f3b6c6a4246247f29 /src/tty.rs | |
parent | 2395066318fea516bc0efbc7aecfb90a0d2548da (diff) | |
download | alacritty-bd8bd26c8bd6f9dfc988e222b57a71cf94902c4d.tar.gz alacritty-bd8bd26c8bd6f9dfc988e222b57a71cf94902c4d.zip |
Add support for macOS
Alacritty now runs on macOS using CoreText for font rendering.
The font rendering subsystems were moved into a separate crate called
`font`. The font crate provides a unified (albeit limited) API which
wraps CoreText on macOS and FreeType/FontConfig on other platforms. The
unified API differed slightly from what the original Rasterizer for
freetype implemented, and it was updated accordingly.
The cell separation properties (sep_x and sep_y) are now premultiplied
into the cell width and height. They were previously passed through as
uniforms to the shaders; removing them prevents a lot of redundant work.
`libc` has some differences between Linux and macOS. `__errno_location`
is not available on macOS, and the `errno` crate was brought in to
provide a cross-platform API for dealing with errno.
Differences in `openpty` were handled by implementing a macOS specific
version. It would be worth investigating a way to unify the
implementations at some point.
A type mismatch with TIOCSCTTY was resolved with a cast.
Differences in libc::passwd struct fields were resolved by using
std::mem::uninitialized instead of zeroing the struct ourselves. This
has the benefit of being much cleaner.
The thread setup had to be changed to support both macOS and Linux.
macOS requires that events from the window be handled on the main
thread. Failure to do so will prevent the glutin window from even
showing up! For this reason, the renderer and parser were moved to their
own thread, and the input is received on the main thread. This is
essentially reverse the setup prior to this commit. Renderer
initialization (and thus font cache initialization) had to be moved to
the rendering thread as well since there's no way to make_context(null)
with glx on Linux. Trying to just call make_context a second time on the
rendering thread had resulted in a panic!.
Diffstat (limited to 'src/tty.rs')
-rw-r--r-- | src/tty.rs | 40 |
1 files changed, 27 insertions, 13 deletions
@@ -47,9 +47,7 @@ pub fn process_should_exit() -> bool { /// Get the current value of errno fn errno() -> c_int { - unsafe { - ptr::read(libc::__errno_location() as *const _) - } + ::errno::errno().0 } enum Relation { @@ -74,6 +72,7 @@ fn fork() -> Relation { } /// Get raw fds for master/slave ends of a new pty +#[cfg(target_os = "linux")] fn openpty(rows: u8, cols: u8) -> (c_int, c_int) { let mut master: c_int = 0; let mut slave: c_int = 0; @@ -96,10 +95,33 @@ fn openpty(rows: u8, cols: u8) -> (c_int, c_int) { (master, slave) } +#[cfg(target_os = "macos")] +fn openpty(rows: u8, cols: u8) -> (c_int, c_int) { + let mut master: c_int = 0; + let mut slave: c_int = 0; + + let mut win = winsize { + ws_row: rows as libc::c_ushort, + ws_col: cols as libc::c_ushort, + ws_xpixel: 0, + ws_ypixel: 0, + }; + + let res = unsafe { + libc::openpty(&mut master, &mut slave, ptr::null_mut(), ptr::null_mut(), &mut win) + }; + + if res < 0 { + die!("openpty failed"); + } + + (master, slave) +} + /// Really only needed on BSD, but should be fine elsewhere fn set_controlling_terminal(fd: c_int) { let res = unsafe { - libc::ioctl(fd, libc::TIOCSCTTY, 0) + libc::ioctl(fd, libc::TIOCSCTTY as _, 0) }; if res < 0 { @@ -125,15 +147,7 @@ struct Passwd<'a> { /// If `buf` is changed while `Passwd` is alive, bad thing will almost certainly happen. fn get_pw_entry<'a>(buf: &'a mut [i8; 1024]) -> Passwd<'a> { // Create zeroed passwd struct - let mut entry = libc::passwd { - pw_name: ptr::null_mut(), - pw_passwd: ptr::null_mut(), - pw_uid: 0, - pw_gid: 0, - pw_gecos: ptr::null_mut(), - pw_dir: ptr::null_mut(), - pw_shell: ptr::null_mut(), - }; + let mut entry: libc::passwd = unsafe { ::std::mem::uninitialized() }; let mut res: *mut libc::passwd = ptr::null_mut(); |