1
0
Fork 0
forked from wry/wry

macros: add opaque macro

This commit is contained in:
Julian Orth 2026-04-02 16:29:43 +02:00
parent 0a5b00f269
commit 9880f78ec4
16 changed files with 60 additions and 115 deletions

View file

@ -10,13 +10,13 @@ use {
wl_display::WlDisplay,
wl_registry::WlRegistry,
wl_surface::{WlSurface, commit_timeline::CommitTimelines},
xdg_activation_token_v1::ActivationToken,
},
leaks::Tracker,
object::{Interface, Object, ObjectId, WL_DISPLAY_ID},
security_context_acceptor::AcceptorMetadata,
state::State,
utils::{
activation_token::ActivationToken,
asyncevent::AsyncEvent,
buffd::{MsgFormatter, MsgParser, MsgParserError, OutBufferSwapchain},
copyhashmap::{CopyHashMap, Locked},

View file

@ -9,13 +9,12 @@ use {
config::handler::ConfigProxyHandler,
ifs::wl_seat::SeatId,
state::State,
tree::{TileState, ToplevelData},
tree::{TileState, ToplevelData, ToplevelIdentifier},
utils::{
clonecell::CloneCell,
nice::{JAY_NO_REALTIME, dont_allow_config_so},
numcell::NumCell,
ptr_ext::PtrExt,
toplevel_identifier::ToplevelIdentifier,
unlink_on_drop::UnlinkOnDrop,
xrd::xrd,
},

View file

@ -28,8 +28,8 @@ use {
tagged_acceptor::TaggedAcceptorError,
theme::{ThemeColor, ThemeSized},
tree::{
ContainerSplit, OutputNode, TearingMode, TileState, ToplevelData, ToplevelNode,
VrrMode, WorkspaceNode, toplevel_create_split, toplevel_parent_container,
ContainerSplit, OutputNode, TearingMode, TileState, ToplevelData, ToplevelIdentifier,
ToplevelNode, VrrMode, WorkspaceNode, toplevel_create_split, toplevel_parent_container,
toplevel_set_floating, toplevel_set_workspace,
},
utils::{
@ -40,7 +40,6 @@ use {
oserror::{OsError, OsErrorExt},
stack::Stack,
timer::{TimerError, TimerFd},
toplevel_identifier::ToplevelIdentifier,
},
},
bincode::Options,

View file

@ -10,11 +10,8 @@ use {
criteria::{CritMgrExt, CritUpstreamNode, crit_leaf::CritLeafMatcher},
egui_adapter::egui_platform::icons::ICON_OPEN_IN_NEW,
state::State,
tree::ToplevelData,
utils::{
copyhashmap::CopyHashMap, static_text::StaticText,
toplevel_identifier::ToplevelIdentifier,
},
tree::{ToplevelData, ToplevelIdentifier},
utils::{copyhashmap::CopyHashMap, static_text::StaticText},
},
ahash::AHashMap,
egui::{

View file

@ -9,12 +9,11 @@ use {
criteria::{CritMgrExt, CritUpstreamNode, crit_leaf::CritLeafMatcher},
egui_adapter::egui_platform::icons::ICON_OPEN_IN_NEW,
state::State,
tree::{NodeId, ToplevelData, ToplevelNode, ToplevelType},
tree::{NodeId, ToplevelData, ToplevelIdentifier, ToplevelNode, ToplevelType},
utils::{
copyhashmap::CopyHashMap,
event_listener::{EventListener, LazyEventSourceListener},
static_text::StaticText,
toplevel_identifier::ToplevelIdentifier,
},
},
ahash::AHashMap,

View file

@ -29,11 +29,8 @@ use {
},
ifs::wl_seat::WlSeatGlobal,
state::State,
tree::{NodeId, ToplevelData, ToplevelNode},
utils::{
copyhashmap::CopyHashMap, hash_map_ext::HashMapExt, queue::AsyncQueue,
toplevel_identifier::ToplevelIdentifier,
},
tree::{NodeId, ToplevelData, ToplevelIdentifier, ToplevelNode},
utils::{copyhashmap::CopyHashMap, hash_map_ext::HashMapExt, queue::AsyncQueue},
},
jay_config::window::{ContentType, WindowType},
linearize::static_map,

View file

@ -30,7 +30,8 @@ use {
leaks::Tracker,
object::{Object, Version},
screenshoter::take_screenshot,
utils::{errorfmt::ErrorFmt, toplevel_identifier::ToplevelIdentifier},
tree::ToplevelIdentifier,
utils::errorfmt::ErrorFmt,
wire::{
JayCompositorId, JayScreenshotId,
jay_compositor::{self, *},

View file

@ -16,9 +16,10 @@ use {
rect::Rect,
tree::{
self, ContainerNode, DisplayNode, FloatNode, Node, NodeVisitor, OutputNode,
PlaceholderNode, ToplevelData, ToplevelNodeBase, ToplevelType, WorkspaceNode,
PlaceholderNode, ToplevelData, ToplevelIdentifier, ToplevelNodeBase, ToplevelType,
WorkspaceNode,
},
utils::{opaque::OpaqueError, opt::Opt, toplevel_identifier::ToplevelIdentifier},
utils::{opaque::OpaqueError, opt::Opt},
wire::{JayTreeQueryId, jay_tree_query::*},
},
isnt::std_1::primitive::IsntStrExt,

View file

@ -3,13 +3,14 @@ use {
client::{Client, ClientError},
leaks::Tracker,
object::{Object, Version},
utils::activation_token::{ActivationToken, activation_token},
wire::{XdgActivationTokenV1Id, xdg_activation_token_v1::*},
},
std::{cell::Cell, rc::Rc},
thiserror::Error,
};
opaque!(ActivationToken, activation_token);
const MAX_TOKENS_PER_CLIENT: usize = 8;
pub struct XdgActivationTokenV1 {

View file

@ -2,10 +2,10 @@ use {
crate::{
client::{Client, ClientError},
globals::{Global, GlobalName},
ifs::xdg_activation_token_v1::XdgActivationTokenV1,
ifs::xdg_activation_token_v1::{ActivationToken, XdgActivationTokenV1},
leaks::Tracker,
object::{Object, Version},
utils::{activation_token::ActivationToken, errorfmt::ErrorFmt, opaque::OpaqueError},
utils::{errorfmt::ErrorFmt, opaque::OpaqueError},
wire::{XdgActivationV1Id, xdg_activation_v1::*},
},
std::rc::Rc,

View file

@ -900,3 +900,36 @@ macro_rules! dynload {
});
};
}
macro_rules! opaque {
($ty:ident, $fun:ident) => {
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash, Ord, PartialOrd)]
pub struct $ty(crate::utils::opaque::Opaque);
unsafe impl crate::utils::clonecell::UnsafeCellCloneSafe for $ty {}
pub fn $fun() -> $ty {
$ty(crate::utils::opaque::opaque())
}
impl $ty {
pub fn to_string(self) -> arrayvec::ArrayString<{ crate::utils::opaque::OPAQUE_LEN }> {
self.0.to_string()
}
}
impl std::fmt::Display for $ty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::str::FromStr for $ty {
type Err = crate::utils::opaque::OpaqueError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}
};
}

View file

@ -87,6 +87,7 @@ use {
workspace_manager::WorkspaceManagerState,
wp_drm_lease_connector_v1::WpDrmLeaseConnectorV1,
wp_drm_lease_device_v1::WpDrmLeaseDeviceV1Global,
xdg_activation_token_v1::ActivationToken,
zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1,
zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1,
zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1,
@ -107,13 +108,12 @@ use {
tree::{
ContainerNode, ContainerSplit, Direction, DisplayNode, FindTreeUsecase, FloatNode,
FoundNode, LatchListener, Node, NodeIds, NodeVisitorBase, OutputNode, PlaceholderNode,
TearingMode, TileState, ToplevelData, ToplevelNode, ToplevelNodeBase, Transform,
VrrMode, WorkspaceDisplayOrder, WorkspaceNode, WsMoveConfig, generic_node_visitor,
move_ws_to_output,
TearingMode, TileState, ToplevelData, ToplevelIdentifier, ToplevelNode,
ToplevelNodeBase, Transform, VrrMode, WorkspaceDisplayOrder, WorkspaceNode,
WsMoveConfig, generic_node_visitor, move_ws_to_output,
},
udmabuf::UdmabufHolder,
utils::{
activation_token::ActivationToken,
asyncevent::AsyncEvent,
bindings::Bindings,
clonecell::CloneCell,
@ -128,7 +128,6 @@ use {
queue::AsyncQueue,
refcounted::RefCounted,
run_toplevel::RunToplevel,
toplevel_identifier::ToplevelIdentifier,
},
video::{
dmabuf::DmaBufIds,

View file

@ -31,15 +31,9 @@ use {
NodeLayerLink, OutputNode, PlaceholderNode, WorkspaceNode,
},
utils::{
array_to_tuple::ArrayToTuple,
clonecell::CloneCell,
copyhashmap::CopyHashMap,
event_listener::LazyEventSource,
hash_map_ext::HashMapExt,
numcell::NumCell,
rc_eq::rc_eq,
threshold_counter::ThresholdCounter,
toplevel_identifier::{ToplevelIdentifier, toplevel_identifier},
array_to_tuple::ArrayToTuple, clonecell::CloneCell, copyhashmap::CopyHashMap,
event_listener::LazyEventSource, hash_map_ext::HashMapExt, numcell::NumCell,
rc_eq::rc_eq, threshold_counter::ThresholdCounter,
},
wire::{
ExtForeignToplevelHandleV1Id, ExtImageCopyCaptureSessionV1Id, JayScreencastId,
@ -55,6 +49,8 @@ use {
},
};
opaque!(ToplevelIdentifier, toplevel_identifier);
tree_id!(ToplevelNodeId);
pub trait ToplevelNode: ToplevelNodeBase {

View file

@ -1,4 +1,3 @@
pub mod activation_token;
pub mod array;
pub mod array_to_tuple;
pub mod asyncevent;
@ -60,7 +59,6 @@ pub mod string_ext;
pub mod syncqueue;
pub mod threshold_counter;
pub mod timer;
pub mod toplevel_identifier;
pub mod tri;
pub mod unlink_on_drop;
pub mod vec_ext;

View file

@ -1,35 +0,0 @@
use {
crate::utils::opaque::{OPAQUE_LEN, Opaque, OpaqueError, opaque},
arrayvec::ArrayString,
std::{
fmt::{Display, Formatter},
str::FromStr,
},
};
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
pub struct ActivationToken(Opaque);
pub fn activation_token() -> ActivationToken {
ActivationToken(opaque())
}
impl ActivationToken {
pub fn to_string(self) -> ArrayString<OPAQUE_LEN> {
self.0.to_string()
}
}
impl Display for ActivationToken {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl FromStr for ActivationToken {
type Err = OpaqueError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}

View file

@ -1,40 +0,0 @@
use {
crate::utils::{
clonecell::UnsafeCellCloneSafe,
opaque::{OPAQUE_LEN, Opaque, OpaqueError, opaque},
},
arrayvec::ArrayString,
std::{
fmt::{Display, Formatter},
str::FromStr,
},
};
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash, Ord, PartialOrd)]
pub struct ToplevelIdentifier(Opaque);
unsafe impl UnsafeCellCloneSafe for ToplevelIdentifier {}
pub fn toplevel_identifier() -> ToplevelIdentifier {
ToplevelIdentifier(opaque())
}
impl ToplevelIdentifier {
pub fn to_string(self) -> ArrayString<OPAQUE_LEN> {
self.0.to_string()
}
}
impl Display for ToplevelIdentifier {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl FromStr for ToplevelIdentifier {
type Err = OpaqueError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}