diff --git a/Cargo.toml b/Cargo.toml index b71af54f..adb47a8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "winit" -version = "0.4.8" +version = "0.4.9" authors = ["The winit contributors, Pierre Krieger "] description = "Cross-platform window creation library." keywords = ["windowing"] @@ -18,26 +18,26 @@ shared_library = "0.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" +cocoa = "0.3" core-foundation = "0" -core-graphics = "0" +core-graphics = "0.3" [target.i686-pc-windows-gnu.dependencies] winapi = "0.2" @@ -75,46 +75,53 @@ dwmapi-sys = "0.1" 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] 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] 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] 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] 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] 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] 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] 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.4" diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 1200de20..23a6e2a1 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -33,10 +33,10 @@ 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::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}; @@ -65,11 +65,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); } @@ -78,7 +79,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); // need to notify context before (?) event @@ -98,7 +99,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)); } @@ -106,7 +107,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)); } @@ -118,7 +119,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:), @@ -132,7 +133,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(); }); @@ -149,7 +150,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 } @@ -189,7 +190,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(); } } @@ -209,12 +210,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(), + NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantPast(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } event } @@ -234,12 +239,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(), + NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantFuture(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } if event.is_none() { @@ -357,7 +366,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 | @@ -557,8 +568,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]; } } @@ -654,7 +665,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 { @@ -735,7 +746,15 @@ 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())) }, _ => { None }, } 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/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/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/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/win32/event.rs b/src/api/win32/event.rs index ad4598ad..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::Browser_back), - winapi::VK_BROWSER_FORWARD => Some(VirtualKeyCode::Browser_forward), - 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::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_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_BROWSER_BACK => Some(VirtualKeyCode::NavigateBackward), + winapi::VK_BROWSER_FORWARD => Some(VirtualKeyCode::NavigateForward), + 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_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), diff --git a/src/api/x11/events.rs b/src/api/x11/events.rs index 408a3ec9..1c6668c3 100644 --- a/src/api/x11/events.rs +++ b/src/api/x11/events.rs @@ -997,6 +997,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/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/api/x11/mod.rs b/src/api/x11/mod.rs index b67744b9..d5f9470b 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, WindowProxy}; diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index c7fa9373..ea327eb4 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -314,7 +314,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"))) @@ -743,29 +743,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 | @@ -784,11 +816,6 @@ impl Window { } } }, - - // Nothing needs to change - (Grab, Grab) | (Normal, Normal) => Ok(()), - - _ => unimplemented!(), } } diff --git a/src/events.rs b/src/events.rs index 27ed8b78..9fff1fb7 100644 --- a/src/events.rs +++ b/src/events.rs @@ -31,11 +31,18 @@ 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), + /// 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, @@ -257,6 +264,8 @@ pub enum VirtualKeyCode { Multiply, Mute, MyComputer, + NavigateForward, // also called "Prior" + NavigateBackward, // also called "Next" NextTrack, NoConvert, NumpadComma, diff --git a/src/lib.rs b/src/lib.rs index e7ce2779..e92dc031 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 925b0925..4c6237f4 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 7f019e82..2664d31b 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"))] pub use self::api_dispatch::{Window, WindowProxy, MonitorId, get_available_monitors, get_primary_monitor}; pub use self::api_dispatch::{WaitEventsIterator, PollEventsIterator}; 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;