1
0
Fork 0
forked from wry/wry

Merge pull request #93 from mahkoh/jorth/bitflags

all: remove bitflags dependency
This commit is contained in:
mahkoh 2024-02-16 15:09:21 +01:00 committed by GitHub
commit 82b3650e67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 134 additions and 151 deletions

1
Cargo.lock generated
View file

@ -499,7 +499,6 @@ dependencies = [
"ash", "ash",
"backtrace", "backtrace",
"bincode", "bincode",
"bitflags 2.4.2",
"bstr", "bstr",
"byteorder", "byteorder",
"chrono", "chrono",

View file

@ -21,7 +21,6 @@ log = { version = "0.4.20", features = ["std"] }
futures-util = "0.3.30" futures-util = "0.3.30"
num-traits = "0.2.17" num-traits = "0.2.17"
num-derive = "0.4.1" num-derive = "0.4.1"
bitflags = "2.4.2"
libloading = "0.8.1" libloading = "0.8.1"
bstr = { version = "1.9.0", default-features = false, features = ["std"] } bstr = { version = "1.9.0", default-features = false, features = ["std"] }
isnt = "0.1.0" isnt = "0.1.0"

View file

@ -5,7 +5,7 @@ use {
EGL_DEBUG_MSG_ERROR_KHR, EGL_DEBUG_MSG_INFO_KHR, EGL_DEBUG_MSG_WARN_KHR, EGL_NONE, EGL_DEBUG_MSG_ERROR_KHR, EGL_DEBUG_MSG_INFO_KHR, EGL_DEBUG_MSG_WARN_KHR, EGL_NONE,
EGL_OPENGL_ES_API, EGL_TRUE, EGL_OPENGL_ES_API, EGL_TRUE,
}, },
ext::{get_client_ext, ClientExt}, ext::{get_client_ext, ClientExt, EXT_PLATFORM_BASE, KHR_DEBUG, KHR_PLATFORM_GBM},
proc::ExtProc, proc::ExtProc,
RenderError, RenderError,
}, },
@ -32,13 +32,13 @@ pub(crate) static PROCS: Lazy<ExtProc> = Lazy::new(ExtProc::load);
pub(crate) static EXTS: Lazy<ClientExt> = Lazy::new(get_client_ext); pub(crate) static EXTS: Lazy<ClientExt> = Lazy::new(get_client_ext);
pub(in crate::gfx_apis::gl) fn init() -> Result<(), RenderError> { pub(in crate::gfx_apis::gl) fn init() -> Result<(), RenderError> {
if !EXTS.contains(ClientExt::EXT_PLATFORM_BASE) { if !EXTS.contains(EXT_PLATFORM_BASE) {
return Err(RenderError::ExtPlatformBase); return Err(RenderError::ExtPlatformBase);
} }
if !EXTS.contains(ClientExt::KHR_PLATFORM_GBM) { if !EXTS.contains(KHR_PLATFORM_GBM) {
return Err(RenderError::GbmExt); return Err(RenderError::GbmExt);
} }
if EXTS.contains(ClientExt::KHR_DEBUG) { if EXTS.contains(KHR_DEBUG) {
let attrib: &[EGLAttrib] = &[ let attrib: &[EGLAttrib] = &[
EGL_DEBUG_MSG_CRITICAL_KHR as _, EGL_DEBUG_MSG_CRITICAL_KHR as _,
EGL_TRUE as _, EGL_TRUE as _,

View file

@ -9,7 +9,7 @@ use {
}, },
PROCS, PROCS,
}, },
ext::{DisplayExt, GlExt}, ext::{GlExt, EXT_CREATE_CONTEXT_ROBUSTNESS},
sys::{ sys::{
GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB, GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB,
GL_UNKNOWN_CONTEXT_RESET_ARB, GL_UNKNOWN_CONTEXT_RESET_ARB,
@ -44,11 +44,7 @@ static mut CURRENT: EGLContext = EGLContext::none();
impl EglContext { impl EglContext {
pub fn reset_status(&self) -> Option<ResetStatus> { pub fn reset_status(&self) -> Option<ResetStatus> {
if !self if !self.dpy.exts.contains(EXT_CREATE_CONTEXT_ROBUSTNESS) {
.dpy
.exts
.contains(DisplayExt::EXT_CREATE_CONTEXT_ROBUSTNESS)
{
return None; return None;
} }
let status = self.with_current(|| unsafe { let status = self.with_current(|| unsafe {

View file

@ -23,7 +23,12 @@ use {
}, },
PROCS, PROCS,
}, },
ext::{get_display_ext, get_gl_ext, DisplayExt, GlExt}, ext::{
get_display_ext, get_gl_ext, DisplayExt, GlExt, EXT_CREATE_CONTEXT_ROBUSTNESS,
EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS, GL_OES_EGL_IMAGE, GL_OES_EGL_IMAGE_EXTERNAL,
KHR_IMAGE_BASE, KHR_NO_CONFIG_CONTEXT, KHR_SURFACELESS_CONTEXT,
MESA_CONFIGLESS_CONTEXT,
},
sys::{ sys::{
eglInitialize, EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, eglInitialize, EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
EGL_LOSE_CONTEXT_ON_RESET_EXT, EGL_PLATFORM_GBM_KHR, EGL_LOSE_CONTEXT_ON_RESET_EXT, EGL_PLATFORM_GBM_KHR,
@ -74,7 +79,7 @@ impl EglDisplay {
return Err(RenderError::GetDisplay); return Err(RenderError::GetDisplay);
} }
let mut dpy = EglDisplay { let mut dpy = EglDisplay {
exts: DisplayExt::empty(), exts: DisplayExt::none(),
formats: AHashMap::new(), formats: AHashMap::new(),
gbm: Rc::new(gbm), gbm: Rc::new(gbm),
dpy, dpy,
@ -85,22 +90,19 @@ impl EglDisplay {
return Err(RenderError::Initialize); return Err(RenderError::Initialize);
} }
dpy.exts = get_display_ext(dpy.dpy); dpy.exts = get_display_ext(dpy.dpy);
if !dpy.exts.intersects(DisplayExt::KHR_IMAGE_BASE) { if !dpy.exts.intersects(KHR_IMAGE_BASE) {
return Err(RenderError::ImageBase); return Err(RenderError::ImageBase);
} }
if !dpy if !dpy.exts.intersects(EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS) {
.exts
.intersects(DisplayExt::EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS)
{
return Err(RenderError::DmaBufImport); return Err(RenderError::DmaBufImport);
} }
if !dpy if !dpy
.exts .exts
.intersects(DisplayExt::KHR_NO_CONFIG_CONTEXT | DisplayExt::MESA_CONFIGLESS_CONTEXT) .intersects(KHR_NO_CONFIG_CONTEXT | MESA_CONFIGLESS_CONTEXT)
{ {
return Err(RenderError::ConfiglessContext); return Err(RenderError::ConfiglessContext);
} }
if !dpy.exts.intersects(DisplayExt::KHR_SURFACELESS_CONTEXT) { if !dpy.exts.intersects(KHR_SURFACELESS_CONTEXT) {
return Err(RenderError::SurfacelessContext); return Err(RenderError::SurfacelessContext);
} }
dpy.formats = query_formats(dpy.dpy)?; dpy.formats = query_formats(dpy.dpy)?;
@ -113,10 +115,7 @@ impl EglDisplay {
self: &Rc<Self>, self: &Rc<Self>,
) -> Result<Rc<EglContext>, RenderError> { ) -> Result<Rc<EglContext>, RenderError> {
let mut attrib = vec![EGL_CONTEXT_CLIENT_VERSION, 2]; let mut attrib = vec![EGL_CONTEXT_CLIENT_VERSION, 2];
if self if self.exts.contains(EXT_CREATE_CONTEXT_ROBUSTNESS) {
.exts
.contains(DisplayExt::EXT_CREATE_CONTEXT_ROBUSTNESS)
{
attrib.push(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT); attrib.push(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
attrib.push(EGL_LOSE_CONTEXT_ON_RESET_EXT); attrib.push(EGL_LOSE_CONTEXT_ON_RESET_EXT);
} else { } else {
@ -136,17 +135,17 @@ impl EglDisplay {
} }
let mut ctx = EglContext { let mut ctx = EglContext {
dpy: self.clone(), dpy: self.clone(),
ext: GlExt::empty(), ext: GlExt::none(),
ctx, ctx,
formats: Default::default(), formats: Default::default(),
}; };
ctx.ext = ctx.with_current(|| Ok(get_gl_ext()))?; ctx.ext = ctx.with_current(|| Ok(get_gl_ext()))?;
if !ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE) { if !ctx.ext.contains(GL_OES_EGL_IMAGE) {
return Err(RenderError::OesEglImage); return Err(RenderError::OesEglImage);
} }
ctx.formats = { ctx.formats = {
let mut formats = AHashMap::new(); let mut formats = AHashMap::new();
let supports_external_only = ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE_EXTERNAL); let supports_external_only = ctx.ext.contains(GL_OES_EGL_IMAGE_EXTERNAL);
for (&drm, format) in &self.formats { for (&drm, format) in &self.formats {
if format.implicit_external_only && !supports_external_only { if format.implicit_external_only && !supports_external_only {
continue; continue;

View file

@ -46,95 +46,74 @@ where
base base
} }
bitflags::bitflags! { bitflags! {
#[derive(Copy, Clone, Debug)] ClientExt: u32;
pub struct ClientExt: u32 { EXT_CLIENT_EXTENSION = 1 << 0,
const EXT_CLIENT_EXTENSION = 1 << 0; EXT_PLATFORM_BASE = 1 << 1,
const EXT_PLATFORM_BASE = 1 << 1; KHR_PLATFORM_GBM = 1 << 2,
const KHR_PLATFORM_GBM = 1 << 2; KHR_DEBUG = 1 << 3,
const KHR_DEBUG = 1 << 3;
}
} }
pub fn get_client_ext() -> ClientExt { pub fn get_client_ext() -> ClientExt {
let map = [ let map = [
("EGL_EXT_platform_base", ClientExt::EXT_PLATFORM_BASE), ("EGL_EXT_platform_base", EXT_PLATFORM_BASE),
("EGL_KHR_platform_gbm", ClientExt::KHR_PLATFORM_GBM), ("EGL_KHR_platform_gbm", KHR_PLATFORM_GBM),
("EGL_KHR_debug", ClientExt::KHR_DEBUG), ("EGL_KHR_debug", KHR_DEBUG),
]; ];
match unsafe { get_dpy_extensions(EGLDisplay::none()) } { match unsafe { get_dpy_extensions(EGLDisplay::none()) } {
Some(exts) => get_typed_ext(&exts, ClientExt::EXT_CLIENT_EXTENSION, &map), Some(exts) => get_typed_ext(&exts, EXT_CLIENT_EXTENSION, &map),
_ => ClientExt::empty(), _ => ClientExt::none(),
} }
} }
bitflags::bitflags! { bitflags! {
#[derive(Copy, Clone, Debug)] DisplayExt: u32;
pub struct DisplayExt: u32 { KHR_IMAGE_BASE = 1 << 0,
const KHR_IMAGE_BASE = 1 << 0; EXT_IMAGE_DMA_BUF_IMPORT = 1 << 1,
const EXT_IMAGE_DMA_BUF_IMPORT = 1 << 1; EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS = 1 << 2,
const EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS = 1 << 2; KHR_NO_CONFIG_CONTEXT = 1 << 3,
const KHR_NO_CONFIG_CONTEXT = 1 << 3; MESA_CONFIGLESS_CONTEXT = 1 << 4,
const MESA_CONFIGLESS_CONTEXT = 1 << 4; KHR_SURFACELESS_CONTEXT = 1 << 5,
const KHR_SURFACELESS_CONTEXT = 1 << 5; IMG_CONTEXT_PRIORITY = 1 << 6,
const IMG_CONTEXT_PRIORITY = 1 << 6; EXT_CREATE_CONTEXT_ROBUSTNESS = 1 << 7,
const EXT_CREATE_CONTEXT_ROBUSTNESS = 1 << 7;
}
} }
pub(crate) unsafe fn get_display_ext(dpy: EGLDisplay) -> DisplayExt { pub(crate) unsafe fn get_display_ext(dpy: EGLDisplay) -> DisplayExt {
let map = [ let map = [
("EGL_KHR_image_base", DisplayExt::KHR_IMAGE_BASE), ("EGL_KHR_image_base", KHR_IMAGE_BASE),
( ("EGL_EXT_image_dma_buf_import", EXT_IMAGE_DMA_BUF_IMPORT),
"EGL_EXT_image_dma_buf_import",
DisplayExt::EXT_IMAGE_DMA_BUF_IMPORT,
),
( (
"EGL_EXT_image_dma_buf_import_modifiers", "EGL_EXT_image_dma_buf_import_modifiers",
DisplayExt::EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS, EXT_IMAGE_DMA_BUF_IMPORT_MODIFIERS,
), ),
( ("EGL_KHR_no_config_context", KHR_NO_CONFIG_CONTEXT),
"EGL_KHR_no_config_context", ("EGL_MESA_configless_context", MESA_CONFIGLESS_CONTEXT),
DisplayExt::KHR_NO_CONFIG_CONTEXT, ("EGL_KHR_surfaceless_context", KHR_SURFACELESS_CONTEXT),
), ("EGL_IMG_context_priority", IMG_CONTEXT_PRIORITY),
(
"EGL_MESA_configless_context",
DisplayExt::MESA_CONFIGLESS_CONTEXT,
),
(
"EGL_KHR_surfaceless_context",
DisplayExt::KHR_SURFACELESS_CONTEXT,
),
("EGL_IMG_context_priority", DisplayExt::IMG_CONTEXT_PRIORITY),
( (
"EGL_EXT_create_context_robustness", "EGL_EXT_create_context_robustness",
DisplayExt::EXT_CREATE_CONTEXT_ROBUSTNESS, EXT_CREATE_CONTEXT_ROBUSTNESS,
), ),
]; ];
match get_dpy_extensions(dpy) { match get_dpy_extensions(dpy) {
Some(exts) => get_typed_ext(&exts, DisplayExt::empty(), &map), Some(exts) => get_typed_ext(&exts, DisplayExt::none(), &map),
_ => DisplayExt::empty(), _ => DisplayExt::none(),
} }
} }
bitflags::bitflags! { bitflags! {
#[derive(Copy, Clone, Debug)] GlExt: u32;
pub struct GlExt: u32 { GL_OES_EGL_IMAGE = 1 << 0,
const GL_OES_EGL_IMAGE = 1 << 0; GL_OES_EGL_IMAGE_EXTERNAL = 1 << 1,
const GL_OES_EGL_IMAGE_EXTERNAL = 1 << 1;
}
} }
pub fn get_gl_ext() -> GlExt { pub fn get_gl_ext() -> GlExt {
let map = [ let map = [
("GL_OES_EGL_image", GlExt::GL_OES_EGL_IMAGE), ("GL_OES_EGL_image", GL_OES_EGL_IMAGE),
( ("GL_OES_EGL_image_external", GL_OES_EGL_IMAGE_EXTERNAL),
"GL_OES_EGL_image_external",
GlExt::GL_OES_EGL_IMAGE_EXTERNAL,
),
]; ];
match unsafe { get_extensions(glGetString(GL_EXTENSIONS) as _) } { match unsafe { get_extensions(glGetString(GL_EXTENSIONS) as _) } {
Some(exts) => get_typed_ext(&exts, GlExt::empty(), &map), Some(exts) => get_typed_ext(&exts, GlExt::none(), &map),
_ => GlExt::empty(), _ => GlExt::none(),
} }
} }

View file

@ -3,7 +3,7 @@ use {
format::Format, format::Format,
gfx_apis::gl::{ gfx_apis::gl::{
egl::{context::EglContext, image::EglImage, PROCS}, egl::{context::EglContext, image::EglImage, PROCS},
ext::GlExt, ext::GL_OES_EGL_IMAGE_EXTERNAL,
gl::sys::{ gl::sys::{
glBindTexture, glDeleteTextures, glGenTextures, glPixelStorei, glTexImage2D, glBindTexture, glDeleteTextures, glGenTextures, glPixelStorei, glTexImage2D,
glTexParameteri, GLint, GLuint, GL_CLAMP_TO_EDGE, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glTexParameteri, GLint, GLuint, GL_CLAMP_TO_EDGE, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
@ -38,7 +38,7 @@ impl GlTexture {
ctx: &Rc<EglContext>, ctx: &Rc<EglContext>,
img: &Rc<EglImage>, img: &Rc<EglImage>,
) -> Result<GlTexture, RenderError> { ) -> Result<GlTexture, RenderError> {
if !ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE_EXTERNAL) { if !ctx.ext.contains(GL_OES_EGL_IMAGE_EXTERNAL) {
return Err(RenderError::ExternalUnsupported); return Err(RenderError::ExternalUnsupported);
} }
let target = image_target(img.external_only); let target = image_target(img.external_only);

View file

@ -7,7 +7,7 @@ use {
}, },
gfx_apis::gl::{ gfx_apis::gl::{
egl::{context::EglContext, display::EglDisplay}, egl::{context::EglContext, display::EglDisplay},
ext::GlExt, ext::GL_OES_EGL_IMAGE_EXTERNAL,
gl::{ gl::{
program::GlProgram, render_buffer::GlRenderBuffer, sys::GLint, texture::GlTexture, program::GlProgram, render_buffer::GlRenderBuffer, sys::GLint, texture::GlTexture,
}, },
@ -100,7 +100,7 @@ impl GlRenderContext {
tex_vert, tex_vert,
include_str!("../shaders/tex-alpha.frag.glsl"), include_str!("../shaders/tex-alpha.frag.glsl"),
)?; )?;
let tex_external = if ctx.ext.contains(GlExt::GL_OES_EGL_IMAGE_EXTERNAL) { let tex_external = if ctx.ext.contains(GL_OES_EGL_IMAGE_EXTERNAL) {
let solid = GlProgram::from_shaders( let solid = GlProgram::from_shaders(
ctx, ctx,
tex_vert, tex_vert,

View file

@ -6,7 +6,10 @@ use {
ifs::{ ifs::{
wl_seat::{NodeSeatState, WlSeatGlobal}, wl_seat::{NodeSeatState, WlSeatGlobal},
wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt}, wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt},
xdg_positioner::{XdgPositioned, XdgPositioner, CA}, xdg_positioner::{
XdgPositioned, XdgPositioner, CA_FLIP_X, CA_FLIP_Y, CA_RESIZE_X, CA_RESIZE_Y,
CA_SLIDE_X, CA_SLIDE_Y,
},
}, },
leaks::Tracker, leaks::Tracker,
object::Object, object::Object,
@ -114,8 +117,8 @@ impl XdgPopup {
let output_pos = ws.output.get().global.pos.get(); let output_pos = ws.output.get().global.pos.get();
let mut overflow = output_pos.get_overflow(&abs_pos); let mut overflow = output_pos.get_overflow(&abs_pos);
if !overflow.is_contained() { if !overflow.is_contained() {
let mut flip_x = positioner.ca.contains(CA::FLIP_X) && overflow.x_overflow(); let mut flip_x = positioner.ca.contains(CA_FLIP_X) && overflow.x_overflow();
let mut flip_y = positioner.ca.contains(CA::FLIP_Y) && overflow.y_overflow(); let mut flip_y = positioner.ca.contains(CA_FLIP_Y) && overflow.y_overflow();
if flip_x || flip_y { if flip_x || flip_y {
let mut adj_rel = positioner.get_position(flip_x, flip_y); let mut adj_rel = positioner.get_position(flip_x, flip_y);
let mut adj_abs = adj_rel.move_(parent_abs.x1(), parent_abs.y1()); let mut adj_abs = adj_rel.move_(parent_abs.x1(), parent_abs.y1());
@ -141,14 +144,14 @@ impl XdgPopup {
} }
} }
let (mut dx, mut dy) = (0, 0); let (mut dx, mut dy) = (0, 0);
if positioner.ca.contains(CA::SLIDE_X) && overflow.x_overflow() { if positioner.ca.contains(CA_SLIDE_X) && overflow.x_overflow() {
dx = if overflow.left > 0 || overflow.left + overflow.right > 0 { dx = if overflow.left > 0 || overflow.left + overflow.right > 0 {
parent_abs.x1() - abs_pos.x1() parent_abs.x1() - abs_pos.x1()
} else { } else {
parent_abs.x2() - abs_pos.x2() parent_abs.x2() - abs_pos.x2()
}; };
} }
if positioner.ca.contains(CA::SLIDE_Y) && overflow.y_overflow() { if positioner.ca.contains(CA_SLIDE_Y) && overflow.y_overflow() {
dy = if overflow.top > 0 || overflow.top + overflow.bottom > 0 { dy = if overflow.top > 0 || overflow.top + overflow.bottom > 0 {
parent_abs.y1() - abs_pos.y1() parent_abs.y1() - abs_pos.y1()
} else { } else {
@ -161,11 +164,11 @@ impl XdgPopup {
overflow = output_pos.get_overflow(&abs_pos); overflow = output_pos.get_overflow(&abs_pos);
} }
let (mut dx1, mut dx2, mut dy1, mut dy2) = (0, 0, 0, 0); let (mut dx1, mut dx2, mut dy1, mut dy2) = (0, 0, 0, 0);
if positioner.ca.contains(CA::RESIZE_X) { if positioner.ca.contains(CA_RESIZE_X) {
dx1 = overflow.left.max(0); dx1 = overflow.left.max(0);
dx2 = -overflow.right.max(0); dx2 = -overflow.right.max(0);
} }
if positioner.ca.contains(CA::RESIZE_Y) { if positioner.ca.contains(CA_RESIZE_Y) {
dy1 = overflow.top.max(0); dy1 = overflow.top.max(0);
dy2 = -overflow.bottom.max(0); dy2 = -overflow.bottom.max(0);
} }

View file

@ -24,45 +24,41 @@ const BOTTOM_LEFT: u32 = 6;
const TOP_RIGHT: u32 = 7; const TOP_RIGHT: u32 = 7;
const BOTTOM_RIGHT: u32 = 8; const BOTTOM_RIGHT: u32 = 8;
bitflags::bitflags! { bitflags! {
#[derive(Copy, Clone, Default, Debug)] Edge: u32;
pub struct Edge: u32 { E_TOP = 1 << 0,
const TOP = 1 << 0; E_BOTTOM = 1 << 1,
const BOTTOM = 1 << 1; E_LEFT = 1 << 2,
const LEFT = 1 << 2; E_RIGHT = 1 << 3,
const RIGHT = 1 << 3;
}
} }
impl Edge { impl Edge {
fn from_enum(e: u32) -> Option<Self> { fn from_enum(e: u32) -> Option<Self> {
let s = match e { let s = match e {
NONE => Edge::empty(), NONE => Self::none(),
TOP => Edge::TOP, TOP => E_TOP,
BOTTOM => Edge::BOTTOM, BOTTOM => E_BOTTOM,
LEFT => Edge::LEFT, LEFT => E_LEFT,
RIGHT => Edge::RIGHT, RIGHT => E_RIGHT,
TOP_LEFT => Edge::TOP | Edge::LEFT, TOP_LEFT => E_TOP | E_LEFT,
BOTTOM_LEFT => Edge::BOTTOM | Edge::LEFT, BOTTOM_LEFT => E_BOTTOM | E_LEFT,
TOP_RIGHT => Edge::TOP | Edge::RIGHT, TOP_RIGHT => E_TOP | E_RIGHT,
BOTTOM_RIGHT => Edge::BOTTOM | Edge::RIGHT, BOTTOM_RIGHT => E_BOTTOM | E_RIGHT,
_ => return None, _ => return None,
}; };
Some(s) Some(s)
} }
} }
bitflags::bitflags! { bitflags! {
#[derive(Copy, Clone, Default, Debug)] CA: u32;
pub struct CA: u32 { CA_NONE = 0,
const NONE = 0; CA_SLIDE_X = 1,
const SLIDE_X = 1; CA_SLIDE_Y = 2,
const SLIDE_Y = 2; CA_FLIP_X = 4,
const FLIP_X = 4; CA_FLIP_Y = 8,
const FLIP_Y = 8; CA_RESIZE_X = 16,
const RESIZE_X = 16; CA_RESIZE_Y = 32,
const RESIZE_Y = 32;
}
} }
pub struct XdgPositioner { pub struct XdgPositioner {
@ -98,42 +94,42 @@ impl XdgPositioned {
let mut anchor = self.anchor; let mut anchor = self.anchor;
let mut gravity = self.gravity; let mut gravity = self.gravity;
if flip_x { if flip_x {
anchor ^= Edge::LEFT | Edge::RIGHT; anchor ^= E_LEFT | E_RIGHT;
gravity ^= Edge::LEFT | Edge::RIGHT; gravity ^= E_LEFT | E_RIGHT;
} }
if flip_y { if flip_y {
anchor ^= Edge::TOP | Edge::BOTTOM; anchor ^= E_TOP | E_BOTTOM;
gravity ^= Edge::TOP | Edge::BOTTOM; gravity ^= E_TOP | E_BOTTOM;
} }
let mut x1 = self.off_x; let mut x1 = self.off_x;
let mut y1 = self.off_x; let mut y1 = self.off_x;
if anchor.contains(Edge::LEFT) { if anchor.contains(E_LEFT) {
x1 += self.ar.x1(); x1 += self.ar.x1();
} else if anchor.contains(Edge::RIGHT) { } else if anchor.contains(E_RIGHT) {
x1 += self.ar.x2(); x1 += self.ar.x2();
} else { } else {
x1 += self.ar.x1() + self.ar.width() / 2; x1 += self.ar.x1() + self.ar.width() / 2;
} }
if anchor.contains(Edge::TOP) { if anchor.contains(E_TOP) {
y1 += self.ar.y1(); y1 += self.ar.y1();
} else if anchor.contains(Edge::BOTTOM) { } else if anchor.contains(E_BOTTOM) {
y1 += self.ar.y2(); y1 += self.ar.y2();
} else { } else {
y1 += self.ar.y1() + self.ar.height() / 2; y1 += self.ar.y1() + self.ar.height() / 2;
} }
if gravity.contains(Edge::LEFT) { if gravity.contains(E_LEFT) {
x1 -= self.size_width; x1 -= self.size_width;
} else if !gravity.contains(Edge::RIGHT) { } else if !gravity.contains(E_RIGHT) {
x1 -= self.size_width / 2; x1 -= self.size_width / 2;
} }
if gravity.contains(Edge::TOP) { if gravity.contains(E_TOP) {
y1 -= self.size_height; y1 -= self.size_height;
} else if !gravity.contains(Edge::BOTTOM) { } else if !gravity.contains(E_BOTTOM) {
y1 -= self.size_height / 2; y1 -= self.size_height / 2;
} }
@ -218,10 +214,10 @@ impl XdgPositioner {
parser: MsgParser<'_, '_>, parser: MsgParser<'_, '_>,
) -> Result<(), XdgPositionerError> { ) -> Result<(), XdgPositionerError> {
let req: SetConstraintAdjustment = self.client.parse(self, parser)?; let req: SetConstraintAdjustment = self.client.parse(self, parser)?;
let ca = match CA::from_bits(req.constraint_adjustment) { let ca = CA(req.constraint_adjustment);
Some(c) => c, if !ca.is_valid() {
_ => return Err(XdgPositionerError::UnknownCa(req.constraint_adjustment)), return Err(XdgPositionerError::UnknownCa(req.constraint_adjustment));
}; }
self.position.borrow_mut().ca = ca; self.position.borrow_mut().ca = ca;
Ok(()) Ok(())
} }

View file

@ -526,7 +526,7 @@ macro_rules! containing_node_impl {
macro_rules! bitflags { macro_rules! bitflags {
($name:ident: $rep:ty; $($var:ident = $val:expr,)*) => { ($name:ident: $rep:ty; $($var:ident = $val:expr,)*) => {
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq, Default)]
pub struct $name(pub $rep); pub struct $name(pub $rep);
$( $(
@ -543,18 +543,24 @@ macro_rules! bitflags {
pub fn is_some(self) -> bool { pub fn is_some(self) -> bool {
self.0 != 0 self.0 != 0
} }
}
impl crate::utils::bitflags::BitflagsExt for $name { pub fn all() -> Self {
fn contains(self, other: Self) -> bool { Self(0 $(| $val)*)
}
pub fn is_valid(self) -> bool {
Self::all().contains(self)
}
pub fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0 self.0 & other.0 == other.0
} }
fn not_contains(self, other: Self) -> bool { pub fn not_contains(self, other: Self) -> bool {
self.0 & other.0 != other.0 self.0 & other.0 != other.0
} }
fn intersects(self, other: Self) -> bool { pub fn intersects(self, other: Self) -> bool {
self.0 & other.0 != 0 self.0 & other.0 != 0
} }
} }
@ -587,6 +593,12 @@ macro_rules! bitflags {
} }
} }
impl std::ops::BitXorAssign for $name {
fn bitxor_assign(&mut self, rhs: Self) {
self.0 ^= rhs.0;
}
}
impl std::ops::Not for $name { impl std::ops::Not for $name {
type Output = Self; type Output = Self;

View file

@ -30,8 +30,8 @@ use {
}, },
}, },
utils::{ utils::{
bitfield::Bitfield, bitflags::BitflagsExt, buf::TypedBuf, clonecell::CloneCell, bitfield::Bitfield, buf::TypedBuf, clonecell::CloneCell, copyhashmap::CopyHashMap,
copyhashmap::CopyHashMap, errorfmt::ErrorFmt, errorfmt::ErrorFmt,
}, },
video::dmabuf::DmaBuf, video::dmabuf::DmaBuf,
}, },