aboutsummaryrefslogtreecommitdiff
path: root/src/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.rs')
-rw-r--r--src/window.rs51
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
}