Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- **Breaking**, Replaced `VideoMode::refresh_rate` with `VideoMode::refresh_rate_millihertz` providing better precision.
- On Web, add `with_prevent_default` and `with_focusable` to `WindowBuilderExtWebSys` to control whether events should be propagated.
- On Windows, fix focus events being sent to inactive windows.
- **Breaking**, update `raw-window-handle` to `v0.5` and implement `HasRawDisplayHandle` for `Window` and `EventLoopWindowTarget`.

# 0.26.1 (2022-01-05)

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ instant = { version = "0.1", features = ["wasm-bindgen"] }
once_cell = "1.12"
log = "0.4"
serde = { version = "1", optional = true, features = ["serde_derive"] }
raw-window-handle = "0.4.2"
raw-window-handle = "0.5.0"
bitflags = "1"
mint = { version = "0.5.6", optional = true }

Expand All @@ -55,8 +55,8 @@ simple_logger = "2.1.0"

[target.'cfg(target_os = "android")'.dependencies]
# Coordinate the next winit release with android-ndk-rs: https://github.com/rust-windowing/winit/issues/1995
ndk = { git = "https://github.com/rust-windowing/android-ndk-rs", rev = "a0c5e99" }
ndk-glue = { git = "https://github.com/rust-windowing/android-ndk-rs", rev = "a0c5e99" }
ndk = { git = "https://github.com/rust-windowing/android-ndk-rs", rev = "814be08" }
ndk-glue = { git = "https://github.com/rust-windowing/android-ndk-rs", rev = "814be08" }

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
objc = "0.2.7"
Expand Down
8 changes: 8 additions & 0 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{error, fmt};

use instant::Instant;
use once_cell::sync::OnceCell;
use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle};

use crate::{event::Event, monitor::MonitorHandle, platform_impl};

Expand Down Expand Up @@ -337,6 +338,13 @@ impl<T> EventLoopWindowTarget<T> {
}
}

unsafe impl<T> HasRawDisplayHandle for EventLoopWindowTarget<T> {
/// Returns a [`raw_window_handle::RawDisplayHandle`] for the event loop.
fn raw_display_handle(&self) -> RawDisplayHandle {
self.p.raw_display_handle()
}
}

/// Used to send custom events to [`EventLoop`].
pub struct EventLoopProxy<T: 'static> {
event_loop_proxy: platform_impl::EventLoopProxy<T>,
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@
//! # Drawing on the window
//!
//! Winit doesn't directly provide any methods for drawing on a [`Window`]. However it allows you to
//! retrieve the raw handle of the window (see the [`platform`] module and/or the
//! [`raw_window_handle`] method), which in turn allows you to create an
//! OpenGL/Vulkan/DirectX/Metal/etc. context that can be used to render graphics.
//! retrieve the raw handle of the window and display (see the [`platform`] module and/or the
//! [`raw_window_handle`] and [`raw_display_handle`] methods), which in turn allows
//! you to create an OpenGL/Vulkan/DirectX/Metal/etc. context that can be used to render graphics.
//!
//! Note that many platforms will display garbage data in the window's client area if the
//! application doesn't render anything to the window by the time the desktop compositor is ready to
Expand Down Expand Up @@ -129,6 +129,7 @@
//! [`LoopDestroyed`]: event::Event::LoopDestroyed
//! [`platform`]: platform
//! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle
//! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle

#![deny(rust_2018_idioms)]
#![deny(rustdoc::broken_intra_doc_links)]
Expand Down
12 changes: 11 additions & 1 deletion src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use ndk::{
};
use ndk_glue::{Event, LockReadGuard, Rect};
use once_cell::sync::Lazy;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::{
AndroidDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
};

use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
Expand Down Expand Up @@ -639,6 +641,10 @@ impl<T: 'static> EventLoopWindowTarget<T> {
v.push_back(MonitorHandle);
v
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::Android(AndroidDisplayHandle::empty())
}
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
Expand Down Expand Up @@ -829,6 +835,10 @@ impl Window {
}
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::Android(AndroidDisplayHandle::empty())
}

pub fn config(&self) -> Configuration {
CONFIG.read().unwrap().clone()
}
Expand Down
6 changes: 6 additions & 0 deletions src/platform_impl/ios/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::{
sync::mpsc::{self, Receiver, Sender},
};

use raw_window_handle::{RawDisplayHandle, UiKitDisplayHandle};

use crate::{
dpi::LogicalSize,
event::Event,
Expand Down Expand Up @@ -63,6 +65,10 @@ impl<T: 'static> EventLoopWindowTarget<T> {

Some(RootMonitorHandle { inner: monitor })
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::UiKit(UiKitDisplayHandle::empty())
}
}

pub struct EventLoop<T: 'static> {
Expand Down
16 changes: 10 additions & 6 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use raw_window_handle::{RawWindowHandle, UiKitHandle};
use std::{
collections::VecDeque,
ops::{Deref, DerefMut},
};

use objc::runtime::{Class, Object, BOOL, NO, YES};
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, UiKitDisplayHandle, UiKitWindowHandle};

use crate::{
dpi::{self, LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
Expand Down Expand Up @@ -332,11 +332,15 @@ impl Inner {
}

pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut handle = UiKitHandle::empty();
handle.ui_window = self.window as _;
handle.ui_view = self.view as _;
handle.ui_view_controller = self.view_controller as _;
RawWindowHandle::UiKit(handle)
let mut window_handle = UiKitWindowHandle::empty();
window_handle.ui_window = self.window as _;
window_handle.ui_view = self.view as _;
window_handle.ui_view_controller = self.view_controller as _;
RawWindowHandle::UiKit(window_handle)
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::UiKit(UiKitDisplayHandle::empty())
}
}

Expand Down
19 changes: 12 additions & 7 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::{ffi::CStr, mem::MaybeUninit, os::raw::*, sync::Arc};
use once_cell::sync::Lazy;
#[cfg(feature = "x11")]
use parking_lot::Mutex;
use raw_window_handle::RawWindowHandle;
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};

#[cfg(feature = "x11")]
pub use self::x11::XNotSupported;
Expand Down Expand Up @@ -572,13 +572,14 @@ impl Window {
}
}

#[inline]
pub fn raw_window_handle(&self) -> RawWindowHandle {
match self {
#[cfg(feature = "x11")]
Window::X(ref window) => RawWindowHandle::Xlib(window.raw_window_handle()),
#[cfg(feature = "wayland")]
Window::Wayland(ref window) => RawWindowHandle::Wayland(window.raw_window_handle()),
}
x11_or_wayland!(match self; Window(window) => window.raw_window_handle())
}

#[inline]
pub fn raw_display_handle(&self) -> RawDisplayHandle {
x11_or_wayland!(match self; Window(window) => window.raw_display_handle())
}
}

Expand Down Expand Up @@ -810,6 +811,10 @@ impl<T> EventLoopWindowTarget<T> {
EventLoopWindowTarget::X(ref evlp) => evlp.set_device_event_filter(_filter),
}
}

pub fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
x11_or_wayland!(match self; Self(evlp) => evlp.raw_display_handle())
}
}

fn sticky_exit_callback<T, F>(
Expand Down
10 changes: 10 additions & 0 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::process;
use std::rc::Rc;
use std::time::{Duration, Instant};

use raw_window_handle::{RawDisplayHandle, WaylandDisplayHandle};

use sctk::reexports::client::protocol::wl_compositor::WlCompositor;
use sctk::reexports::client::protocol::wl_shm::WlShm;
use sctk::reexports::client::Display;
Expand Down Expand Up @@ -71,6 +73,14 @@ pub struct EventLoopWindowTarget<T> {
_marker: std::marker::PhantomData<T>,
}

impl<T> EventLoopWindowTarget<T> {
pub fn raw_display_handle(&self) -> RawDisplayHandle {
let mut display_handle = WaylandDisplayHandle::empty();
display_handle.display = self.display.get_display_ptr() as *mut _;
RawDisplayHandle::Wayland(display_handle)
}
}

pub struct EventLoop<T: 'static> {
/// Event loop.
event_loop: calloop::EventLoop<'static, WinitState>,
Expand Down
20 changes: 14 additions & 6 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use sctk::reexports::client::Display;

use sctk::reexports::calloop;

use raw_window_handle::WaylandHandle;
use raw_window_handle::{
RawDisplayHandle, RawWindowHandle, WaylandDisplayHandle, WaylandWindowHandle,
};
use sctk::window::Decorations;

use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
Expand Down Expand Up @@ -579,11 +581,17 @@ impl Window {
}

#[inline]
pub fn raw_window_handle(&self) -> WaylandHandle {
let mut handle = WaylandHandle::empty();
handle.display = self.display.get_display_ptr() as *mut _;
handle.surface = self.surface.as_ref().c_ptr() as *mut _;
handle
pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut window_handle = WaylandWindowHandle::empty();
window_handle.surface = self.surface.as_ref().c_ptr() as *mut _;
RawWindowHandle::Wayland(window_handle)
}

#[inline]
pub fn raw_display_handle(&self) -> RawDisplayHandle {
let mut display_handle = WaylandDisplayHandle::empty();
display_handle.display = self.display.get_display_ptr() as *mut _;
RawDisplayHandle::Wayland(display_handle)
}

#[inline]
Expand Down
9 changes: 9 additions & 0 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use std::{
use libc::{self, setlocale, LC_CTYPE};

use mio::{unix::SourceFd, Events, Interest, Poll, Token, Waker};
use raw_window_handle::{RawDisplayHandle, XlibDisplayHandle};

use self::{
dnd::{Dnd, DndState},
Expand Down Expand Up @@ -558,6 +559,14 @@ impl<T> EventLoopWindowTarget<T> {
.select_xinput_events(self.root, ffi::XIAllMasterDevices, mask)
.queue();
}

pub fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let mut display_handle = XlibDisplayHandle::empty();
display_handle.display = self.xconn.display as *mut _;
display_handle.screen =
unsafe { (self.xconn.xlib.XDefaultScreen)(self.xconn.display as *mut _) };
RawDisplayHandle::Xlib(display_handle)
}
}

impl<T: 'static> EventLoopProxy<T> {
Expand Down
21 changes: 14 additions & 7 deletions src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use raw_window_handle::XlibHandle;
use std::{
cmp, env,
ffi::CString,
Expand All @@ -8,10 +7,11 @@ use std::{
ptr, slice,
sync::Arc,
};
use x11_dl::xlib::TrueColor;

use libc;
use parking_lot::Mutex;
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XlibDisplayHandle, XlibWindowHandle};
use x11_dl::xlib::TrueColor;

use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
Expand Down Expand Up @@ -1509,10 +1509,17 @@ impl UnownedWindow {
}

#[inline]
pub fn raw_window_handle(&self) -> XlibHandle {
let mut handle = XlibHandle::empty();
handle.window = self.xlib_window();
handle.display = self.xlib_display();
handle
pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut window_handle = XlibWindowHandle::empty();
window_handle.window = self.xlib_window();
RawWindowHandle::Xlib(window_handle)
}

#[inline]
pub fn raw_display_handle(&self) -> RawDisplayHandle {
let mut display_handle = XlibDisplayHandle::empty();
display_handle.display = self.xlib_display();
display_handle.screen = self.screen_id;
RawDisplayHandle::Xlib(display_handle)
}
}
6 changes: 6 additions & 0 deletions src/platform_impl/macos/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use cocoa::{
foundation::{NSInteger, NSPoint, NSTimeInterval},
};
use objc::rc::autoreleasepool;
use raw_window_handle::{AppKitDisplayHandle, RawDisplayHandle};

use crate::{
event::Event,
Expand Down Expand Up @@ -87,6 +88,11 @@ impl<T: 'static> EventLoopWindowTarget<T> {
let monitor = monitor::primary_monitor();
Some(RootMonitorHandle { inner: monitor })
}

#[inline]
pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
}
}

impl<T> EventLoopWindowTarget<T> {
Expand Down
18 changes: 13 additions & 5 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use raw_window_handle::{AppKitHandle, RawWindowHandle};
use std::{
collections::VecDeque,
convert::TryInto,
Expand All @@ -10,6 +9,10 @@ use std::{
},
};

use raw_window_handle::{
AppKitDisplayHandle, AppKitWindowHandle, RawDisplayHandle, RawWindowHandle,
};

use crate::{
dpi::{
LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size, Size::Logical,
Expand Down Expand Up @@ -1144,10 +1147,15 @@ impl UnownedWindow {

#[inline]
pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut handle = AppKitHandle::empty();
handle.ns_window = *self.ns_window as *mut _;
handle.ns_view = *self.ns_view as *mut _;
RawWindowHandle::AppKit(handle)
let mut window_handle = AppKitWindowHandle::empty();
window_handle.ns_window = *self.ns_window as *mut _;
window_handle.ns_view = *self.ns_view as *mut _;
RawWindowHandle::AppKit(window_handle)
}

#[inline]
pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
}
}

Expand Down
Loading