aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Rouget <me@paulrouget.com>2016-02-19 04:51:02 +0100
committerPaul Rouget <me@paulrouget.com>2016-02-26 11:08:46 +0100
commit68818751f42811472c50ea3f95a430c5c3be2dc9 (patch)
tree21197d5054d3f0ce8d2a524e625871c3c59edec4
parentbd605478d13ab07386c5e6c56434c84b5cce46db (diff)
downloadglutin-68818751f42811472c50ea3f95a430c5c3be2dc9.tar.gz
glutin-68818751f42811472c50ea3f95a430c5c3be2dc9.zip
TouchpadPressure event
-rw-r--r--Cargo.toml4
-rw-r--r--src/api/cocoa/mod.rs11
-rw-r--r--src/events.rs7
3 files changed, 16 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 3cce0ee..4f53c3b 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 <pierre.krieger1708@gmail.com>"]
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 4502405..429572f 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<Event>;
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<Event>;
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<Event> {
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<Event> {
};
Some(MouseWheel(delta))
},
+ NSEventTypePressure => {
+ Some(TouchpadPressure(nsevent.pressure(), nsevent.stage()))
+ },
_ => { None },
}
}
diff --git a/src/events.rs b/src/events.rs
index 27ed8b7..ecc1041 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,