diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api/cocoa/mod.rs | 4 | ||||
-rw-r--r-- | src/api/wayland/events.rs | 4 | ||||
-rw-r--r-- | src/api/win32/callback.rs | 2 | ||||
-rw-r--r-- | src/api/x11/input.rs | 2 | ||||
-rw-r--r-- | src/api/x11/window.rs | 48 | ||||
-rw-r--r-- | src/events.rs | 2 |
6 files changed, 50 insertions, 12 deletions
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index e935805..da7c1ec 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -848,8 +848,8 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> { let view_rect = NSView::frame(*window.view); let scale_factor = window.hidpi_factor(); - Some(MouseMoved(((scale_factor * view_point.x as f32) as i32, - (scale_factor * (view_rect.size.height - view_point.y) as f32) as i32))) + Some(MouseMoved((scale_factor * view_point.x as f32) as i32, + (scale_factor * (view_rect.size.height - view_point.y) as f32) as i32)) }, NSKeyDown => { let mut events = VecDeque::new(); diff --git a/src/api/wayland/events.rs b/src/api/wayland/events.rs index 5e0c3fd..92a0b95 100644 --- a/src/api/wayland/events.rs +++ b/src/api/wayland/events.rs @@ -52,7 +52,7 @@ pub fn translate_event( if known_surfaces.contains(&surface) { focuses.pointer_on = Some(surface); focuses.pointer_at = Some((x, y)); - Some((GlutinEvent::MouseMoved((x as i32, y as i32)), surface)) + Some((GlutinEvent::MouseMoved(x as i32, y as i32), surface)) } else { None } @@ -65,7 +65,7 @@ pub fn translate_event( WlPointerEvent::Motion(_, x, y) => { if let Some(surface) = focuses.pointer_on { focuses.pointer_at = Some((x, y)); - Some((GlutinEvent::MouseMoved((x as i32, y as i32)), surface)) + Some((GlutinEvent::MouseMoved(x as i32, y as i32), surface)) } else { None } diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index 2d10699..337611b 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -126,7 +126,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, let x = winapi::GET_X_LPARAM(lparam) as i32; let y = winapi::GET_Y_LPARAM(lparam) as i32; - send_event(window, MouseMoved((x, y))); + send_event(window, MouseMoved(x, y)); 0 }, diff --git a/src/api/x11/input.rs b/src/api/x11/input.rs index a05b22e..310f1bc 100644 --- a/src/api/x11/input.rs +++ b/src/api/x11/input.rs @@ -241,7 +241,7 @@ impl XInputEventHandler { let new_cursor_pos = (event_data.event_x, event_data.event_y); if new_cursor_pos != self.current_state.cursor_pos { self.current_state.cursor_pos = new_cursor_pos; - Some(MouseMoved((new_cursor_pos.0 as i32, new_cursor_pos.1 as i32))) + Some(MouseMoved(new_cursor_pos.0 as i32, new_cursor_pos.1 as i32)) } else { None } 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 diff --git a/src/events.rs b/src/events.rs index 9fff1fb..d13a0bf 100644 --- a/src/events.rs +++ b/src/events.rs @@ -28,7 +28,7 @@ pub enum Event { /// The cursor has moved on the window. /// /// The parameter are the (x,y) coords in pixels relative to the top-left corner of the window. - MouseMoved((i32, i32)), + MouseMoved(i32, i32), /// A mouse wheel movement or touchpad scroll occurred. MouseWheel(MouseScrollDelta, TouchPhase), |