summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-06-29 20:14:37 -0700
committerJoe Wilm <joe@jwilm.com>2016-06-29 20:14:37 -0700
commita445ae92a87fdf679747a2f308e69a734399f506 (patch)
treebb58b5f05658643c379bb9e74703603156ffbb47
parent22789f35c7ab90a5ada70fdca25ca1c626eb1ca5 (diff)
downloadalacritty-a445ae92a87fdf679747a2f308e69a734399f506.tar.gz
alacritty-a445ae92a87fdf679747a2f308e69a734399f506.zip
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.
-rw-r--r--src/main.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index de0ea05e..2dbbae1d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@
#![feature(range_contains)]
#![feature(inclusive_range_syntax)]
#![feature(io)]
+#![feature(drop_types_in_const)]
#![feature(unicode)]
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,
writer: &mut W,
terminal: &mut Term,
@@ -117,11 +130,11 @@ static FONT_STYLE: &'static str = "Regular";
fn main() {
- let window = glutin::WindowBuilder::new()
- .with_vsync()
- .with_title("Alacritty")
- .build().unwrap();
- // window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
+ let mut window = glutin::WindowBuilder::new()
+ .with_vsync()
+ .with_title("Alacritty")
+ .build().unwrap();
+ window.set_window_resize_callback(Some(window_resize_handler as fn(u32, u32)));
gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
let (width, height) = window.get_inner_size_pixels().unwrap();
@@ -131,8 +144,8 @@ fn main() {
let font_size = 11.;
- let sep_x = 2.0;
- let sep_y = -7.0;
+ let sep_x = 0.0;
+ let sep_y = 0.0;
let desc = FontDesc::new(FONT, FONT_STYLE);
let mut rasterizer = font::Rasterizer::new(96., 96., dpr);
@@ -154,6 +167,9 @@ fn main() {
let (tx, rx) = mpsc::channel();
let reader_tx = tx.clone();
+ unsafe {
+ resize_sender = Some(tx.clone());
+ }
let reader_thread = thread::spawn_named("TTY Reader", move || {
for c in reader.chars() {
let c = c.unwrap();