diff --git a/winit/src/platform_specific/mod.rs b/winit/src/platform_specific/mod.rs index b3f516c3bd..77e851802c 100644 --- a/winit/src/platform_specific/mod.rs +++ b/winit/src/platform_specific/mod.rs @@ -128,10 +128,10 @@ impl PlatformSpecific { None } - pub(crate) fn update_surface_shm(&mut self, surface: &dyn HasWindowHandle, width: u32, height: u32, data: &[u8], offset: Vector) { + pub(crate) fn update_surface_shm(&mut self, surface: &dyn HasWindowHandle, width: u32, height: u32, scale: f64, data: &[u8], offset: Vector) { #[cfg(all(feature = "wayland", target_os = "linux"))] { - return self.wayland.update_surface_shm(surface, width, height, data, offset); + return self.wayland.update_surface_shm(surface, width, height, scale, data, offset); } } } diff --git a/winit/src/platform_specific/wayland/mod.rs b/winit/src/platform_specific/wayland/mod.rs index 267e501a71..16c316c0a7 100644 --- a/winit/src/platform_specific/wayland/mod.rs +++ b/winit/src/platform_specific/wayland/mod.rs @@ -239,12 +239,12 @@ impl WaylandSpecific { } } - pub(crate) fn update_surface_shm(&mut self, window: &dyn HasWindowHandle, width: u32, height: u32, data: &[u8], offset: Vector) { + pub(crate) fn update_surface_shm(&mut self, window: &dyn HasWindowHandle, width: u32, height: u32, scale: f64, data: &[u8], offset: Vector) { if let Some(subsurface_state) = self.subsurface_state.as_mut() { if let RawWindowHandle::Wayland(window) = window.window_handle().unwrap().as_raw() { let id = unsafe { ObjectId::from_ptr(WlSurface::interface(), window.surface.as_ptr().cast()).unwrap() }; let surface = WlSurface::from_id(self.conn.as_ref().unwrap(), id).unwrap(); - subsurface_state.update_surface_shm(&surface, width, height, data, offset); + subsurface_state.update_surface_shm(&surface, width, height, scale, data, offset); } } } diff --git a/winit/src/platform_specific/wayland/subsurface_widget.rs b/winit/src/platform_specific/wayland/subsurface_widget.rs index 18730bce58..288dbb6106 100644 --- a/winit/src/platform_specific/wayland/subsurface_widget.rs +++ b/winit/src/platform_specific/wayland/subsurface_widget.rs @@ -377,7 +377,12 @@ impl SubsurfaceState { .create_surface(&self.qh, SurfaceData::new(None, 1)) } - pub fn update_surface_shm(&self, surface: &WlSurface, width: u32, height: u32, data: &[u8], offset: Vector) { + pub fn update_surface_shm(&self, surface: &WlSurface, width: u32, height: u32, scale: f64, data: &[u8], offset: Vector) { + let wp_viewport = self.wp_viewporter.get_viewport( + &surface, + &self.qh, + cctk::sctk::globals::GlobalData, + ); 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(); @@ -385,7 +390,9 @@ impl SubsurfaceState { 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); + wp_viewport.set_destination((width as f64 / scale) as i32, (height as f64 / scale) as i32); surface.commit(); + wp_viewport.destroy(); } fn create_subsurface(&self, parent: &WlSurface) -> SubsurfaceInstance { diff --git a/winit/src/program.rs b/winit/src/program.rs index f61d32f693..1640702925 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -959,7 +959,7 @@ async fn run_instance<'a, P, C>( .update_subsurfaces(id, &surface); let surface = Arc::new(surface); dnd_surface = Some(surface.clone()); - dnd_buffer = Some((viewport.physical_size(), bytes, icon_surface.offset)); + dnd_buffer = Some((viewport.physical_size(), state.scale_factor(), bytes, icon_surface.offset)); Icon::Surface(dnd::DndSurface(surface)) } else { platform_specific_handler @@ -982,8 +982,8 @@ async fn run_instance<'a, P, C>( ); // This needs to be after `wl_data_device::start_drag` for the offset to have an effect - if let (Some(surface), Some((size, bytes, offset))) = (dnd_surface.as_ref(), dnd_buffer) { - platform_specific_handler.update_surface_shm(&surface, size.width, size.height, &bytes, offset); + if let (Some(surface), Some((size, scale, bytes, offset))) = (dnd_surface.as_ref(), dnd_buffer) { + platform_specific_handler.update_surface_shm(&surface, size.width, size.height, scale, &bytes, offset); } } }