Skip to content

Commit

Permalink
feat: raw-window-handle 0.6 (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Oct 24, 2023
1 parent 4ef5baa commit 853101b
Show file tree
Hide file tree
Showing 21 changed files with 413 additions and 123 deletions.
9 changes: 9 additions & 0 deletions .changes/rwh-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"tao": "patch"
---

This release includes an update to `raw-window-handle` crate to `0.6` but will also provide a feature flags to select which `raw-window-handle` to use:

- `rwh_06` (default): `[email protected]`
- `rwh_05: `[email protected]`
- `rwh_04: `[email protected]`
20 changes: 7 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ repository = "https://github.com/tauri-apps/tao"
documentation = "https://docs.rs/tao"
categories = [ "gui" ]

[features]
default = ["rwh_06"]

[package.metadata.docs.rs]
features = [ "serde" ]
features = ["rwh_04", "rwh_05", "rwh_06", "serde"]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"i686-pc-windows-msvc",
Expand All @@ -29,9 +32,6 @@ targets = [
[workspace]
members = [ "tao-macros" ]

[features]
default = [ ]

[build-dependencies]
cc = "1"

Expand All @@ -41,7 +41,9 @@ lazy_static = "1"
libc = "0.2"
log = "0.4"
serde = { version = "1", optional = true, features = [ "serde_derive" ] }
raw-window-handle = "0.5"
rwh_04 = { package = "raw-window-handle", version = "0.4", optional = true }
rwh_05 = { package = "raw-window-handle", version = "0.5", features = ["std"], optional = true }
rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"], optional = true }
bitflags = "1"
crossbeam-channel = "0.5"
url = "2"
Expand Down Expand Up @@ -110,18 +112,10 @@ windows-implement = "0.51"
]

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
cairo-rs = "0.18"
gio = "0.18"
glib = "0.18"
glib-sys = "0.18"
gtk = "0.18"
gdk = "0.18"
gdk-sys = "0.18"
gdkx11-sys = "0.18"
gdkwayland-sys = "0.18.0"
gdk-pixbuf = "0.18"
x11-dl = "2.21"
zbus = "3"
uuid = { version = "1.5", features = [ "v4" ] }
png = "0.17"
parking_lot = "0.12"
32 changes: 27 additions & 5 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//! [event_loop_proxy]: crate::event_loop::EventLoopProxy
//! [send_event]: crate::event_loop::EventLoopProxy::send_event
use instant::Instant;
use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle};
use std::{error, fmt, marker::PhantomData, ops::Deref};

use crate::{
Expand Down Expand Up @@ -299,10 +298,33 @@ 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()
#[cfg(feature = "rwh_05")]
unsafe impl<T> rwh_05::HasRawDisplayHandle for EventLoop<T> {
fn raw_display_handle(&self) -> rwh_05::RawDisplayHandle {
rwh_05::HasRawDisplayHandle::raw_display_handle(&**self)
}
}

#[cfg(feature = "rwh_06")]
impl<T> rwh_06::HasDisplayHandle for EventLoop<T> {
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
rwh_06::HasDisplayHandle::display_handle(&**self)
}
}

#[cfg(feature = "rwh_05")]
unsafe impl<T> rwh_05::HasRawDisplayHandle for EventLoopWindowTarget<T> {
fn raw_display_handle(&self) -> rwh_05::RawDisplayHandle {
self.p.raw_display_handle_rwh_05()
}
}

#[cfg(feature = "rwh_06")]
impl<T> rwh_06::HasDisplayHandle for EventLoopWindowTarget<T> {
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
let raw = self.p.raw_display_handle_rwh_06()?;
// SAFETY: The display will never be deallocated while the event loop is alive.
Ok(unsafe { rwh_06::DisplayHandle::borrow_raw(raw) })
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@
#[cfg(target_os = "android")]
pub use tao_macros::{android_fn, generate_package_name};

#[cfg(feature = "rwh_04")]
pub use rwh_04 as raw_window_handle;
#[cfg(feature = "rwh_05")]
pub use rwh_05 as raw_window_handle;
#[cfg(feature = "rwh_06")]
pub use rwh_06 as raw_window_handle;

#[allow(unused_imports)]
#[macro_use]
extern crate lazy_static;
Expand Down
61 changes: 51 additions & 10 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ use ndk::{
looper::{ForeignLooper, Poll, ThreadLooper},
};
use ndk_sys::AKeyEvent_getKeyCode;
use raw_window_handle::{
AndroidDisplayHandle, AndroidNdkWindowHandle, RawDisplayHandle, RawWindowHandle,
};
use std::{
collections::VecDeque,
convert::TryInto,
Expand Down Expand Up @@ -446,8 +443,18 @@ impl<T: 'static> EventLoopWindowTarget<T> {
v
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::Android(AndroidDisplayHandle::empty())
#[cfg(feature = "rwh_05")]
#[inline]
pub fn raw_display_handle_rwh_05(&self) -> rwh_05::RawDisplayHandle {
rwh_05::RawDisplayHandle::Android(rwh_05::AndroidDisplayHandle::empty())
}

#[cfg(feature = "rwh_06")]
#[inline]
pub fn raw_display_handle_rwh_06(&self) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
Ok(rwh_06::RawDisplayHandle::Android(
rwh_06::AndroidDisplayHandle::new(),
))
}

pub fn cursor_position(&self) -> Result<PhysicalPosition<f64>, error::ExternalError> {
Expand Down Expand Up @@ -681,21 +688,55 @@ impl Window {
Ok((0, 0).into())
}

pub fn raw_window_handle(&self) -> RawWindowHandle {
#[cfg(feature = "rwh_04")]
pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle {
// TODO: Use main activity instead?
let mut handle = rwh_04::AndroidNdkHandle::empty();
if let Some(w) = ndk_glue::window_manager() {
handle.a_native_window = w.as_obj().as_raw() as *mut _;
} else {
panic!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.");
};
rwh_04::RawWindowHandle::AndroidNdk(handle)
}

#[cfg(feature = "rwh_05")]
pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle {
// TODO: Use main activity instead?
let mut handle = AndroidNdkWindowHandle::empty();
let mut handle = rwh_05::AndroidNdkWindowHandle::empty();
if let Some(w) = ndk_glue::window_manager() {
handle.a_native_window = w.as_obj().as_raw() as *mut _;
} else {
panic!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.");
};
RawWindowHandle::AndroidNdk(handle)
rwh_05::RawWindowHandle::AndroidNdk(handle)
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::Android(AndroidDisplayHandle::empty())
#[cfg(feature = "rwh_05")]
pub fn raw_display_handle_rwh_05(&self) -> rwh_05::RawDisplayHandle {
rwh_05::RawDisplayHandle::Android(rwh_05::AndroidDisplayHandle::empty())
}

#[cfg(feature = "rwh_06")]
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
// TODO: Use main activity instead?
if let Some(w) = ndk_glue::window_manager() {
let native_window =
unsafe { std::ptr::NonNull::new_unchecked(w.as_obj().as_raw() as *mut _) };
// native_window shuldn't be null
let handle = rwh_06::AndroidNdkWindowHandle::new(native_window);
Ok(rwh_06::RawWindowHandle::AndroidNdk(handle))
} else {
Err(rwh_06::HandleError::Unavailable)
}
}

#[cfg(feature = "rwh_06")]
pub fn raw_display_handle_rwh_06(&self) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
Ok(rwh_06::RawDisplayHandle::Android(
rwh_06::AndroidDisplayHandle::new(),
))
}
pub fn config(&self) -> Configuration {
CONFIG.read().unwrap().clone()
}
Expand Down
18 changes: 13 additions & 5 deletions src/platform_impl/ios/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use std::{

use crossbeam_channel::{self as channel, Receiver, Sender};

use raw_window_handle::{RawDisplayHandle, UiKitDisplayHandle};

use crate::{
dpi::{LogicalSize, PhysicalPosition},
error::ExternalError,
Expand Down Expand Up @@ -66,7 +64,7 @@ impl<T: 'static> EventLoopWindowTarget<T> {
}

#[inline]
pub fn monitor_from_point(&self, x: f64, y: f64) -> Option<MonitorHandle> {
pub fn monitor_from_point(&self, _x: f64, _y: f64) -> Option<MonitorHandle> {
warn!("`Window::monitor_from_point` is ignored on iOS");
return None;
}
Expand All @@ -78,8 +76,18 @@ impl<T: 'static> EventLoopWindowTarget<T> {
Some(RootMonitorHandle { inner: monitor })
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::UiKit(UiKitDisplayHandle::empty())
#[cfg(feature = "rwh_05")]
#[inline]
pub fn raw_display_handle_rwh_05(&self) -> rwh_05::RawDisplayHandle {
rwh_05::RawDisplayHandle::UiKit(rwh_05::UiKitDisplayHandle::empty())
}

#[cfg(feature = "rwh_06")]
#[inline]
pub fn raw_display_handle_rwh_06(&self) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
Ok(rwh_06::RawDisplayHandle::UiKit(
rwh_06::UiKitDisplayHandle::new(),
))
}

pub fn cursor_position(&self) -> Result<PhysicalPosition<f64>, ExternalError> {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub use self::{
window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId},
};

pub(crate) use crate::icon::{Icon, NoIcon as PlatformIcon};
pub(crate) use crate::icon::NoIcon as PlatformIcon;

// todo: implement iOS keyboard event
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
Expand Down
1 change: 1 addition & 0 deletions src/platform_impl/ios/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl Drop for MonitorHandle {
impl fmt::Debug for MonitorHandle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[derive(Debug)]
#[allow(unused)]
struct MonitorHandle {
name: Option<String>,
size: PhysicalSize<u32>,
Expand Down
40 changes: 33 additions & 7 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright 2021-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0

use raw_window_handle::{RawDisplayHandle, RawWindowHandle, UiKitDisplayHandle, UiKitWindowHandle};
use std::{
collections::VecDeque,
ops::{Deref, DerefMut},
Expand Down Expand Up @@ -374,7 +373,7 @@ impl Inner {
}

#[inline]
pub fn monitor_from_point(&self, x: f64, y: f64) -> Option<RootMonitorHandle> {
pub fn monitor_from_point(&self, _x: f64, _y: f64) -> Option<RootMonitorHandle> {
warn!("`Window::monitor_from_point` is ignored on iOS");
None
}
Expand All @@ -388,16 +387,43 @@ impl Inner {
self.window.into()
}

pub fn raw_window_handle(&self) -> RawWindowHandle {
let mut window_handle = UiKitWindowHandle::empty();
#[cfg(feature = "rwh_04")]
pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle {
let mut window_handle = rwh_04::UiKitHandle::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)
rwh_04::RawWindowHandle::UiKit(window_handle)
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::UiKit(UiKitDisplayHandle::empty())
#[cfg(feature = "rwh_05")]
pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle {
let mut window_handle = rwh_05::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 _;
rwh_05::RawWindowHandle::UiKit(window_handle)
}

#[cfg(feature = "rwh_05")]
pub fn raw_display_handle_rwh_05(&self) -> rwh_05::RawDisplayHandle {
rwh_05::RawDisplayHandle::UiKit(rwh_05::UiKitDisplayHandle::empty())
}

#[cfg(feature = "rwh_06")]
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
let mut window_handle = rwh_06::UiKitWindowHandle::new({
std::ptr::NonNull::new(self.view as _).expect("self.view should never be null")
});
window_handle.ui_view_controller = std::ptr::NonNull::new(self.view_controller as _);
Ok(rwh_06::RawWindowHandle::UiKit(window_handle))
}

#[cfg(feature = "rwh_06")]
pub fn raw_display_handle_rwh_06(&self) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
Ok(rwh_06::RawDisplayHandle::UiKit(
rwh_06::UiKitDisplayHandle::new(),
))
}

pub fn theme(&self) -> Theme {
Expand Down
1 change: 1 addition & 0 deletions src/platform_impl/linux/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
ptr,
};

use gtk::glib;
use x11_dl::{xinput2, xlib};

use crate::event::{DeviceEvent, ElementState, RawKeyEvent};
Expand Down
Loading

0 comments on commit 853101b

Please sign in to comment.