diff options
author | Zac Pullar-Strecker <zacps@users.noreply.github.com> | 2018-10-17 06:02:52 +1300 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2018-10-16 10:02:52 -0700 |
commit | 15e0deae2b49078b47a782679300cdf99d9ce687 (patch) | |
tree | 8175fbed0def1af08cd2db41583975adbb27dff1 /src/window.rs | |
parent | b41c6b736d67d61e92b174dfea58ae46813934cd (diff) | |
download | alacritty-15e0deae2b49078b47a782679300cdf99d9ce687.tar.gz alacritty-15e0deae2b49078b47a782679300cdf99d9ce687.zip |
Add support for Windows (#1374)
Initial support for Windows is implemented using the winpty translation
layer. Clipboard support for Windows is provided through the `clipboard`
crate, and font rasterization is provided by RustType.
The tty.rs file has been split into OS-specific files to separate
standard pty handling from the winpty implementation.
Several binary components are fetched via build script on windows
including libclang and winpty. These could be integrated more directly
in the future either by building those dependencies as part of the
Alacritty build process or by leveraging git lfs to store the artifacts.
Fixes #28.
Diffstat (limited to 'src/window.rs')
-rw-r--r-- | src/window.rs | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/src/window.rs b/src/window.rs index eac4c014..2c1bf7b2 100644 --- a/src/window.rs +++ b/src/window.rs @@ -17,6 +17,10 @@ use std::ops::Deref; use gl; use glutin::GlContext; +#[cfg(windows)] +use winit::Icon; +#[cfg(windows)] +use image::ImageFormat; use glutin::{ self, ContextBuilder, ControlFlow, CursorState, Event, EventsLoop, MouseCursor as GlutinMouseCursor, WindowBuilder, @@ -27,6 +31,9 @@ use MouseCursor; use cli::Options; use config::{Decorations, WindowConfig}; +#[cfg(windows)] +static WINDOW_ICON: &'static [u8] = include_bytes!("../assets/windows/alacritty.ico"); + /// Default text for the window's title bar, if not overriden. /// /// In X11, this the default value for the `WM_NAME` property. @@ -215,7 +222,7 @@ impl Window { let event_loop = EventsLoop::new(); let title = options.title.as_ref().map_or(DEFAULT_TITLE, |t| t); - let class = options.class.as_ref().map_or(DEFAULT_CLASS, |c| c); + let class = options.class.as_ref().map_or(DEFAULT_TITLE, |c| c); let window_builder = Window::get_platform_window(title, window_config); let window_builder = Window::platform_builder_ext(window_builder, &class); let window = create_gl_window(window_builder.clone(), &event_loop, false) @@ -225,14 +232,14 @@ impl Window { // Text cursor window.set_cursor(GlutinMouseCursor::Text); - // Set OpenGL symbol loader - gl::load_with(|symbol| window.get_proc_address(symbol) as *const _); - // Make the context current so OpenGL operations can run unsafe { window.make_current()?; } + // Set OpenGL symbol loader. This call MUST be after window.make_current on windows. + gl::load_with(|symbol| window.get_proc_address(symbol) as *const _); + let window = Window { event_loop, window, @@ -304,8 +311,11 @@ impl Window { /// Set the window title #[inline] - pub fn set_title(&self, title: &str) { - self.window.set_title(title); + pub fn set_title(&self, _title: &str) { + // Because winpty doesn't know anything about OSC escapes this gets set to an empty + // string on windows + #[cfg(not(windows))] + self.window.set_title(_title); } #[inline] @@ -357,7 +367,7 @@ impl Window { window_builder } - #[cfg(not(target_os = "macos"))] + #[cfg(not(any(target_os = "macos", windows)))] pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder { let decorations = match window_config.decorations() { Decorations::None => false, @@ -371,6 +381,23 @@ impl Window { .with_decorations(decorations) } + #[cfg(windows)] + pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder { + let icon = Icon::from_bytes_with_format(WINDOW_ICON, ImageFormat::ICO).unwrap(); + + let decorations = match window_config.decorations() { + Decorations::None => false, + _ => true, + }; + + WindowBuilder::new() + .with_title(title) + .with_visibility(cfg!(windows)) + .with_decorations(decorations) + .with_transparency(true) + .with_window_icon(Some(icon)) + } + #[cfg(target_os = "macos")] pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder { use glutin::os::macos::WindowBuilderExt; @@ -421,11 +448,13 @@ impl Window { )] pub fn set_urgent(&self, _is_urgent: bool) {} - pub fn set_ime_spot(&self, x: i32, y: i32) { - self.window.set_ime_spot(x, y); + pub fn set_ime_spot(&self, _x: i32, _y: i32) { + // This is not implemented on windows as of winit 0.15.1 + #[cfg(not(windows))] + self.window.set_ime_spot(_x, _y); } - #[cfg(not(target_os = "macos"))] + #[cfg(not(any(target_os = "macos", target_os = "windows")))] pub fn get_window_id(&self) -> Option<usize> { use glutin::os::unix::WindowExt; @@ -435,7 +464,7 @@ impl Window { } } - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "windows"))] pub fn get_window_id(&self) -> Option<usize> { None } |