Skip to content

Commit d8cedc8

Browse files
committed
Merge branch 'master' into feature/windows-cursor-enter-leave
2 parents 475bd5f + 2c1b1a7 commit d8cedc8

17 files changed

Lines changed: 569 additions & 532 deletions

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
fn_args_layout = "Compressed"
1+
fn_params_layout = "Compressed"
22
use_small_heuristics = "Max"
33
use_field_init_shorthand = true

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ opengl = ["uuid", "x11/glx"]
2020

2121
[dependencies]
2222
keyboard-types = { version = "0.6.1", default-features = false }
23-
raw-window-handle = "0.4.2"
23+
raw-window-handle = "0.5"
2424

2525
[target.'cfg(target_os="linux")'.dependencies]
2626
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }

examples/open_window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl WindowHandler for OpenWindowExample {
2929

3030
#[cfg(target_os = "macos")]
3131
match e {
32-
MouseEvent::ButtonPressed { button, modifiers } => {
32+
MouseEvent::ButtonPressed { .. } => {
3333
copy_to_clipboard(&"This is a test!")
3434
}
3535
_ => (),

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ pub enum EventStatus {
157157
/// plugin window is in focus.
158158
Ignored,
159159
/// We are prepared to handle the data in the drag and dropping will
160-
/// result in [DropEffect]
160+
/// result in [DropEffect]
161161
AcceptDrop(DropEffect),
162162
}

src/gl/macos.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::c_void;
22
use std::str::FromStr;
33

4-
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
4+
use raw_window_handle::RawWindowHandle;
55

66
use cocoa::appkit::{
77
NSOpenGLContext, NSOpenGLContextParameter, NSOpenGLPFAAccelerated, NSOpenGLPFAAlphaSize,
@@ -28,10 +28,8 @@ pub struct GlContext {
2828
}
2929

3030
impl GlContext {
31-
pub unsafe fn create(
32-
parent: &impl HasRawWindowHandle, config: GlConfig,
33-
) -> Result<GlContext, GlError> {
34-
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
31+
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
32+
let handle = if let RawWindowHandle::AppKit(handle) = parent {
3533
handle
3634
} else {
3735
return Err(GlError::InvalidWindowHandle);

src/gl/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
33

44
// On X11 creating the context is a two step process
55
#[cfg(not(target_os = "linux"))]
6-
use raw_window_handle::HasRawWindowHandle;
6+
use raw_window_handle::RawWindowHandle;
77

88
#[cfg(target_os = "windows")]
99
mod win;
@@ -77,7 +77,7 @@ pub struct GlContext {
7777
impl GlContext {
7878
#[cfg(not(target_os = "linux"))]
7979
pub(crate) unsafe fn create(
80-
parent: &impl HasRawWindowHandle, config: GlConfig,
80+
parent: &RawWindowHandle, config: GlConfig,
8181
) -> Result<GlContext, GlError> {
8282
platform::GlContext::create(parent, config)
8383
.map(|context| GlContext { context, phantom: PhantomData })

src/gl/win.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::{c_void, CString, OsStr};
22
use std::os::windows::ffi::OsStrExt;
33

4-
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
4+
use raw_window_handle::RawWindowHandle;
55

66
use winapi::shared::minwindef::{HINSTANCE, HMODULE};
77
use winapi::shared::ntdef::WCHAR;
@@ -77,10 +77,8 @@ extern "C" {
7777
}
7878

7979
impl GlContext {
80-
pub unsafe fn create(
81-
parent: &impl HasRawWindowHandle, config: GlConfig,
82-
) -> Result<GlContext, GlError> {
83-
let handle = if let RawWindowHandle::Win32(handle) = parent.raw_window_handle() {
80+
pub unsafe fn create(parent: &RawWindowHandle, config: GlConfig) -> Result<GlContext, GlError> {
81+
let handle = if let RawWindowHandle::Win32(handle) = parent {
8482
handle
8583
} else {
8684
return Err(GlError::InvalidWindowHandle);

src/gl/x11.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::ffi::{c_void, CString};
22
use std::os::raw::{c_int, c_ulong};
33

4-
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
5-
64
use x11::glx;
75
use x11::xlib;
86

@@ -80,20 +78,12 @@ impl GlContext {
8078
///
8179
/// Use [Self::get_fb_config_and_visual] to create both of these things.
8280
pub unsafe fn create(
83-
parent: &impl HasRawWindowHandle, config: FbConfig,
81+
window: c_ulong, display: *mut xlib::_XDisplay, config: FbConfig,
8482
) -> Result<GlContext, GlError> {
85-
let handle = if let RawWindowHandle::Xlib(handle) = parent.raw_window_handle() {
86-
handle
87-
} else {
88-
return Err(GlError::InvalidWindowHandle);
89-
};
90-
91-
if handle.display.is_null() {
83+
if display.is_null() {
9284
return Err(GlError::InvalidWindowHandle);
9385
}
9486

95-
let display = handle.display as *mut xlib::_XDisplay;
96-
9787
errors::XErrorHandler::handle(display, |error_handler| {
9888
#[allow(non_snake_case)]
9989
let glXCreateContextAttribsARB: GlXCreateContextAttribsARB = {
@@ -144,21 +134,21 @@ impl GlContext {
144134
return Err(GlError::CreationFailed(CreationFailedError::ContextCreationFailed));
145135
}
146136

147-
let res = glx::glXMakeCurrent(display, handle.window, context);
137+
let res = glx::glXMakeCurrent(display, window, context);
148138
error_handler.check()?;
149139
if res == 0 {
150140
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
151141
}
152142

153-
glXSwapIntervalEXT(display, handle.window, config.gl_config.vsync as i32);
143+
glXSwapIntervalEXT(display, window, config.gl_config.vsync as i32);
154144
error_handler.check()?;
155145

156146
if glx::glXMakeCurrent(display, 0, std::ptr::null_mut()) == 0 {
157147
error_handler.check()?;
158148
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
159149
}
160150

161-
Ok(GlContext { window: handle.window, display, context })
151+
Ok(GlContext { window, display, context })
162152
})
163153
}
164154

src/macos/keyboard.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
//! Conversion of platform keyboard event into cross-platform event.
2020
21+
use std::cell::Cell;
22+
2123
use cocoa::appkit::{NSEvent, NSEventModifierFlags, NSEventType};
2224
use cocoa::base::id;
2325
use cocoa::foundation::NSString;
@@ -44,7 +46,7 @@ pub(crate) fn from_nsstring(s: id) -> String {
4446
/// Most of the logic in this module is adapted from Mozilla, and in particular
4547
/// TextInputHandler.mm.
4648
pub(crate) struct KeyboardState {
47-
last_mods: NSEventModifierFlags,
49+
last_mods: Cell<NSEventModifierFlags>,
4850
}
4951

5052
/// Convert a macOS platform key code (keyCode field of NSEvent).
@@ -269,11 +271,15 @@ fn is_modifier_code(code: Code) -> bool {
269271

270272
impl KeyboardState {
271273
pub(crate) fn new() -> KeyboardState {
272-
let last_mods = NSEventModifierFlags::empty();
274+
let last_mods = Cell::new(NSEventModifierFlags::empty());
273275
KeyboardState { last_mods }
274276
}
275277

276-
pub(crate) fn process_native_event(&mut self, event: id) -> Option<KeyboardEvent> {
278+
pub(crate) fn last_mods(&self) -> NSEventModifierFlags {
279+
self.last_mods.get()
280+
}
281+
282+
pub(crate) fn process_native_event(&self, event: id) -> Option<KeyboardEvent> {
277283
unsafe {
278284
let event_type = event.eventType();
279285
let key_code = event.keyCode();
@@ -288,8 +294,8 @@ impl KeyboardState {
288294
// We use `bits` here because we want to distinguish the
289295
// device dependent bits (when both left and right keys
290296
// may be pressed, for example).
291-
let any_down = raw_mods.bits() & !self.last_mods.bits();
292-
self.last_mods = raw_mods;
297+
let any_down = raw_mods.bits() & !self.last_mods.get().bits();
298+
self.last_mods.set(raw_mods);
293299
if is_modifier_code(code) {
294300
if any_down == 0 {
295301
KeyState::Up

src/macos/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,15 @@ mod view;
33
mod window;
44

55
pub use window::*;
6+
7+
#[allow(non_upper_case_globals)]
8+
mod consts {
9+
use cocoa::foundation::NSUInteger;
10+
11+
pub const NSDragOperationNone: NSUInteger = 0;
12+
pub const NSDragOperationCopy: NSUInteger = 1;
13+
pub const NSDragOperationLink: NSUInteger = 2;
14+
pub const NSDragOperationGeneric: NSUInteger = 4;
15+
pub const NSDragOperationMove: NSUInteger = 16;
16+
}
17+
use consts::*;

0 commit comments

Comments
 (0)