1
0
Fork 0
forked from wry/wry

macros: auto generate bitflag variants

This commit is contained in:
Julian Orth 2026-02-26 15:50:01 +01:00
parent 39289cdd44
commit 71294b0fd1
9 changed files with 129 additions and 71 deletions

View file

@ -17,12 +17,12 @@ pub struct AllocatorError(#[from] pub Box<dyn Error + Send>);
bitflags! { bitflags! {
BufferUsage: u32; BufferUsage: u32;
BO_USE_SCANOUT = 1 << 0, BO_USE_SCANOUT,
BO_USE_CURSOR = 1 << 1, BO_USE_CURSOR,
BO_USE_RENDERING = 1 << 2, BO_USE_RENDERING,
BO_USE_WRITE = 1 << 3, BO_USE_WRITE,
BO_USE_LINEAR = 1 << 4, BO_USE_LINEAR,
BO_USE_PROTECTED = 1 << 5, BO_USE_PROTECTED,
} }
pub trait Allocator { pub trait Allocator {

View file

@ -127,9 +127,9 @@ impl Display for ConnectorKernelId {
bitflags! { bitflags! {
ConnectorCaps: u32; ConnectorCaps: u32;
CONCAP_CONNECTOR = 1 << 0, CONCAP_CONNECTOR,
CONCAP_MODE_SETTING = 1 << 1, CONCAP_MODE_SETTING,
CONCAP_PHYSICAL_DISPLAY = 1 << 2, CONCAP_PHYSICAL_DISPLAY,
} }
pub trait Connector: Any { pub trait Connector: Any {
@ -343,11 +343,11 @@ pub const AXIS_120: i32 = 120;
bitflags! { bitflags! {
Leds: u32; Leds: u32;
LED_NUM_LOCK = 1 << 0, LED_NUM_LOCK,
LED_CAPS_LOCK = 1 << 1, LED_CAPS_LOCK,
LED_SCROLL_LOCK = 1 << 2, LED_SCROLL_LOCK,
LED_COMPOSE = 1 << 3, LED_COMPOSE,
LED_KANA = 1 << 4, LED_KANA,
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -34,8 +34,8 @@ use {
bitflags! { bitflags! {
ClMatcherChange: u32; ClMatcherChange: u32;
CL_CHANGED_DESTROYED = 1 << 0, CL_CHANGED_DESTROYED,
CL_CHANGED_NEW = 1 << 1, CL_CHANGED_NEW,
} }
type ClmFixedRootMatcher<T> = FixedRootMatcher<Rc<Client>, T>; type ClmFixedRootMatcher<T> = FixedRootMatcher<Rc<Client>, T>;

View file

@ -45,21 +45,21 @@ use {
bitflags! { bitflags! {
TlMatcherChange: u32; TlMatcherChange: u32;
TL_CHANGED_DESTROYED = 1 << 0, TL_CHANGED_DESTROYED,
TL_CHANGED_NEW = 1 << 1, TL_CHANGED_NEW,
TL_CHANGED_TITLE = 1 << 2, TL_CHANGED_TITLE,
TL_CHANGED_APP_ID = 1 << 3, TL_CHANGED_APP_ID,
TL_CHANGED_FLOATING = 1 << 4, TL_CHANGED_FLOATING,
TL_CHANGED_VISIBLE = 1 << 5, TL_CHANGED_VISIBLE,
TL_CHANGED_URGENT = 1 << 6, TL_CHANGED_URGENT,
TL_CHANGED_SEAT_FOCI = 1 << 7, TL_CHANGED_SEAT_FOCI,
TL_CHANGED_FULLSCREEN = 1 << 8, TL_CHANGED_FULLSCREEN,
TL_CHANGED_JUST_MAPPED = 1 << 9, TL_CHANGED_JUST_MAPPED,
TL_CHANGED_TAG = 1 << 10, TL_CHANGED_TAG,
TL_CHANGED_CLASS_INST = 1 << 11, TL_CHANGED_CLASS_INST,
TL_CHANGED_ROLE = 1 << 12, TL_CHANGED_ROLE,
TL_CHANGED_WORKSPACE = 1 << 13, TL_CHANGED_WORKSPACE,
TL_CHANGED_CONTENT_TY = 1 << 14, TL_CHANGED_CONTENT_TY,
} }
type TlmFixedRootMatcher<T> = FixedRootMatcher<ToplevelData, T>; type TlmFixedRootMatcher<T> = FixedRootMatcher<ToplevelData, T>;

View file

@ -713,8 +713,8 @@ pub trait AsyncShmGfxTextureCallback {
bitflags! { bitflags! {
StagingBufferUsecase: u32; StagingBufferUsecase: u32;
STAGING_UPLOAD = 1 << 0, STAGING_UPLOAD,
STAGING_DOWNLOAD = 1 << 1, STAGING_DOWNLOAD,
} }
pub trait GfxStagingBuffer: Any { pub trait GfxStagingBuffer: Any {

View file

@ -50,11 +50,11 @@ where
bitflags! { bitflags! {
ClientExt: u32; ClientExt: u32;
EXT_CLIENT_EXTENSION = 1 << 0, EXT_CLIENT_EXTENSION,
EXT_PLATFORM_BASE = 1 << 1, EXT_PLATFORM_BASE,
KHR_PLATFORM_GBM = 1 << 2, KHR_PLATFORM_GBM,
KHR_DEBUG = 1 << 3, KHR_DEBUG,
EXT_DEVICE_QUERY = 1 << 4, EXT_DEVICE_QUERY,
} }
pub fn get_client_ext() -> ClientExt { pub fn get_client_ext() -> ClientExt {
@ -72,17 +72,17 @@ pub fn get_client_ext() -> ClientExt {
bitflags! { bitflags! {
DisplayExt: u32; DisplayExt: u32;
KHR_IMAGE_BASE = 1 << 0, KHR_IMAGE_BASE,
EXT_IMAGE_DMA_BUF_IMPORT = 1 << 1, EXT_IMAGE_DMA_BUF_IMPORT,
EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS = 1 << 2, EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS,
KHR_NO_CONFIG_CONTEXT = 1 << 3, KHR_NO_CONFIG_CONTEXT,
MESA_CONFIGLESS_CONTEXT = 1 << 4, MESA_CONFIGLESS_CONTEXT,
KHR_SURFACELESS_CONTEXT = 1 << 5, KHR_SURFACELESS_CONTEXT,
IMG_CONTEXT_PRIORITY = 1 << 6, IMG_CONTEXT_PRIORITY,
EXT_CREATE_CONTEXT_ROBUSTNESS = 1 << 7, EXT_CREATE_CONTEXT_ROBUSTNESS,
KHR_FENCE_SYNC = 1 << 8, KHR_FENCE_SYNC,
KHR_WAIT_SYNC = 1 << 9, KHR_WAIT_SYNC,
ANDROID_NATIVE_FENCE_SYNC = 1 << 10, ANDROID_NATIVE_FENCE_SYNC,
} }
pub(crate) unsafe fn get_display_ext(dpy: EGLDisplay) -> DisplayExt { pub(crate) unsafe fn get_display_ext(dpy: EGLDisplay) -> DisplayExt {
@ -113,8 +113,8 @@ pub(crate) unsafe fn get_display_ext(dpy: EGLDisplay) -> DisplayExt {
bitflags! { bitflags! {
GlExt: u32; GlExt: u32;
GL_OES_EGL_IMAGE = 1 << 0, GL_OES_EGL_IMAGE,
GL_OES_EGL_IMAGE_EXTERNAL = 1 << 1, GL_OES_EGL_IMAGE_EXTERNAL,
} }
pub fn get_gl_ext() -> Result<GlExt, RenderError> { pub fn get_gl_ext() -> Result<GlExt, RenderError> {
@ -133,7 +133,7 @@ pub fn get_gl_ext() -> Result<GlExt, RenderError> {
bitflags! { bitflags! {
DevExt: u32; DevExt: u32;
MESA_DEVICE_SOFTWARE = 1 << 0, MESA_DEVICE_SOFTWARE,
} }
pub fn get_device_ext(procs: &ExtProc, dpy: EGLDisplay) -> Result<DevExt, RenderError> { pub fn get_device_ext(procs: &ExtProc, dpy: EGLDisplay) -> Result<DevExt, RenderError> {

View file

@ -376,20 +376,20 @@ impl JayHeadManagerSessionV1RequestHandler for JayHeadManagerSessionV1 {
} }
bitflags! { bitflags! {
ToSend: u32; ToSend: u32;
CORE_INFO = 1 << 0, CORE_INFO,
COMPOSITOR_SPACE_INFO_FULL = 1 << 1, COMPOSITOR_SPACE_INFO_FULL,
COMPOSITOR_SPACE_INFO_POS = 1 << 2, COMPOSITOR_SPACE_INFO_POS,
COMPOSITOR_SPACE_INFO_SIZE = 1 << 3, COMPOSITOR_SPACE_INFO_SIZE,
COMPOSITOR_SPACE_INFO_TRANSFORM = 1 << 4, COMPOSITOR_SPACE_INFO_TRANSFORM,
COMPOSITOR_SPACE_INFO_SCALE = 1 << 5, COMPOSITOR_SPACE_INFO_SCALE,
MODE_INFO = 1 << 6, MODE_INFO,
NON_DESKTOP_INFO = 1 << 7, NON_DESKTOP_INFO,
VRR_MODE_INFO = 1 << 8, VRR_MODE_INFO,
TEARING_MODE_INFO = 1 << 9, TEARING_MODE_INFO,
FORMAT_INFO = 1 << 10, FORMAT_INFO,
DRM_COLOR_SPACE_INFO = 1 << 11, DRM_COLOR_SPACE_INFO,
BRIGHTNESS_INFO = 1 << 12, BRIGHTNESS_INFO,
COMPOSITOR_SPACE_INFO_ENABLED = 1 << 13, COMPOSITOR_SPACE_INFO_ENABLED,
} }
for head in self.heads.lock().values() { for head in self.heads.lock().values() {
let pending = mem::take(&mut *head.common.pending.borrow_mut()); let pending = mem::take(&mut *head.common.pending.borrow_mut());

View file

@ -25,10 +25,10 @@ pub const ANCHOR_BOTTOM_RIGHT: u32 = 8;
bitflags! { bitflags! {
Edge: u32; Edge: u32;
E_TOP = 1 << 0, E_TOP,
E_BOTTOM = 1 << 1, E_BOTTOM,
E_LEFT = 1 << 2, E_LEFT,
E_RIGHT = 1 << 3, E_RIGHT,
} }
impl Edge { impl Edge {

View file

@ -456,8 +456,34 @@ macro_rules! fatal {
}} }}
} }
#[expect(clippy::allow_attributes)]
#[allow(dead_code)]
pub trait Bitflag {
type Type;
}
macro_rules! bitflags { macro_rules! bitflags {
($name:ident: $rep:ty; $($var:ident,)*) => {
with_builtin_macros::with_eager_expansions! {
bitflags! {
$name: $rep;
#{concat_idents!($name, Enum)};
$(
$var = 1 << #{concat_idents!($name, Enum)}::$var as u32,
)*
}
}
};
($name:ident: $rep:ty; $($var:ident = $val:expr,)*) => { ($name:ident: $rep:ty; $($var:ident = $val:expr,)*) => {
with_builtin_macros::with_eager_expansions! {
bitflags! {
$name: $rep;
#{concat_idents!($name, Enum)};
$($var = $val,)*
}
}
};
($name:ident: $rep:ty; $enum_name:ident; $($var:ident = $val:expr,)*) => {
#[derive(Copy, Clone, Eq, PartialEq, Default)] #[derive(Copy, Clone, Eq, PartialEq, Default)]
pub struct $name(pub $rep); pub struct $name(pub $rep);
@ -499,6 +525,20 @@ macro_rules! bitflags {
pub fn intersects(self, other: Self) -> bool { pub fn intersects(self, other: Self) -> bool {
self.0 & other.0 != 0 self.0 & other.0 != 0
} }
#[allow(clippy::allow_attributes, clippy::bad_bit_mask)]
pub fn to_map(self) -> linearize::StaticCopyMap<$enum_name, bool> {
let mut res = linearize::StaticCopyMap::default();
let v = self.0;
$(
res[$enum_name::$var] = v & $val == $val;
)*
res
}
}
impl crate::macros::Bitflag for $name {
type Type = $rep;
} }
impl std::ops::BitOr for $name { impl std::ops::BitOr for $name {
@ -567,7 +607,25 @@ macro_rules! bitflags {
Ok(()) Ok(())
} }
} }
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, linearize::Linearize)]
#[expect(clippy::allow_attributes)]
pub enum $enum_name {
$(
#[allow(non_camel_case_types, dead_code)]
$var,
)*
}
impl $enum_name {
#[allow(clippy::allow_attributes, dead_code)]
pub fn to_bits(self) -> $name {
match self {
$(Self::$var => $var,)*
}
}
}
};
} }
macro_rules! pw_opcodes { macro_rules! pw_opcodes {