Repository: PistonDevelopers/glfw-rs (language: rust)

Issue:
Mutable self ref
Why don`t set_\* methods require '&self' parameter to be mutable ('&mut self')?



Discussion / hints:
I have thought about this for a while. The inner pointer is just a handle so it doesn't require it, but maybe it would be better to show that things a changing on a semantic level? I dunno. What do you think @larsbergstrom?

It is not ready for PR right now but what do you think about https://github.com/ozkriff/glfw-rs/commit/8e4010 ?

I'm not sure this wins anything and might introduce RefCells where there previously were none. But I think it makes it a more logical interface.

I think it is a good idea. It allows frameworks to give lend the glfw objects without fear of them being modified accidentally.

Can you do anything with it at all without it being mutable?

On Wed, Mar 26, 2014 at 2:12 PM, Colin Sherratt notifications@github.comwrote:

> I think it is a good idea. It allows frameworks to give lend the glfw
> objects without fear of them being modified accidentally.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/bjz/glfw-rs/issues/104#issuecomment-38719537
> .

## 

http://octayn.net/

Getting cursor position, what keys are down, size of the screen. That kind of information should not require a mutable reference.

@ozkriff That looks good.


Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 6207bd7d..3c4b1e80 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,6 +27,8 @@ default = ["glfw-sys"]
 [dependencies]
 semver = "*"
 log = "*"
+bitflags = "*"
+libc = "*"
 
 [dependencies.glfw-sys]
 git = "https://github.com/servo/glfw"
diff --git a/examples/clipboard.rs b/examples/clipboard.rs
index 05549928..0f48f6bf 100644
--- a/examples/clipboard.rs
+++ b/examples/clipboard.rs
@@ -18,9 +18,9 @@ extern crate glfw;
 use glfw::{Action, Context, Key};
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
-    let (window, events) = glfw.create_window(300, 300, "Clipboard Test", glfw::WindowMode::Windowed)
+    let (mut window, events) = glfw.create_window(300, 300, "Clipboard Test", glfw::WindowMode::Windowed)
         .expect("Failed to create GLFW window.");
 
     window.set_key_polling(true);
@@ -30,7 +30,7 @@ fn main() {
     while !window.should_close() {
         glfw.poll_events();
         for (_, event) in glfw::flush_messages(&events) {
-            handle_window_event(&window, event);
+            handle_window_event(&mut window, event);
         }
     }
 }
@@ -41,7 +41,7 @@ static NATIVE_MOD: glfw::Modifiers = glfw::Super;
 #[cfg(not(target_os = "macos"))]
 static NATIVE_MOD: glfw::Modifiers = glfw::Control;
 
-fn handle_window_event(window: &glfw::Window, event: glfw::WindowEvent) {
+fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
     match event {
         glfw::WindowEvent::Key(key, _, action, mods) => {
             if action == Action::Press {
diff --git a/examples/cursor.rs b/examples/cursor.rs
index 2ef80f54..a7f448dc 100644
--- a/examples/cursor.rs
+++ b/examples/cursor.rs
@@ -18,9 +18,9 @@ extern crate glfw;
 use glfw::{Action, Context, CursorMode, Key};
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
-    let (window, events) = glfw.create_window(800, 600, "Hello, I am a window.", glfw::WindowMode::Windowed)
+    let (mut window, events) = glfw.create_window(800, 600, "Hello, I am a window.", glfw::WindowMode::Windowed)
         .expect("Failed to create GLFW window.");
 
     window.set_cursor_mode(CursorMode::Disabled);
@@ -32,12 +32,12 @@ fn main() {
     while !window.should_close() {
         glfw.poll_events();
         for (_, event) in glfw::flush_messages(&events) {
-            handle_window_event(&window, event);
+            handle_window_event(&mut window, event);
         }
     }
 }
 
-fn handle_window_event(window: &glfw::Window, event: glfw::WindowEvent) {
+fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
     match event {
         glfw::WindowEvent::CursorPos(xpos, ypos) => println!("Cursor position: ({:?}, {:?})", xpos, ypos),
         glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => window.set_should_close(true),
diff --git a/examples/defaults.rs b/examples/defaults.rs
index da8f3c7d..c0866d08 100644
--- a/examples/defaults.rs
+++ b/examples/defaults.rs
@@ -18,11 +18,11 @@ extern crate glfw;
 use glfw::Context;
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
     glfw.window_hint(glfw::WindowHint::Visible(true));
 
-    let (window, _) = glfw.create_window(640, 480, "Defaults", glfw::WindowMode::Windowed)
+    let (mut window, _) = glfw.create_window(640, 480, "Defaults", glfw::WindowMode::Windowed)
         .expect("Failed to create GLFW window.");
 
     window.make_current();
diff --git a/examples/error.rs b/examples/error.rs
index 0028e588..d7295124 100644
--- a/examples/error.rs
+++ b/examples/error.rs
@@ -21,7 +21,7 @@ extern crate glfw;
 use std::cell::Cell;
 
 fn main() {
-    let glfw = glfw::init(Some(
+    let mut glfw = glfw::init(Some(
         glfw::Callback {
             f: error_callback as fn(glfw::Error, String, &Cell<usize>),
             data: Cell::new(0),
diff --git a/examples/events.rs b/examples/events.rs
index 34f3de46..59c76fea 100644
--- a/examples/events.rs
+++ b/examples/events.rs
@@ -18,11 +18,11 @@ extern crate glfw;
 use glfw::{Action, Context, Key};
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
     glfw.window_hint(glfw::WindowHint::Resizable(true));
 
-    let (window, events) = glfw.create_window(800, 600, "Hello, I am a window.", glfw::WindowMode::Windowed)
+    let (mut window, events) = glfw.create_window(800, 600, "Hello, I am a window.", glfw::WindowMode::Windowed)
         .expect("Failed to create GLFW window.");
 
     window.set_sticky_keys(true);
@@ -53,12 +53,12 @@ fn main() {
     while !window.should_close() {
         glfw.poll_events();
         for event in glfw::flush_messages(&events) {
-            handle_window_event(&window, event);
+            handle_window_event(&mut window, event);
         }
     }
 }
 
-fn handle_window_event(window: &glfw::Window, (time, event): (f64, glfw::WindowEvent)) {
+fn handle_window_event(window: &mut glfw::Window, (time, event): (f64, glfw::WindowEvent)) {
     match event {
         glfw::WindowEvent::Pos(x, y)                      => window.set_title(format!("Time: {:?}, Window pos: ({:?}, {:?})", time, x, y).as_slice()),
         glfw::WindowEvent::Size(w, h)                     => window.set_title(format!("Time: {:?}, Window size: ({:?}, {:?})", time, w, h).as_slice()),
diff --git a/examples/monitors.rs b/examples/monitors.rs
index 276ad4e0..aa84d347 100644
--- a/examples/monitors.rs
+++ b/examples/monitors.rs
@@ -18,7 +18,7 @@ extern crate glfw;
 use glfw::{Action, Context, Key};
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
     glfw.with_connected_monitors(|monitors| {
         for monitor in monitors.iter() {
@@ -26,7 +26,7 @@ fn main() {
         }
     });
 
-    let (window, events) = glfw.with_primary_monitor(|m| {
+    let (mut window, events) = glfw.with_primary_monitor(|m| {
         glfw.create_window(300, 300, "Hello this is window",
             m.map_or(glfw::WindowMode::Windowed, |m| glfw::WindowMode::FullScreen(m)))
     }).expect("Failed to create GLFW window.");
@@ -37,12 +37,12 @@ fn main() {
     while !window.should_close() {
         glfw.poll_events();
         for (_, event) in glfw::flush_messages(&events) {
-            handle_window_event(&window, event);
+            handle_window_event(&mut window, event);
         }
     }
 }
 
-fn handle_window_event(window: &glfw::Window, event: glfw::WindowEvent) {
+fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
     match event {
         glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
             window.set_should_close(true)
diff --git a/examples/render_task.rs b/examples/render_task.rs
index dc212c7a..03d2c101 100644
--- a/examples/render_task.rs
+++ b/examples/render_task.rs
@@ -23,7 +23,7 @@ use glfw::{Action, Context, Key};
 use std::thread::Builder;
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
     let (mut window, events) = glfw.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
         .expect("Failed to create GLFW window.");
@@ -41,7 +41,7 @@ fn main() {
     while !window.should_close() {
         glfw.poll_events();
         for (_, event) in glfw::flush_messages(&events) {
-            handle_window_event(&window, event);
+            handle_window_event(&mut window, event);
         }
     }
 
@@ -52,7 +52,7 @@ fn main() {
     let _ = render_task_done;
 }
 
-fn render(context: glfw::RenderContext, finish: Receiver<()>) {
+fn render(mut context: glfw::RenderContext, finish: Receiver<()>) {
     context.make_current();
     loop {
         // Check if the rendering should stop.
@@ -67,7 +67,7 @@ fn render(context: glfw::RenderContext, finish: Receiver<()>) {
     glfw::make_context_current(None);
 }
 
-fn handle_window_event(window: &glfw::Window, event: glfw::WindowEvent) {
+fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
     match event {
         glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
             window.set_should_close(true)
diff --git a/examples/title.rs b/examples/title.rs
index 0d6f763c..0b32b9b8 100644
--- a/examples/title.rs
+++ b/examples/title.rs
@@ -18,9 +18,9 @@ extern crate glfw;
 use glfw::{Action, Context, Key};
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
-    let (window, events) = glfw.create_window(400, 400, "English 日本語 русский язык 官話", glfw::WindowMode::Windowed)
+    let (mut window, events) = glfw.create_window(400, 400, "English 日本語 русский язык 官話", glfw::WindowMode::Windowed)
         .expect("Failed to create GLFW window.");
 
     window.set_key_polling(true);
@@ -30,12 +30,12 @@ fn main() {
     while !window.should_close() {
         glfw.poll_events();
         for (_, event) in glfw::flush_messages(&events) {
-            handle_window_event(&window, event);
+            handle_window_event(&mut window, event);
         }
     }
 }
 
-fn handle_window_event(window: &glfw::Window, event: glfw::WindowEvent) {
+fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
     match event {
         glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
             window.set_should_close(true)
diff --git a/examples/window.rs b/examples/window.rs
index 78a990c8..856f5edf 100644
--- a/examples/window.rs
+++ b/examples/window.rs
@@ -18,9 +18,9 @@ extern crate glfw;
 use glfw::{Action, Context, Key};
 
 fn main() {
-    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 
-    let (window, events) = glfw.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
+    let (mut window, events) = glfw.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
         .expect("Failed to create GLFW window.");
 
     window.set_key_polling(true);
@@ -29,12 +29,12 @@ fn main() {
     while !window.should_close() {
         glfw.poll_events();
         for (_, event) in glfw::flush_messages(&events) {
-            handle_window_event(&window, event);
+            handle_window_event(&mut window, event);
         }
     }
 }
 
-fn handle_window_event(window: &glfw::Window, event: glfw::WindowEvent) {
+fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
     match event {
         glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
             window.set_should_close(true)
diff --git a/src/lib.rs b/src/lib.rs
index d9a5bdd4..5d912d4b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,10 +32,10 @@
 //! use glfw::{Action, Context, Key};
 //!
 //! fn main() {
-//!    let glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
+//!    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
 //!
 //!     // Create a windowed mode window and its OpenGL context
-//!     let (window, events) = glfw.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
+//!     let (mut window, events) = glfw.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
 //!         .expect("Failed to create GLFW window.");
 //!
 //!     // Make the window's context current
@@ -67,6 +67,8 @@ extern crate semver;
 extern crate libc;
 #[macro_use]
 extern crate log;
+#[macro_use]
+extern crate bitflags;
 
 use libc::{c_double, c_float, c_int};
 use libc::{c_ushort, c_void};
@@ -76,7 +78,6 @@ use std::sync::mpsc::{channel, Receiver, Sender};
 use std::fmt;
 use std::marker::Send;
 use std::ptr;
-use std::vec;
 use std::slice;
 use semver::Version;
 
@@ -445,7 +446,7 @@ impl Glfw {
     /// // triggers a task failure when a GLFW error is encountered.
     /// glfw.set_error_callback(glfw::FAIL_ON_ERRORS);
     /// ~~~
-    pub fn set_error_callback<UserData: 'static>(&self, callback: Option<ErrorCallback<UserData>>) {
+    pub fn set_error_callback<UserData: 'static>(&mut self, callback: Option<ErrorCallback<UserData>>) {
         match callback {
             Some(f) => callbacks::error::set(f),
             None    => callbacks::error::unset(),
@@ -453,7 +454,7 @@ impl Glfw {
     }
 
     /// Sets the monitor callback, overwriting the previous one stored.
-    pub fn set_monitor_callback<UserData: 'static>(&self, callback: Option<MonitorCallback<UserData>>) {
+    pub fn set_monitor_callback<UserData: 'static>(&mut self, callback: Option<MonitorCallback<UserData>>) {
         match callback {
             Some(f) => callbacks::monitor::set(f),
             None    => callbacks::monitor::unset(),
@@ -534,7 +535,7 @@ impl Glfw {
     /// glfw.window_hint(glfw::WindowHint::OpenglForwardCompat(true));
     /// glfw.window_hint(glfw::WindowHint::OpenglProfile(glfw::OpenGlProfileHint::Core));
     /// ~~~
-    pub fn window_hint(&self, hint: WindowHint) {
+    pub fn window_hint(&mut self, hint: WindowHint) {
         match hint {
             WindowHint::RedBits(bits)                   => unsafe { ffi::glfwWindowHint(ffi::RED_BITS,              bits as c_int) },
             WindowHint::GreenBits(bits)                 => unsafe { ffi::glfwWindowHint(ffi::GREEN_BITS,            bits as c_int) },
@@ -570,7 +571,7 @@ impl Glfw {
     /// their default values.
     ///
     /// Wrapper for `glfwDefaultWindowHints`.
-    pub fn default_window_hints(&self) {
+    pub fn default_window_hints(&mut self) {
         unsafe { ffi::glfwDefaultWindowHints(); }
     }
 
@@ -617,7 +618,7 @@ impl Glfw {
     /// then the current context is detached.
     ///
     /// Wrapper for `glfwMakeContextCurrent`.
-    pub fn make_context_current(&self, context: Option<&Window>) {
+    pub fn make_context_current(&mut self, context: Option<&Window>) {
         match context {
             Some(window) => unsafe { ffi::glfwMakeContextCurrent(window.ptr) },
             None         => unsafe { ffi::glfwMakeContextCurrent(ptr::null_mut()) },
@@ -633,7 +634,7 @@ impl Glfw {
     /// Immediately process the received events.
     ///
     /// Wrapper for `glfwPollEvents`.
-    pub fn poll_events(&self) {
+    pub fn poll_events(&mut self) {
         unsafe { ffi::glfwPollEvents(); }
     }
 
@@ -641,7 +642,7 @@ impl Glfw {
     /// equivalent of `Glfw::poll_events`.
     ///
     /// Wrapper for `glfwWaitEvents`.
-    pub fn wait_events(&self) {
+    pub fn wait_events(&mut self) {
         unsafe { ffi::glfwWaitEvents(); }
     }
 
@@ -657,7 +658,7 @@ impl Glfw {
     /// Sets the value of the GLFW timer.
     ///
     /// Wrapper for `glfwSetTime`.
-    pub fn set_time(&self, time: f64) {
+    pub fn set_time(&mut self, time: f64) {
         unsafe { ffi::glfwSetTime(time as c_double); }
     }
 
@@ -665,7 +666,7 @@ impl Glfw {
     /// the current context and returning from `Window::swap_buffers`.
     ///
     /// Wrapper for `glfwSwapInterval`.
-    pub fn set_swap_interval(&self, interval: u32) {
+    pub fn set_swap_interval(&mut self, interval: u32) {
         unsafe { ffi::glfwSwapInterval(interval as c_int); }
     }
 
@@ -723,7 +724,7 @@ pub fn get_version() -> Version {
 /// Replacement for `String::from_raw_buf`
 pub unsafe fn string_from_c_str(c_str: *const i8) -> String {
     use std::ffi::c_str_to_bytes;
-    String::from_utf8_lossy(c_str_to_bytes(&c_str)).into_owned()  
+    String::from_utf8_lossy(c_str_to_bytes(&c_str)).into_owned()
 }
 
 /// Replacement for `ToCStr::with_c_str`
@@ -796,7 +797,7 @@ impl Monitor {
     }
 
     /// Wrapper for `glfwSetGamma`.
-    pub fn set_gamma(&self, gamma: f32) {
+    pub fn set_gamma(&mut self, gamma: f32) {
         unsafe { ffi::glfwSetGamma(self.ptr, gamma as c_float); }
     }
 
@@ -816,7 +817,7 @@ impl Monitor {
     }
 
     /// Wrapper for `glfwSetGammaRamp`.
-    pub fn set_gamma_ramp(&self, ramp: &mut GammaRamp) {
+    pub fn set_gamma_ramp(&mut self, ramp: &mut GammaRamp) {
         unsafe {
             ffi::glfwSetGammaRamp(
                 self.ptr,
@@ -1120,7 +1121,7 @@ impl Window {
     /// current context, it will make it the current context.
     ///
     /// Wrapper for `glfwGetProcAddress`.
-    pub fn get_proc_address(&self, procname: &str) -> GLProc {
+    pub fn get_proc_address(&mut self, procname: &str) -> GLProc {
         if self.ptr != unsafe { ffi::glfwGetCurrentContext() } {
             self.make_current();
         }
@@ -1153,14 +1154,14 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetWindowShouldClose`.
-    pub fn set_should_close(&self, value: bool) {
+    pub fn set_should_close(&mut self, value: bool) {
         unsafe { ffi::glfwSetWindowShouldClose(self.ptr, value as c_int) }
     }
 
     /// Sets the title of the window.
     ///
     /// Wrapper for `glfwSetWindowTitle`.
-    pub fn set_title(&self, title: &str) {
+    pub fn set_title(&mut self, title: &str) {
         unsafe {
             with_c_str(title, |title| {
                 ffi::glfwSetWindowTitle(self.ptr, title);
@@ -1179,7 +1180,7 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetWindowPos`.
-    pub fn set_pos(&self, xpos: i32, ypos: i32) {
+    pub fn set_pos(&mut self, xpos: i32, ypos: i32) {
         unsafe { ffi::glfwSetWindowPos(self.ptr, xpos as c_int, ypos as c_int); }
     }
 
@@ -1194,7 +1195,7 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetWindowSize`.
-    pub fn set_size(&self, width: i32, height: i32) {
+    pub fn set_size(&mut self, width: i32, height: i32) {
         unsafe { ffi::glfwSetWindowSize(self.ptr, width as c_int, height as c_int); }
     }
 
@@ -1209,22 +1210,22 @@ impl Window {
     }
 
     /// Wrapper for `glfwIconifyWindow`.
-    pub fn iconify(&self) {
+    pub fn iconify(&mut self) {
         unsafe { ffi::glfwIconifyWindow(self.ptr); }
     }
 
     /// Wrapper for `glfwRestoreWindow`.
-    pub fn restore(&self) {
+    pub fn restore(&mut self) {
         unsafe { ffi::glfwRestoreWindow(self.ptr); }
     }
 
     /// Wrapper for `glfwShowWindow`.
-    pub fn show(&self) {
+    pub fn show(&mut self) {
         unsafe { ffi::glfwShowWindow(self.ptr); }
     }
 
     /// Wrapper for `glfwHideWindow`.
-    pub fn hide(&self) {
+    pub fn hide(&mut self) {
         unsafe { ffi::glfwHideWindow(self.ptr); }
     }
 
@@ -1320,11 +1321,11 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetWindowPosCallback`.
-    pub fn set_pos_polling(&self, should_poll: bool) {
+    pub fn set_pos_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetWindowPosCallback, window_pos_callback);
     }
 
-    pub fn set_all_polling(&self, should_poll: bool) {
+    pub fn set_all_polling(&mut self, should_poll: bool) {
         self.set_pos_polling(should_poll);
         self.set_size_polling(should_poll);
         self.set_close_polling(should_poll);
@@ -1341,32 +1342,32 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetWindowSizeCallback`.
-    pub fn set_size_polling(&self, should_poll: bool) {
+    pub fn set_size_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetWindowSizeCallback, window_size_callback);
     }
 
     /// Wrapper for `glfwSetWindowCloseCallback`.
-    pub fn set_close_polling(&self, should_poll: bool) {
+    pub fn set_close_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetWindowCloseCallback, window_close_callback);
     }
 
     /// Wrapper for `glfwSetWindowRefreshCallback`.
-    pub fn set_refresh_polling(&self, should_poll: bool) {
+    pub fn set_refresh_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetWindowRefreshCallback, window_refresh_callback);
     }
 
     /// Wrapper for `glfwSetWindowFocusCallback`.
-    pub fn set_focus_polling(&self, should_poll: bool) {
+    pub fn set_focus_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetWindowFocusCallback, window_focus_callback);
     }
 
     /// Wrapper for `glfwSetWindowIconifyCallback`.
-    pub fn set_iconify_polling(&self, should_poll: bool) {
+    pub fn set_iconify_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetWindowIconifyCallback, window_iconify_callback);
     }
 
     /// Wrapper for `glfwSetFramebufferSizeCallback`.
-    pub fn set_framebuffer_size_polling(&self, should_poll: bool) {
+    pub fn set_framebuffer_size_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetFramebufferSizeCallback, framebuffer_size_callback);
     }
 
@@ -1376,7 +1377,7 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetInputMode` called with `CURSOR`.
-    pub fn set_cursor_mode(&self, mode: CursorMode) {
+    pub fn set_cursor_mode(&mut self, mode: CursorMode) {
         unsafe { ffi::glfwSetInputMode(self.ptr, ffi::CURSOR, mode as c_int); }
     }
 
@@ -1386,7 +1387,7 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetInputMode` called with `STICKY_KEYS`.
-    pub fn set_sticky_keys(&self, value: bool) {
+    pub fn set_sticky_keys(&mut self, value: bool) {
         unsafe { ffi::glfwSetInputMode(self.ptr, ffi::STICKY_KEYS, value as c_int); }
     }
 
@@ -1396,7 +1397,7 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetInputMode` called with `STICKY_MOUSE_BUTTONS`.
-    pub fn set_sticky_mouse_buttons(&self, value: bool) {
+    pub fn set_sticky_mouse_buttons(&mut self, value: bool) {
         unsafe { ffi::glfwSetInputMode(self.ptr, ffi::STICKY_MOUSE_BUTTONS, value as c_int); }
     }
 
@@ -1421,42 +1422,42 @@ impl Window {
     }
 
     /// Wrapper for `glfwSetCursorPos`.
-    pub fn set_cursor_pos(&self, xpos: f64, ypos: f64) {
+    pub fn set_cursor_pos(&mut self, xpos: f64, ypos: f64) {
         unsafe { ffi::glfwSetCursorPos(self.ptr, xpos as c_double, ypos as c_double); }
     }
 
     /// Wrapper for `glfwSetKeyCallback`.
-    pub fn set_key_polling(&self, should_poll: bool) {
+    pub fn set_key_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetKeyCallback, key_callback);
     }
 
     /// Wrapper for `glfwSetCharCallback`.
-    pub fn set_char_polling(&self, should_poll: bool) {
+    pub fn set_char_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetCharCallback, char_callback);
     }
 
     /// Wrapper for `glfwSetMouseButtonCallback`.
-    pub fn set_mouse_button_polling(&self, should_poll: bool) {
+    pub fn set_mouse_button_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetMouseButtonCallback, mouse_button_callback);
     }
 
     /// Wrapper for `glfwSetCursorPosCallback`.
-    pub fn set_cursor_pos_polling(&self, should_poll: bool) {
+    pub fn set_cursor_pos_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetCursorPosCallback, cursor_pos_callback);
     }
 
     /// Wrapper for `glfwSetCursorEnterCallback`.
-    pub fn set_cursor_enter_polling(&self, should_poll: bool) {
+    pub fn set_cursor_enter_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetCursorEnterCallback, cursor_enter_callback);
     }
 
     /// Wrapper for `glfwSetScrollCallback`.
-    pub fn set_scroll_polling(&self, should_poll: bool) {
+    pub fn set_scroll_polling(&mut self, should_poll: bool) {
         set_window_callback!(self, should_poll, glfwSetScrollCallback, scroll_callback);
     }
 
     /// Wrapper for `glfwGetClipboardString`.
-    pub fn set_clipboard_string(&self, string: &str) {
+    pub fn set_clipboard_string(&mut self, string: &str) {
         unsafe {
             with_c_str(string, |string| {
                 ffi::glfwSetClipboardString(self.ptr, string);
@@ -1556,7 +1557,7 @@ pub trait Context {
     /// updates before swapping the buffers.
     ///
     /// Wrapper for `glfwSwapBuffers`.
-    fn swap_buffers(&self) {
+    fn swap_buffers(&mut self) {
         let ptr = self.window_ptr();
         unsafe { ffi::glfwSwapBuffers(ptr); }
     }
@@ -1567,7 +1568,7 @@ pub trait Context {
     }
 
     /// Wrapper for `glfwMakeContextCurrent`
-    fn make_current(&self) {
+    fn make_current(&mut self) {
         let ptr = self.window_ptr();
         unsafe { ffi::glfwMakeContextCurrent(ptr); }
     }


Test patch: