Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update rust crate winit to 0.30 #1235

Merged
merged 4 commits into from
Jan 1, 2025
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ libc = "0.2"
[dev-dependencies]
pollster = "0.3.0"
tao = "0.31"
wgpu = "0.19"
winit = "0.29"
wgpu = "23"
winit = "0.30"
getrandom = "0.2"
http-range = "0.1"
percent-encoding = "2.3"
Expand Down
220 changes: 128 additions & 92 deletions examples/multiwebview.rs
Original file line number Diff line number Diff line change
@@ -1,132 +1,168 @@
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use winit::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
application::ApplicationHandler,
event::WindowEvent,
event_loop::{ActiveEventLoop, EventLoop},
window::{Window, WindowId},
};
use wry::{
dpi::{LogicalPosition, LogicalSize},
Rect, WebViewBuilder,
};

fn main() -> wry::Result<()> {
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
{
use gtk::prelude::DisplayExtManual;
#[derive(Default)]
struct State {
window: Option<Window>,
webview1: Option<wry::WebView>,
webview2: Option<wry::WebView>,
webview3: Option<wry::WebView>,
webview4: Option<wry::WebView>,
}

gtk::init()?;
if gtk::gdk::Display::default().unwrap().backend().is_wayland() {
panic!("This example doesn't support wayland!");
}
impl ApplicationHandler for State {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let mut attributes = Window::default_attributes();
attributes.inner_size = Some(LogicalSize::new(800, 800).into());
let window = event_loop.create_window(attributes).unwrap();

// we need to ignore this error here otherwise it will be catched by winit and will be
// make the example crash
winit::platform::x11::register_xlib_error_hook(Box::new(|_display, error| {
let error = error as *mut x11_dl::xlib::XErrorEvent;
(unsafe { (*error).error_code }) == 170
}));
}
let size = window.inner_size().to_logical::<u32>(window.scale_factor());

let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new()
.with_inner_size(winit::dpi::LogicalSize::new(800, 800))
.build(&event_loop)
.unwrap();

let size = window.inner_size().to_logical::<u32>(window.scale_factor());

let webview = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(0, 0).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://tauri.app")
.build(&window)?;
let webview2 = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(size.width / 2, 0).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://github.com/tauri-apps/wry")
.build(&window)?;
let webview3 = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(0, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://twitter.com/TauriApps")
.build(&window)?;
let webview4 = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://google.com")
.build(&window)?;

event_loop
.run(move |event, evl| {
evl.set_control_flow(ControlFlow::Poll);

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
while gtk::events_pending() {
gtk::main_iteration_do(false);
}
let webview1 = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(0, 0).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://tauri.app")
.build_as_child(&window)
.unwrap();

let webview2 = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(size.width / 2, 0).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://github.com/tauri-apps/wry")
.build_as_child(&window)
.unwrap();

match event {
Event::WindowEvent {
event: WindowEvent::Resized(size),
..
} => {
let webview3 = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(0, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://twitter.com/TauriApps")
.build_as_child(&window)
.unwrap();

let webview4 = WebViewBuilder::new()
.with_bounds(Rect {
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.with_url("https://google.com")
.build_as_child(&window)
.unwrap();

self.window = Some(window);
self.webview1 = Some(webview1);
self.webview2 = Some(webview2);
self.webview3 = Some(webview3);
self.webview4 = Some(webview4);
}

fn window_event(
&mut self,
_event_loop: &ActiveEventLoop,
_window_id: WindowId,
event: WindowEvent,
) {
match event {
WindowEvent::Resized(size) => {
if let (Some(window), Some(webview1), Some(webview2), Some(webview3), Some(webview4)) = (
&self.window,
&self.webview1,
&self.webview2,
&self.webview3,
&self.webview4,
) {
let size = size.to_logical::<u32>(window.scale_factor());
webview

webview1
.set_bounds(Rect {
position: LogicalPosition::new(0, 0).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.unwrap();

webview2
.set_bounds(Rect {
position: LogicalPosition::new(size.width / 2, 0).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.unwrap();

webview3
.set_bounds(Rect {
position: LogicalPosition::new(0, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.unwrap();

webview4
.set_bounds(Rect {
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
})
.unwrap();
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => evl.exit(),
_ => {}
}
})
.unwrap();
WindowEvent::CloseRequested => {
std::process::exit(0);
}
_ => {}
}
}

fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
{
while gtk::events_pending() {
gtk::main_iteration_do(false);
}
}
}
}

fn main() -> wry::Result<()> {
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
{
use gtk::prelude::DisplayExtManual;

gtk::init()?;
if gtk::gdk::Display::default().unwrap().backend().is_wayland() {
panic!("This example doesn't support wayland!");
}

winit::platform::x11::register_xlib_error_hook(Box::new(|_display, error| {
let error = error as *mut x11_dl::xlib::XErrorEvent;
(unsafe { (*error).error_code }) == 170
}));
}

let event_loop = EventLoop::new().unwrap();
let mut state = State::default();
event_loop.run_app(&mut state).unwrap();

Ok(())
}
Loading
Loading