Add an offset to IconSurface, so icon can be offset from custor
This commit is contained in:
parent
ed5de12e69
commit
b4168e69cc
3 changed files with 32 additions and 14 deletions
|
|
@ -6,7 +6,10 @@ use std::collections::HashMap;
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||||
use cctk::sctk::reexports::client::Connection;
|
use cctk::sctk::reexports::client::Connection;
|
||||||
use iced_graphics::{Compositor, compositor};
|
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;
|
use raw_window_handle::HasWindowHandle;
|
||||||
|
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||||
|
|
@ -149,12 +152,13 @@ impl PlatformSpecific {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
|
offset: Vector,
|
||||||
) {
|
) {
|
||||||
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
#[cfg(all(feature = "wayland", target_os = "linux"))]
|
||||||
{
|
{
|
||||||
return self
|
return self
|
||||||
.wayland
|
.wayland
|
||||||
.update_surface_shm(surface, width, height, data);
|
.update_surface_shm(surface, width, height, data, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ use cctk::sctk::seat::keyboard::Modifiers;
|
||||||
use cursor_icon::CursorIcon;
|
use cursor_icon::CursorIcon;
|
||||||
use iced_futures::futures::channel::mpsc;
|
use iced_futures::futures::channel::mpsc;
|
||||||
use iced_graphics::{Compositor, compositor};
|
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::{DisplayHandle, HasDisplayHandle, HasWindowHandle};
|
||||||
use raw_window_handle::{HasRawDisplayHandle, RawWindowHandle};
|
use raw_window_handle::{HasRawDisplayHandle, RawWindowHandle};
|
||||||
use sctk_event::SctkEvent;
|
use sctk_event::SctkEvent;
|
||||||
|
|
@ -245,6 +245,7 @@ impl WaylandSpecific {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
|
offset: Vector,
|
||||||
) {
|
) {
|
||||||
if let Some(subsurface_state) = self.subsurface_state.as_mut() {
|
if let Some(subsurface_state) = self.subsurface_state.as_mut() {
|
||||||
if let RawWindowHandle::Wayland(window) =
|
if let RawWindowHandle::Wayland(window) =
|
||||||
|
|
@ -261,7 +262,7 @@ impl WaylandSpecific {
|
||||||
WlSurface::from_id(self.conn.as_ref().unwrap(), id)
|
WlSurface::from_id(self.conn.as_ref().unwrap(), id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
subsurface_state
|
subsurface_state
|
||||||
.update_surface_shm(&surface, width, height, data);
|
.update_surface_shm(&surface, width, height, data, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// TODO z-order option?
|
// TODO z-order option?
|
||||||
|
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
ContentFit, Element, Length, Rectangle, Size,
|
ContentFit, Element, Length, Rectangle, Size, Vector,
|
||||||
layout::{self, Layout},
|
layout::{self, Layout},
|
||||||
mouse, renderer,
|
mouse, renderer,
|
||||||
widget::{self, Widget},
|
widget::{self, Widget},
|
||||||
|
|
@ -25,7 +25,6 @@ use cctk::sctk::{
|
||||||
compositor::SurfaceData,
|
compositor::SurfaceData,
|
||||||
error::GlobalError,
|
error::GlobalError,
|
||||||
globals::{GlobalData, ProvidesBoundGlobal},
|
globals::{GlobalData, ProvidesBoundGlobal},
|
||||||
shm::slot::SlotPool,
|
|
||||||
reexports::client::{
|
reexports::client::{
|
||||||
Connection, Dispatch, Proxy, QueueHandle, delegate_noop,
|
Connection, Dispatch, Proxy, QueueHandle, delegate_noop,
|
||||||
protocol::{
|
protocol::{
|
||||||
|
|
@ -39,6 +38,7 @@ use cctk::sctk::{
|
||||||
wl_surface::WlSurface,
|
wl_surface::WlSurface,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
shm::slot::SlotPool,
|
||||||
};
|
};
|
||||||
use iced_futures::core::window;
|
use iced_futures::core::window;
|
||||||
use wayland_backend::client::ObjectId;
|
use wayland_backend::client::ObjectId;
|
||||||
|
|
@ -252,7 +252,6 @@ impl PartialEq for SubsurfaceBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Dispatch<WlShmPool, GlobalData> for SctkState {
|
impl Dispatch<WlShmPool, GlobalData> for SctkState {
|
||||||
fn event(
|
fn event(
|
||||||
_: &mut SctkState,
|
_: &mut SctkState,
|
||||||
|
|
@ -300,8 +299,7 @@ impl Dispatch<WlBuffer, GlobalData> for SctkState {
|
||||||
_: &QueueHandle<SctkState>,
|
_: &QueueHandle<SctkState>,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
wl_buffer::Event::Release => {
|
wl_buffer::Event::Release => {}
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -371,18 +369,33 @@ pub struct SubsurfaceState {
|
||||||
|
|
||||||
impl SubsurfaceState {
|
impl SubsurfaceState {
|
||||||
pub fn create_surface(&self) -> WlSurface {
|
pub fn create_surface(&self) -> WlSurface {
|
||||||
self
|
self.wl_compositor
|
||||||
.wl_compositor
|
|
||||||
.create_surface(&self.qh, SurfaceData::new(None, 1))
|
.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 shm = ShmGlobal(&self.wl_shm);
|
||||||
let mut pool = SlotPool::new(width as usize * height as usize * 4, &shm).unwrap();
|
let mut pool =
|
||||||
let (buffer, canvas) = pool.create_buffer(width as i32, height as i32, width as i32 * 4, wl_shm::Format::Argb8888).unwrap();
|
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);
|
canvas[0..width as usize * height as usize * 4].copy_from_slice(data);
|
||||||
surface.damage_buffer(0, 0, width as i32, height as i32);
|
surface.damage_buffer(0, 0, width as i32, height as i32);
|
||||||
buffer.attach_to(&surface);
|
buffer.attach_to(&surface);
|
||||||
|
surface.offset(offset.x as i32, offset.y as i32);
|
||||||
surface.commit();
|
surface.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue