Skip to content

Commit

Permalink
Merge branch 'master' into MissingX11FocusIn
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorc authored Sep 10, 2024
2 parents d4eff84 + dfea49f commit b9f7ed6
Show file tree
Hide file tree
Showing 51 changed files with 1,027 additions and 1,069 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ image = { version = "0.25.0", default-features = false, features = ["png"] }
tracing = { version = "0.1.40", default-features = false, features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dev-dependencies]
softbuffer = { version = "0.4.0", default-features = false, features = [
[target.'cfg(not(target_os = "android"))'.dev-dependencies]
softbuffer = { version = "0.4.6", default-features = false, features = [
"x11",
"x11-dlopen",
"wayland",
Expand Down
4 changes: 2 additions & 2 deletions examples/child_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> Result<(), impl std::error::Error> {
let attributes = WindowAttributes::default()
.with_title("parent window")
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_inner_size(LogicalSize::new(640.0f32, 480.0f32));
.with_surface_size(LogicalSize::new(640.0f32, 480.0f32));
let window = event_loop.create_window(attributes).unwrap();

println!("Parent window id: {:?})", window.id());
Expand Down Expand Up @@ -79,7 +79,7 @@ fn main() -> Result<(), impl std::error::Error> {
let parent = parent.raw_window_handle().unwrap();
let mut window_attributes = WindowAttributes::default()
.with_title("child window")
.with_inner_size(LogicalSize::new(200.0f32, 200.0f32))
.with_surface_size(LogicalSize::new(200.0f32, 200.0f32))
.with_position(Position::Logical(LogicalPosition::new(0.0, 0.0)))
.with_visible(true);
// `with_parent_window` is unsafe. Parent window must be a valid window.
Expand Down
2 changes: 1 addition & 1 deletion examples/run_on_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
let window_attributes = WindowAttributes::default()
.with_title("Fantastic window number one!")
.with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0));
.with_surface_size(winit::dpi::LogicalSize::new(128.0, 128.0));
let window = event_loop.create_window(window_attributes).unwrap();
self.window_id = Some(window.id());
self.window = Some(window);
Expand Down
2 changes: 1 addition & 1 deletion examples/util/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod platform {

pub fn fill_window(window: &dyn Window) {
GC.with(|gc| {
let size = window.inner_size();
let size = window.surface_size();
let (Some(width), Some(height)) =
(NonZeroU32::new(size.width), NonZeroU32::new(size.height))
else {
Expand Down
62 changes: 31 additions & 31 deletions examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
use std::collections::HashMap;
use std::error::Error;
use std::fmt::Debug;
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
use std::num::NonZeroU32;
use std::sync::mpsc::{self, Receiver, Sender};
use std::sync::Arc;
use std::{fmt, mem};

use ::tracing::{error, info};
use cursor_icon::CursorIcon;
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
use rwh_06::{DisplayHandle, HasDisplayHandle};
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
use softbuffer::{Context, Surface};
use winit::application::ApplicationHandler;
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize};
use winit::error::ExternalError;
use winit::error::RequestError;
use winit::event::{DeviceEvent, DeviceId, Ime, MouseButton, MouseScrollDelta, WindowEvent};
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::keyboard::{Key, ModifiersState};
Expand Down Expand Up @@ -76,21 +76,21 @@ struct Application {
receiver: Receiver<Action>,
sender: Sender<Action>,
/// Custom cursors assets.
custom_cursors: Result<Vec<CustomCursor>, ExternalError>,
custom_cursors: Result<Vec<CustomCursor>, RequestError>,
/// Application icon.
icon: Icon,
windows: HashMap<WindowId, WindowState>,
/// Drawing context.
///
/// With OpenGL it could be EGLDisplay.
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
context: Option<Context<DisplayHandle<'static>>>,
}

impl Application {
fn new(event_loop: &EventLoop, receiver: Receiver<Action>, sender: Sender<Action>) -> Self {
// SAFETY: we drop the context right before the event loop is stopped, thus making it safe.
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
let context = Some(
Context::new(unsafe {
std::mem::transmute::<DisplayHandle<'_>, DisplayHandle<'static>>(
Expand Down Expand Up @@ -119,7 +119,7 @@ impl Application {
Self {
receiver,
sender,
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
context,
custom_cursors,
icon,
Expand Down Expand Up @@ -389,7 +389,7 @@ impl ApplicationHandler for Application {
};

match event {
WindowEvent::Resized(size) => {
WindowEvent::SurfaceResized(size) => {
window.resize(size);
},
WindowEvent::Focused(focused) => {
Expand Down Expand Up @@ -545,7 +545,7 @@ impl ApplicationHandler for Application {
}
}

#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
fn exiting(&mut self, _event_loop: &dyn ActiveEventLoop) {
// We must drop the context here.
self.context = None;
Expand All @@ -559,7 +559,7 @@ struct WindowState {
/// Render surface.
///
/// NOTE: This surface must be dropped before the `Window`.
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
surface: Surface<DisplayHandle<'static>, Arc<dyn Window>>,
/// The actual winit Window.
window: Arc<dyn Window>,
Expand Down Expand Up @@ -595,7 +595,7 @@ impl WindowState {

// SAFETY: the surface is dropped before the `window` which provided it with handle, thus
// it doesn't outlive it.
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
let surface = Surface::new(app.context.as_ref().unwrap(), Arc::clone(&window))?;

let theme = window.theme().unwrap_or(Theme::Dark);
Expand All @@ -607,14 +607,14 @@ impl WindowState {
let ime = true;
window.set_ime_allowed(ime);

let size = window.inner_size();
let size = window.surface_size();
let mut state = Self {
#[cfg(macos_platform)]
option_as_alt: window.option_as_alt(),
custom_idx: app.custom_cursors.as_ref().map(Vec::len).unwrap_or(1) - 1,
cursor_grab: CursorGrabMode::None,
named_idx,
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
surface,
window,
theme,
Expand Down Expand Up @@ -681,12 +681,12 @@ impl WindowState {

/// Toggle resize increments on a window.
fn toggle_resize_increments(&mut self) {
let new_increments = match self.window.resize_increments() {
let new_increments = match self.window.surface_resize_increments() {
Some(_) => None,
None => Some(LogicalSize::new(25.0, 25.0).into()),
};
info!("Had increments: {}", new_increments.is_none());
self.window.set_resize_increments(new_increments);
self.window.set_surface_resize_increments(new_increments);
}

/// Toggle fullscreen.
Expand Down Expand Up @@ -725,22 +725,22 @@ impl WindowState {
self.window.set_option_as_alt(self.option_as_alt);
}

/// Swap the window dimensions with `request_inner_size`.
/// Swap the window dimensions with `request_surface_size`.
fn swap_dimensions(&mut self) {
let old_inner_size = self.window.inner_size();
let mut inner_size = old_inner_size;
let old_surface_size = self.window.surface_size();
let mut surface_size = old_surface_size;

mem::swap(&mut inner_size.width, &mut inner_size.height);
info!("Requesting resize from {old_inner_size:?} to {inner_size:?}");
mem::swap(&mut surface_size.width, &mut surface_size.height);
info!("Requesting resize from {old_surface_size:?} to {surface_size:?}");

if let Some(new_inner_size) = self.window.request_inner_size(inner_size.into()) {
if old_inner_size == new_inner_size {
if let Some(new_surface_size) = self.window.request_surface_size(surface_size.into()) {
if old_surface_size == new_surface_size {
info!("Inner size change got ignored");
} else {
self.resize(new_inner_size);
self.resize(new_surface_size);
}
} else {
info!("Request inner size is asynchronous");
info!("Requesting surface size is asynchronous");
}
}

Expand Down Expand Up @@ -793,10 +793,10 @@ impl WindowState {
Ok(())
}

/// Resize the window to the new size.
/// Resize the surface to the new size.
fn resize(&mut self, size: PhysicalSize<u32>) {
info!("Resized to {size:?}");
#[cfg(not(any(android_platform, ios_platform)))]
info!("Surface resized to {size:?}");
#[cfg(not(android_platform))]
{
let (width, height) = match (NonZeroU32::new(size.width), NonZeroU32::new(size.height))
{
Expand Down Expand Up @@ -840,7 +840,7 @@ impl WindowState {
},
};

let win_size = self.window.inner_size();
let win_size = self.window.surface_size();
let border_size = BORDER_SIZE * self.window.scale_factor();

let x_direction = if position.x < border_size {
Expand Down Expand Up @@ -889,7 +889,7 @@ impl WindowState {
}

/// Draw the window contents.
#[cfg(not(any(android_platform, ios_platform)))]
#[cfg(not(android_platform))]
fn draw(&mut self) -> Result<(), Box<dyn Error>> {
if self.occluded {
info!("Skipping drawing occluded window={:?}", self.window.id());
Expand All @@ -911,7 +911,7 @@ impl WindowState {
Ok(())
}

#[cfg(any(android_platform, ios_platform))]
#[cfg(android_platform)]
fn draw(&mut self) -> Result<(), Box<dyn Error>> {
info!("Drawing but without rendering...");
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/x11_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> Result<(), Box<dyn Error>> {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
let window_attributes = WindowAttributes::default()
.with_title("An embedded window!")
.with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0))
.with_surface_size(winit::dpi::LogicalSize::new(128.0, 128.0))
.with_embed_parent_window(self.parent_window_id);

self.window = Some(event_loop.create_window(window_attributes).unwrap());
Expand Down
21 changes: 20 additions & 1 deletion src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ changelog entry.
and `Serialize` on many types.
- Add `MonitorHandle::current_video_mode()`.
- Add basic iOS IME support. The soft keyboard can now be shown using `Window::set_ime_allowed`.
- On macOS, add `WindowExtMacOS::set_borderless_game` and `WindowAttributesExtMacOS::with_borderless_game`
to fully disable the menu bar and dock in Borderless Fullscreen as commonly done in games.

### Changed

Expand All @@ -85,7 +87,7 @@ changelog entry.
`ApplicationHandler::resumed/suspended()`.

`ApplicationHandler::can_create_surfaces()` should, for portability reasons
to Android, be the only place to create render surfaces.
to Android, be the only place to create render surfaces.

`ApplicationHandler::resumed/suspended()` are now only emitted by iOS and Web
and now signify actually resuming/suspending the application.
Expand All @@ -105,6 +107,23 @@ changelog entry.
- On iOS, no longer act as-if the application successfully open all URLs. Override
`application:didFinishLaunchingWithOptions:` and provide the desired behaviour yourself.
- On X11, remove our dependency on libXcursor. (#3749)
- Renamed the following APIs to make it clearer that the sizes apply to the underlying surface:
- `WindowEvent::Resized` to `SurfaceResized`.
- `InnerSizeWriter` to `SurfaceSizeWriter`.
- `WindowAttributes.inner_size` to `surface_size`.
- `WindowAttributes.min_inner_size` to `min_surface_size`.
- `WindowAttributes.max_inner_size` to `max_surface_size`.
- `WindowAttributes.resize_increments` to `surface_resize_increments`.
- `WindowAttributes::with_inner_size` to `with_surface_size`.
- `WindowAttributes::with_min_inner_size` to `with_min_surface_size`.
- `WindowAttributes::with_max_inner_size` to `with_max_surface_size`.
- `WindowAttributes::with_resize_increments` to `with_surface_resize_increments`.
- `Window::inner_size` to `surface_size`.
- `Window::request_inner_size` to `request_surface_size`.
- `Window::set_min_inner_size` to `set_min_surface_size`.
- `Window::set_max_inner_size` to `set_max_surface_size`.

To migrate, you can probably just replace all instances of `inner_size` with `surface_size` in your codebase.
- On X11, fix XInput handling that prevented a new window from getting the focus. (#2841)

### Removed
Expand Down
Loading

0 comments on commit b9f7ed6

Please sign in to comment.