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

Split out Surface from Window #3942

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ece7569
split surface from window, linux impl
jgcodes2020 Oct 9, 2024
6148318
cargo format
jgcodes2020 Oct 9, 2024
cb8e03d
fix docs
jgcodes2020 Oct 9, 2024
9e0955c
fix docs for real this time
jgcodes2020 Oct 9, 2024
9174c7f
actually fix docs
jgcodes2020 Oct 9, 2024
3f83bbb
fix some stupid edits
jgcodes2020 Oct 9, 2024
240486a
move handles and monitor methods to Surface
jgcodes2020 Oct 12, 2024
12fb98a
Downcasting (linux impl)
jgcodes2020 Oct 12, 2024
4f5f6fe
doc fix
jgcodes2020 Oct 12, 2024
4a39a87
Rename WindowId and WindowEvent to SurfaceId and SurfaceEvent
jgcodes2020 Oct 12, 2024
190633b
port web backend names
jgcodes2020 Oct 13, 2024
bc10ce9
Rename enum variant to SurfaceEvent, fix Windows
jgcodes2020 Oct 18, 2024
07cfc01
Fix Linux and Web platforms
jgcodes2020 Oct 18, 2024
dde143b
Add changelog entry
jgcodes2020 Oct 18, 2024
44d205d
implement as_window for Web window
jgcodes2020 Oct 19, 2024
c5efc69
implement Android
jgcodes2020 Oct 21, 2024
f47c3f1
fix SurfaceId on Android
jgcodes2020 Oct 21, 2024
9b34bc5
fix SurfaceId on Android
jgcodes2020 Oct 21, 2024
1428596
try to fix apple and orbital
jgcodes2020 Oct 22, 2024
ae1d413
do impl split for apple and orbital
jgcodes2020 Oct 22, 2024
de71fd5
try to fix impl split for apple and orbital
jgcodes2020 Oct 22, 2024
970f05d
small fixes to get everything to pass CI
jgcodes2020 Oct 22, 2024
1301ea1
even more fixes to pass CI
jgcodes2020 Oct 23, 2024
0e1234d
Merge branch 'master' into window-surface-split
jgcodes2020 Oct 23, 2024
f704c68
post-merge fixes
jgcodes2020 Oct 23, 2024
ac97e65
remove a few remaining instances of WindowId
jgcodes2020 Oct 23, 2024
918ddf6
cargo fmt
jgcodes2020 Oct 23, 2024
a88dac3
improve changelog entry
jgcodes2020 Oct 23, 2024
ddde870
cargo +nightly fmt
jgcodes2020 Oct 24, 2024
be6b958
mark the renaming types stuff as breaking in the changelog
jgcodes2020 Oct 24, 2024
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
20 changes: 10 additions & 10 deletions examples/child_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ fn main() -> Result<(), impl std::error::Error> {

use winit::application::ApplicationHandler;
use winit::dpi::{LogicalPosition, LogicalSize, Position};
use winit::event::{ElementState, KeyEvent, WindowEvent};
use winit::event::{ElementState, KeyEvent, SurfaceEvent};
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::raw_window_handle::HasRawWindowHandle;
use winit::window::{Window, WindowAttributes, WindowId};
use winit::window::{SurfaceId, Window, WindowAttributes};

#[path = "util/fill.rs"]
mod fill;

#[derive(Default)]
struct Application {
parent_window_id: Option<WindowId>,
windows: HashMap<WindowId, Box<dyn Window>>,
parent_window_id: Option<SurfaceId>,
windows: HashMap<SurfaceId, Box<dyn Window>>,
}

impl ApplicationHandler for Application {
Expand All @@ -36,23 +36,23 @@ fn main() -> Result<(), impl std::error::Error> {
fn window_event(
&mut self,
event_loop: &dyn ActiveEventLoop,
window_id: winit::window::WindowId,
event: WindowEvent,
window_id: winit::window::SurfaceId,
event: SurfaceEvent,
) {
match event {
WindowEvent::CloseRequested => {
SurfaceEvent::CloseRequested => {
self.windows.clear();
event_loop.exit();
},
WindowEvent::PointerEntered { device_id: _, .. } => {
SurfaceEvent::PointerEntered { device_id: _, .. } => {
// On x11, println when the cursor entered in a window even if the child window
// is created by some key inputs.
// the child windows are always placed at (0, 0) with size (200, 200) in the
// parent window, so we also can see this log when we move
// the cursor around (200, 200) in parent window.
println!("cursor entered in the window {window_id:?}");
},
WindowEvent::KeyboardInput {
SurfaceEvent::KeyboardInput {
event: KeyEvent { state: ElementState::Pressed, .. },
..
} => {
Expand All @@ -62,7 +62,7 @@ fn main() -> Result<(), impl std::error::Error> {
println!("Child window created with id: {child_id:?}");
self.windows.insert(child_id, child_window);
},
WindowEvent::RedrawRequested => {
SurfaceEvent::RedrawRequested => {
if let Some(window) = self.windows.get(&window_id) {
fill::fill_window(window.as_ref());
}
Expand Down
14 changes: 7 additions & 7 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use ::tracing::{info, warn};
#[cfg(web_platform)]
use web_time as time;
use winit::application::ApplicationHandler;
use winit::event::{ElementState, KeyEvent, StartCause, WindowEvent};
use winit::event::{ElementState, KeyEvent, StartCause, SurfaceEvent};
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
use winit::keyboard::{Key, NamedKey};
use winit::window::{Window, WindowAttributes, WindowId};
use winit::window::{SurfaceId, Window, WindowAttributes};

#[path = "util/fill.rs"]
mod fill;
Expand Down Expand Up @@ -75,16 +75,16 @@ impl ApplicationHandler for ControlFlowDemo {
fn window_event(
&mut self,
_event_loop: &dyn ActiveEventLoop,
_window_id: WindowId,
event: WindowEvent,
_window_id: SurfaceId,
event: SurfaceEvent,
) {
info!("{event:?}");

match event {
WindowEvent::CloseRequested => {
SurfaceEvent::CloseRequested => {
self.close_requested = true;
},
WindowEvent::KeyboardInput {
SurfaceEvent::KeyboardInput {
event: KeyEvent { logical_key: key, state: ElementState::Pressed, .. },
..
} => match key.as_ref() {
Expand All @@ -111,7 +111,7 @@ impl ApplicationHandler for ControlFlowDemo {
},
_ => (),
},
WindowEvent::RedrawRequested => {
SurfaceEvent::RedrawRequested => {
let window = self.window.as_ref().unwrap();
window.pre_present_notify();
fill::fill_window(window.as_ref());
Expand Down
12 changes: 6 additions & 6 deletions examples/pump_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ fn main() -> std::process::ExitCode {
use std::time::Duration;

use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event::SurfaceEvent;
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::platform::pump_events::{EventLoopExtPumpEvents, PumpStatus};
use winit::window::{Window, WindowAttributes, WindowId};
use winit::window::{SurfaceId, Window, WindowAttributes};

#[path = "util/fill.rs"]
mod fill;
Expand All @@ -30,8 +30,8 @@ fn main() -> std::process::ExitCode {
fn window_event(
&mut self,
event_loop: &dyn ActiveEventLoop,
_window_id: WindowId,
event: WindowEvent,
_window_id: SurfaceId,
event: SurfaceEvent,
) {
println!("{event:?}");

Expand All @@ -41,8 +41,8 @@ fn main() -> std::process::ExitCode {
};

match event {
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::RedrawRequested => {
SurfaceEvent::CloseRequested => event_loop.exit(),
SurfaceEvent::RedrawRequested => {
fill::fill_window(window.as_ref());
window.request_redraw();
},
Expand Down
16 changes: 8 additions & 8 deletions examples/run_on_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
use std::time::Duration;

use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event::SurfaceEvent;
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::platform::run_on_demand::EventLoopExtRunOnDemand;
use winit::window::{Window, WindowAttributes, WindowId};
use winit::window::{SurfaceId, Window, WindowAttributes};

#[path = "util/fill.rs"]
mod fill;

#[derive(Default)]
struct App {
idx: usize,
window_id: Option<WindowId>,
window_id: Option<SurfaceId>,
window: Option<Box<dyn Window>>,
}

Expand All @@ -40,10 +40,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fn window_event(
&mut self,
event_loop: &dyn ActiveEventLoop,
window_id: WindowId,
event: WindowEvent,
window_id: SurfaceId,
event: SurfaceEvent,
) {
if event == WindowEvent::Destroyed && self.window_id == Some(window_id) {
if event == SurfaceEvent::Destroyed && self.window_id == Some(window_id) {
println!(
"--------------------------------------------------------- Window {} Destroyed",
self.idx
Expand All @@ -59,7 +59,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};

match event {
WindowEvent::CloseRequested => {
SurfaceEvent::CloseRequested => {
println!(
"--------------------------------------------------------- Window {} \
CloseRequested",
Expand All @@ -68,7 +68,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fill::cleanup_window(window.as_ref());
self.window = None;
},
WindowEvent::RedrawRequested => {
SurfaceEvent::RedrawRequested => {
fill::fill_window(window.as_ref());
},
_ => (),
Expand Down
4 changes: 2 additions & 2 deletions examples/util/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod platform {
use std::num::NonZeroU32;

use softbuffer::{Context, Surface};
use winit::window::{Window, WindowId};
use winit::window::{SurfaceId, Window};

thread_local! {
// NOTE: You should never do things like that, create context and drop it before
Expand All @@ -37,7 +37,7 @@ mod platform {
context: RefCell<Context<&'static dyn Window>>,

/// The hash map of window IDs to surfaces.
surfaces: HashMap<WindowId, Surface<&'static dyn Window, &'static dyn Window>>,
surfaces: HashMap<SurfaceId, Surface<&'static dyn Window, &'static dyn Window>>,
}

impl GraphicsContext {
Expand Down
Loading
Loading