diff --git a/winit/src/platform_specific/mod.rs b/winit/src/platform_specific/mod.rs index cd8053c5..940b58ef 100644 --- a/winit/src/platform_specific/mod.rs +++ b/winit/src/platform_specific/mod.rs @@ -6,7 +6,10 @@ use std::collections::HashMap; #[cfg(all(feature = "wayland", target_os = "linux"))] use cctk::sctk::reexports::client::Connection; use iced_graphics::{Compositor, compositor}; -use iced_runtime::{core::window, platform_specific, user_interface}; +use iced_runtime::{ + core::{Vector, window}, + platform_specific, user_interface, +}; use raw_window_handle::HasWindowHandle; #[cfg(all(feature = "wayland", target_os = "linux"))] @@ -149,12 +152,13 @@ impl PlatformSpecific { width: u32, height: u32, data: &[u8], + offset: Vector, ) { #[cfg(all(feature = "wayland", target_os = "linux"))] { return self .wayland - .update_surface_shm(surface, width, height, data); + .update_surface_shm(surface, width, height, data, offset); } } } diff --git a/winit/src/platform_specific/wayland/mod.rs b/winit/src/platform_specific/wayland/mod.rs index bf125e12..24ba60fa 100644 --- a/winit/src/platform_specific/wayland/mod.rs +++ b/winit/src/platform_specific/wayland/mod.rs @@ -17,7 +17,7 @@ use cctk::sctk::seat::keyboard::Modifiers; use cursor_icon::CursorIcon; use iced_futures::futures::channel::mpsc; use iced_graphics::{Compositor, compositor}; -use iced_runtime::core::window; +use iced_runtime::core::{Vector, window}; use raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle}; use raw_window_handle::{HasRawDisplayHandle, RawWindowHandle}; use sctk_event::SctkEvent; @@ -245,6 +245,7 @@ impl WaylandSpecific { width: u32, height: u32, data: &[u8], + offset: Vector, ) { if let Some(subsurface_state) = self.subsurface_state.as_mut() { if let RawWindowHandle::Wayland(window) = @@ -261,7 +262,7 @@ impl WaylandSpecific { WlSurface::from_id(self.conn.as_ref().unwrap(), id) .unwrap(); subsurface_state - .update_surface_shm(&surface, width, height, data); + .update_surface_shm(&surface, width, height, data, offset); } } } diff --git a/winit/src/platform_specific/wayland/subsurface_widget.rs b/winit/src/platform_specific/wayland/subsurface_widget.rs index b2e716c9..76d3e9e9 100644 --- a/winit/src/platform_specific/wayland/subsurface_widget.rs +++ b/winit/src/platform_specific/wayland/subsurface_widget.rs @@ -1,7 +1,7 @@ // TODO z-order option? use crate::core::{ - ContentFit, Element, Length, Rectangle, Size, + ContentFit, Element, Length, Rectangle, Size, Vector, layout::{self, Layout}, mouse, renderer, widget::{self, Widget}, @@ -25,7 +25,6 @@ use cctk::sctk::{ compositor::SurfaceData, error::GlobalError, globals::{GlobalData, ProvidesBoundGlobal}, - shm::slot::SlotPool, reexports::client::{ Connection, Dispatch, Proxy, QueueHandle, delegate_noop, protocol::{ @@ -39,6 +38,7 @@ use cctk::sctk::{ wl_surface::WlSurface, }, }, + shm::slot::SlotPool, }; use iced_futures::core::window; use wayland_backend::client::ObjectId; @@ -252,7 +252,6 @@ impl PartialEq for SubsurfaceBuffer { } } - impl Dispatch for SctkState { fn event( _: &mut SctkState, @@ -300,8 +299,7 @@ impl Dispatch for SctkState { _: &QueueHandle, ) { match event { - wl_buffer::Event::Release => { - } + wl_buffer::Event::Release => {} _ => unreachable!(), } } @@ -371,18 +369,33 @@ pub struct SubsurfaceState { impl SubsurfaceState { pub fn create_surface(&self) -> WlSurface { - self - .wl_compositor + self.wl_compositor .create_surface(&self.qh, SurfaceData::new(None, 1)) } - pub fn update_surface_shm(&self, surface: &WlSurface, width: u32, height: u32, data: &[u8]) { + pub fn update_surface_shm( + &self, + surface: &WlSurface, + width: u32, + height: u32, + data: &[u8], + offset: Vector, + ) { let shm = ShmGlobal(&self.wl_shm); - let mut pool = SlotPool::new(width as usize * height as usize * 4, &shm).unwrap(); - let (buffer, canvas) = pool.create_buffer(width as i32, height as i32, width as i32 * 4, wl_shm::Format::Argb8888).unwrap(); + let mut pool = + SlotPool::new(width as usize * height as usize * 4, &shm).unwrap(); + let (buffer, canvas) = pool + .create_buffer( + width as i32, + height as i32, + width as i32 * 4, + wl_shm::Format::Argb8888, + ) + .unwrap(); canvas[0..width as usize * height as usize * 4].copy_from_slice(data); surface.damage_buffer(0, 0, width as i32, height as i32); buffer.attach_to(&surface); + surface.offset(offset.x as i32, offset.y as i32); surface.commit(); }