Fix resizing on macOS
The resize callback is the only way to perform live resizing on macOS. A callback is provided, and a static variable is used to provide a Sender to that function so that resize events may be processed in the usual way.
This commit is contained in:
parent
22789f35c7
commit
a445ae92a8
24
src/main.rs
24
src/main.rs
|
@ -3,6 +3,7 @@
|
||||||
#![feature(range_contains)]
|
#![feature(range_contains)]
|
||||||
#![feature(inclusive_range_syntax)]
|
#![feature(inclusive_range_syntax)]
|
||||||
#![feature(io)]
|
#![feature(io)]
|
||||||
|
#![feature(drop_types_in_const)]
|
||||||
#![feature(unicode)]
|
#![feature(unicode)]
|
||||||
|
|
||||||
extern crate font;
|
extern crate font;
|
||||||
|
@ -61,6 +62,18 @@ impl<'a, W: Write> input::Notify for WriteNotifier<'a, W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Channel used by resize handling on mac
|
||||||
|
static mut resize_sender: Option<mpsc::Sender<Event>> = None;
|
||||||
|
|
||||||
|
/// Resize handling for Mac
|
||||||
|
fn window_resize_handler(width: u32, height: u32) {
|
||||||
|
unsafe {
|
||||||
|
if let Some(ref tx) = resize_sender {
|
||||||
|
let _ = tx.send(Event::Glutin(glutin::Event::Resized(width, height)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_event<W>(event: Event,
|
fn handle_event<W>(event: Event,
|
||||||
writer: &mut W,
|
writer: &mut W,
|
||||||
terminal: &mut Term,
|
terminal: &mut Term,
|
||||||
|
@ -117,11 +130,11 @@ static FONT_STYLE: &'static str = "Regular";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let window = glutin::WindowBuilder::new()
|
let mut window = glutin::WindowBuilder::new()
|
||||||
.with_vsync()
|
.with_vsync()
|
||||||
.with_title("Alacritty")
|
.with_title("Alacritty")
|
||||||
.build().unwrap();
|
.build().unwrap();
|
||||||
// window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
|
window.set_window_resize_callback(Some(window_resize_handler as fn(u32, u32)));
|
||||||
|
|
||||||
gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
|
gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
|
||||||
let (width, height) = window.get_inner_size_pixels().unwrap();
|
let (width, height) = window.get_inner_size_pixels().unwrap();
|
||||||
|
@ -131,8 +144,8 @@ fn main() {
|
||||||
|
|
||||||
let font_size = 11.;
|
let font_size = 11.;
|
||||||
|
|
||||||
let sep_x = 2.0;
|
let sep_x = 0.0;
|
||||||
let sep_y = -7.0;
|
let sep_y = 0.0;
|
||||||
|
|
||||||
let desc = FontDesc::new(FONT, FONT_STYLE);
|
let desc = FontDesc::new(FONT, FONT_STYLE);
|
||||||
let mut rasterizer = font::Rasterizer::new(96., 96., dpr);
|
let mut rasterizer = font::Rasterizer::new(96., 96., dpr);
|
||||||
|
@ -154,6 +167,9 @@ fn main() {
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
let reader_tx = tx.clone();
|
let reader_tx = tx.clone();
|
||||||
|
unsafe {
|
||||||
|
resize_sender = Some(tx.clone());
|
||||||
|
}
|
||||||
let reader_thread = thread::spawn_named("TTY Reader", move || {
|
let reader_thread = thread::spawn_named("TTY Reader", move || {
|
||||||
for c in reader.chars() {
|
for c in reader.chars() {
|
||||||
let c = c.unwrap();
|
let c = c.unwrap();
|
||||||
|
|
Loading…
Reference in New Issue