From 65760b2434370a5e886b3fc8467225756f18ff09 Mon Sep 17 00:00:00 2001 From: Seaotatop Date: Wed, 7 Jun 2023 12:39:58 -0500 Subject: [PATCH] Added files that didn't get added, removed empty file --- src/backend/udev.rs | 86 +++++++++++++++++++++++++++++++++++++++++ src/main.rs | 1 - src/render.rs | 26 +++++++++++++ src/render/pointer.rs | 90 +++++++++++++++++++++++++++++++++++++++++++ src/tag.rs | 0 5 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 src/backend/udev.rs create mode 100644 src/render.rs create mode 100644 src/render/pointer.rs delete mode 100644 src/tag.rs diff --git a/src/backend/udev.rs b/src/backend/udev.rs new file mode 100644 index 0000000..c863c05 --- /dev/null +++ b/src/backend/udev.rs @@ -0,0 +1,86 @@ +use std::collections::HashMap; + +use smithay::{ + backend::{ + allocator::gbm::{GbmAllocator, GbmDevice}, + drm::{compositor::DrmCompositor, DrmDeviceFd, DrmNode, GbmBufferedSurface}, + renderer::{ + damage::OutputDamageTracker, + gles::GlesRenderer, + multigpu::{gbm::GbmGlesBackend, GpuManager}, + }, + session::libseat::LibSeatSession, + }, + desktop::utils::OutputPresentationFeedback, + output::Output, + reexports::{ + drm::control::crtc, + wayland_server::{backend::GlobalId, protocol::wl_surface::WlSurface, DisplayHandle}, + }, +}; + +use crate::state::State; + +use super::Backend; + +pub struct UdevData { + session: LibSeatSession, + display_handle: DisplayHandle, + primary_gpu: DrmNode, + gpu_manager: GpuManager>, + backends: HashMap, +} + +impl Backend for UdevData { + fn seat_name(&self) -> String { + todo!() + } + + fn reset_buffers(&mut self, output: &Output) { + todo!() + } + + fn early_import(&mut self, surface: &WlSurface) { + todo!() + } +} + +struct BackendData { + surfaces: HashMap, + gbm_device: GbmDevice, +} + +struct SurfaceData { + global: Option, + display_handle: DisplayHandle, + device_id: DrmNode, + render_node: DrmNode, + compositor: SurfaceComposition, + // TODO: dmabuf_feedback +} + +impl Drop for SurfaceData { + fn drop(&mut self) { + if let Some(global) = self.global.take() { + self.display_handle.remove_global::>(global); + } + } +} + +type RenderSurface = + GbmBufferedSurface, Option>; + +type GbmDrmCompositor = DrmCompositor< + GbmAllocator, + GbmDevice, + Option, + DrmDeviceFd, +>; + +enum SurfaceComposition { + Surface { + surface: RenderSurface, + damage_tracker: OutputDamageTracker, + }, + Compositor(GbmDrmCompositor), +} diff --git a/src/main.rs b/src/main.rs index 9f500c2..9b2b59d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ mod layout; mod pointer; mod render; mod state; -mod tag; mod window; mod xdg; diff --git a/src/render.rs b/src/render.rs new file mode 100644 index 0000000..ca41bda --- /dev/null +++ b/src/render.rs @@ -0,0 +1,26 @@ +use smithay::{ + backend::renderer::{ + element::{surface::WaylandSurfaceRenderElement, Wrap}, + ImportAll, ImportMem, + }, + desktop::space::SpaceRenderElements, + render_elements, +}; + +use self::pointer::PointerRenderElement; + +pub mod pointer; + +render_elements! { + pub CustomRenderElements where R: ImportAll + ImportMem; + Pointer=PointerRenderElement, + Surface=WaylandSurfaceRenderElement, +} + +render_elements! { + pub OutputRenderElements where R: ImportAll + ImportMem; + Space=SpaceRenderElements, + Window=Wrap, + Custom=CustomRenderElements, + // TODO: preview +} diff --git a/src/render/pointer.rs b/src/render/pointer.rs new file mode 100644 index 0000000..8c6c95b --- /dev/null +++ b/src/render/pointer.rs @@ -0,0 +1,90 @@ +use smithay::{ + backend::renderer::{ + element::{ + surface::{self, WaylandSurfaceRenderElement}, + texture::{TextureBuffer, TextureRenderElement}, + AsRenderElements, + }, + ImportAll, Renderer, Texture, + }, + input::pointer::CursorImageStatus, + render_elements, + utils::{Physical, Point, Scale}, +}; + +pub struct PointerElement { + texture: Option>, + status: CursorImageStatus, +} + +impl Default for PointerElement { + fn default() -> Self { + Self { + texture: Default::default(), + status: CursorImageStatus::Default, + } + } +} + +impl PointerElement { + pub fn new() -> Self { + Default::default() + } + + pub fn set_status(&mut self, status: CursorImageStatus) { + self.status = status; + } + + pub fn set_texture(&mut self, texture: TextureBuffer) { + self.texture = Some(texture); + } +} + +render_elements! { + pub PointerRenderElement where R: ImportAll; + Surface=WaylandSurfaceRenderElement, + Texture=TextureRenderElement<::TextureId>, +} + +impl AsRenderElements for PointerElement +where + T: Texture + Clone + 'static, + R: Renderer + ImportAll, +{ + type RenderElement = PointerRenderElement; + + fn render_elements>( + &self, + renderer: &mut R, + location: Point, + scale: Scale, + alpha: f32, + ) -> Vec { + match &self.status { + CursorImageStatus::Hidden => vec![], + CursorImageStatus::Default => { + if let Some(texture) = self.texture.as_ref() { + vec![PointerRenderElement::::from( + TextureRenderElement::from_texture_buffer( + location.to_f64(), + texture, + None, + None, + None, + ), + ) + .into()] + } else { + vec![] + } + } + CursorImageStatus::Surface(surface) => { + let elements: Vec> = + surface::render_elements_from_surface_tree( + renderer, surface, location, scale, alpha, + ); + elements.into_iter().map(C::from).collect() + } + } + } +} diff --git a/src/tag.rs b/src/tag.rs deleted file mode 100644 index e69de29..0000000