mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 23:01:30 +11:00
Add missing get_api stubs.
Add hidpi_factor() support for retina displays. Fix Resize and MouseMoved events to handle retina displays. Fix inverted y position for MouseMoved events on mac. Fix initial painting on retina display.
This commit is contained in:
parent
bcda363188
commit
fd5e77f23e
|
@ -63,6 +63,10 @@ impl HeadlessContext {
|
||||||
pub fn get_proc_address(&self, _addr: &str) -> *const () {
|
pub fn get_proc_address(&self, _addr: &str) -> *const () {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_api(&self) -> ::Api {
|
||||||
|
::Api::OpenGl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "headless")]
|
#[cfg(feature = "headless")]
|
||||||
|
@ -284,6 +288,10 @@ impl Window {
|
||||||
|
|
||||||
pub fn set_cursor(&self, _: MouseCursor) {
|
pub fn set_cursor(&self, _: MouseCursor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for Window {}
|
unsafe impl Send for Window {}
|
||||||
|
|
|
@ -621,6 +621,13 @@ impl Window {
|
||||||
pub fn set_cursor(&self, cursor: MouseCursor) {
|
pub fn set_cursor(&self, cursor: MouseCursor) {
|
||||||
self.window.set_cursor(cursor);
|
self.window.set_cursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the ratio between the backing framebuffer resolution and the
|
||||||
|
/// window size in screen pixels. This is typically one for a normal display
|
||||||
|
/// and two for a retina display.
|
||||||
|
pub fn hidpi_factor(&self) -> f32 {
|
||||||
|
self.window.hidpi_factor()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
|
|
|
@ -97,6 +97,10 @@ impl HeadlessContext {
|
||||||
};
|
};
|
||||||
symbol as *const ()
|
symbol as *const ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_api(&self) -> ::Api {
|
||||||
|
::Api::OpenGl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for HeadlessContext {}
|
unsafe impl Send for HeadlessContext {}
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct DelegateState<'a> {
|
||||||
is_closed: bool,
|
is_closed: bool,
|
||||||
context: id,
|
context: id,
|
||||||
view: id,
|
view: id,
|
||||||
|
window: id,
|
||||||
handler: Option<fn(u32, u32)>,
|
handler: Option<fn(u32, u32)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +118,8 @@ extern fn window_did_resize(this: id, _: id) -> id {
|
||||||
match state.handler {
|
match state.handler {
|
||||||
Some(handler) => {
|
Some(handler) => {
|
||||||
let rect = NSView::frame(state.view);
|
let rect = NSView::frame(state.view);
|
||||||
(handler)(rect.size.width as u32, rect.size.height as u32);
|
let scale_factor = state.window.backingScaleFactor() as f32;
|
||||||
|
(handler)((scale_factor * rect.size.width as f32) as u32, (scale_factor * rect.size.height as f32) as u32);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
@ -360,6 +362,7 @@ impl Window {
|
||||||
let mut ds = DelegateState {
|
let mut ds = DelegateState {
|
||||||
is_closed: self.is_closed.get(),
|
is_closed: self.is_closed.get(),
|
||||||
context: self.context,
|
context: self.context,
|
||||||
|
window: self.window,
|
||||||
view: self.view,
|
view: self.view,
|
||||||
handler: self.resize,
|
handler: self.resize,
|
||||||
};
|
};
|
||||||
|
@ -380,8 +383,17 @@ impl Window {
|
||||||
NSRightMouseUp => { events.push_back(MouseInput(Released, RightMouseButton)); },
|
NSRightMouseUp => { events.push_back(MouseInput(Released, RightMouseButton)); },
|
||||||
NSMouseMoved => {
|
NSMouseMoved => {
|
||||||
let window_point = event.locationInWindow();
|
let window_point = event.locationInWindow();
|
||||||
let view_point = self.view.convertPoint_fromView_(window_point, nil);
|
let window: id = msg_send()(event, selector("window"));
|
||||||
events.push_back(MouseMoved((view_point.x as i32, view_point.y as i32)));
|
let view_point = if window == 0 {
|
||||||
|
let window_rect = self.window.convertRectFromScreen_(NSRect::new(window_point, NSSize::new(0.0, 0.0)));
|
||||||
|
self.view.convertPoint_fromView_(window_rect.origin, nil)
|
||||||
|
} else {
|
||||||
|
self.view.convertPoint_fromView_(window_point, nil)
|
||||||
|
};
|
||||||
|
let view_rect = NSView::frame(self.view);
|
||||||
|
let scale_factor = self.hidpi_factor();
|
||||||
|
events.push_back(MouseMoved(((scale_factor * view_point.x as f32) as i32,
|
||||||
|
(scale_factor * (view_rect.size.height - view_point.y) as f32) as i32)));
|
||||||
},
|
},
|
||||||
NSKeyDown => {
|
NSKeyDown => {
|
||||||
let received_c_str = event.characters().UTF8String();
|
let received_c_str = event.characters().UTF8String();
|
||||||
|
@ -461,6 +473,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn make_current(&self) {
|
pub unsafe fn make_current(&self) {
|
||||||
|
let _: id = msg_send()(self.context, selector("update"));
|
||||||
self.context.makeCurrentContext();
|
self.context.makeCurrentContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,4 +508,10 @@ impl Window {
|
||||||
pub fn set_cursor(&self, cursor: MouseCursor) {
|
pub fn set_cursor(&self, cursor: MouseCursor) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hidpi_factor(&self) -> f32 {
|
||||||
|
unsafe {
|
||||||
|
self.window.backingScaleFactor() as f32
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,6 +289,10 @@ impl Window {
|
||||||
pub fn set_cursor(&self, cursor: MouseCursor) {
|
pub fn set_cursor(&self, cursor: MouseCursor) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
|
|
|
@ -658,4 +658,8 @@ impl Window {
|
||||||
ffi::XFlush(self.x.display);
|
ffi::XFlush(self.x.display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hidpi_factor(&self) -> f32 {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue