Fix build errors on BSD

This updates winit and glutin to the latest git versions instead of
relying on releases to fix a build failure on BSD.

Unfortunately the upstream version bumps might still take a bit and
there hasn't been any feedback with regards to a planned release date.

This also fixes a slight issue on Windows where selections would start
when focusing a window and a build failure with some Linux systems

Fixes #2243.
Fixes #2170.
Fixes #2244.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee86955..bdede35 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -53,6 +53,7 @@
 - URLs stopping at double-width characters
 - Fix `start_maximized` option on X11
 - Error when parsing URLs ending with Unicode outside of the ascii range
+- On Windows, focusing a Window will no longer start a selection
 
 ## Version 0.2.9
 
diff --git a/Cargo.lock b/Cargo.lock
index 3b02f53..d58d7cb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -56,7 +56,7 @@
  "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "font 0.1.0",
  "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "glutin 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glutin 0.20.0 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)",
  "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -570,6 +570,15 @@
 ]
 
 [[package]]
+name = "debug_stub_derive"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
 name = "deflate"
 version = "0.7.19"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -936,65 +945,68 @@
 [[package]]
 name = "glutin"
 version = "0.20.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix#ea545cb4a353b7335d4a6efc34ae4fb3caddfe33"
 dependencies = [
  "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "glutin_egl_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "glutin_gles2_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "glutin_glx_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "glutin_wgl_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "debug_stub_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glutin_egl_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)",
+ "glutin_emscripten_sys 0.1.0 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)",
+ "glutin_gles2_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)",
+ "glutin_glx_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)",
+ "glutin_wgl_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)",
  "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
  "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "takeable-option 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "wayland-client 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "winit 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winit 0.19.0 (git+https://github.com/chrisduerr/winit?branch=bsd-build-fix)",
 ]
 
 [[package]]
 name = "glutin_egl_sys"
 version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix#ea545cb4a353b7335d4a6efc34ae4fb3caddfe33"
 dependencies = [
  "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
+name = "glutin_emscripten_sys"
+version = "0.1.0"
+source = "git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix#ea545cb4a353b7335d4a6efc34ae4fb3caddfe33"
+
+[[package]]
 name = "glutin_gles2_sys"
 version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix#ea545cb4a353b7335d4a6efc34ae4fb3caddfe33"
 dependencies = [
  "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
  "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "glutin_glx_sys"
 version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix#ea545cb4a353b7335d4a6efc34ae4fb3caddfe33"
 dependencies = [
  "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
  "x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "glutin_wgl_sys"
 version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix#ea545cb4a353b7335d4a6efc34ae4fb3caddfe33"
 dependencies = [
  "gl_generator 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -2231,6 +2243,16 @@
 
 [[package]]
 name = "syn"
+version = "0.11.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syn"
 version = "0.15.30"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
@@ -2240,6 +2262,14 @@
 ]
 
 [[package]]
+name = "synom"
+version = "0.11.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
 name = "synstructure"
 version = "0.10.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2251,6 +2281,11 @@
 ]
 
 [[package]]
+name = "takeable-option"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
 name = "tempfile"
 version = "3.0.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2499,6 +2534,11 @@
 
 [[package]]
 name = "unicode-xid"
+version = "0.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "unicode-xid"
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
@@ -2694,7 +2734,7 @@
 [[package]]
 name = "winit"
 version = "0.19.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/chrisduerr/winit?branch=bsd-build-fix#57680d2d17e797ebaa36191a1ef1c0ebdf44de34"
 dependencies = [
  "android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2871,6 +2911,7 @@
 "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
 "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
 "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c"
+"checksum debug_stub_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "496b7f8a2f853313c3ca370641d7ff3e42c32974fdccda8f0684599ed0a3ff6b"
 "checksum deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8a6abb26e16e8d419b5c78662aa9f82857c2386a073da266840e474d5055ec86"
 "checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
 "checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a"
@@ -2913,11 +2954,12 @@
 "checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd"
 "checksum gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5"
 "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
-"checksum glutin 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff663466cd51f6fda5976e8a6f02a9fd65b8dde0b9b11db8344585174d015b2c"
-"checksum glutin_egl_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55294554b495063a8dc641bffb657e3e6f21f3829a5dfcbdb1a80787dbb9f6ca"
-"checksum glutin_gles2_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b33e192f35b6f76ad3efb2ddf2184a1ff17106c42f11269f66151ba3036996a8"
-"checksum glutin_glx_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1ee3e318f8dc8eb5a6c3a6b98a22d574a54f4f8c136bdae38d7e0e42ca810ebc"
-"checksum glutin_wgl_sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2d0f023d00cfb4a100f6af038c9d03e182daa328796a915b56b0d69942066c8d"
+"checksum glutin 0.20.0 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)" = "<none>"
+"checksum glutin_egl_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)" = "<none>"
+"checksum glutin_emscripten_sys 0.1.0 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)" = "<none>"
+"checksum glutin_gles2_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)" = "<none>"
+"checksum glutin_glx_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)" = "<none>"
+"checksum glutin_wgl_sys 0.1.2 (git+https://github.com/chrisduerr/glutin?branch=bsd-build-fix)" = "<none>"
 "checksum h2 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "910a5e7be6283a9c91b3982fa5188368c8719cce2a3cf3b86048673bf9d9c36b"
 "checksum http 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fe67e3678f2827030e89cc4b9e7ecd16d52f132c0b940ab5005f88e821500f6a"
 "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83"
@@ -3056,8 +3098,11 @@
 "checksum stb_truetype 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "69b7df505db8e81d54ff8be4693421e5b543e08214bd8d99eb761fcb4d5668ba"
 "checksum string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b639411d0b9c738748b5397d5ceba08e648f4f1992231aa859af1a017f31f60b"
 "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
+"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
 "checksum syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)" = "66c8865bf5a7cbb662d8b011950060b3c8743dca141b054bf7195b20d314d8e2"
+"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
 "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
+"checksum takeable-option 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d77adff586b9bd922afef7791341ed94b09845e11225929217efe949e6366d43"
 "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a"
 "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
 "checksum terminfo 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8e51065bafd2abe106b6036483b69d1741f4a1ec56ce8a2378de341637de689e"
@@ -3083,6 +3128,7 @@
 "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
 "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426"
 "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
+"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
 "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
 "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
 "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
@@ -3109,7 +3155,7 @@
 "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
 "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
 "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba"
-"checksum winit 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6175dab24830b5b69adfa6e1c36b26784bd038a3ac883b29c3ef3df5f3f9daed"
+"checksum winit 0.19.0 (git+https://github.com/chrisduerr/winit?branch=bsd-build-fix)" = "<none>"
 "checksum winpty-sys 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dade7ecea144b3578a02925f93900f32370abfb8768630883971f4ef716b568"
 "checksum winreg 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf285379f20d7f26abd990d9a566be9d31ab7a9d335299baaa1f0604f5f96af"
 "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
diff --git a/Cargo.toml b/Cargo.toml
index 270d0d4..dd0b99b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -42,7 +42,7 @@
 fnv = "1"
 unicode-width = "0.1"
 arraydeque = "0.4"
-glutin = { version = "0.20", features = ["icon_loading"] }
+glutin = { git = "https://github.com/chrisduerr/glutin", branch = "bsd-build-fix", features = ["icon_loading"] }
 env_logger = "0.6.0"
 base64 = "0.10.0"
 static_assertions = "0.3.0"
diff --git a/src/window.rs b/src/window.rs
index 85dee27..6e3d7cd 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -21,7 +21,8 @@
 #[cfg(windows)]
 use glutin::Icon;
 use glutin::{
-    self, ContextBuilder, ContextTrait, ControlFlow, Event, EventsLoop, MouseCursor, WindowBuilder,
+    self, ContextBuilder, ContextTrait, ControlFlow, Event, EventsLoop, MouseCursor,
+    PossiblyCurrentContext, PossiblyCurrentContextTrait, WindowBuilder,
 };
 #[cfg(windows)]
 use image::ImageFormat;
@@ -53,7 +54,7 @@
 /// Wraps the underlying windowing library to provide a stable API in Alacritty
 pub struct Window {
     event_loop: EventsLoop,
-    window: glutin::WindowedContext,
+    windowed_context: glutin::WindowedContext<PossiblyCurrentContext>,
     mouse_visible: bool,
 
     /// Whether or not the window is the focused window.
@@ -118,12 +119,17 @@
     window: WindowBuilder,
     event_loop: &EventsLoop,
     srgb: bool,
-) -> ::std::result::Result<glutin::WindowedContext, glutin::CreationError> {
-    ContextBuilder::new()
+) -> Result<glutin::WindowedContext<PossiblyCurrentContext>> {
+    let windowed_context = ContextBuilder::new()
         .with_srgb(srgb)
         .with_vsync(true)
         .with_hardware_acceleration(None)
-        .build_windowed(window, event_loop)
+        .build_windowed(window, event_loop)?;
+
+    // Make the context current so OpenGL operations can run
+    let windowed_context = unsafe { windowed_context.make_current().map_err(|(_, e)| e)? };
+
+    Ok(windowed_context)
 }
 
 impl Window {
@@ -136,8 +142,9 @@
         let title = options.title.as_ref().map_or(DEFAULT_NAME, |t| t);
         let class = options.class.as_ref().map_or(DEFAULT_NAME, |c| c);
         let window_builder = Window::get_platform_window(title, class, window_config);
-        let window = create_gl_window(window_builder.clone(), &event_loop, false)
+        let windowed_context = create_gl_window(window_builder.clone(), &event_loop, false)
             .or_else(|_| create_gl_window(window_builder, &event_loop, true))?;
+        let window = windowed_context.window();
         window.show();
 
         // Maximize window after mapping in X11
@@ -151,15 +158,11 @@
         // Text cursor
         window.set_cursor(MouseCursor::Text);
 
-        // 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 _);
+        gl::load_with(|symbol| windowed_context.get_proc_address(symbol) as *const _);
 
-        let window = Window { event_loop, window, mouse_visible: true, is_focused: false };
+        let window =
+            Window { event_loop, windowed_context, mouse_visible: true, is_focused: false };
 
         window.run_os_extensions();
 
@@ -171,27 +174,27 @@
     /// Some window properties are provided since subsystems like font
     /// rasterization depend on DPI and scale factor.
     pub fn device_properties(&self) -> DeviceProperties {
-        DeviceProperties { scale_factor: self.window.get_hidpi_factor() }
+        DeviceProperties { scale_factor: self.window().get_hidpi_factor() }
     }
 
     pub fn inner_size_pixels(&self) -> Option<LogicalSize> {
-        self.window.get_inner_size()
+        self.window().get_inner_size()
     }
 
     pub fn set_inner_size(&mut self, size: LogicalSize) {
-        self.window.set_inner_size(size);
+        self.window().set_inner_size(size);
     }
 
     // TODO: use `with_position` once available
     // Upstream issue: https://github.com/tomaka/winit/issues/806
     pub fn set_position(&mut self, x: i32, y: i32) {
-        let logical = PhysicalPosition::from((x, y)).to_logical(self.window.get_hidpi_factor());
-        self.window.set_position(logical);
+        let logical = PhysicalPosition::from((x, y)).to_logical(self.window().get_hidpi_factor());
+        self.window().set_position(logical);
     }
 
     #[inline]
     pub fn hidpi_factor(&self) -> f64 {
-        self.window.get_hidpi_factor()
+        self.window().get_hidpi_factor()
     }
 
     #[inline]
@@ -201,7 +204,7 @@
 
     #[inline]
     pub fn swap_buffers(&self) -> Result<()> {
-        self.window.swap_buffers().map_err(From::from)
+        self.windowed_context.swap_buffers().map_err(From::from)
     }
 
     /// Poll for any available events
@@ -215,7 +218,7 @@
 
     #[inline]
     pub fn resize(&self, size: PhysicalSize) {
-        self.window.resize(size);
+        self.windowed_context.resize(size);
     }
 
     /// Block waiting for events
@@ -230,19 +233,19 @@
     /// Set the window title
     #[inline]
     pub fn set_title(&self, title: &str) {
-        self.window.set_title(title);
+        self.window().set_title(title);
     }
 
     #[inline]
     pub fn set_mouse_cursor(&self, cursor: MouseCursor) {
-        self.window.set_cursor(cursor);
+        self.window().set_cursor(cursor);
     }
 
     /// Set mouse cursor visible
     pub fn set_mouse_visible(&mut self, visible: bool) {
         if visible != self.mouse_visible {
             self.mouse_visible = visible;
-            self.window.hide_cursor(!visible);
+            self.window().hide_cursor(!visible);
         }
     }
 
@@ -330,27 +333,27 @@
     ))]
     pub fn set_urgent(&self, is_urgent: bool) {
         use glutin::os::unix::WindowExt;
-        self.window.set_urgent(is_urgent);
+        self.window().set_urgent(is_urgent);
     }
 
     #[cfg(target_os = "macos")]
     pub fn set_urgent(&self, is_urgent: bool) {
         use glutin::os::macos::WindowExt;
-        self.window.request_user_attention(is_urgent);
+        self.window().request_user_attention(is_urgent);
     }
 
     #[cfg(windows)]
     pub fn set_urgent(&self, _is_urgent: bool) {}
 
     pub fn set_ime_spot(&self, pos: LogicalPosition) {
-        self.window.set_ime_spot(pos);
+        self.window().set_ime_spot(pos);
     }
 
     #[cfg(not(any(target_os = "macos", target_os = "windows")))]
     pub fn get_window_id(&self) -> Option<usize> {
         use glutin::os::unix::WindowExt;
 
-        match self.window.get_xlib_window() {
+        match self.window().get_xlib_window() {
             Some(xlib_window) => Some(xlib_window as usize),
             None => None,
         }
@@ -363,7 +366,11 @@
 
     /// Hide the window
     pub fn hide(&self) {
-        self.window.hide();
+        self.window().hide();
+    }
+
+    fn window(&self) -> &glutin::Window {
+        self.windowed_context.window()
     }
 }
 
@@ -393,8 +400,8 @@
         use std::ptr;
         use x11_dl::xlib::{self, PropModeReplace, XA_CARDINAL};
 
-        let xlib_display = self.window.get_xlib_display();
-        let xlib_window = self.window.get_xlib_window();
+        let xlib_display = self.window().get_xlib_display();
+        let xlib_window = self.window().get_xlib_window();
 
         if let (Some(xlib_window), Some(xlib_display)) = (xlib_window, xlib_display) {
             let xlib = xlib::Xlib::open().expect("get xlib");