aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2016-03-30 09:15:13 +0200
committertomaka <pierre.krieger1708@gmail.com>2016-03-30 09:15:13 +0200
commit9a129aa86204cb798d33b3ed009de14e342748c1 (patch)
tree06952222d0be79125f5cd2afca8226d21fc792bc
parent89dd63b9ceac72a7ca274724d2b81033ddb5d4ed (diff)
parent0e9fad5d2350467921af2d2e3ab0b26a1b749080 (diff)
downloadglutin-9a129aa86204cb798d33b3ed009de14e342748c1.tar.gz
glutin-9a129aa86204cb798d33b3ed009de14e342748c1.zip
Merge pull request #750 from BonsaiDen/x11_window_size_constraints
Add support for X11 window size constraints
-rw-r--r--src/api/x11/window.rs48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs
index b4019e4..b84dc09 100644
--- a/src/api/x11/window.rs
+++ b/src/api/x11/window.rs
@@ -3,7 +3,7 @@ use CreationError;
use CreationError::OsError;
use libc;
use std::borrow::Borrow;
-use std::{mem, ptr};
+use std::{mem, ptr, cmp};
use std::cell::Cell;
use std::sync::atomic::AtomicBool;
use std::collections::VecDeque;
@@ -310,11 +310,23 @@ impl Window {
pf_reqs: &PixelFormatRequirements, opengl: &GlAttributes<&Window>)
-> Result<Window, CreationError>
{
- let dimensions = window_attrs.dimensions.unwrap_or((800, 600));
+ let dimensions = {
+
+ // x11 only applies constraints when the window is actively resized
+ // by the user, so we have to manually apply the initial constraints
+ let mut dimensions = window_attrs.dimensions.unwrap_or((800, 600));
+ if let Some(max) = window_attrs.max_dimensions {
+ dimensions.0 = cmp::min(dimensions.0, max.0);
+ dimensions.1 = cmp::min(dimensions.1, max.1);
+ }
+
+ if let Some(min) = window_attrs.min_dimensions {
+ dimensions.0 = cmp::max(dimensions.0, min.0);
+ dimensions.1 = cmp::max(dimensions.1, min.1);
+ }
+ dimensions
- // not implemented
- assert!(window_attrs.min_dimensions.is_none());
- assert!(window_attrs.max_dimensions.is_none());
+ };
let screen_id = match window_attrs.monitor {
Some(PlatformMonitorId::X(MonitorId(_, monitor))) => monitor as i32,
@@ -589,6 +601,32 @@ impl Window {
(display.xf86vmode.XF86VidModeSetViewPort)(display.display, screen_id, 0, 0);
display.check_errors().expect("Failed to call XF86VidModeSetViewPort");
}
+
+ } else {
+
+ // set size hints
+ let mut size_hints: ffi::XSizeHints = unsafe { mem::zeroed() };
+ size_hints.flags = ffi::PSize;
+ size_hints.width = dimensions.0 as i32;
+ size_hints.height = dimensions.1 as i32;
+
+ if let Some(dimensions) = window_attrs.min_dimensions {
+ size_hints.flags |= ffi::PMinSize;
+ size_hints.min_width = dimensions.0 as i32;
+ size_hints.min_height = dimensions.1 as i32;
+ }
+
+ if let Some(dimensions) = window_attrs.max_dimensions {
+ size_hints.flags |= ffi::PMaxSize;
+ size_hints.max_width = dimensions.0 as i32;
+ size_hints.max_height = dimensions.1 as i32;
+ }
+
+ unsafe {
+ (display.xlib.XSetNormalHints)(display.display, window, &mut size_hints);
+ display.check_errors().expect("Failed to call XSetNormalHints");
+ }
+
}
// finish creating the OpenGL context