1
0
Fork 0
forked from wry/wry

all: remove bitflags dependency

This commit is contained in:
Julian Orth 2024-02-16 15:02:14 +01:00
parent 63ed3fa689
commit 9497d6b0cf
12 changed files with 134 additions and 151 deletions

View file

@ -6,7 +6,10 @@ use {
ifs::{
wl_seat::{NodeSeatState, WlSeatGlobal},
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,
object::Object,
@ -114,8 +117,8 @@ impl XdgPopup {
let output_pos = ws.output.get().global.pos.get();
let mut overflow = output_pos.get_overflow(&abs_pos);
if !overflow.is_contained() {
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_x = positioner.ca.contains(CA_FLIP_X) && overflow.x_overflow();
let mut flip_y = positioner.ca.contains(CA_FLIP_Y) && overflow.y_overflow();
if 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());
@ -141,14 +144,14 @@ impl XdgPopup {
}
}
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 {
parent_abs.x1() - abs_pos.x1()
} else {
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 {
parent_abs.y1() - abs_pos.y1()
} else {
@ -161,11 +164,11 @@ impl XdgPopup {
overflow = output_pos.get_overflow(&abs_pos);
}
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);
dx2 = -overflow.right.max(0);
}
if positioner.ca.contains(CA::RESIZE_Y) {
if positioner.ca.contains(CA_RESIZE_Y) {
dy1 = overflow.top.max(0);
dy2 = -overflow.bottom.max(0);
}

View file

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