-
Notifications
You must be signed in to change notification settings - Fork 902
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
Add wayland specific code to examples for windows to appear #780
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] | ||
extern crate smithay_client_toolkit as sctk; | ||
|
||
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] | ||
use winit::os::unix::WindowExt; | ||
|
||
// Wayland requires the commiting of a surface to display a window | ||
pub fn init_wayland(window: &winit::Window) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is emitting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarity, I'd actually rather move the |
||
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] | ||
{ | ||
if let Some(winit_display) = window.get_wayland_display() { | ||
if let Some(surface) = window.get_wayland_surface() { | ||
use self::sctk::reexports::client::protocol::wl_shm; | ||
use self::sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests; | ||
use self::sctk::reexports::client::{Display, Proxy}; | ||
use self::sctk::utils::DoubleMemPool; | ||
use self::sctk::wayland_client::sys::client::wl_display; | ||
use self::sctk::Environment; | ||
|
||
let (width, height): (u32, u32) = window.get_inner_size().unwrap().into(); | ||
let (display, mut event_queue) = | ||
unsafe { Display::from_external_display(winit_display as *mut wl_display) }; | ||
let env = Environment::from_display(&*display, &mut event_queue).unwrap(); | ||
let mut pools = | ||
DoubleMemPool::new(&env.shm, || {}).expect("Failed to create a memory pool !"); | ||
let surface = unsafe { Proxy::from_c_ptr(surface as *mut _) }; | ||
|
||
if let Some(pool) = pools.pool() { | ||
pool.resize(4 * (width * height) as usize) | ||
.expect("Failed to resize the memory pool."); | ||
let new_buffer = pool.buffer( | ||
0, | ||
width as i32, | ||
height as i32, | ||
4 * width as i32, | ||
wl_shm::Format::Argb8888, | ||
); | ||
surface.attach(Some(&new_buffer), 0, 0); | ||
surface.commit(); | ||
event_queue.sync_roundtrip().unwrap(); | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
extern crate winit; | ||
|
||
mod helpers; | ||
|
||
fn main() { | ||
let event_loop = winit::EventsLoop::new(); | ||
let window = winit::WindowBuilder::new().build(&event_loop).unwrap(); | ||
// Wayland requires the commiting of a surface to display a window | ||
helpers::init_wayland(&window); | ||
println!("{:#?}\nPrimary: {:#?}", window.get_available_monitors(), window.get_primary_monitor()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the
smithay-client-toolkit
dependency changed to refer to thegit
version instead of thecrates.io
version? I'm pretty sure will prevent us from pushing this update tocrates.io
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires changes from SCTK that are not yet released, though given how things are coming, next version of SCTK will be a breaking change (upgrade to wayland-client 0.22).
I plan to make the upgrade as part of the event loop 2.0 refactor, so I'd say this PR should wait until the eventloop 2.0 story is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, that was... written in original PR comment. Whoops. I guess I should read everything before making these sorts of comments 😅.