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

Issue:
Getting the current monitor?
Hello, I'm trying to implement fullscreen and windowed modes and I can't seem to figure out how to properly get the current monitor. This is the code I was hoping would work (but unfortunately didn't, as the `ptr` field of `glfw::Monitor` is private and can't be assigned to):
```rs
let mut monitor = unsafe {
    let mut monitor = glfw::Monitor { ptr: glfw::ffi::glfwGetWindowMonitor(window.window_ptr()) };
    monitor
};
```
This is what the Window guide on the GLFW website says for C++:
```rs
GLFWmonitor* monitor = glfwGetWindowMonitor(window);
```
I'm new to Rust, so if something is obvious and I'm just missing it I apologize in advance.
Getting the current monitor?
Hello, I'm trying to implement fullscreen and windowed modes and I can't seem to figure out how to properly get the current monitor. This is the code I was hoping would work (but unfortunately didn't, as the `ptr` field of `glfw::Monitor` is private and can't be assigned to):
```rs
let mut monitor = unsafe {
    let mut monitor = glfw::Monitor { ptr: glfw::ffi::glfwGetWindowMonitor(window.window_ptr()) };
    monitor
};
```
This is what the Window guide on the GLFW website says for C++:
```rs
GLFWmonitor* monitor = glfwGetWindowMonitor(window);
```
I'm new to Rust, so if something is obvious and I'm just missing it I apologize in advance.


Discussion / hints:
Yeah, it seems that we need `Monitor::from_ptr`.

Could also add `Monitor::from_window`.
> Yeah, it seems that we need `Monitor::from_ptr`.
> 
> Could also add `Monitor::from_window`.

Just use `From<GLFWMonitor>`.


------
This still doesn't answer the question of how you obtain a `Monitor`
Yeah, it seems that we need `Monitor::from_ptr`.

Could also add `Monitor::from_window`.
> Yeah, it seems that we need `Monitor::from_ptr`.
> 
> Could also add `Monitor::from_window`.

Just use `From<GLFWMonitor>`.


------
This still doesn't answer the question of how you obtain a `Monitor`

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index ef80398e..f7f37cdc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1477,6 +1477,25 @@ impl std::fmt::Debug for Monitor {
 }
 
 impl Monitor {
+
+    /// Wrapper for `glfwGetPrimaryMonitor`.
+    pub fn from_primary() -> Self {
+        unsafe {
+            Self {
+                ptr: ffi::glfwGetPrimaryMonitor()
+            }
+        }
+    }
+
+    /// Wrapper for `glfwGetWindowMonitor`.
+    pub fn from_window(window: &Window) -> Self {
+        unsafe {
+            Self {
+                ptr: ffi::glfwGetWindowMonitor(window.ptr)
+            }
+        }
+    }
+
     /// Wrapper for `glfwGetMonitorPos`.
     pub fn get_pos(&self) -> (i32, i32) {
         unsafe {


Test patch: