1
0
Fork 0
forked from wry/wry

autocommit 2022-03-29 15:40:59 CEST

This commit is contained in:
Julian Orth 2022-03-29 15:40:59 +02:00
parent 6ebf731aea
commit 9842264fad
39 changed files with 121 additions and 92 deletions

View file

@ -1,3 +1,16 @@
#![allow(
clippy::len_zero,
clippy::needless_lifetimes,
clippy::enum_variant_names,
clippy::useless_format,
clippy::redundant_clone,
clippy::collapsible_if,
clippy::unnecessary_to_owned,
clippy::match_like_matches_macro,
clippy::too_many_arguments,
clippy::iter_skip_next,
)]
extern crate core; extern crate core;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};

View file

@ -149,7 +149,7 @@ fn write_egl_procs<W: Write>(f: &mut W) -> anyhow::Result<()> {
writeln!(f)?; writeln!(f)?;
writeln!(f, "#[derive(Copy, Clone, Debug)]")?; writeln!(f, "#[derive(Copy, Clone, Debug)]")?;
writeln!(f, "pub struct ExtProc {{")?; writeln!(f, "pub struct ExtProc {{")?;
for (name, _, _) in map.iter().copied() { for (name, _, _) in map.iter() {
writeln!(f, " {}: *mut u8,", name)?; writeln!(f, " {}: *mut u8,", name)?;
} }
writeln!(f, "}}")?; writeln!(f, "}}")?;

View file

@ -432,15 +432,15 @@ fn write_type2<W: Write>(f: &mut W, lt: &str, ty: &Type) -> Result<()> {
Type::Fd => "Rc<OwnedFd>", Type::Fd => "Rc<OwnedFd>",
Type::Array(e) => { Type::Array(e) => {
write!(f, "Cow<{}, [", lt)?; write!(f, "Cow<{}, [", lt)?;
write_type2(f, lt, &e)?; write_type2(f, lt, e)?;
write!(f, "]>")?; write!(f, "]>")?;
return Ok(()); return Ok(());
} }
Type::DictEntry(k, v) => { Type::DictEntry(k, v) => {
write!(f, "DictEntry<")?; write!(f, "DictEntry<")?;
write_type2(f, lt, &k)?; write_type2(f, lt, k)?;
write!(f, ", ")?; write!(f, ", ")?;
write_type2(f, lt, &v)?; write_type2(f, lt, v)?;
write!(f, ">")?; write!(f, ">")?;
return Ok(()); return Ok(());
} }
@ -450,7 +450,7 @@ fn write_type2<W: Write>(f: &mut W, lt: &str, ty: &Type) -> Result<()> {
if idx > 0 { if idx > 0 {
write!(f, ", ")?; write!(f, ", ")?;
} }
write_type2(f, lt, &fs)?; write_type2(f, lt, fs)?;
} }
write!(f, ")")?; write!(f, ")")?;
return Ok(()); return Ok(());
@ -671,7 +671,7 @@ fn write_element<W: Write>(f: &mut W, element: Element, indent: &str) -> Result<
{ {
let indent = format!("{} ", indent); let indent = format!("{} ", indent);
for component in &element.components { for component in &element.components {
write_component(f, &element, &component, &indent)?; write_component(f, &element, component, &indent)?;
} }
write_module(f, element, &indent)?; write_module(f, element, &indent)?;
} }

View file

@ -362,9 +362,7 @@ impl<'a> Parser<'a> {
} }
Ok(Type::String(len)) Ok(Type::String(len))
})(); })();
let ty = ty.with_context(|| format!("While parsing string starting in line {}", line))?
ty.with_context(|| format!("While parsing string starting in line {}", line))?;
ty
} }
b"list" => { b"list" => {
let (line, body) = self.expect_tree(TreeDelim::Paren)?; let (line, body) = self.expect_tree(TreeDelim::Paren)?;
@ -381,9 +379,7 @@ impl<'a> Parser<'a> {
} }
Ok(Type::List(Box::new(ty), len)) Ok(Type::List(Box::new(ty), len))
})(); })();
let ty = ty.with_context(|| format!("While parsing list starting in line {}", line))?
ty.with_context(|| format!("While parsing list starting in line {}", line))?;
ty
} }
b"bitmask" => { b"bitmask" => {
let (line, body) = self.expect_tree(TreeDelim::Paren)?; let (line, body) = self.expect_tree(TreeDelim::Paren)?;
@ -397,9 +393,7 @@ impl<'a> Parser<'a> {
} }
Ok(Type::Bitmask(name.to_owned(), len)) Ok(Type::Bitmask(name.to_owned(), len))
})(); })();
let ty = ty.with_context(|| format!("While parsing bitmask starting in line {}", line))?
ty.with_context(|| format!("While parsing bitmask starting in line {}", line))?;
ty
} }
b"enum" => { b"enum" => {
let (line, body) = self.expect_tree(TreeDelim::Paren)?; let (line, body) = self.expect_tree(TreeDelim::Paren)?;
@ -413,9 +407,7 @@ impl<'a> Parser<'a> {
} }
Ok(Type::Enum(Box::new(ty), len)) Ok(Type::Enum(Box::new(ty), len))
})(); })();
let ty = ty.with_context(|| format!("While parsing enum starting in line {}", line))?
ty.with_context(|| format!("While parsing enum starting in line {}", line))?;
ty
} }
_ => Type::Named(ty.to_owned()), _ => Type::Named(ty.to_owned()),
}; };

View file

@ -76,7 +76,7 @@ fn configure_seat(s: Seat) {
s.bind(MOD | SYM_p, || Command::new("xeyes").spawn()); s.bind(MOD | SYM_p, || Command::new("xeyes").spawn());
s.bind(MOD | SYM_q, || quit()); s.bind(MOD | SYM_q, quit);
s.bind(CTRL | ALT | SYM_F1, || switch_to_vt(1)); s.bind(CTRL | ALT | SYM_F1, || switch_to_vt(1));
s.bind(CTRL | ALT | SYM_F2, || switch_to_vt(2)); s.bind(CTRL | ALT | SYM_F2, || switch_to_vt(2));

View file

@ -1,3 +1,5 @@
#![allow(clippy::declare_interior_mutable_const, clippy::type_complexity)]
use crate::_private::ipc::{ClientMessage, InitMessage, Response, ServerMessage}; use crate::_private::ipc::{ClientMessage, InitMessage, Response, ServerMessage};
use crate::_private::{bincode_ops, logging, Config, ConfigEntry, ConfigEntryGen, VERSION}; use crate::_private::{bincode_ops, logging, Config, ConfigEntry, ConfigEntryGen, VERSION};
use crate::keyboard::keymap::Keymap; use crate::keyboard::keymap::Keymap;

View file

@ -228,7 +228,7 @@ fn create_connector(
master: dev.master.clone(), master: dev.master.clone(),
output_id: state.output_ids.next(), output_id: state.output_ids.next(),
crtcs, crtcs,
mode: CloneCell::new(info.modes.first().cloned().map(|m| Rc::new(m))), mode: CloneCell::new(info.modes.first().cloned().map(Rc::new)),
modes: info.modes, modes: info.modes,
buffers: Default::default(), buffers: Default::default(),
next_buffer: Default::default(), next_buffer: Default::default(),
@ -749,7 +749,7 @@ impl MetalBackend {
let bo = dev.dev.gbm.create_bo( let bo = dev.dev.gbm.create_bo(
width, width,
height, height,
&format, format,
GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT, GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT,
); );
let bo = match bo { let bo = match bo {
@ -929,7 +929,7 @@ pub struct RenderBuffer {
} }
fn modes_equal(a: &DrmModeInfo, b: &DrmModeInfo) -> bool { fn modes_equal(a: &DrmModeInfo, b: &DrmModeInfo) -> bool {
true && a.clock == b.clock a.clock == b.clock
&& a.hdisplay == b.hdisplay && a.hdisplay == b.hdisplay
&& a.hsync_start == b.hsync_start && a.hsync_start == b.hsync_start
&& a.hsync_end == b.hsync_end && a.hsync_end == b.hsync_end

View file

@ -329,7 +329,7 @@ impl XBackendData {
modifier: INVALID_MODIFIER, modifier: INVALID_MODIFIER,
}; };
let mut images = [None, None]; let mut images = [None, None];
for i in 0..2 { for image in &mut images {
let bo = self let bo = self
.gbm .gbm
.create_bo(width, height, &format, GBM_BO_USE_RENDERING)?; .create_bo(width, height, &format, GBM_BO_USE_RENDERING)?;
@ -358,7 +358,7 @@ impl XBackendData {
} }
pfb.pixmap pfb.pixmap
}; };
images[i] = Some(XImage { *image = Some(XImage {
pixmap: Cell::new(pixmap), pixmap: Cell::new(pixmap),
fb: CloneCell::new(fb), fb: CloneCell::new(fb),
idle: Cell::new(true), idle: Cell::new(true),

View file

@ -367,12 +367,10 @@ impl Client {
pub fn lookup<Id: WaylandObjectLookup>(&self, id: Id) -> Result<Rc<Id::Object>, ClientError> { pub fn lookup<Id: WaylandObjectLookup>(&self, id: Id) -> Result<Rc<Id::Object>, ClientError> {
match Id::lookup(self, id) { match Id::lookup(self, id) {
Some(t) => Ok(t), Some(t) => Ok(t),
_ => { _ => Err(ClientError::LookupError(LookupError {
return Err(ClientError::LookupError(LookupError { interface: Id::INTERFACE,
interface: Id::INTERFACE, id: id.into(),
id: id.into(), })),
}))
}
} }
} }
} }

View file

@ -210,7 +210,7 @@ impl ConfigProxyHandler {
let seat = self.get_seat(seat)?; let seat = self.get_seat(seat)?;
self.send(&ServerMessage::Response { self.send(&ServerMessage::Response {
response: Response::GetMono { response: Response::GetMono {
mono: seat.get_mono().unwrap_or(false).into(), mono: seat.get_mono().unwrap_or(false),
}, },
}); });
Ok(()) Ok(())

View file

@ -200,8 +200,8 @@ const NO_AUTO_START: u8 = 0x2;
#[allow(dead_code)] #[allow(dead_code)]
const ALLOW_INTERACTIVE_AUTHORIZATION: u8 = 0x4; const ALLOW_INTERACTIVE_AUTHORIZATION: u8 = 0x4;
pub const BUS_DEST: &'static str = "org.freedesktop.DBus"; pub const BUS_DEST: &str = "org.freedesktop.DBus";
pub const BUS_PATH: &'static str = "/org/freedesktop/dbus"; pub const BUS_PATH: &str = "/org/freedesktop/dbus";
#[derive(Default, Debug)] #[derive(Default, Debug)]
struct Headers<'a> { struct Headers<'a> {

View file

@ -60,7 +60,7 @@ impl<'a> Formatter<'a> {
pub fn write_variant(&mut self, variant: &Variant) { pub fn write_variant(&mut self, variant: &Variant) {
let pos = self.buf.len(); let pos = self.buf.len();
self.buf.push(0); self.buf.push(0);
variant.write_signature(&mut self.buf); variant.write_signature(self.buf);
self.buf.push(0); self.buf.push(0);
self.buf[pos] = (self.buf.len() - pos - 2) as u8; self.buf[pos] = (self.buf.len() - pos - 2) as u8;
self.write_variant_body(variant); self.write_variant_body(variant);

View file

@ -68,6 +68,7 @@ impl Incoming {
self.incoming self.incoming
.fill_msg_buf(remaining as usize, msg_buf) .fill_msg_buf(remaining as usize, msg_buf)
.await?; .await?;
#[allow(clippy::drop_ref)]
drop(msg_buf); drop(msg_buf);
let msg_buf = unsafe { msg_buf_data.get().deref().deref() }; let msg_buf = unsafe { msg_buf_data.get().deref().deref() };
let headers = &msg_buf[FIXED_HEADER_SIZE..FIXED_HEADER_SIZE + headers_len as usize]; let headers = &msg_buf[FIXED_HEADER_SIZE..FIXED_HEADER_SIZE + headers_len as usize];
@ -78,7 +79,7 @@ impl Incoming {
} }
let fds: Vec<_> = self.incoming.fds.drain(..unix_fds).collect(); let fds: Vec<_> = self.incoming.fds.drain(..unix_fds).collect();
let mut parser = Parser { let mut parser = Parser {
buf: &msg_buf, buf: msg_buf,
pos: FIXED_HEADER_SIZE + dyn_header_len as usize, pos: FIXED_HEADER_SIZE + dyn_header_len as usize,
fds: &fds, fds: &fds,
}; };

View file

@ -354,7 +354,7 @@ where
struct AsyncReplyHandler<T: Message<'static>>(Rc<AsyncReplySlot<T>>); struct AsyncReplyHandler<T: Message<'static>>(Rc<AsyncReplySlot<T>>);
impl<T: Message<'static>> AsyncReplyHandler<T> { impl<T: Message<'static>> AsyncReplyHandler<T> {
fn complete(self: Box<Self>, res: Result<Reply<T>, DbusError>) { fn complete(self, res: Result<Reply<T>, DbusError>) {
self.0.data.set(Some(res)); self.0.data.set(Some(res));
if let Some(waker) = self.0.waker.take() { if let Some(waker) = self.0.waker.take() {
waker.wake(); waker.wake();

View file

@ -284,7 +284,7 @@ impl DrmMaster {
master: self.clone(), master: self.clone(),
fb, fb,
}), }),
Err(e) => return Err(DrmError::AddFb(e)), Err(e) => Err(DrmError::AddFb(e)),
} }
} }
@ -544,11 +544,11 @@ pub struct DrmModeInfo {
impl DrmModeInfo { impl DrmModeInfo {
pub fn create_blob(&self, master: &Rc<DrmMaster>) -> Result<PropBlob, DrmError> { pub fn create_blob(&self, master: &Rc<DrmMaster>) -> Result<PropBlob, DrmError> {
let raw = self.into_raw(); let raw = self.to_raw();
master.create_blob(&raw) master.create_blob(&raw)
} }
pub fn into_raw(&self) -> drm_mode_modeinfo { pub fn to_raw(&self) -> drm_mode_modeinfo {
let mut name = [0u8; DRM_DISPLAY_MODE_LEN]; let mut name = [0u8; DRM_DISPLAY_MODE_LEN];
let len = name.len().min(self.name.len()); let len = name.len().min(self.name.len());
name[..len].copy_from_slice(&self.name.as_bytes()[..len]); name[..len].copy_from_slice(&self.name.as_bytes()[..len]);

View file

@ -87,7 +87,7 @@ pub fn get_minor_type(min: u64) -> Result<NodeType, OsError> {
} }
} }
const DRM_DIR_NAME: &'static str = "/dev/dri"; const DRM_DIR_NAME: &str = "/dev/dri";
fn device_dir(maj: u64, min: u64) -> Ustring { fn device_dir(maj: u64, min: u64) -> Ustring {
uapi::format_ustr!("/sys/dev/char/{maj}:{min}/device/drm") uapi::format_ustr!("/sys/dev/char/{maj}:{min}/device/drm")
@ -264,11 +264,11 @@ pub fn mode_getproperty(
prop.count_values = 0; prop.count_values = 0;
let mut props = let mut props =
Vec::<drm_mode_property_enum>::with_capacity(prop.count_enum_blobs as usize); Vec::<drm_mode_property_enum>::with_capacity(prop.count_enum_blobs as usize);
prop.enum_blob_ptr = props.as_mut_ptr() as _;
get(&mut prop)?;
unsafe { unsafe {
props.set_len(prop.count_enum_blobs as usize); props.set_len(prop.count_enum_blobs as usize);
} }
prop.enum_blob_ptr = props.as_mut_ptr() as _;
get(&mut prop)?;
let mut values = Vec::with_capacity(props.len()); let mut values = Vec::with_capacity(props.len());
for v in props { for v in props {
values.push(DrmPropertyEnumValue { values.push(DrmPropertyEnumValue {

View file

@ -52,6 +52,7 @@ use std::ops::{Deref, DerefMut};
use std::rc::Rc; use std::rc::Rc;
use thiserror::Error; use thiserror::Error;
use uapi::{c, Errno, OwnedFd}; use uapi::{c, Errno, OwnedFd};
use crate::utils::rc_eq::rc_eq;
const POINTER: u32 = 1; const POINTER: u32 = 1;
const KEYBOARD: u32 = 2; const KEYBOARD: u32 = 2;
@ -193,7 +194,7 @@ impl WlSeatGlobal {
for seat in client.values() { for seat in client.values() {
let kbs = seat.keyboards.lock(); let kbs = seat.keyboards.lock();
for kb in kbs.values() { for kb in kbs.values() {
let fd = match seat.keymap_fd(&keymap) { let fd = match seat.keymap_fd(keymap) {
Ok(fd) => fd, Ok(fd) => fd,
Err(e) => { Err(e) => {
log::error!("Could not creat a file descriptor to transfer the keymap to client {}: {}", id, ErrorFmt(e)); log::error!("Could not creat a file descriptor to transfer the keymap to client {}: {}", id, ErrorFmt(e));
@ -344,7 +345,7 @@ impl WlSeatGlobal {
pub fn set_cursor(&self, cursor: Option<Rc<dyn Cursor>>) { pub fn set_cursor(&self, cursor: Option<Rc<dyn Cursor>>) {
if let Some(old) = self.cursor.get() { if let Some(old) = self.cursor.get() {
if let Some(new) = cursor.as_ref() { if let Some(new) = cursor.as_ref() {
if Rc::ptr_eq(&old, new) { if rc_eq(&old, new) {
return; return;
} }
} }

View file

@ -236,7 +236,7 @@ impl WlSeatGlobal {
client: &Rc<Client>, client: &Rc<Client>,
) { ) {
match field.get() { match field.get() {
Some(sel) => ipc::offer_source_to::<T>(&sel, &client), Some(sel) => ipc::offer_source_to::<T>(&sel, client),
None => T::for_each_device(self, client.id, |dd| { None => T::for_each_device(self, client.id, |dd| {
T::send_selection(dd, ObjectId::NONE.into()); T::send_selection(dd, ObjectId::NONE.into());
}), }),
@ -441,7 +441,7 @@ impl WlSeatGlobal {
pub fn focus_surface(&self, surface: &WlSurface) { pub fn focus_surface(&self, surface: &WlSurface) {
let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect(); let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect();
let serial = self.serial.fetch_add(1); let serial = self.serial.fetch_add(1);
self.surface_kb_event(0, &surface, |k| { self.surface_kb_event(0, surface, |k| {
k.send_enter(serial, surface.id, &pressed_keys) k.send_enter(serial, surface.id, &pressed_keys)
}); });
let ModifierState { let ModifierState {
@ -452,7 +452,7 @@ impl WlSeatGlobal {
.. ..
} = self.kb_state.borrow().mods(); } = self.kb_state.borrow().mods();
let serial = self.serial.fetch_add(1); let serial = self.serial.fetch_add(1);
self.surface_kb_event(0, &surface, |k| { self.surface_kb_event(0, surface, |k| {
k.send_modifiers(serial, mods_depressed, mods_latched, mods_locked, group) k.send_modifiers(serial, mods_depressed, mods_latched, mods_locked, group)
}); });

View file

@ -275,7 +275,7 @@ impl PointerOwner for GrabPointerOwner {
icon.dnd_icons.insert(seat.id(), seat.clone()); icon.dnd_icons.insert(seat.id(), seat.clone());
} }
if let Some(new) = &src { if let Some(new) = &src {
ipc::attach_seat::<WlDataDevice>(&new, seat, ipc::Role::Dnd)?; ipc::attach_seat::<WlDataDevice>(new, seat, ipc::Role::Dnd)?;
} }
*seat.dropped_dnd.borrow_mut() = None; *seat.dropped_dnd.borrow_mut() = None;
let pointer_owner = Rc::new(DndPointerOwner { let pointer_owner = Rc::new(DndPointerOwner {

View file

@ -126,7 +126,7 @@ impl WlSubsurface {
self.sync_ancestor.set(sync_ancestor); self.sync_ancestor.set(sync_ancestor);
self.depth.set(depth); self.depth.set(depth);
self.surface.ext.set(self.clone()); self.surface.ext.set(self.clone());
update_children_attach(&self, sync_ancestor, depth)?; update_children_attach(self, sync_ancestor, depth)?;
Ok(()) Ok(())
} }

View file

@ -530,7 +530,7 @@ impl XdgSurfaceExt for XdgToplevel {
if let Some(workspace) = self.xdg.workspace.get() { if let Some(workspace) = self.xdg.workspace.get() {
let output = workspace.output.get(); let output = workspace.output.get();
let bindings = output.global.bindings.borrow_mut(); let bindings = output.global.bindings.borrow_mut();
for binding in bindings.get(&self.xdg.surface.client.id) { if let Some(binding) = bindings.get(&self.xdg.surface.client.id) {
for binding in binding.values() { for binding in binding.values() {
self.xdg.surface.send_enter(binding.id); self.xdg.surface.send_enter(binding.id);
} }

View file

@ -115,7 +115,7 @@ impl Session {
.handle_signal::<org::freedesktop::login1::session::ResumeDevice, _>( .handle_signal::<org::freedesktop::login1::session::ResumeDevice, _>(
Some(LOGIND_NAME), Some(LOGIND_NAME),
Some(&self.session_path), Some(&self.session_path),
move |v| f(v), f,
) )
} }

View file

@ -11,7 +11,23 @@
clippy::needless_lifetimes, clippy::needless_lifetimes,
clippy::enum_variant_names, clippy::enum_variant_names,
clippy::useless_format, clippy::useless_format,
clippy::redundant_clone clippy::redundant_clone,
clippy::collapsible_if,
clippy::match_like_matches_macro,
clippy::collapsible_else_if,
clippy::identity_op,
clippy::module_inception,
clippy::single_char_pattern,
clippy::too_many_arguments,
clippy::from_over_into,
clippy::single_match,
clippy::upper_case_acronyms,
clippy::manual_map,
clippy::type_complexity,
clippy::option_map_unit_fn,
clippy::wrong_self_convention,
clippy::single_char_add_str,
clippy::ptr_eq,
)] )]
use crate::cli::{Cli, Cmd}; use crate::cli::{Cli, Cmd};

View file

@ -214,7 +214,7 @@ impl PangoCairoContext {
} }
Ok(PangoLayout { Ok(PangoLayout {
c: self.clone(), c: self.clone(),
l: l, l,
}) })
} }
} }

View file

@ -28,9 +28,9 @@ pub mod display;
pub mod image; pub mod image;
pub mod sys; pub mod sys;
pub(super) static PROCS: Lazy<ExtProc> = Lazy::new(|| ExtProc::load()); pub(super) static PROCS: Lazy<ExtProc> = Lazy::new(ExtProc::load);
pub(super) static EXTS: Lazy<ClientExt> = Lazy::new(|| get_client_ext()); pub(super) static EXTS: Lazy<ClientExt> = Lazy::new(get_client_ext);
pub fn init() -> Result<(), RenderError> { pub fn init() -> Result<(), RenderError> {
if !EXTS.contains(ClientExt::EXT_PLATFORM_BASE) { if !EXTS.contains(ClientExt::EXT_PLATFORM_BASE) {

View file

@ -1,3 +1,3 @@
#![allow(non_snake_case, dead_code)] #![allow(non_snake_case, dead_code, clippy::unused_unit)]
include!(concat!(env!("OUT_DIR"), "/egl_procs.rs")); include!(concat!(env!("OUT_DIR"), "/egl_procs.rs"));

View file

@ -19,6 +19,7 @@ use crate::theme::Color;
use crate::tree::{ContainerNode, FloatNode, Node, OutputNode, WorkspaceNode}; use crate::tree::{ContainerNode, FloatNode, Node, OutputNode, WorkspaceNode};
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc; use std::rc::Rc;
use crate::utils::rc_eq::rc_eq;
pub struct Renderer<'a> { pub struct Renderer<'a> {
pub(super) ctx: &'a Rc<RenderContext>, pub(super) ctx: &'a Rc<RenderContext>,
@ -201,7 +202,7 @@ impl Renderer<'_> {
} }
pub fn render_texture(&mut self, texture: &Texture, x: i32, y: i32, format: &Format) { pub fn render_texture(&mut self, texture: &Texture, x: i32, y: i32, format: &Format) {
assert!(Rc::ptr_eq(&self.ctx.ctx, &texture.ctx.ctx)); assert!(rc_eq(&self.ctx.ctx, &texture.ctx.ctx));
unsafe { unsafe {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);

View file

@ -18,7 +18,7 @@ impl Color {
} }
fn to_f32(c: u8) -> f32 { fn to_f32(c: u8) -> f32 {
c as f32 / 255 as f32 c as f32 / 255f32
} }
impl Color { impl Color {

View file

@ -21,6 +21,7 @@ use std::fmt::{Debug, Formatter};
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut, Sub}; use std::ops::{Deref, DerefMut, Sub};
use std::rc::Rc; use std::rc::Rc;
use crate::utils::rc_eq::rc_eq;
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -197,14 +198,12 @@ impl ContainerNode {
pub fn prepend_child(self: &Rc<Self>, new: Rc<dyn Node>) { pub fn prepend_child(self: &Rc<Self>, new: Rc<dyn Node>) {
if let Some(child) = self.children.first() { if let Some(child) = self.children.first() {
self.add_child_before_(&child, new); self.add_child_before_(&child, new);
return;
} }
} }
pub fn append_child(self: &Rc<Self>, new: Rc<dyn Node>) { pub fn append_child(self: &Rc<Self>, new: Rc<dyn Node>) {
if let Some(child) = self.children.last() { if let Some(child) = self.children.last() {
self.add_child_after_(&child, new); self.add_child_after_(&child, new);
return;
} }
} }
@ -271,7 +270,7 @@ impl ContainerNode {
let new_child_factor = 1.0 / num_children as f64; let new_child_factor = 1.0 / num_children as f64;
let mut sum_factors = 0.0; let mut sum_factors = 0.0;
for child in self.children.iter() { for child in self.children.iter() {
let factor = if Rc::ptr_eq(&child.node, &new) { let factor = if rc_eq(&child.node, &new) {
new_child_factor new_child_factor
} else { } else {
child.factor.get() * (1.0 - new_child_factor) child.factor.get() * (1.0 - new_child_factor)
@ -588,7 +587,7 @@ impl ContainerNode {
} }
if let Some(ctx) = &ctx { if let Some(ctx) = &ctx {
let title = c.title.borrow_mut(); let title = c.title.borrow_mut();
match text::render(&ctx, width, th, &font, &title, Color::GREY) { match text::render(ctx, width, th, &font, &title, Color::GREY) {
Ok(t) => rd.titles.push(ContainerTitle { Ok(t) => rd.titles.push(ContainerTitle {
x: pos, x: pos,
y: 0, y: 0,
@ -626,7 +625,7 @@ impl ContainerNode {
rd.underline_rects.push(rect); rd.underline_rects.push(rect);
if let Some(ctx) = &ctx { if let Some(ctx) = &ctx {
let title = c.title.borrow_mut(); let title = c.title.borrow_mut();
match text::render(&ctx, body.width(), th, &font, &title, Color::GREY) { match text::render(ctx, body.width(), th, &font, &title, Color::GREY) {
Ok(t) => rd.titles.push(ContainerTitle { Ok(t) => rd.titles.push(ContainerTitle {
x: body.x1(), x: body.x1(),
y: body.y1() - th - 1, y: body.y1() - th - 1,

View file

@ -25,3 +25,4 @@ pub mod trim;
pub mod vasprintf; pub mod vasprintf;
pub mod vec_ext; pub mod vec_ext;
pub mod vecstorage; pub mod vecstorage;
pub mod rc_eq;

View file

@ -65,7 +65,7 @@ impl OutBufferSwapchain {
pub fn commit(&mut self) { pub fn commit(&mut self) {
if self.cur.write_pos > 0 { if self.cur.write_pos > 0 {
let new = self.free.pop().unwrap_or_else(|| Default::default()); let new = self.free.pop().unwrap_or_default();
let old = mem::replace(&mut self.cur, new); let old = mem::replace(&mut self.cur, new);
self.pending.push_back(old); self.pending.push_back(old);
} }

View file

@ -224,7 +224,7 @@ impl<T> NodeRef<T> {
{ {
unsafe { unsafe {
let data = self.data.as_ref(); let data = self.data.as_ref();
let other = peer(&data).get(); let other = peer(data).get();
if other.as_ref().data.is_some() { if other.as_ref().data.is_some() {
other.as_ref().rc.fetch_add(1); other.as_ref().rc.fetch_add(1);
Some(NodeRef { data: other }) Some(NodeRef { data: other })

View file

@ -5,7 +5,7 @@ use uapi::c::c_int;
use uapi::{c, Errno}; use uapi::{c, Errno};
static ERRORS: Lazy<&'static [Option<&'static str>]> = Lazy::new(|| { static ERRORS: Lazy<&'static [Option<&'static str>]> = Lazy::new(|| {
static MSGS: &'static [(c::c_int, &'static str)] = &[ static MSGS: &[(c::c_int, &str)] = &[
(c::EWOULDBLOCK, "Operation would block"), (c::EWOULDBLOCK, "Operation would block"),
(c::ENOTSUP, "Not supported"), (c::ENOTSUP, "Not supported"),
(c::EHWPOISON, "Memory page has hardware error"), (c::EHWPOISON, "Memory page has hardware error"),

5
src/utils/rc_eq.rs Normal file
View file

@ -0,0 +1,5 @@
use std::rc::Rc;
pub fn rc_eq<T: ?Sized>(a: &Rc<T>, b: &Rc<T>) -> bool {
Rc::as_ptr(a) as *const u8 == Rc::as_ptr(b) as *const u8
}

View file

@ -1,4 +1,4 @@
#![allow(unused_imports, unused_variables, dead_code, unused_assignments)] #![allow(unused_imports, unused_variables, dead_code, unused_assignments, clippy::eval_order_dependence, clippy::double_parens, clippy::unnecessary_cast)]
use crate::xcon::{Formatter, Message, Parser, Request, XEvent, XconError}; use crate::xcon::{Formatter, Message, Parser, Request, XEvent, XconError};
use bstr::BStr; use bstr::BStr;

View file

@ -257,7 +257,7 @@ struct AsyncReplyHandler<T: Message<'static>> {
} }
impl<T: Message<'static>> AsyncReplyHandler<T> { impl<T: Message<'static>> AsyncReplyHandler<T> {
fn done(self: Box<Self>, res: Result<Reply<T>, XconError>) { fn done(self, res: Result<Reply<T>, XconError>) {
if let Some(slot) = self.slot.upgrade() { if let Some(slot) = self.slot.upgrade() {
slot.data.set(Some(res)); slot.data.set(Some(res));
if let Some(waker) = slot.waker.take() { if let Some(waker) = slot.waker.take() {

View file

@ -61,7 +61,7 @@ impl<'a> Parser<'a> {
Ok(self.fds[self.fds_pos - 1].clone()) Ok(self.fds[self.fds_pos - 1].clone())
} }
pub fn read_pod<'b, T: Pod>(&mut self) -> Result<T, XconError> { pub fn read_pod<T: Pod>(&mut self) -> Result<T, XconError> {
match uapi::pod_read_init(&self.buf[self.pos..]) { match uapi::pod_read_init(&self.buf[self.pos..]) {
Ok(v) => { Ok(v) => {
self.pos += mem::size_of::<T>(); self.pos += mem::size_of::<T>();

View file

@ -24,19 +24,19 @@ use uapi::{c, pipe2, Errno, OwnedFd};
#[derive(Debug, Error)] #[derive(Debug, Error)]
enum XWaylandError { enum XWaylandError {
#[error("Could not create a wayland socket")] #[error("Could not create a wayland socket")]
SocketFailed(#[source] crate::utils::oserror::OsError), SocketFailed(#[source] OsError),
#[error("/tmp/.X11-unix does not exist")] #[error("/tmp/.X11-unix does not exist")]
MissingSocketDir, MissingSocketDir,
#[error("Could not stat /tmp/.X11-unix")] #[error("Could not stat /tmp/.X11-unix")]
StatSocketDir(#[source] crate::utils::oserror::OsError), StatSocketDir(#[source] OsError),
#[error("/tmp/.X11-unix is not a directory")] #[error("/tmp/.X11-unix is not a directory")]
NotASocketDir, NotASocketDir,
#[error("/tmp/.X11-unix is writable")] #[error("/tmp/.X11-unix is writable")]
SocketDirNotWritable, SocketDirNotWritable,
#[error("Could not write to the lock file")] #[error("Could not write to the lock file")]
WriteLockFile(#[source] std::io::Error), WriteLockFile(#[source] OsError),
#[error("Could not open the lock file for reading")] #[error("Could not open the lock file for reading")]
ReadLockFile(#[source] std::io::Error), ReadLockFile(#[source] OsError),
#[error("The lock file does not contain a PID")] #[error("The lock file does not contain a PID")]
NotALockFile(#[source] ParseIntError), NotALockFile(#[source] ParseIntError),
#[error("The socket is already in use")] #[error("The socket is already in use")]
@ -183,17 +183,18 @@ async fn run(
pub fn build_args(fds: &[OwnedFd]) -> (String, Vec<String>) { pub fn build_args(fds: &[OwnedFd]) -> (String, Vec<String>) {
let prog = "Xwayland".to_string(); let prog = "Xwayland".to_string();
let mut args = vec![]; let args = vec![
args.push("-terminate".to_string()); "-terminate".to_string(),
args.push("-rootless".to_string()); "-rootless".to_string(),
args.push("-verbose".to_string()); "-verbose".to_string(),
args.push(10.to_string()); 10.to_string(),
args.push("-displayfd".to_string()); "-displayfd".to_string(),
args.push(fds[0].raw().to_string()); fds[0].raw().to_string(),
args.push("-listenfd".to_string()); "-listenfd".to_string(),
args.push(fds[1].raw().to_string()); fds[1].raw().to_string(),
args.push("-wm".to_string()); "-wm".to_string(),
args.push(fds[2].raw().to_string()); fds[2].raw().to_string(),
];
(prog, args) (prog, args)
} }

View file

@ -326,8 +326,8 @@ impl Wm {
c, c,
atoms, atoms,
never_focus, never_focus,
root: root, root,
xwin: xwin, xwin,
client, client,
windows: Default::default(), windows: Default::default(),
windows_by_surface_id: Default::default(), windows_by_surface_id: Default::default(),
@ -687,7 +687,7 @@ impl Wm {
{ {
data.info.icccm_hints.input.set(1); data.info.icccm_hints.input.set(1);
} }
self.compute_input_model(&data); self.compute_input_model(data);
} }
async fn load_window_wm_normal_hints(&self, data: &Rc<XwindowData>) { async fn load_window_wm_normal_hints(&self, data: &Rc<XwindowData>) {
@ -838,7 +838,7 @@ impl Wm {
} }
data.info data.info
.never_focus .never_focus
.set(buf.iter().any(|t| self.never_focus.contains(&t))); .set(buf.iter().any(|t| self.never_focus.contains(t)));
data.info.window_types.clear(); data.info.window_types.clear();
data.info data.info
.window_types .window_types
@ -852,7 +852,7 @@ impl Wm {
log::error!("The xwindow has already been constructed"); log::error!("The xwindow has already been constructed");
return; return;
} }
let window = Rc::new(Xwindow::new(&data, &surface, &self.queue)); let window = Rc::new(Xwindow::new(data, &surface, &self.queue));
if let Err(e) = window.install() { if let Err(e) = window.install() {
log::error!( log::error!(
"Could not attach the xwindow to the surface: {}", "Could not attach the xwindow to the surface: {}",
@ -912,7 +912,7 @@ impl Wm {
async fn handle_event(&mut self, event: &Event) { async fn handle_event(&mut self, event: &Event) {
match event.ext() { match event.ext() {
Some(_) => {} Some(_) => {}
_ => self.handle_core_event(&event).await, _ => self.handle_core_event(event).await,
} }
} }
@ -1489,8 +1489,7 @@ impl Wm {
} }
fn update_wants_floating(&self, data: &Rc<XwindowData>) { fn update_wants_floating(&self, data: &Rc<XwindowData>) {
let res = false let res = data.info.modal.get()
|| data.info.modal.get()
|| data || data
.info .info
.window_types .window_types