Skip to content

Commit

Permalink
Merge pull request rust-windowing#59 from servo/merge
Browse files Browse the repository at this point in the history
Merge from upstream
  • Loading branch information
SimonSapin committed Dec 30, 2015
2 parents 82f2d28 + 940a978 commit 8d02133
Show file tree
Hide file tree
Showing 25 changed files with 1,867 additions and 1,196 deletions.
38 changes: 19 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "servo-glutin"
version = "0.4.5"
version = "0.4.6"
authors = ["tomaka <pierre.krieger1708@gmail.com>"]
description = "Cross-plaform OpenGL context provider."
keywords = ["windowing", "opengl"]
Expand Down Expand Up @@ -89,44 +89,44 @@ dwmapi-sys = "0.1"

[target.i686-unknown-linux-gnu.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.2.1", features = ["egl", "dlopen"] }
wayland-kbd = "0.2.0"
wayland-window = "0.1.0"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"

[target.x86_64-unknown-linux-gnu.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.2.1", features = ["egl", "dlopen"] }
wayland-kbd = "0.2.0"
wayland-window = "0.1.0"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"

[target.arm-unknown-linux-gnueabihf.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.2.1", features = ["egl", "dlopen"] }
wayland-kbd = "0.2.0"
wayland-window = "0.1.0"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"

[target.aarch64-unknown-linux-gnu.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.2.1", features = ["egl", "dlopen"] }
wayland-kbd = "0.2.0"
wayland-window = "0.1.0"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"

[target.x86_64-unknown-dragonfly.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.2.1", features = ["egl", "dlopen"] }
wayland-kbd = "0.2.0"
wayland-window = "0.1.0"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"

[target.x86_64-unknown-freebsd.dependencies]
osmesa-sys = "0.0.5"
wayland-client = { version = "0.2.1", features = ["egl", "dlopen"] }
wayland-kbd = "0.2.0"
wayland-window = "0.1.0"
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
wayland-kbd = "0.3.3"
wayland-window = "0.2.2"
x11-dl = "~2.2"

[target.i686-unknown-linux-gnu.dependencies.x11]
Expand Down
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ fn main() {
let target = env::var("TARGET").unwrap();
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());

println!("cargo:rerun-if-changed=build.rs");

if target.contains("windows") {
let mut file = File::create(&dest.join("wgl_bindings.rs")).unwrap();
gl_generator::generate_bindings(gl_generator::StaticGenerator,
Expand All @@ -26,10 +28,12 @@ fn main() {
"WGL_ARB_create_context".to_string(),
"WGL_ARB_create_context_profile".to_string(),
"WGL_ARB_create_context_robustness".to_string(),
"WGL_ARB_context_flush_control".to_string(),
"WGL_ARB_extensions_string".to_string(),
"WGL_ARB_framebuffer_sRGB".to_string(),
"WGL_ARB_multisample".to_string(),
"WGL_ARB_pixel_format".to_string(),
"WGL_ARB_pixel_format_float".to_string(),
"WGL_EXT_create_context_es2_profile".to_string(),
"WGL_EXT_extensions_string".to_string(),
"WGL_EXT_framebuffer_sRGB".to_string(),
Expand Down Expand Up @@ -76,8 +80,11 @@ fn main() {
"GLX_ARB_create_context".to_string(),
"GLX_ARB_create_context_profile".to_string(),
"GLX_ARB_create_context_robustness".to_string(),
"GLX_ARB_context_flush_control".to_string(),
"GLX_ARB_fbconfig_float".to_string(),
"GLX_ARB_framebuffer_sRGB".to_string(),
"GLX_EXT_framebuffer_sRGB".to_string(),
"GLX_ARB_multisample".to_string(),
"GLX_EXT_swap_control".to_string(),
"GLX_SGI_swap_control".to_string()
],
Expand Down
6 changes: 3 additions & 3 deletions examples/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ mod support;
#[cfg(target_os = "android")]
android_start!(main);

fn main() {
fn main() {
let window = glutin::WindowBuilder::new().build().unwrap();
window.set_title("A fantastic window!");
window.set_title("A fantastic window!");
unsafe { window.make_current().unwrap() };

let context = support::load(&window);
let cursors = [MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::NoneCursor, MouseCursor::Cell, MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy, MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing, MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut, MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize, MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize, MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize, MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize, MouseCursor::ColResize, MouseCursor::RowResize];
let mut cursor_idx = 0;

for event in window.wait_events() {
match event {
Event::KeyboardInput(ElementState::Pressed, _, _) => {
Expand Down
7 changes: 4 additions & 3 deletions examples/grabbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fn main() {

let context = support::load(&window);
let mut grabbed = false;
for event in window.poll_events() {

for event in window.wait_events() {
match event {
Event::KeyboardInput(ElementState::Pressed, _, _) => {
if grabbed {
Expand All @@ -33,6 +33,8 @@ fn main() {
}
},

Event::Closed => break,

a @ Event::MouseMoved(_) => {
println!("{:?}", a);
},
Expand All @@ -44,4 +46,3 @@ fn main() {
let _ = window.swap_buffers();
}
}

4 changes: 4 additions & 0 deletions src/api/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ impl Window {
{
use std::{mem, ptr};

// not implemented
assert!(win_attribs.min_dimensions.is_none());
assert!(win_attribs.max_dimensions.is_none());

let opengl = opengl.clone().map_sharing(|w| &w.context);

let native_window = unsafe { android_glue::get_native_window() };
Expand Down
77 changes: 50 additions & 27 deletions src/api/cocoa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use GlProfile;
use GlRequest;
use PixelFormat;
use PixelFormatRequirements;
use ReleaseBehavior;
use Robustness;
use WindowAttributes;
use native_monitor::NativeMonitorId;
Expand All @@ -33,7 +34,7 @@ use core_foundation::base::TCFType;
use core_foundation::string::CFString;
use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};

use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh};
use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh, CGWarpMouseCursorPosition};

use std::ffi::CStr;
use std::collections::VecDeque;
Expand Down Expand Up @@ -268,6 +269,10 @@ impl Window {
unimplemented!()
}

// not implemented
assert!(win_attribs.min_dimensions.is_none());
assert!(win_attribs.max_dimensions.is_none());

match opengl.robustness {
Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
return Err(CreationError::RobustnessNotSupported);
Expand Down Expand Up @@ -366,7 +371,7 @@ impl Window {
let count: NSUInteger = msg_send![screens, count];
let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber"));
let mut matching_screen: Option<id> = None;
for i in (0..count) {
for i in 0..count {
let screen = msg_send![screens, objectAtIndex:i as NSUInteger];
let device_description = NSScreen::deviceDescription(screen);
let value: id = msg_send![device_description, objectForKey:*key];
Expand All @@ -392,26 +397,24 @@ impl Window {
}
};

let masks = match (attrs.decorations, attrs.transparent) {
(true, false) =>
// Classic opaque window with titlebar
NSClosableWindowMask as NSUInteger |
NSMiniaturizableWindowMask as NSUInteger |
NSResizableWindowMask as NSUInteger |
NSTitledWindowMask as NSUInteger,
(false, false) =>
// Opaque window without a titlebar
NSClosableWindowMask as NSUInteger |
NSMiniaturizableWindowMask as NSUInteger |
NSResizableWindowMask as NSUInteger |
NSTitledWindowMask as NSUInteger |
NSFullSizeContentViewWindowMask as NSUInteger,
(_, true) =>
// Fully transparent window.
// No shadow, decorations or borders.
NSBorderlessWindowMask as NSUInteger
let masks = if screen.is_some() || attrs.transparent {
// Fullscreen or transparent window
NSBorderlessWindowMask as NSUInteger
} else if attrs.decorations {
// Classic opaque window with titlebar
NSClosableWindowMask as NSUInteger |
NSMiniaturizableWindowMask as NSUInteger |
NSResizableWindowMask as NSUInteger |
NSTitledWindowMask as NSUInteger
} else {
// Opaque window without a titlebar
NSClosableWindowMask as NSUInteger |
NSMiniaturizableWindowMask as NSUInteger |
NSResizableWindowMask as NSUInteger |
NSTitledWindowMask as NSUInteger |
NSFullSizeContentViewWindowMask as NSUInteger
};

let window = IdRef::new(NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
frame,
masks,
Expand Down Expand Up @@ -489,6 +492,8 @@ impl Window {
let alpha_depth = pf_reqs.alpha_bits.unwrap_or(8);
let color_depth = pf_reqs.color_bits.unwrap_or(24) + alpha_depth;

// TODO: handle hardware_accelerated parameter of pf_reqs

let mut attributes = vec![
NSOpenGLPFADoubleBuffer as u32,
NSOpenGLPFAClosestPolicy as u32,
Expand All @@ -499,10 +504,19 @@ impl Window {
NSOpenGLPFAOpenGLProfile as u32, profile,
];

// A color depth higher than 64 implies we're using either 16-bit
// floats or 32-bit floats and OS X requires a flag to be set
// accordingly.
if color_depth >= 64 {
if pf_reqs.release_behavior != ReleaseBehavior::Flush {
return Err(CreationError::NoAvailablePixelFormat);
}

if pf_reqs.stereoscopy {
unimplemented!(); // TODO:
}

if pf_reqs.double_buffer == Some(false) {
unimplemented!(); // TODO:
}

if pf_reqs.float_color_buffer {
attributes.push(NSOpenGLPFAColorFloat as u32);
}

Expand Down Expand Up @@ -751,8 +765,17 @@ impl Window {
}

#[inline]
pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> {
unimplemented!();
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
let (window_x, window_y) = self.get_position().unwrap_or((0, 0));
let (cursor_x, cursor_y) = (window_x + x, window_y + y);

unsafe {
// TODO: Check for errors.
let _ = CGWarpMouseCursorPosition(CGPoint { x: cursor_x as CGFloat, y: cursor_y as CGFloat });
let _ = CGAssociateMouseAndMouseCursorPosition(true);
}

Ok(())
}
}

Expand Down
Loading

0 comments on commit 8d02133

Please sign in to comment.