From 68818751f42811472c50ea3f95a430c5c3be2dc9 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Fri, 19 Feb 2016 04:51:02 +0100 Subject: [PATCH 01/15] TouchpadPressure event --- Cargo.toml | 4 ++-- src/api/cocoa/mod.rs | 11 +++++++---- src/events.rs | 7 +++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3cce0ee6..4f53c3b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "glutin" -version = "0.4.8" +version = "0.4.9" authors = ["The glutin contributors, Pierre Krieger "] description = "Cross-platform OpenGL context provider." keywords = ["windowing", "opengl"] @@ -40,7 +40,7 @@ objc = "0.1.8" [target.x86_64-apple-darwin.dependencies] objc = "0.1.8" cgl = "0.1" -cocoa = "0.2" +cocoa = "0.2.4" core-foundation = "0" core-graphics = "0" diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 45024059..429572f3 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -42,7 +42,7 @@ use std::sync::Mutex; use std::ascii::AsciiExt; use std::ops::Deref; -use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed, Focused}; +use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed, Focused, TouchpadPressure}; use events::ElementState::{Pressed, Released}; use events::MouseButton; use events; @@ -225,7 +225,7 @@ impl<'a> Iterator for PollEventsIterator<'a> { let event: Option; unsafe { let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( - NSAnyEventMask.bits(), + NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantPast(nil), NSDefaultRunLoopMode, YES); @@ -250,7 +250,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> { let event: Option; unsafe { let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( - NSAnyEventMask.bits(), + NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantFuture(nil), NSDefaultRunLoopMode, YES); @@ -810,7 +810,7 @@ impl Clone for IdRef { unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option { if nsevent == nil { return None; } - let event_type = msg_send![nsevent, type]; + let event_type = nsevent.eventType(); NSApp().sendEvent_(if let NSKeyDown = event_type { nil } else { nsevent }); match event_type { @@ -893,6 +893,9 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option { }; Some(MouseWheel(delta)) }, + NSEventTypePressure => { + Some(TouchpadPressure(nsevent.pressure(), nsevent.stage())) + }, _ => { None }, } } diff --git a/src/events.rs b/src/events.rs index 27ed8b78..ecc10418 100644 --- a/src/events.rs +++ b/src/events.rs @@ -36,6 +36,13 @@ pub enum Event { /// An event from the mouse has been received. MouseInput(ElementState, MouseButton), + /// Touchpad pressure event. + /// + /// At the moment, only supported on Apple forcetouch-capable macbooks. + /// The parameters are: pressure level (value between 0 and 1 representing how hard the touchpad + /// is being pressed) and stage (integer representing the click level). + TouchpadPressure(f32, i64), + /// The event loop was woken up by another thread. Awakened, From bcd7999bf60c49c6df5f1e1536b53c44d5801e13 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 29 Feb 2016 15:10:35 -0800 Subject: [PATCH 02/15] cocoa: Post Awakened events at the end of the queue to avoid floods. Closes servo/webrender#179. --- src/api/cocoa/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 429572f3..abcd7354 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -204,7 +204,7 @@ impl WindowProxy { NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_( nil, NSApplicationDefined, NSPoint::new(0.0, 0.0), NSEventModifierFlags::empty(), 0.0, 0, nil, NSApplicationActivatedEventType, 0, 0); - NSApp().postEvent_atStart_(event, YES); + NSApp().postEvent_atStart_(event, NO); pool.drain(); } } From 74a28adba2a07d56bce9592f24196442192e68e0 Mon Sep 17 00:00:00 2001 From: Kirill Zdornyy Date: Tue, 1 Mar 2016 18:06:13 -0800 Subject: [PATCH 03/15] Fix this_platform_is_not_supported on OpenBSD. I followed the steps of @mneumann. --- Cargo.toml | 7 +++++++ build.rs | 2 +- src/api/caca/mod.rs | 2 +- src/api/dlopen.rs | 2 +- src/api/egl/ffi.rs | 2 +- src/api/egl/mod.rs | 2 +- src/api/glx/mod.rs | 2 +- src/api/osmesa/mod.rs | 2 +- src/api/wayland/mod.rs | 2 +- src/api/x11/mod.rs | 2 +- src/lib.rs | 4 ++-- src/os/unix.rs | 2 +- src/platform/linux/mod.rs | 2 +- src/platform/mod.rs | 4 ++-- 14 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4f53c3b2..a282b604 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,3 +131,10 @@ wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" x11-dl = "~2.3" + +[target.x86_64-unknown-openbsd.dependencies] +osmesa-sys = "0.0.5" +wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } +wayland-kbd = "0.3.3" +wayland-window = "0.2.2" +x11-dl = "~2.3" diff --git a/build.rs b/build.rs index bf25c959..53671730 100644 --- a/build.rs +++ b/build.rs @@ -63,7 +63,7 @@ fn main() { "1.5", "core", &mut file).unwrap(); } - if target.contains("linux") || target.contains("dragonfly") || target.contains("freebsd") { + if target.contains("linux") || target.contains("dragonfly") || target.contains("freebsd") || target.contains("openbsd") { let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap(); gl_generator::generate_bindings(gl_generator::StructGenerator, gl_generator::registry::Ns::Glx, diff --git a/src/api/caca/mod.rs b/src/api/caca/mod.rs index e73fa6c8..63b4b9cd 100644 --- a/src/api/caca/mod.rs +++ b/src/api/caca/mod.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] #![allow(unused_variables, dead_code)] use libc; diff --git a/src/api/dlopen.rs b/src/api/dlopen.rs index bacdd2c9..01049137 100644 --- a/src/api/dlopen.rs +++ b/src/api/dlopen.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] #![allow(dead_code)] use std::os::raw::{c_void, c_char, c_int}; diff --git a/src/api/egl/ffi.rs b/src/api/egl/ffi.rs index ae02e308..9ed32c82 100644 --- a/src/api/egl/ffi.rs +++ b/src/api/egl/ffi.rs @@ -33,5 +33,5 @@ pub type EGLNativeWindowType = winapi::HWND; pub type EGLNativeWindowType = *const libc::c_void; #[cfg(target_os = "android")] pub type EGLNativeWindowType = *const libc::c_void; -#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] +#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] pub type EGLNativeWindowType = *const libc::c_void; diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs index ca3dc2aa..b9e4e383 100644 --- a/src/api/egl/mod.rs +++ b/src/api/egl/mod.rs @@ -1,5 +1,5 @@ #![cfg(any(target_os = "windows", target_os = "linux", target_os = "android", - target_os = "dragonfly", target_os = "freebsd"))] + target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] #![allow(unused_variables)] use ContextError; diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs index 95b6f99e..dcdc21c5 100644 --- a/src/api/glx/mod.rs +++ b/src/api/glx/mod.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] use ContextError; use CreationError; diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs index 7ef243a3..f66dce54 100644 --- a/src/api/osmesa/mod.rs +++ b/src/api/osmesa/mod.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] extern crate osmesa_sys; diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index b6a26021..77f018e5 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor}; pub use self::window::{PollEventsIterator, WaitEventsIterator, Window, WindowProxy}; diff --git a/src/api/x11/mod.rs b/src/api/x11/mod.rs index 54626fe9..3dc31b50 100644 --- a/src/api/x11/mod.rs +++ b/src/api/x11/mod.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor}; pub use self::window::{Window, XWindow, PollEventsIterator, WaitEventsIterator, Context, WindowProxy}; diff --git a/src/lib.rs b/src/lib.rs index a27aa72d..fb03bed6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,9 +54,9 @@ extern crate cocoa; extern crate core_foundation; #[cfg(target_os = "macos")] extern crate core_graphics; -#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] extern crate x11_dl; -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))] +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] #[macro_use(wayland_env)] extern crate wayland_client; diff --git a/src/os/unix.rs b/src/os/unix.rs index f42b3c6b..61c89bc3 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] use libc; use Window; diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 9a9eb3f8..18658352 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] use Api; use ContextError; diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 8527da20..975d4301 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -3,7 +3,7 @@ pub use self::platform::*; #[cfg(target_os = "windows")] #[path="windows/mod.rs"] mod platform; -#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))] +#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] #[path="linux/mod.rs"] mod platform; #[cfg(target_os = "macos")] @@ -21,5 +21,5 @@ mod platform; #[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"), not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"), - not(target_os = "freebsd"), not(target_os = "emscripten")))] + not(target_os = "freebsd"), not(target_os = "openbsd"), not(target_os = "emscripten")))] use this_platform_is_not_supported; From 08c311839f9c65faa358b0540a3ff6b2eb19ff14 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Wed, 2 Mar 2016 16:40:19 +0100 Subject: [PATCH 04/15] Fix memory leak while creating NSEvent and swapping buffers (Fixes #514) --- src/api/cocoa/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index abcd7354..ca77ce91 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -224,12 +224,16 @@ impl<'a> Iterator for PollEventsIterator<'a> { let event: Option; unsafe { + let pool = NSAutoreleasePool::new(nil); + let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantPast(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } event } @@ -249,12 +253,16 @@ impl<'a> Iterator for WaitEventsIterator<'a> { let event: Option; unsafe { + let pool = NSAutoreleasePool::new(nil); + let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantFuture(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } if event.is_none() { @@ -747,7 +755,11 @@ impl GlContext for Window { #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { - unsafe { self.context.flushBuffer(); } + unsafe { + let pool = NSAutoreleasePool::new(nil); + self.context.flushBuffer(); + let _: () = msg_send![pool, release]; + } Ok(()) } From 7886ff9acdbc4961359725536c1a15e2cbb3d4f5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 2 Mar 2016 16:13:13 -0800 Subject: [PATCH 05/15] Add phases to wheel events. Needed for apps to support overscroll on the Mac. --- src/api/cocoa/mod.rs | 13 +++++++++---- src/api/wayland/events.rs | 6 ++++-- src/api/win32/callback.rs | 3 ++- src/api/x11/input.rs | 5 +++-- src/events.rs | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index abcd7354..db3f7498 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -42,10 +42,10 @@ use std::sync::Mutex; use std::ascii::AsciiExt; use std::ops::Deref; -use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed, Focused, TouchpadPressure}; use events::ElementState::{Pressed, Released}; -use events::MouseButton; -use events; +use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput}; +use events::Event::{MouseWheel, Closed, Focused, TouchpadPressure}; +use events::{self, MouseButton, TouchPhase}; pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor}; pub use self::headless::HeadlessContext; @@ -891,7 +891,12 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option { LineDelta(scale_factor * nsevent.scrollingDeltaX() as f32, scale_factor * nsevent.scrollingDeltaY() as f32) }; - Some(MouseWheel(delta)) + let phase = match nsevent.phase() { + NSEventPhaseMayBegin | NSEventPhaseBegan => TouchPhase::Started, + NSEventPhaseEnded => TouchPhase::Ended, + _ => TouchPhase::Moved, + }; + Some(MouseWheel(delta, phase)) }, NSEventTypePressure => { Some(TouchpadPressure(nsevent.pressure(), nsevent.stage())) diff --git a/src/api/wayland/events.rs b/src/api/wayland/events.rs index 8b180205..5e0c3fd0 100644 --- a/src/api/wayland/events.rs +++ b/src/api/wayland/events.rs @@ -1,5 +1,6 @@ use std::collections::HashSet; +use TouchPhase; use Event as GlutinEvent; use ElementState; use MouseButton; @@ -98,7 +99,8 @@ pub fn translate_event( WlPointerAxis::HorizontalScroll => { MouseScrollDelta::PixelDelta(0.0, amplitude as f32) } - } + }, + TouchPhase::Moved ), surface)) } else { None @@ -107,4 +109,4 @@ pub fn translate_event( }, _ => None } -} \ No newline at end of file +} diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index 0215c9f9..2d10699d 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -134,12 +134,13 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, winapi::WM_MOUSEWHEEL => { use events::Event::MouseWheel; use events::MouseScrollDelta::LineDelta; + use events::TouchPhase; let value = (wparam >> 16) as i16; let value = value as i32; let value = value as f32 / winapi::WHEEL_DELTA as f32; - send_event(window, MouseWheel(LineDelta(0.0, value))); + send_event(window, MouseWheel(LineDelta(0.0, value), TouchPhase::Moved)); 0 }, diff --git a/src/api/x11/input.rs b/src/api/x11/input.rs index 2ebc9897..a05b22e1 100644 --- a/src/api/x11/input.rs +++ b/src/api/x11/input.rs @@ -201,7 +201,7 @@ impl XInputEventHandler { } else { -1.0 }; - Some(MouseWheel(LineDelta(0.0, delta))) + Some(MouseWheel(LineDelta(0.0, delta), TouchPhase::Moved)) } else { // emulated button event from a touch/smooth-scroll // event. Ignore these events and handle scrolling @@ -235,7 +235,8 @@ impl XInputEventHandler { } if scroll_delta.0.abs() > 0.0 || scroll_delta.1.abs() > 0.0 { - Some(MouseWheel(LineDelta(scroll_delta.0 as f32, scroll_delta.1 as f32))) + Some(MouseWheel(LineDelta(scroll_delta.0 as f32, scroll_delta.1 as f32), + TouchPhase::Moved)) } else { let new_cursor_pos = (event_data.event_x, event_data.event_y); if new_cursor_pos != self.current_state.cursor_pos { diff --git a/src/events.rs b/src/events.rs index ecc10418..8049c167 100644 --- a/src/events.rs +++ b/src/events.rs @@ -31,7 +31,7 @@ pub enum Event { MouseMoved((i32, i32)), /// A mouse wheel movement or touchpad scroll occurred. - MouseWheel(MouseScrollDelta), + MouseWheel(MouseScrollDelta, TouchPhase), /// An event from the mouse has been received. MouseInput(ElementState, MouseButton), From 717d0184c0da42aee24b9041a73d9505016c9c29 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 8 Mar 2016 22:59:15 -0700 Subject: [PATCH 06/15] Pin core-graphics to 0.2 since cocoa 0.2.4 does --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a282b604..cda4d75f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ objc = "0.1.8" cgl = "0.1" cocoa = "0.2.4" core-foundation = "0" -core-graphics = "0" +core-graphics = "0.2" [target.i686-pc-windows-gnu.dependencies] winapi = "0.2" From 7249529654afe4b3ac6628be45bd2d8bb15dcaf4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 14 Mar 2016 15:51:10 -0700 Subject: [PATCH 07/15] Make Mac borderless windows resizable and draggable. Despite the fact that the style mask contains `NSTitledWindowMask`, the title doesn't show up for two reasons: (a) we draw over it; (b) we make it invisible with a call to `-[NSWindow setTitleVisibility:]`. Addresses servo/servo#9856 and servo/servo#9878. Partially addresses servo/servo#9812. --- src/api/cocoa/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index db3f7498..08fabddb 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -404,7 +404,9 @@ impl Window { let masks = if screen.is_some() || attrs.transparent { // Fullscreen or transparent window - NSBorderlessWindowMask as NSUInteger + NSBorderlessWindowMask as NSUInteger | + NSResizableWindowMask as NSUInteger | + NSTitledWindowMask as NSUInteger } else if attrs.decorations { // Classic opaque window with titlebar NSClosableWindowMask as NSUInteger | From c0adb8d87eb929db037c2cce2082bfb5f7627119 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 14 Mar 2016 20:22:16 -0400 Subject: [PATCH 08/15] Fix Mac build by bumping core-graphics. At the time of writing, Glutin requires 0.2.x and cocoa requires 0.3.x. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cda4d75f..3a251c29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ objc = "0.1.8" cgl = "0.1" cocoa = "0.2.4" core-foundation = "0" -core-graphics = "0.2" +core-graphics = "0.3" [target.i686-pc-windows-gnu.dependencies] winapi = "0.2" From 1de66e4efbd428e5cefa422e6c771e225cab1829 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 27 Feb 2016 15:29:06 +0530 Subject: [PATCH 09/15] Add support for navigation keys --- Cargo.toml | 18 +++++++++--------- src/api/win32/event.rs | 8 ++++---- src/api/x11/events.rs | 3 +++ src/events.rs | 2 ++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a251c29..294d55d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,60 +81,60 @@ osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.i586-unknown-linux-gnu.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.x86_64-unknown-linux-gnu.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.arm-unknown-linux-gnueabihf.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.armv7-unknown-linux-gnueabihf.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.aarch64-unknown-linux-gnu.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.x86_64-unknown-dragonfly.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.x86_64-unknown-freebsd.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" [target.x86_64-unknown-openbsd.dependencies] osmesa-sys = "0.0.5" wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] } wayland-kbd = "0.3.3" wayland-window = "0.2.2" -x11-dl = "~2.3" +x11-dl = "~2.4" diff --git a/src/api/win32/event.rs b/src/api/win32/event.rs index ad4598ad..f60ec7e7 100644 --- a/src/api/win32/event.rs +++ b/src/api/win32/event.rs @@ -148,10 +148,10 @@ pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (S winapi::VK_LCONTROL => Some(VirtualKeyCode::Lcontrol), winapi::VK_RCONTROL => Some(VirtualKeyCode::Rcontrol), winapi::VK_LMENU => Some(VirtualKeyCode::Lmenu), - winapi::VK_RMENU => Some(VirtualKeyCode::Rmenu), - winapi::VK_BROWSER_BACK => Some(VirtualKeyCode::Browser_back), - winapi::VK_BROWSER_FORWARD => Some(VirtualKeyCode::Browser_forward), - winapi::VK_BROWSER_REFRESH => Some(VirtualKeyCode::Browser_refresh), + winapi::VK_RMENU => Some(VirtualKeyCode::Rmenu),*/ + winapi::VK_BROWSER_BACK => Some(VirtualKeyCode::NavigateBackward), + winapi::VK_BROWSER_FORWARD => Some(VirtualKeyCode::NavigateForward), + /*winapi::VK_BROWSER_REFRESH => Some(VirtualKeyCode::Browser_refresh), winapi::VK_BROWSER_STOP => Some(VirtualKeyCode::Browser_stop), winapi::VK_BROWSER_SEARCH => Some(VirtualKeyCode::Browser_search), winapi::VK_BROWSER_FAVORITES => Some(VirtualKeyCode::Browser_favorites), diff --git a/src/api/x11/events.rs b/src/api/x11/events.rs index 408a3ec9..d497319d 100644 --- a/src/api/x11/events.rs +++ b/src/api/x11/events.rs @@ -3,6 +3,7 @@ use super::ffi; use VirtualKeyCode; pub fn keycode_to_element(scancode: libc::c_uint) -> Option { + println!("{:?}", scancode); Some(match scancode { ffi::XK_BackSpace => events::VirtualKeyCode::Back, ffi::XK_Tab => events::VirtualKeyCode::Tab, @@ -997,6 +998,8 @@ pub fn keycode_to_element(scancode: libc::c_uint) -> Option { //ffi::XK_hebrew_taw => events::VirtualKeyCode::Hebrew_taw, //ffi::XK_hebrew_taf => events::VirtualKeyCode::Hebrew_taf, //ffi::XK_Hebrew_switch => events::VirtualKeyCode::Hebrew_switch, + ffi::XF86XK_Back => VirtualKeyCode::NavigateBackward, + ffi::XF86XK_Forward => VirtualKeyCode::NavigateForward, _ => return None }) } diff --git a/src/events.rs b/src/events.rs index 8049c167..9fff1fb7 100644 --- a/src/events.rs +++ b/src/events.rs @@ -264,6 +264,8 @@ pub enum VirtualKeyCode { Multiply, Mute, MyComputer, + NavigateForward, // also called "Prior" + NavigateBackward, // also called "Next" NextTrack, NoConvert, NumpadComma, From 28599a5d792eaa718882ef522177b3b46f6dec6f Mon Sep 17 00:00:00 2001 From: UK992 Date: Fri, 18 Mar 2016 02:44:48 +0100 Subject: [PATCH 10/15] Uncomment more keys on win32 --- src/api/win32/event.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api/win32/event.rs b/src/api/win32/event.rs index f60ec7e7..c4946bb2 100644 --- a/src/api/win32/event.rs +++ b/src/api/win32/event.rs @@ -167,12 +167,12 @@ pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (S winapi::VK_LAUNCH_MEDIA_SELECT => Some(VirtualKeyCode::Launch_media_select), winapi::VK_LAUNCH_APP1 => Some(VirtualKeyCode::Launch_app1), winapi::VK_LAUNCH_APP2 => Some(VirtualKeyCode::Launch_app2), - winapi::VK_OEM_1 => Some(VirtualKeyCode::Oem_1), - winapi::VK_OEM_PLUS => Some(VirtualKeyCode::Oem_plus), - winapi::VK_OEM_COMMA => Some(VirtualKeyCode::Oem_comma), - winapi::VK_OEM_MINUS => Some(VirtualKeyCode::Oem_minus), - winapi::VK_OEM_PERIOD => Some(VirtualKeyCode::Oem_period), - winapi::VK_OEM_2 => Some(VirtualKeyCode::Oem_2), + winapi::VK_OEM_1 => Some(VirtualKeyCode::Oem_1),*/ + winapi::VK_OEM_PLUS => Some(VirtualKeyCode::Add), + winapi::VK_OEM_COMMA => Some(VirtualKeyCode::Comma), + winapi::VK_OEM_MINUS => Some(VirtualKeyCode::Minus), + winapi::VK_OEM_PERIOD => Some(VirtualKeyCode::Period), + /*winapi::VK_OEM_2 => Some(VirtualKeyCode::Oem_2), winapi::VK_OEM_3 => Some(VirtualKeyCode::Oem_3), winapi::VK_OEM_4 => Some(VirtualKeyCode::Oem_4), winapi::VK_OEM_5 => Some(VirtualKeyCode::Oem_5), From 9e2a179daaa9f61b80733f1c0739b203a4bbaa8c Mon Sep 17 00:00:00 2001 From: Adam Casey Date: Sat, 19 Mar 2016 09:45:14 +0000 Subject: [PATCH 11/15] Enable more Windows keys This should enable most required keys on Windows. Mappings taken from: https://msdn.microsoft.com/en-gb/library/windows/desktop/dd375731%28v=vs.85%29.aspx and applied with some guesswork to the Glutin names. --- src/api/win32/event.rs | 62 +++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/src/api/win32/event.rs b/src/api/win32/event.rs index c4946bb2..a4de7503 100644 --- a/src/api/win32/event.rs +++ b/src/api/win32/event.rs @@ -42,7 +42,7 @@ pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (S winapi::VK_KANJI => Some(VirtualKeyCode::Kanji), winapi::VK_ESCAPE => Some(VirtualKeyCode::Escape), winapi::VK_CONVERT => Some(VirtualKeyCode::Convert), - //winapi::VK_NONCONVERT => Some(VirtualKeyCode::Nonconvert), + winapi::VK_NONCONVERT => Some(VirtualKeyCode::NoConvert), //winapi::VK_ACCEPT => Some(VirtualKeyCode::Accept), //winapi::VK_MODECHANGE => Some(VirtualKeyCode::Modechange), winapi::VK_SPACE => Some(VirtualKeyCode::Space), @@ -143,44 +143,38 @@ pub fn vkeycode_to_element(wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> (S winapi::VK_F24 => Some(VirtualKeyCode::F24),*/ winapi::VK_NUMLOCK => Some(VirtualKeyCode::Numlock), winapi::VK_SCROLL => Some(VirtualKeyCode::Scroll), - /*winapi::VK_LSHIFT => Some(VirtualKeyCode::Lshift), - winapi::VK_RSHIFT => Some(VirtualKeyCode::Rshift), - winapi::VK_LCONTROL => Some(VirtualKeyCode::Lcontrol), - winapi::VK_RCONTROL => Some(VirtualKeyCode::Rcontrol), - winapi::VK_LMENU => Some(VirtualKeyCode::Lmenu), - winapi::VK_RMENU => Some(VirtualKeyCode::Rmenu),*/ winapi::VK_BROWSER_BACK => Some(VirtualKeyCode::NavigateBackward), winapi::VK_BROWSER_FORWARD => Some(VirtualKeyCode::NavigateForward), - /*winapi::VK_BROWSER_REFRESH => Some(VirtualKeyCode::Browser_refresh), - winapi::VK_BROWSER_STOP => Some(VirtualKeyCode::Browser_stop), - winapi::VK_BROWSER_SEARCH => Some(VirtualKeyCode::Browser_search), - winapi::VK_BROWSER_FAVORITES => Some(VirtualKeyCode::Browser_favorites), - winapi::VK_BROWSER_HOME => Some(VirtualKeyCode::Browser_home), - winapi::VK_VOLUME_MUTE => Some(VirtualKeyCode::Volume_mute), - winapi::VK_VOLUME_DOWN => Some(VirtualKeyCode::Volume_down), - winapi::VK_VOLUME_UP => Some(VirtualKeyCode::Volume_up), - winapi::VK_MEDIA_NEXT_TRACK => Some(VirtualKeyCode::Media_next_track), - winapi::VK_MEDIA_PREV_TRACK => Some(VirtualKeyCode::Media_prev_track), - winapi::VK_MEDIA_STOP => Some(VirtualKeyCode::Media_stop), - winapi::VK_MEDIA_PLAY_PAUSE => Some(VirtualKeyCode::Media_play_pause), - winapi::VK_LAUNCH_MAIL => Some(VirtualKeyCode::Launch_mail), - winapi::VK_LAUNCH_MEDIA_SELECT => Some(VirtualKeyCode::Launch_media_select), - winapi::VK_LAUNCH_APP1 => Some(VirtualKeyCode::Launch_app1), - winapi::VK_LAUNCH_APP2 => Some(VirtualKeyCode::Launch_app2), - winapi::VK_OEM_1 => Some(VirtualKeyCode::Oem_1),*/ - winapi::VK_OEM_PLUS => Some(VirtualKeyCode::Add), + winapi::VK_BROWSER_REFRESH => Some(VirtualKeyCode::WebRefresh), + winapi::VK_BROWSER_STOP => Some(VirtualKeyCode::WebStop), + winapi::VK_BROWSER_SEARCH => Some(VirtualKeyCode::WebSearch), + winapi::VK_BROWSER_FAVORITES => Some(VirtualKeyCode::WebFavorites), + winapi::VK_BROWSER_HOME => Some(VirtualKeyCode::WebHome), + winapi::VK_VOLUME_MUTE => Some(VirtualKeyCode::Mute), + winapi::VK_VOLUME_DOWN => Some(VirtualKeyCode::VolumeDown), + winapi::VK_VOLUME_UP => Some(VirtualKeyCode::VolumeUp), + winapi::VK_MEDIA_NEXT_TRACK => Some(VirtualKeyCode::NextTrack), + winapi::VK_MEDIA_PREV_TRACK => Some(VirtualKeyCode::PrevTrack), + winapi::VK_MEDIA_STOP => Some(VirtualKeyCode::MediaStop), + winapi::VK_MEDIA_PLAY_PAUSE => Some(VirtualKeyCode::PlayPause), + winapi::VK_LAUNCH_MAIL => Some(VirtualKeyCode::Mail), + winapi::VK_LAUNCH_MEDIA_SELECT => Some(VirtualKeyCode::MediaSelect), + /*winapi::VK_LAUNCH_APP1 => Some(VirtualKeyCode::Launch_app1), + winapi::VK_LAUNCH_APP2 => Some(VirtualKeyCode::Launch_app2),*/ + winapi::VK_OEM_PLUS => Some(VirtualKeyCode::Equals), winapi::VK_OEM_COMMA => Some(VirtualKeyCode::Comma), winapi::VK_OEM_MINUS => Some(VirtualKeyCode::Minus), winapi::VK_OEM_PERIOD => Some(VirtualKeyCode::Period), - /*winapi::VK_OEM_2 => Some(VirtualKeyCode::Oem_2), - winapi::VK_OEM_3 => Some(VirtualKeyCode::Oem_3), - winapi::VK_OEM_4 => Some(VirtualKeyCode::Oem_4), - winapi::VK_OEM_5 => Some(VirtualKeyCode::Oem_5), - winapi::VK_OEM_6 => Some(VirtualKeyCode::Oem_6), - winapi::VK_OEM_7 => Some(VirtualKeyCode::Oem_7), - winapi::VK_OEM_8 => Some(VirtualKeyCode::Oem_8), - winapi::VK_OEM_102 => Some(VirtualKeyCode::Oem_102), - winapi::VK_PROCESSKEY => Some(VirtualKeyCode::Processkey), + /*winapi::VK_OEM_1 => Some(VirtualKeyCode::Oem_1), + winapi::VK_OEM_2 => Some(VirtualKeyCode::Oem_2), + winapi::VK_OEM_3 => Some(VirtualKeyCode::Oem_3), + winapi::VK_OEM_4 => Some(VirtualKeyCode::Oem_4), + winapi::VK_OEM_5 => Some(VirtualKeyCode::Oem_5), + winapi::VK_OEM_6 => Some(VirtualKeyCode::Oem_6), + winapi::VK_OEM_7 => Some(VirtualKeyCode::Oem_7), + winapi::VK_OEM_8 => Some(VirtualKeyCode::Oem_8), */ + winapi::VK_OEM_102 => Some(VirtualKeyCode::OEM102), + /*winapi::VK_PROCESSKEY => Some(VirtualKeyCode::Processkey), winapi::VK_PACKET => Some(VirtualKeyCode::Packet), winapi::VK_ATTN => Some(VirtualKeyCode::Attn), winapi::VK_CRSEL => Some(VirtualKeyCode::Crsel), From c5268309c39933e13e86bd33a9fe0b7fa8c88b14 Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Sun, 20 Mar 2016 16:04:11 -0700 Subject: [PATCH 12/15] Update objc to 0.2. --- Cargo.toml | 14 +++++++------- src/api/cocoa/mod.rs | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 294d55d9..ddf8160c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,24 +23,24 @@ khronos_api = "1.0" version = "0.1" [target.i386-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.x86_64-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.aarch64-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.armv7s-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.armv7-apple-ios.dependencies] -objc = "0.1.8" +objc = "0.2" [target.x86_64-apple-darwin.dependencies] -objc = "0.1.8" +objc = "0.2" cgl = "0.1" -cocoa = "0.2.4" +cocoa = "0.3" core-foundation = "0" core-graphics = "0.3" diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index bec56d29..e9358055 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -79,11 +79,12 @@ struct WindowDelegate { impl WindowDelegate { /// Get the delegate class, initiailizing it neccessary fn class() -> *const Class { + use std::os::raw::c_void; use std::sync::{Once, ONCE_INIT}; extern fn window_should_close(this: &Object, _: Sel, _: id) -> BOOL { unsafe { - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = state as *mut DelegateState; (*state).pending_events.lock().unwrap().push_back(Closed); } @@ -92,7 +93,7 @@ impl WindowDelegate { extern fn window_did_resize(this: &Object, _: Sel, _: id) { unsafe { - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = &mut *(state as *mut DelegateState); let _: () = msg_send![*state.context, update]; @@ -111,7 +112,7 @@ impl WindowDelegate { // TODO: center the cursor if the window had mouse grab when it // lost focus - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = state as *mut DelegateState; (*state).pending_events.lock().unwrap().push_back(Focused(true)); } @@ -119,7 +120,7 @@ impl WindowDelegate { extern fn window_did_resign_key(this: &Object, _: Sel, _: id) { unsafe { - let state: *mut libc::c_void = *this.get_ivar("glutinState"); + let state: *mut c_void = *this.get_ivar("glutinState"); let state = state as *mut DelegateState; (*state).pending_events.lock().unwrap().push_back(Focused(false)); } @@ -131,7 +132,7 @@ impl WindowDelegate { INIT.call_once(|| unsafe { // Create new NSWindowDelegate let superclass = Class::get("NSObject").unwrap(); - let mut decl = ClassDecl::new(superclass, "GlutinWindowDelegate").unwrap(); + let mut decl = ClassDecl::new("GlutinWindowDelegate", superclass).unwrap(); // Add callback methods decl.add_method(sel!(windowShouldClose:), @@ -145,7 +146,7 @@ impl WindowDelegate { window_did_resign_key as extern fn(&Object, Sel, id)); // Store internal state as user data - decl.add_ivar::<*mut libc::c_void>("glutinState"); + decl.add_ivar::<*mut c_void>("glutinState"); delegate_class = decl.register(); }); @@ -162,7 +163,7 @@ impl WindowDelegate { unsafe { let delegate = IdRef::new(msg_send![WindowDelegate::class(), new]); - (&mut **delegate).set_ivar("glutinState", state_ptr as *mut libc::c_void); + (&mut **delegate).set_ivar("glutinState", state_ptr as *mut ::std::os::raw::c_void); let _: () = msg_send![*state.window, setDelegate:*delegate]; WindowDelegate { state: state, _this: delegate } @@ -673,8 +674,8 @@ impl Window { let sel = Sel::register(cursor_name); let cls = Class::get("NSCursor").unwrap(); unsafe { - use objc::MessageArguments; - let cursor: id = ().send(cls as *const _ as id, sel); + use objc::Message; + let cursor: id = cls.send_message(sel, ()).unwrap(); let _: () = msg_send![cursor, set]; } } From 267221af3e239c79a2617c46ba3f1259663c29f7 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Mon, 21 Mar 2016 18:42:54 +0000 Subject: [PATCH 13/15] Implement CursorState::Hide for x11 --- src/api/x11/window.rs | 55 ++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index 8cae2bef..b4019e47 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -339,7 +339,7 @@ impl Window { let m = (0 .. mode_num).map(|i| { let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m }).find(|m| m.hdisplay >= dimensions.0 as u16 && m.vdisplay >= dimensions.1 as u16); - + match m { Some(m) => Some(m), None => return Err(OsError(format!("Could not find a suitable graphics mode"))) @@ -845,29 +845,61 @@ impl Window { self.x.display.check_errors().expect("Failed to call XcursorLibraryLoadCursor"); (self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, xcursor); (self.x.display.xlib.XFlush)(self.x.display.display); + (self.x.display.xlib.XFreeCursor)(self.x.display.display, xcursor); self.x.display.check_errors().expect("Failed to call XDefineCursor"); } } pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { - use CursorState::{ Grab, Normal }; + use CursorState::{ Grab, Normal, Hide }; let mut cursor_state = self.cursor_state.lock().unwrap(); - match (state, *cursor_state) { - (Normal, Grab) => { + (Normal, Normal) | (Hide, Hide) | (Grab, Grab) => return Ok(()), + _ => {}, + } + + match *cursor_state { + Grab => { unsafe { (self.x.display.xlib.XUngrabPointer)(self.x.display.display, ffi::CurrentTime); self.x.display.check_errors().expect("Failed to call XUngrabPointer"); - *cursor_state = Normal; - Ok(()) } }, - - (Grab, Normal) => { + Normal => {}, + Hide => { unsafe { - *cursor_state = Grab; + let xcursor = (self.x.display.xlib.XCreateFontCursor)(self.x.display.display, 68/*XC_left_ptr*/); + self.x.display.check_errors().expect("Failed to call XCreateFontCursor"); + (self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, xcursor); + self.x.display.check_errors().expect("Failed to call XDefineCursor"); + (self.x.display.xlib.XFlush)(self.x.display.display); + (self.x.display.xlib.XFreeCursor)(self.x.display.display, xcursor); + } + }, + } + *cursor_state = state; + match state { + Normal => Ok(()), + Hide => { + let data = &[0, 0, 0, 0, 0, 0, 0, 0]; + unsafe { + let mut black = ffi::XColor { + red: 0, green: 0, blue: 0, + pad: 0, pixel: 0, flags: 0, + }; + let bitmap = (self.x.display.xlib.XCreateBitmapFromData)(self.x.display.display, self.x.window, data.as_ptr(), 8, 8); + let cursor = (self.x.display.xlib.XCreatePixmapCursor)(self.x.display.display, bitmap, bitmap, &mut black, &mut black, 0, 0); + (self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, cursor); + self.x.display.check_errors().expect("Failed to call XDefineCursor"); + (self.x.display.xlib.XFreeCursor)(self.x.display.display, cursor); + (self.x.display.xlib.XFreePixmap)(self.x.display.display, bitmap); + } + Ok(()) + }, + Grab => { + unsafe { match (self.x.display.xlib.XGrabPointer)( self.x.display.display, self.x.window, ffi::False, (ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::EnterWindowMask | @@ -886,11 +918,6 @@ impl Window { } } }, - - // Nothing needs to change - (Grab, Grab) | (Normal, Normal) => Ok(()), - - _ => unimplemented!(), } } From 5c4bfe1379836ca034b610f8246a1f6a621ee2e2 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Mon, 21 Mar 2016 18:49:00 +0000 Subject: [PATCH 14/15] Remove a debug print added in 1de66e4ef --- src/api/x11/events.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/x11/events.rs b/src/api/x11/events.rs index d497319d..1c6668c3 100644 --- a/src/api/x11/events.rs +++ b/src/api/x11/events.rs @@ -3,7 +3,6 @@ use super::ffi; use VirtualKeyCode; pub fn keycode_to_element(scancode: libc::c_uint) -> Option { - println!("{:?}", scancode); Some(match scancode { ffi::XK_BackSpace => events::VirtualKeyCode::Back, ffi::XK_Tab => events::VirtualKeyCode::Tab, From e8b3570db411b6e39596553c5c13febc153a60a6 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 24 Mar 2016 14:03:38 +1100 Subject: [PATCH 15/15] Update gl_generator to v0.5 --- Cargo.toml | 3 +- build.rs | 242 ++++++++++++++++++++++------------------------------- 2 files changed, 102 insertions(+), 143 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ddf8160c..f1434d17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,7 @@ libc = "0.2" shared_library = "0.1.0" [build-dependencies] -gl_generator = "0.4" -khronos_api = "1.0" +gl_generator = "0.5" [target.arm-linux-androideabi.dependencies.android_glue] version = "0.1" diff --git a/build.rs b/build.rs index 53671730..7d911f51 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,6 @@ extern crate gl_generator; -extern crate khronos_api; +use gl_generator::{Registry, Api, Profile, Fallbacks}; use std::env; use std::fs::File; use std::path::PathBuf; @@ -13,175 +13,135 @@ fn main() { if target.contains("windows") { let mut file = File::create(&dest.join("wgl_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StaticGenerator, - gl_generator::registry::Ns::Wgl, - gl_generator::Fallbacks::All, - khronos_api::WGL_XML, vec![], - "1.0", "core", &mut file).unwrap(); + Registry::new(Api::Wgl, (1, 0), Profile::Core, Fallbacks::All, []) + .write_bindings(gl_generator::StaticGenerator, &mut file) + .unwrap(); let mut file = File::create(&dest.join("wgl_extra_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StructGenerator, - gl_generator::registry::Ns::Wgl, - gl_generator::Fallbacks::All, - khronos_api::WGL_XML, - vec![ - "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(), - "WGL_EXT_swap_control".to_string(), - ], - "1.0", "core", &mut file).unwrap(); + Registry::new(Api::Wgl, (1, 0), Profile::Core, Fallbacks::All, [ + "WGL_ARB_create_context", + "WGL_ARB_create_context_profile", + "WGL_ARB_create_context_robustness", + "WGL_ARB_context_flush_control", + "WGL_ARB_extensions_string", + "WGL_ARB_framebuffer_sRGB", + "WGL_ARB_multisample", + "WGL_ARB_pixel_format", + "WGL_ARB_pixel_format_float", + "WGL_EXT_create_context_es2_profile", + "WGL_EXT_extensions_string", + "WGL_EXT_framebuffer_sRGB", + "WGL_EXT_swap_control", + ]) + .write_bindings(gl_generator::StructGenerator, &mut file).unwrap(); let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StructGenerator, - gl_generator::registry::Ns::Egl, - gl_generator::Fallbacks::All, - khronos_api::EGL_XML, - vec![ - "EGL_KHR_create_context".to_string(), - "EGL_EXT_create_context_robustness".to_string(), - "EGL_KHR_create_context_no_error".to_string(), - "EGL_KHR_platform_x11".to_string(), - "EGL_KHR_platform_android".to_string(), - "EGL_KHR_platform_wayland".to_string(), - "EGL_KHR_platform_gbm".to_string(), - "EGL_EXT_platform_base".to_string(), - "EGL_EXT_platform_x11".to_string(), - "EGL_MESA_platform_gbm".to_string(), - "EGL_EXT_platform_wayland".to_string(), - "EGL_EXT_platform_device".to_string(), - ], - "1.5", "core", &mut file).unwrap(); + Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [ + "EGL_KHR_create_context", + "EGL_EXT_create_context_robustness", + "EGL_KHR_create_context_no_error", + "EGL_KHR_platform_x11", + "EGL_KHR_platform_android", + "EGL_KHR_platform_wayland", + "EGL_KHR_platform_gbm", + "EGL_EXT_platform_base", + "EGL_EXT_platform_x11", + "EGL_MESA_platform_gbm", + "EGL_EXT_platform_wayland", + "EGL_EXT_platform_device", + ]) + .write_bindings(gl_generator::StructGenerator, &mut file).unwrap(); } if target.contains("linux") || target.contains("dragonfly") || target.contains("freebsd") || target.contains("openbsd") { let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StructGenerator, - gl_generator::registry::Ns::Glx, - gl_generator::Fallbacks::All, - khronos_api::GLX_XML, vec![], - "1.4", "core", &mut file).unwrap(); + Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, []) + .write_bindings(gl_generator::StructGenerator, &mut file).unwrap(); let mut file = File::create(&dest.join("glx_extra_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StructGenerator, - gl_generator::registry::Ns::Glx, - gl_generator::Fallbacks::All, - khronos_api::GLX_XML, - vec![ - "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() - ], - "1.4", "core", &mut file).unwrap(); + Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, [ + "GLX_ARB_create_context", + "GLX_ARB_create_context_profile", + "GLX_ARB_create_context_robustness", + "GLX_ARB_context_flush_control", + "GLX_ARB_fbconfig_float", + "GLX_ARB_framebuffer_sRGB", + "GLX_EXT_framebuffer_sRGB", + "GLX_ARB_multisample", + "GLX_EXT_swap_control", + "GLX_SGI_swap_control" + ]) + .write_bindings(gl_generator::StructGenerator, &mut file).unwrap(); let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StructGenerator, - gl_generator::registry::Ns::Egl, - gl_generator::Fallbacks::All, - khronos_api::EGL_XML, - vec![ - "EGL_KHR_create_context".to_string(), - "EGL_EXT_create_context_robustness".to_string(), - "EGL_KHR_create_context_no_error".to_string(), - "EGL_KHR_platform_x11".to_string(), - "EGL_KHR_platform_android".to_string(), - "EGL_KHR_platform_wayland".to_string(), - "EGL_KHR_platform_gbm".to_string(), - "EGL_EXT_platform_base".to_string(), - "EGL_EXT_platform_x11".to_string(), - "EGL_MESA_platform_gbm".to_string(), - "EGL_EXT_platform_wayland".to_string(), - "EGL_EXT_platform_device".to_string(), - ], - "1.5", "core", &mut file).unwrap(); + Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [ + "EGL_KHR_create_context", + "EGL_EXT_create_context_robustness", + "EGL_KHR_create_context_no_error", + "EGL_KHR_platform_x11", + "EGL_KHR_platform_android", + "EGL_KHR_platform_wayland", + "EGL_KHR_platform_gbm", + "EGL_EXT_platform_base", + "EGL_EXT_platform_x11", + "EGL_MESA_platform_gbm", + "EGL_EXT_platform_wayland", + "EGL_EXT_platform_device", + ]) + .write_bindings(gl_generator::StructGenerator, &mut file).unwrap(); } if target.contains("android") { let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StaticStructGenerator, - gl_generator::registry::Ns::Egl, - gl_generator::Fallbacks::All, - khronos_api::EGL_XML, - vec![ - "EGL_KHR_create_context".to_string(), - "EGL_EXT_create_context_robustness".to_string(), - "EGL_KHR_create_context_no_error".to_string(), - "EGL_KHR_platform_x11".to_string(), - "EGL_KHR_platform_android".to_string(), - "EGL_KHR_platform_wayland".to_string(), - "EGL_KHR_platform_gbm".to_string(), - "EGL_EXT_platform_base".to_string(), - "EGL_EXT_platform_x11".to_string(), - "EGL_MESA_platform_gbm".to_string(), - "EGL_EXT_platform_wayland".to_string(), - "EGL_EXT_platform_device".to_string(), - ], - "1.5", "core", &mut file).unwrap(); + Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [ + "EGL_KHR_create_context", + "EGL_EXT_create_context_robustness", + "EGL_KHR_create_context_no_error", + "EGL_KHR_platform_x11", + "EGL_KHR_platform_android", + "EGL_KHR_platform_wayland", + "EGL_KHR_platform_gbm", + "EGL_EXT_platform_base", + "EGL_EXT_platform_x11", + "EGL_MESA_platform_gbm", + "EGL_EXT_platform_wayland", + "EGL_EXT_platform_device", + ]) + .write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap(); } if target.contains("ios") { let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StaticStructGenerator, - gl_generator::registry::Ns::Egl, - gl_generator::Fallbacks::All, - khronos_api::EGL_XML, - vec![ - "EGL_KHR_create_context".to_string(), - "EGL_EXT_create_context_robustness".to_string(), - "EGL_KHR_create_context_no_error".to_string(), - "EGL_KHR_platform_x11".to_string(), - "EGL_KHR_platform_android".to_string(), - "EGL_KHR_platform_wayland".to_string(), - "EGL_KHR_platform_gbm".to_string(), - "EGL_EXT_platform_base".to_string(), - "EGL_EXT_platform_x11".to_string(), - "EGL_MESA_platform_gbm".to_string(), - "EGL_EXT_platform_wayland".to_string(), - "EGL_EXT_platform_device".to_string(), - ], - "1.5", "core", &mut file).unwrap(); + Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [ + "EGL_KHR_create_context", + "EGL_EXT_create_context_robustness", + "EGL_KHR_create_context_no_error", + "EGL_KHR_platform_x11", + "EGL_KHR_platform_android", + "EGL_KHR_platform_wayland", + "EGL_KHR_platform_gbm", + "EGL_EXT_platform_base", + "EGL_EXT_platform_x11", + "EGL_MESA_platform_gbm", + "EGL_EXT_platform_wayland", + "EGL_EXT_platform_device", + ]) + .write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap(); let mut file = File::create(&dest.join("gles2_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StaticStructGenerator, - gl_generator::registry::Ns::Gles2, - gl_generator::Fallbacks::None, - khronos_api::GL_XML, - vec![], - "2.0", "core", &mut file).unwrap(); + Registry::new(Api::Gles2, (2, 0), Profile::Core, Fallbacks::None, []) + .write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap(); } if target.contains("darwin") { let mut file = File::create(&dest.join("gl_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::GlobalGenerator, - gl_generator::registry::Ns::Gl, - gl_generator::Fallbacks::All, - khronos_api::GL_XML, - vec!["GL_EXT_framebuffer_object".to_string()], - "3.2", "core", &mut file).unwrap(); + Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, ["GL_EXT_framebuffer_object"]) + .write_bindings(gl_generator::GlobalGenerator, &mut file).unwrap(); } // TODO: only build the bindings below if we run tests/examples let mut file = File::create(&dest.join("test_gl_bindings.rs")).unwrap(); - gl_generator::generate_bindings(gl_generator::StructGenerator, - gl_generator::registry::Ns::Gles2, - gl_generator::Fallbacks::All, - khronos_api::GL_XML, vec![], - "3.0", "core", &mut file).unwrap(); + Registry::new(Api::Gles2, (3, 0), Profile::Core, Fallbacks::All, []) + .write_bindings(gl_generator::StructGenerator, &mut file).unwrap(); }