diff --git a/src/backend.rs b/src/backend.rs index 6831b632..6d70597e 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -39,13 +39,11 @@ linear_ids!(ConnectorIds, ConnectorId); linear_ids!(InputDeviceIds, InputDeviceId); linear_ids!(DrmDeviceIds, DrmDeviceId); -pub trait Backend { +pub trait Backend: Any { fn run(self: Rc) -> SpawnedFuture>>; fn clear(&self) { // nothing } - #[cfg_attr(not(feature = "it"), expect(dead_code))] - fn into_any(self: Rc) -> Rc; fn switch_to(&self, vtnr: u32) { let _ = vtnr; diff --git a/src/backends/dummy.rs b/src/backends/dummy.rs index 2a035ffe..4f3b40ad 100644 --- a/src/backends/dummy.rs +++ b/src/backends/dummy.rs @@ -6,7 +6,7 @@ use { }, video::drm::ConnectorType, }, - std::{any::Any, error::Error, rc::Rc}, + std::{error::Error, rc::Rc}, }; pub struct DummyBackend; @@ -15,10 +15,6 @@ impl Backend for DummyBackend { fn run(self: Rc) -> SpawnedFuture>> { unreachable!(); } - - fn into_any(self: Rc) -> Rc { - self - } } pub struct DummyOutput { diff --git a/src/backends/metal.rs b/src/backends/metal.rs index ac5a0fd6..731d3a15 100644 --- a/src/backends/metal.rs +++ b/src/backends/metal.rs @@ -52,7 +52,6 @@ use { }, bstr::ByteSlice, std::{ - any::Any, cell::{Cell, RefCell}, error::Error, ffi::{CStr, CString}, @@ -233,10 +232,6 @@ impl Backend for MetalBackend { } } - fn into_any(self: Rc) -> Rc { - self - } - fn switch_to(&self, vtnr: u32) { self.session.switch_to(vtnr, move |res| { if let Err(e) = res { diff --git a/src/backends/x.rs b/src/backends/x.rs index 7ce71e85..edc74761 100644 --- a/src/backends/x.rs +++ b/src/backends/x.rs @@ -52,7 +52,6 @@ use { }, jay_config::video::GfxApi, std::{ - any::Any, borrow::Cow, cell::{Cell, RefCell}, collections::VecDeque, @@ -251,10 +250,6 @@ impl Backend for XBackend { Ok(()) }) } - - fn into_any(self: Rc) -> Rc { - self - } } pub struct XBackend { diff --git a/src/cpu_worker.rs b/src/cpu_worker.rs index 61ac1bd3..3383de6e 100644 --- a/src/cpu_worker.rs +++ b/src/cpu_worker.rs @@ -45,15 +45,13 @@ pub trait CpuWork: Send { } } -pub trait AsyncCpuWork { +pub trait AsyncCpuWork: Any { fn run( self: Box, eng: &Rc, ring: &Rc, completion: WorkCompletion, ) -> SpawnedFuture; - - fn into_any(self: Box) -> Box; } pub struct WorkCompletion { diff --git a/src/cpu_worker/jobs/read_write.rs b/src/cpu_worker/jobs/read_write.rs index bb1db28f..6ebcfba2 100644 --- a/src/cpu_worker/jobs/read_write.rs +++ b/src/cpu_worker/jobs/read_write.rs @@ -89,7 +89,7 @@ impl CpuWork for ReadWriteWork { } fn async_work_done(&mut self, work: Box) { - let work = work.into_any().downcast().unwrap(); + let work = (work as Box).downcast().unwrap(); self.config = Some(work); } } @@ -144,8 +144,4 @@ impl AsyncCpuWork for ReadWriteWorkConfig { completion.complete(self) }) } - - fn into_any(self: Box) -> Box { - self - } } diff --git a/src/cpu_worker/tests.rs b/src/cpu_worker/tests.rs index 02f6d0ff..4f9ab2b7 100644 --- a/src/cpu_worker/tests.rs +++ b/src/cpu_worker/tests.rs @@ -71,10 +71,6 @@ impl AsyncCpuWork for AsyncWork { completion.complete(self) }) } - - fn into_any(self: Box) -> Box { - self - } } fn run(cancel: bool) { diff --git a/src/cursor.rs b/src/cursor.rs index e09c3dc7..f7305c77 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -335,8 +335,7 @@ impl CursorImageScaled { extents: Rect::new_sized(-xhot, -yhot, width, height).unwrap(), tex: ctx .clone() - .shmem_texture(None, data, ARGB8888, width, height, width * 4, None)? - .into_texture(), + .shmem_texture(None, data, ARGB8888, width, height, width * 4, None)?, })) } } diff --git a/src/gfx_api.rs b/src/gfx_api.rs index 6ae04642..d68b88da 100644 --- a/src/gfx_api.rs +++ b/src/gfx_api.rs @@ -292,9 +292,7 @@ pub enum ResetStatus { Other(u32), } -pub trait GfxBlendBuffer: Debug { - fn into_any(self: Rc) -> Rc; -} +pub trait GfxBlendBuffer: Any + Debug {} pub trait GfxFramebuffer: Debug { fn physical_size(&self) -> (i32, i32); @@ -321,7 +319,6 @@ pub trait GfxFramebuffer: Debug { } pub trait GfxInternalFramebuffer: GfxFramebuffer { - fn into_fb(self: Rc) -> Rc; fn stride(&self) -> i32; fn staging_size(&self) -> usize; @@ -645,17 +642,13 @@ pub trait GfxImage { fn height(&self) -> i32; } -pub trait GfxTexture: Debug { +pub trait GfxTexture: Any + Debug { fn size(&self) -> (i32, i32); - fn as_any(&self) -> &dyn Any; - fn into_any(self: Rc) -> Rc; fn dmabuf(&self) -> Option<&DmaBuf>; fn format(&self) -> &'static Format; } -pub trait ShmGfxTexture: GfxTexture { - fn into_texture(self: Rc) -> Rc; -} +pub trait ShmGfxTexture: GfxTexture {} pub trait AsyncShmGfxTextureCallback { fn completed(self: Rc, res: Result<(), GfxError>); @@ -667,9 +660,8 @@ bitflags! { STAGING_DOWNLOAD = 1 << 1, } -pub trait GfxStagingBuffer { +pub trait GfxStagingBuffer: Any { fn size(&self) -> usize; - fn into_any(self: Rc) -> Rc; } pub trait AsyncShmGfxTextureTransferCancellable { @@ -729,8 +721,6 @@ pub trait AsyncShmGfxTexture: GfxTexture { height: i32, stride: i32, ) -> bool; - - fn into_texture(self: Rc) -> Rc; } pub trait GfxContext: Debug { @@ -792,10 +782,6 @@ pub trait GfxContext: Debug { fn size(&self) -> usize { self.0 } - - fn into_any(self: Rc) -> Rc { - self - } } Rc::new(Dummy(size)) } diff --git a/src/gfx_apis/gl.rs b/src/gfx_apis/gl.rs index d9b62411..e49f44a0 100644 --- a/src/gfx_apis/gl.rs +++ b/src/gfx_apis/gl.rs @@ -95,7 +95,7 @@ use { }, isnt::std_1::vec::IsntVecExt, once_cell::sync::Lazy, - std::{cell::RefCell, error::Error, rc::Rc, sync::Arc}, + std::{any::Any, cell::RefCell, error::Error, rc::Rc, sync::Arc}, thiserror::Error, }; @@ -439,7 +439,7 @@ fn handle_explicit_sync(ctx: &GlRenderContext, img: Option<&Rc>, sync: impl dyn GfxTexture { fn as_gl(&self) -> &Texture { - self.as_any() + (self as &dyn Any) .downcast_ref() .expect("Non-gl texture passed into gl") } diff --git a/src/gfx_apis/gl/renderer/framebuffer.rs b/src/gfx_apis/gl/renderer/framebuffer.rs index e952778f..92b293f4 100644 --- a/src/gfx_apis/gl/renderer/framebuffer.rs +++ b/src/gfx_apis/gl/renderer/framebuffer.rs @@ -127,10 +127,6 @@ impl GfxFramebuffer for Framebuffer { } impl GfxInternalFramebuffer for Framebuffer { - fn into_fb(self: Rc) -> Rc { - self - } - fn stride(&self) -> i32 { self.gl.rb.stride } diff --git a/src/gfx_apis/gl/renderer/texture.rs b/src/gfx_apis/gl/renderer/texture.rs index 1055557f..e6b1d7da 100644 --- a/src/gfx_apis/gl/renderer/texture.rs +++ b/src/gfx_apis/gl/renderer/texture.rs @@ -18,7 +18,6 @@ use { video::dmabuf::DmaBuf, }, std::{ - any::Any, cell::Cell, fmt::{Debug, Formatter}, rc::Rc, @@ -52,14 +51,6 @@ impl GfxTexture for Texture { (self.width(), self.height()) } - fn as_any(&self) -> &dyn Any { - self - } - - fn into_any(self: Rc) -> Rc { - self - } - fn dmabuf(&self) -> Option<&DmaBuf> { self.gl.img.as_ref().map(|i| &i.dmabuf) } @@ -69,11 +60,7 @@ impl GfxTexture for Texture { } } -impl ShmGfxTexture for Texture { - fn into_texture(self: Rc) -> Rc { - self - } -} +impl ShmGfxTexture for Texture {} impl AsyncShmGfxTexture for Texture { fn async_upload( @@ -136,8 +123,4 @@ impl AsyncShmGfxTexture for Texture { && height == self.gl.height && stride == self.gl.stride } - - fn into_texture(self: Rc) -> Rc { - self - } } diff --git a/src/gfx_apis/vulkan.rs b/src/gfx_apis/vulkan.rs index 7124c311..cddac79e 100644 --- a/src/gfx_apis/vulkan.rs +++ b/src/gfx_apis/vulkan.rs @@ -28,7 +28,7 @@ use { format::Format, gfx_api::{ AsyncShmGfxTexture, GfxBlendBuffer, GfxContext, GfxError, GfxFormat, GfxImage, - GfxInternalFramebuffer, GfxStagingBuffer, ResetStatus, STAGING_DOWNLOAD, + GfxInternalFramebuffer, GfxStagingBuffer, GfxTexture, ResetStatus, STAGING_DOWNLOAD, STAGING_UPLOAD, ShmGfxTexture, StagingBufferUsecase, }, gfx_apis::vulkan::{ @@ -272,7 +272,7 @@ impl GfxContext for Context { damage: Option<&[Rect]>, ) -> Result, GfxError> { if let Some(old) = old { - let old = old.into_texture().into_vk(&self.0.device.device); + let old = (old as Rc).into_vk(&self.0.device.device); let shm = match &old.ty { VulkanImageMemory::DmaBuf(_) => unreachable!(), VulkanImageMemory::Blend(_) => unreachable!(), diff --git a/src/gfx_apis/vulkan/blend_buffer.rs b/src/gfx_apis/vulkan/blend_buffer.rs index 5845453c..a6a53813 100644 --- a/src/gfx_apis/vulkan/blend_buffer.rs +++ b/src/gfx_apis/vulkan/blend_buffer.rs @@ -14,7 +14,7 @@ use { ImageTiling, ImageType, ImageViewCreateInfo, ImageViewType, SampleCountFlags, SharingMode, }, gpu_alloc::UsageFlags, - std::{any::Any, cell::Cell, collections::hash_map::Entry, rc::Rc}, + std::{cell::Cell, collections::hash_map::Entry, rc::Rc}, }; impl VulkanRenderer { @@ -113,8 +113,4 @@ impl VulkanRenderer { } } -impl GfxBlendBuffer for VulkanImage { - fn into_any(self: Rc) -> Rc { - self - } -} +impl GfxBlendBuffer for VulkanImage {} diff --git a/src/gfx_apis/vulkan/image.rs b/src/gfx_apis/vulkan/image.rs index ab49b254..a8ae6e2b 100644 --- a/src/gfx_apis/vulkan/image.rs +++ b/src/gfx_apis/vulkan/image.rs @@ -32,7 +32,6 @@ use { }, gpu_alloc::UsageFlags, std::{ - any::Any, cell::Cell, fmt::{Debug, Formatter}, mem, @@ -591,10 +590,6 @@ impl GfxFramebuffer for VulkanImage { } impl GfxInternalFramebuffer for VulkanImage { - fn into_fb(self: Rc) -> Rc { - self - } - fn stride(&self) -> i32 { let VulkanImageMemory::Internal(shm) = &self.ty else { unreachable!(); @@ -637,14 +632,6 @@ impl GfxTexture for VulkanImage { (self.width as _, self.height as _) } - fn as_any(&self) -> &dyn Any { - self - } - - fn into_any(self: Rc) -> Rc { - self - } - fn dmabuf(&self) -> Option<&DmaBuf> { match &self.ty { VulkanImageMemory::DmaBuf(b) => Some(&b.template.dmabuf), @@ -658,11 +645,7 @@ impl GfxTexture for VulkanImage { } } -impl ShmGfxTexture for VulkanImage { - fn into_texture(self: Rc) -> Rc { - self - } -} +impl ShmGfxTexture for VulkanImage {} impl AsyncShmGfxTexture for VulkanImage { fn staging_size(&self) -> usize { @@ -711,10 +694,6 @@ impl AsyncShmGfxTexture for VulkanImage { && self.height == height as u32 && self.stride == stride as u32 } - - fn into_texture(self: Rc) -> Rc { - self - } } impl AsyncShmGfxTextureTransferCancellable for VulkanImage { diff --git a/src/gfx_apis/vulkan/renderer.rs b/src/gfx_apis/vulkan/renderer.rs index 1bf5f8d2..95f6f5ea 100644 --- a/src/gfx_apis/vulkan/renderer.rs +++ b/src/gfx_apis/vulkan/renderer.rs @@ -60,6 +60,7 @@ use { jay_algorithms::rect::Tag, linearize::{Linearize, LinearizeExt, StaticMap, static_map}, std::{ + any::Any, borrow::Cow, cell::{Cell, RefCell}, collections::hash_map::Entry, @@ -1967,8 +1968,7 @@ impl VulkanImage { impl dyn GfxTexture { fn as_vk(&self, device: &Device) -> &VulkanImage { - let img: &VulkanImage = self - .as_any() + let img: &VulkanImage = (self as &dyn Any) .downcast_ref() .expect("Non-vulkan texture passed into vulkan"); img.assert_device(device); @@ -1976,8 +1976,7 @@ impl dyn GfxTexture { } pub(super) fn into_vk(self: Rc, device: &Device) -> Rc { - let img: Rc = self - .into_any() + let img: Rc = (self as Rc) .downcast() .expect("Non-vulkan texture passed into vulkan"); img.assert_device(device); @@ -1987,8 +1986,7 @@ impl dyn GfxTexture { impl dyn GfxBlendBuffer { pub(super) fn into_vk(self: Rc, device: &Device) -> Rc { - let img: Rc = self - .into_any() + let img: Rc = (self as Rc) .downcast() .expect("Non-vulkan blend buffer passed into vulkan"); img.assert_device(device); diff --git a/src/gfx_apis/vulkan/staging.rs b/src/gfx_apis/vulkan/staging.rs index 8a711b4d..7d8c6e36 100644 --- a/src/gfx_apis/vulkan/staging.rs +++ b/src/gfx_apis/vulkan/staging.rs @@ -178,10 +178,6 @@ impl GfxStagingBuffer for VulkanStagingShell { fn size(&self) -> usize { self.size as _ } - - fn into_any(self: Rc) -> Rc { - self - } } impl VulkanStagingShell { @@ -196,8 +192,7 @@ impl VulkanStagingShell { impl dyn GfxStagingBuffer { pub(super) fn into_vk(self: Rc, device: &Device) -> Rc { - let shell: Rc = self - .into_any() + let shell: Rc = (self as Rc) .downcast() .expect("Non-vulkan staging buffer passed into vulkan"); shell.assert_device(device); diff --git a/src/ifs/ext_image_copy/ext_image_copy_capture_frame_v1.rs b/src/ifs/ext_image_copy/ext_image_copy_capture_frame_v1.rs index d90612e4..126e50ab 100644 --- a/src/ifs/ext_image_copy/ext_image_copy_capture_frame_v1.rs +++ b/src/ifs/ext_image_copy/ext_image_copy_capture_frame_v1.rs @@ -138,11 +138,7 @@ impl ExtImageCopyCaptureFrameV1 { Some(s) => s, _ => ctx.create_staging_buffer(bridge.staging_size(), STAGING_DOWNLOAD), }; - let res = f( - bridge.clone().into_fb(), - AcquireSync::Unnecessary, - ReleaseSync::None, - ); + let res = f(bridge.clone(), AcquireSync::Unnecessary, ReleaseSync::None); if let Err(e) = res { log::error!("Could not copy frame to staging texture: {}", ErrorFmt(e)); return Err(FrameFailureReason::Unknown); diff --git a/src/ifs/ext_image_copy/ext_image_copy_capture_session_v1.rs b/src/ifs/ext_image_copy/ext_image_copy_capture_session_v1.rs index 3ac1c7c6..2ea51a6b 100644 --- a/src/ifs/ext_image_copy/ext_image_copy_capture_session_v1.rs +++ b/src/ifs/ext_image_copy/ext_image_copy_capture_session_v1.rs @@ -291,7 +291,7 @@ impl LatchListener for ExtImageCopyCaptureSessionV1 { self.force_capture.set(true); return; } - frame.copy_node(on, tl.tl_as_node(), data.desired_pixel_size()); + frame.copy_node(on, &*tl, data.desired_pixel_size()); } } diff --git a/src/ifs/jay_screencast.rs b/src/ifs/jay_screencast.rs index f55ccec0..2c7d67bb 100644 --- a/src/ifs/jay_screencast.rs +++ b/src/ifs/jay_screencast.rs @@ -195,7 +195,7 @@ impl JayScreencast { AcquireSync::Implicit, ReleaseSync::Implicit, self.client.state.color_manager.srgb_srgb(), - tl.tl_as_node(), + &*tl, &self.client.state, Some(tl.node_absolute_position()), scale, diff --git a/src/ifs/wl_buffer.rs b/src/ifs/wl_buffer.rs index 4c3f4835..9c26747f 100644 --- a/src/ifs/wl_buffer.rs +++ b/src/ifs/wl_buffer.rs @@ -212,12 +212,9 @@ impl WlBuffer { match &*self.storage.borrow() { None => None, Some(s) => match s { - WlBufferStorage::Shm { .. } => surface - .shm_textures - .front() - .tex - .get() - .map(|t| t.into_texture()), + WlBufferStorage::Shm { .. } => { + surface.shm_textures.front().tex.get().map(|t| t as _) + } WlBufferStorage::Dmabuf { tex, .. } => tex.clone(), }, } diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index 2b9c2b55..bb3f4415 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -420,8 +420,8 @@ impl WlSeatGlobal { Some(cn) => cn, _ => return, }; - let kb_foci = collect_kb_foci(tl.clone().tl_into_node()); - cn.cnode_remove_child2(tl.tl_as_node(), true); + let kb_foci = collect_kb_foci(tl.clone()); + cn.cnode_remove_child2(&*tl, true); if !ws.visible.get() { for focus in kb_foci { old_ws.clone().node_do_focus(&focus, Direction::Unspecified); @@ -604,7 +604,7 @@ impl WlSeatGlobal { }; if let Some(pn) = pn.node_into_containing_node() { let cn = ContainerNode::new(&self.state, &ws, tl.clone(), axis); - pn.cnode_replace_child(tl.tl_as_node(), cn); + pn.cnode_replace_child(&*tl, cn); } } @@ -612,7 +612,7 @@ impl WlSeatGlobal { if let Some(tl) = self.keyboard_node.get().node_toplevel() { if let Some(parent) = tl.tl_data().parent.get() { if let Some(tl) = parent.node_toplevel() { - self.focus_node(tl.tl_into_node()); + self.focus_node(tl); } } } @@ -646,10 +646,10 @@ impl WlSeatGlobal { _ => return, }; if !floating { - parent.cnode_remove_child2(tl.tl_as_node(), true); + parent.cnode_remove_child2(&*tl, true); self.state.map_tiled(tl); } else if let Some(ws) = data.workspace.get() { - parent.cnode_remove_child2(tl.tl_as_node(), true); + parent.cnode_remove_child2(&*tl, true); let (width, height) = data.float_size(&ws); self.state.map_floating(tl, width, height, &ws, None); } diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 62428281..9bddd746 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -926,7 +926,7 @@ impl WlSeatGlobal { pub fn focus_toplevel(self: &Rc, n: Rc) { let node = match n.tl_focus_child() { Some(n) => n, - _ => n.tl_into_node(), + _ => n, }; self.focus_node(node); } diff --git a/src/ifs/wl_seat/pointer_owner.rs b/src/ifs/wl_seat/pointer_owner.rs index 8d520a01..3db8e89b 100644 --- a/src/ifs/wl_seat/pointer_owner.rs +++ b/src/ifs/wl_seat/pointer_owner.rs @@ -1089,7 +1089,7 @@ impl WindowManagementGrabUsecase for MoveToplevelGrabPointerOwner { ) { let (x, y) = seat.pointer_cursor.position(); let (x, y) = (x.round_down() - self.dx, y.round_down() - self.dy); - parent.cnode_set_child_position(tl.tl_as_node(), x, y); + parent.cnode_set_child_position(&**tl, x, y); } } @@ -1144,7 +1144,7 @@ impl WindowManagementGrabUsecase for ResizeToplevelGrabPointerOwner { } } if x1.is_some() || x2.is_some() || y1.is_some() || y2.is_some() { - parent.cnode_resize_child(tl.tl_as_node(), x1, y1, x2, y2); + parent.cnode_resize_child(&**tl, x1, y1, x2, y2); } } } @@ -1230,13 +1230,11 @@ impl UiDragUsecase for TileDragUsecase { let placeholder = Rc::new_cyclic(|weak| PlaceholderNode::new_empty(&seat.state, weak)); src_parent .clone() - .cnode_replace_child(src.tl_as_node(), placeholder.clone()); + .cnode_replace_child(&*src, placeholder.clone()); placeholder }; let new_container = |workspace: &Rc| { - src_parent - .clone() - .cnode_remove_child2(src.tl_as_node(), true); + src_parent.clone().cnode_remove_child2(&*src, true); let cn = ContainerNode::new( &seat.state, &workspace, @@ -1251,8 +1249,8 @@ impl UiDragUsecase for TileDragUsecase { return; }; let placeholder = detach(); - dst_parent.cnode_replace_child(dst.tl_as_node(), src); - src_parent.cnode_replace_child(placeholder.tl_as_node(), dst); + dst_parent.cnode_replace_child(&*dst, src); + src_parent.cnode_replace_child(&*placeholder, dst); } TddType::Split { node, @@ -1268,12 +1266,12 @@ impl UiDragUsecase for TileDragUsecase { }; let placeholder = detach(); let cn = ContainerNode::new(&seat.state, &ws, node.clone(), split); - pn.cnode_replace_child(node.tl_as_node(), cn.clone()); + pn.cnode_replace_child(&*node, cn.clone()); match before { - true => cn.add_child_before(node.tl_as_node(), src), - false => cn.add_child_after(node.tl_as_node(), src), + true => cn.add_child_before(&*node, src), + false => cn.add_child_after(&*node, src), } - src_parent.cnode_remove_child(placeholder.tl_as_node()); + src_parent.cnode_remove_child(&*placeholder); } TddType::Insert { container, @@ -1282,10 +1280,10 @@ impl UiDragUsecase for TileDragUsecase { } => { let placeholder = detach(); match before { - true => container.add_child_before(neighbor.tl_as_node(), src), - false => container.add_child_after(neighbor.tl_as_node(), src), + true => container.add_child_before(&*neighbor, src), + false => container.add_child_after(&*neighbor, src), }; - src_parent.cnode_remove_child(placeholder.tl_as_node()); + src_parent.cnode_remove_child(&*placeholder); } TddType::NewWorkspace { output } => { new_container(&output.ensure_workspace()); @@ -1294,12 +1292,12 @@ impl UiDragUsecase for TileDragUsecase { new_container(&workspace); } TddType::MoveToWorkspace { workspace } => { - src_parent.cnode_remove_child(src.tl_as_node()); + src_parent.cnode_remove_child(&*src); seat.state.map_tiled_on(src, &workspace); } TddType::MoveToNewWorkspace { output } => { let ws = output.generate_workspace(); - src_parent.cnode_remove_child(src.tl_as_node()); + src_parent.cnode_remove_child(&*src); seat.state.map_tiled_on(src, &ws); } } diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index ec7bdf1a..59c72a61 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -1656,7 +1656,7 @@ impl WlSurface { pub fn request_activation(&self) { if let Some(tl) = self.toplevel.get() { - tl.tl_data().request_attention(tl.tl_as_node()); + tl.tl_data().request_attention(&*tl); } } diff --git a/src/ifs/wl_surface/tray.rs b/src/ifs/wl_surface/tray.rs index 96424d07..273a8380 100644 --- a/src/ifs/wl_surface/tray.rs +++ b/src/ifs/wl_surface/tray.rs @@ -77,7 +77,6 @@ impl TrayItemData { pub trait DynTrayItem: Node { fn send_current_configure(&self); fn data(&self) -> &TrayItemData; - fn into_node(self: Rc) -> Rc; fn set_position(&self, abs_pos: Rect, rel_pos: Rect); fn destroy_popups(&self); fn destroy_node(&self); @@ -93,10 +92,6 @@ impl DynTrayItem for T { ::data(self) } - fn into_node(self: Rc) -> Rc { - self - } - fn set_position(&self, abs_pos: Rect, rel_pos: Rect) { let data = self.data(); data.surface diff --git a/src/ifs/wl_surface/x_surface/xwindow.rs b/src/ifs/wl_surface/x_surface/xwindow.rs index 7a87b269..eb4981cf 100644 --- a/src/ifs/wl_surface/x_surface/xwindow.rs +++ b/src/ifs/wl_surface/x_surface/xwindow.rs @@ -488,8 +488,6 @@ impl ToplevelNodeBase for Xwindow { } impl StackedNode for Xwindow { - stacked_node_impl!(); - fn stacked_set_visible(&self, visible: bool) { self.damage_override_redirect(); self.tl_set_visible(visible); diff --git a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs index 937808d2..270a8cdf 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs @@ -356,8 +356,6 @@ impl Node for XdgPopup { } impl StackedNode for XdgPopup { - stacked_node_impl!(); - fn stacked_prepare_set_visible(&self) { self.set_visible_prepared.set(true); } diff --git a/src/it.rs b/src/it.rs index f91dd4d4..1ce659ee 100644 --- a/src/it.rs +++ b/src/it.rs @@ -16,7 +16,7 @@ use { log::Level, parking_lot::Mutex, std::{ - cell::Cell, collections::VecDeque, future::pending, pin::Pin, rc::Rc, sync::Arc, + any::Any, cell::Cell, collections::VecDeque, future::pending, pin::Pin, rc::Rc, sync::Arc, time::SystemTime, }, uapi::c, @@ -132,7 +132,7 @@ fn run_test(it_run: &ItRun, test: &'static dyn TestCase, cfg: Rc) { sun_path[path.len()] = 0; addr }; - let backend: Rc = state.backend.get().into_any().downcast().unwrap(); + let backend: Rc = (state.backend.get() as Rc).downcast().unwrap(); let testrun = Rc::new(TestRun { state: state.clone(), backend, diff --git a/src/it/test_backend.rs b/src/it/test_backend.rs index 31275aad..a098e208 100644 --- a/src/it/test_backend.rs +++ b/src/it/test_backend.rs @@ -30,7 +30,7 @@ use { }, }, bstr::ByteSlice, - std::{any::Any, cell::Cell, error::Error, io, os::unix::ffi::OsStrExt, pin::Pin, rc::Rc}, + std::{cell::Cell, error::Error, io, os::unix::ffi::OsStrExt, pin::Pin, rc::Rc}, thiserror::Error, uapi::c, }; @@ -287,10 +287,6 @@ impl Backend for TestBackend { }) } - fn into_any(self: Rc) -> Rc { - self - } - fn switch_to(&self, vtnr: u32) { let _ = vtnr; } diff --git a/src/it/test_gfx_api.rs b/src/it/test_gfx_api.rs index 658358da..ecbfdc10 100644 --- a/src/it/test_gfx_api.rs +++ b/src/it/test_gfx_api.rs @@ -278,14 +278,6 @@ impl GfxTexture for TestGfxImage { } } - fn as_any(&self) -> &dyn Any { - self - } - - fn into_any(self: Rc) -> Rc { - self - } - fn dmabuf(&self) -> Option<&DmaBuf> { match self { TestGfxImage::Shm(_) => None, @@ -298,11 +290,7 @@ impl GfxTexture for TestGfxImage { } } -impl ShmGfxTexture for TestGfxImage { - fn into_texture(self: Rc) -> Rc { - self - } -} +impl ShmGfxTexture for TestGfxImage {} impl AsyncShmGfxTexture for TestGfxImage { fn async_upload( @@ -344,10 +332,6 @@ impl AsyncShmGfxTexture for TestGfxImage { }; shm.format == format && shm.width == width && shm.height == height && shm.stride == stride } - - fn into_texture(self: Rc) -> Rc { - self - } } impl GfxImage for TestGfxImage { @@ -573,10 +557,6 @@ impl GfxFramebuffer for TestGfxFb { } impl GfxInternalFramebuffer for TestGfxFb { - fn into_fb(self: Rc) -> Rc { - self - } - fn stride(&self) -> i32 { let TestGfxImage::Shm(shm) = &*self.img else { unreachable!(); @@ -604,7 +584,7 @@ impl GfxInternalFramebuffer for TestGfxFb { impl dyn GfxTexture { fn as_native(&self) -> &TestGfxImage { - self.as_any() + (self as &dyn Any) .downcast_ref() .expect("Non-test texture passed into vulkan") } diff --git a/src/it/test_utils/test_object_ext.rs b/src/it/test_utils/test_object_ext.rs index 7ef4ad1a..34355b2f 100644 --- a/src/it/test_utils/test_object_ext.rs +++ b/src/it/test_utils/test_object_ext.rs @@ -1,6 +1,6 @@ use { crate::{it::test_error::TestError, object::Object}, - std::rc::Rc, + std::{any::Any, rc::Rc}, }; pub trait TestObjectExt { @@ -9,7 +9,7 @@ pub trait TestObjectExt { impl TestObjectExt for dyn Object { fn downcast(self: Rc) -> Result, TestError> { - match self.into_any().downcast() { + match (self as Rc).downcast() { Ok(t) => Ok(t), _ => bail!("Object has an incompatible type id"), } diff --git a/src/macros.rs b/src/macros.rs index 13d1db66..c16639b9 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -49,10 +49,6 @@ macro_rules! object_base { $version } - fn into_any($self: std::rc::Rc) -> std::rc::Rc { - $self - } - fn handle_request( $self: std::rc::Rc, client: &crate::client::Client, @@ -458,14 +454,6 @@ macro_rules! fatal { }} } -macro_rules! stacked_node_impl { - () => { - fn stacked_into_node(self: Rc) -> Rc { - self - } - }; -} - macro_rules! bitflags { ($name:ident: $rep:ty; $($var:ident = $val:expr,)*) => { #[derive(Copy, Clone, Eq, PartialEq, Default)] diff --git a/src/object.rs b/src/object.rs index 728def76..24005b66 100644 --- a/src/object.rs +++ b/src/object.rs @@ -36,11 +36,9 @@ impl Display for ObjectId { } } -pub trait ObjectBase { +pub trait ObjectBase: Any { fn id(&self) -> ObjectId; fn version(&self) -> Version; - #[cfg_attr(not(feature = "it"), expect(dead_code))] - fn into_any(self: Rc) -> Rc; fn handle_request( self: Rc, client: &Client, diff --git a/src/portal/ptl_text.rs b/src/portal/ptl_text.rs index 02ea796d..5e8da166 100644 --- a/src/portal/ptl_text.rs +++ b/src/portal/ptl_text.rs @@ -98,5 +98,5 @@ pub fn render( None, ) .ok() - .map(|t| (t.into_texture(), measurement)) + .map(|t| (t as _, measurement)) } diff --git a/src/renderer.rs b/src/renderer.rs index afa16502..16841c33 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -80,7 +80,7 @@ impl Renderer<'_> { let srgb_srgb = self.state.color_manager.srgb_srgb(); let srgb = &srgb_srgb.linear; if let Some(fs) = fullscreen { - fs.tl_as_node().node_render(self, x, y, None); + fs.node_render(self, x, y, None); } else { render_layer!(output.layers[0]); render_layer!(output.layers[1]); diff --git a/src/state.rs b/src/state.rs index 703d8f7a..66c74e5d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -678,7 +678,7 @@ impl State { .get() .and_then(|n| n.node_into_container()); if let Some(lap) = lap { - lap.add_child_after(la.tl_as_node(), node); + lap.add_child_after(&*la, node); } else { c.append_child(node); } @@ -1120,7 +1120,7 @@ impl State { acquire_sync, ReleaseSync::None, src_cd, - &fb.clone().into_fb(), + &(fb.clone() as Rc), AcquireSync::Unnecessary, ReleaseSync::None, transform, diff --git a/src/text.rs b/src/text.rs index 06b49a1c..2052a41c 100644 --- a/src/text.rs +++ b/src/text.rs @@ -383,12 +383,7 @@ impl TextTexture { } pub fn texture(&self) -> Option> { - self.data - .textures - .front() - .tex - .get() - .map(|t| t.into_texture()) + self.data.textures.front().tex.get().map(|t| t as _) } fn apply_config(&self, on_completed: Rc, config: Config<'_>) { diff --git a/src/tree/container.rs b/src/tree/container.rs index f6fb23ab..91728ce6 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -856,7 +856,7 @@ impl ContainerNode { return; } if !preserve_focus { - let seats = collect_kb_foci(mc.node.clone().tl_into_node()); + let seats = collect_kb_foci(mc.node.clone()); mc.node.tl_set_visible(false); for seat in seats { child @@ -898,7 +898,7 @@ impl ContainerNode { let mut seats = SmallVec::<[_; 3]>::new(); for other in self.children.iter() { if other.node.node_id() != child_id { - collect_kb_foci2(other.node.clone().tl_into_node(), &mut seats); + collect_kb_foci2(other.node.clone(), &mut seats); other.node.tl_set_visible(false); } } @@ -996,9 +996,7 @@ impl ContainerNode { // CASE 1: This is the only child of the container. Replace the container by the child. if self.num_children.get() == 1 { if let Some(parent) = self.toplevel_data.parent.get() { - if !self.toplevel_data.is_fullscreen.get() - && parent.cnode_accepts_child(child.tl_as_node()) - { + if !self.toplevel_data.is_fullscreen.get() && parent.cnode_accepts_child(&*child) { parent.cnode_replace_child(self.deref(), child.clone()); } } @@ -1019,13 +1017,13 @@ impl ContainerNode { }; if let Some(neighbor) = neighbor { if let Some(cn) = neighbor.node.clone().node_into_container() { - if cn.cnode_accepts_child(child.tl_as_node()) { + if cn.cnode_accepts_child(&*child) { if let Some(mc) = self.mono_child.get() { if mc.node.node_id() == child.node_id() { self.activate_child2(&neighbor, true); } } - self.cnode_remove_child2(child.tl_as_node(), true); + self.cnode_remove_child2(&*child, true); cn.insert_child(child, direction); return; } @@ -1053,7 +1051,7 @@ impl ContainerNode { Some(p) => p, _ => return, }; - self.cnode_remove_child2(child.tl_as_node(), true); + self.cnode_remove_child2(&*child, true); match prev { true => parent.add_child_before(&*neighbor, child.clone()), false => parent.add_child_after(&*neighbor, child.clone()), @@ -1567,7 +1565,7 @@ impl Node for ContainerNode { if content.contains(x, y) { let (x, y) = content.translate(x, y); tree.push(FoundNode { - node: child.node.clone().tl_into_node(), + node: child.node.clone(), x, y, }); diff --git a/src/tree/float.rs b/src/tree/float.rs index 53e21f92..5c61fe69 100644 --- a/src/tree/float.rs +++ b/src/tree/float.rs @@ -614,7 +614,7 @@ impl Node for FloatNode { let x = x - bw; let y = y - bw - th - 1; tree.push(FoundNode { - node: child.clone().tl_into_node(), + node: child.clone(), x, y, }); @@ -833,8 +833,6 @@ impl ContainingNode for FloatNode { } impl StackedNode for FloatNode { - stacked_node_impl!(); - fn stacked_set_visible(&self, visible: bool) { if self.visible.replace(visible) != visible { self.state.damage(self.position.get()); diff --git a/src/tree/output.rs b/src/tree/output.rs index 8a67c9ad..11277e08 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -881,7 +881,7 @@ impl OutputNode { let (x, y) = ext.translate(x_abs, y_abs); let idx = tree.len(); tree.push(FoundNode { - node: stacked.deref().clone().stacked_into_node(), + node: stacked.deref().clone(), x, y, }); @@ -1401,11 +1401,11 @@ impl Node for OutputNode { } if let Some(fs) = fullscreen { tree.push(FoundNode { - node: fs.clone().tl_into_node(), + node: fs.clone(), x, y, }); - fs.tl_as_node().node_find_tree_at(x, y, tree, usecase) + fs.node_find_tree_at(x, y, tree, usecase) } else { let mut search_layers = true; let non_exclusive_rect = self.non_exclusive_rect_rel.get(); @@ -1419,7 +1419,7 @@ impl Node for OutputNode { if pos.contains(x, y) { let (x, y) = pos.translate(x, y); tree.push(FoundNode { - node: item.deref().clone().into_node(), + node: item.deref().clone(), x, y, }); diff --git a/src/tree/stacked.rs b/src/tree/stacked.rs index 1a5d6cbc..c5ad3f41 100644 --- a/src/tree/stacked.rs +++ b/src/tree/stacked.rs @@ -1,7 +1,6 @@ -use {crate::tree::Node, std::rc::Rc}; +use crate::tree::Node; pub trait StackedNode: Node { - fn stacked_into_node(self: Rc) -> Rc; fn stacked_prepare_set_visible(&self) { // nothing } diff --git a/src/tree/toplevel.rs b/src/tree/toplevel.rs index 37c43c0e..4d5ec230 100644 --- a/src/tree/toplevel.rs +++ b/src/tree/toplevel.rs @@ -40,9 +40,6 @@ use { tree_id!(ToplevelNodeId); pub trait ToplevelNode: ToplevelNodeBase { - fn tl_as_node(&self) -> &dyn Node; - fn tl_into_node(self: Rc) -> Rc; - fn tl_into_dyn(self: Rc) -> Rc; fn tl_surface_active_changed(&self, active: bool); fn tl_set_fullscreen(self: Rc, fullscreen: bool); fn tl_title_changed(&self); @@ -56,18 +53,6 @@ pub trait ToplevelNode: ToplevelNodeBase { } impl ToplevelNode for T { - fn tl_as_node(&self) -> &dyn Node { - self - } - - fn tl_into_node(self: Rc) -> Rc { - self - } - - fn tl_into_dyn(self: Rc) -> Rc { - self - } - fn tl_surface_active_changed(&self, active: bool) { let data = self.tl_data(); data.update_active(self, || { @@ -79,10 +64,10 @@ impl ToplevelNode for T { let data = self.tl_data(); if fullscreen { if let Some(ws) = data.workspace.get() { - data.set_fullscreen2(&data.state, self.clone().tl_into_dyn(), &ws); + data.set_fullscreen2(&data.state, self.clone(), &ws); } } else { - data.unset_fullscreen(&data.state, self.clone().tl_into_dyn()); + data.unset_fullscreen(&data.state, self.clone()); } } @@ -323,7 +308,7 @@ impl ToplevelData { if active_old != active_new { tl.tl_set_active(active_new); if let Some(parent) = self.parent.get() { - parent.node_child_active_changed(tl.tl_as_node(), active_new, 1); + parent.node_child_active_changed(tl, active_new, 1); } } } @@ -480,14 +465,14 @@ impl ToplevelData { } let placeholder = Rc::new_cyclic(|weak| PlaceholderNode::new_for(state, node.clone(), weak)); - parent.cnode_replace_child(node.tl_as_node(), placeholder.clone()); + parent.cnode_replace_child(&*node, placeholder.clone()); let mut kb_foci = Default::default(); if ws.visible.get() { if let Some(container) = ws.container.get() { kb_foci = collect_kb_foci(container); } for stacked in ws.stacked.iter() { - collect_kb_foci2(stacked.deref().clone().stacked_into_node(), &mut kb_foci); + collect_kb_foci2(stacked.deref().clone(), &mut kb_foci); } } *data = Some(FullscreenedData { @@ -501,9 +486,7 @@ impl ToplevelData { node.clone() .tl_change_extents(&ws.output.get().global.pos.get()); for seat in kb_foci { - node.clone() - .tl_into_node() - .node_do_focus(&seat, Direction::Unspecified); + node.clone().node_do_focus(&seat, Direction::Unspecified); } } @@ -527,7 +510,7 @@ impl ToplevelData { ); return; } - Some(f) if f.tl_as_node().node_id() != node.tl_as_node().node_id() => { + Some(f) if f.node_id() != node.node_id() => { log::error!( "Node is supposed to be fullscreened on a workspace but the workspace has a different node attached." ); @@ -542,12 +525,10 @@ impl ToplevelData { } let parent = fd.placeholder.tl_data().parent.get().unwrap(); parent.cnode_replace_child(fd.placeholder.deref(), node.clone()); - if node.tl_as_node().node_visible() { + if node.node_visible() { let kb_foci = collect_kb_foci(fd.placeholder.clone()); for seat in kb_foci { - node.clone() - .tl_into_node() - .node_do_focus(&seat, Direction::Unspecified); + node.clone().node_do_focus(&seat, Direction::Unspecified); } } fd.placeholder diff --git a/src/tree/workspace.rs b/src/tree/workspace.rs index d374517e..fd98dc93 100644 --- a/src/tree/workspace.rs +++ b/src/tree/workspace.rs @@ -277,7 +277,7 @@ impl Node for WorkspaceNode { visitor.visit_container(&c); } if let Some(fs) = self.fullscreen.get() { - fs.tl_into_node().node_visit(visitor); + fs.node_visit(visitor); } } @@ -291,7 +291,7 @@ impl Node for WorkspaceNode { fn node_do_focus(self: Rc, seat: &Rc, direction: Direction) { if let Some(fs) = self.fullscreen.get() { - fs.tl_into_node().node_do_focus(seat, direction); + fs.node_do_focus(seat, direction); } else if let Some(container) = self.container.get() { container.node_do_focus(seat, direction); } else if let Some(float) = self @@ -359,7 +359,7 @@ impl ContainingNode for WorkspaceNode { fn cnode_replace_child(self: Rc, old: &dyn Node, new: Rc) { if let Some(container) = self.container.get() { if container.node_id() == old.node_id() { - let new = match new.tl_into_node().node_into_container() { + let new = match new.node_into_container() { Some(c) => c, _ => { log::error!("cnode_replace_child called with non-container new"); @@ -383,7 +383,7 @@ impl ContainingNode for WorkspaceNode { } } if let Some(fs) = self.fullscreen.get() { - if fs.tl_as_node().node_id() == child.node_id() { + if fs.node_id() == child.node_id() { self.remove_fullscreen_node(); return; }