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

@ -228,7 +228,7 @@ fn create_connector(
master: dev.master.clone(),
output_id: state.output_ids.next(),
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,
buffers: Default::default(),
next_buffer: Default::default(),
@ -749,7 +749,7 @@ impl MetalBackend {
let bo = dev.dev.gbm.create_bo(
width,
height,
&format,
format,
GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT,
);
let bo = match bo {
@ -929,7 +929,7 @@ pub struct RenderBuffer {
}
fn modes_equal(a: &DrmModeInfo, b: &DrmModeInfo) -> bool {
true && a.clock == b.clock
a.clock == b.clock
&& a.hdisplay == b.hdisplay
&& a.hsync_start == b.hsync_start
&& a.hsync_end == b.hsync_end

View file

@ -329,7 +329,7 @@ impl XBackendData {
modifier: INVALID_MODIFIER,
};
let mut images = [None, None];
for i in 0..2 {
for image in &mut images {
let bo = self
.gbm
.create_bo(width, height, &format, GBM_BO_USE_RENDERING)?;
@ -358,7 +358,7 @@ impl XBackendData {
}
pfb.pixmap
};
images[i] = Some(XImage {
*image = Some(XImage {
pixmap: Cell::new(pixmap),
fb: CloneCell::new(fb),
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> {
match Id::lookup(self, id) {
Some(t) => Ok(t),
_ => {
return Err(ClientError::LookupError(LookupError {
interface: Id::INTERFACE,
id: id.into(),
}))
}
_ => Err(ClientError::LookupError(LookupError {
interface: Id::INTERFACE,
id: id.into(),
})),
}
}
}

View file

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

View file

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

View file

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

View file

@ -68,6 +68,7 @@ impl Incoming {
self.incoming
.fill_msg_buf(remaining as usize, msg_buf)
.await?;
#[allow(clippy::drop_ref)]
drop(msg_buf);
let msg_buf = unsafe { msg_buf_data.get().deref().deref() };
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 mut parser = Parser {
buf: &msg_buf,
buf: msg_buf,
pos: FIXED_HEADER_SIZE + dyn_header_len as usize,
fds: &fds,
};

View file

@ -354,7 +354,7 @@ where
struct AsyncReplyHandler<T: Message<'static>>(Rc<AsyncReplySlot<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));
if let Some(waker) = self.0.waker.take() {
waker.wake();

View file

@ -284,7 +284,7 @@ impl DrmMaster {
master: self.clone(),
fb,
}),
Err(e) => return Err(DrmError::AddFb(e)),
Err(e) => Err(DrmError::AddFb(e)),
}
}
@ -544,11 +544,11 @@ pub struct DrmModeInfo {
impl DrmModeInfo {
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)
}
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 len = name.len().min(self.name.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 {
uapi::format_ustr!("/sys/dev/char/{maj}:{min}/device/drm")
@ -264,11 +264,11 @@ pub fn mode_getproperty(
prop.count_values = 0;
let mut props =
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 {
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());
for v in props {
values.push(DrmPropertyEnumValue {

View file

@ -52,6 +52,7 @@ use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use thiserror::Error;
use uapi::{c, Errno, OwnedFd};
use crate::utils::rc_eq::rc_eq;
const POINTER: u32 = 1;
const KEYBOARD: u32 = 2;
@ -193,7 +194,7 @@ impl WlSeatGlobal {
for seat in client.values() {
let kbs = seat.keyboards.lock();
for kb in kbs.values() {
let fd = match seat.keymap_fd(&keymap) {
let fd = match seat.keymap_fd(keymap) {
Ok(fd) => fd,
Err(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>>) {
if let Some(old) = self.cursor.get() {
if let Some(new) = cursor.as_ref() {
if Rc::ptr_eq(&old, new) {
if rc_eq(&old, new) {
return;
}
}

View file

@ -236,7 +236,7 @@ impl WlSeatGlobal {
client: &Rc<Client>,
) {
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| {
T::send_selection(dd, ObjectId::NONE.into());
}),
@ -441,7 +441,7 @@ impl WlSeatGlobal {
pub fn focus_surface(&self, surface: &WlSurface) {
let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect();
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)
});
let ModifierState {
@ -452,7 +452,7 @@ impl WlSeatGlobal {
..
} = self.kb_state.borrow().mods();
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)
});

View file

@ -275,7 +275,7 @@ impl PointerOwner for GrabPointerOwner {
icon.dnd_icons.insert(seat.id(), seat.clone());
}
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;
let pointer_owner = Rc::new(DndPointerOwner {

View file

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

View file

@ -530,7 +530,7 @@ impl XdgSurfaceExt for XdgToplevel {
if let Some(workspace) = self.xdg.workspace.get() {
let output = workspace.output.get();
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() {
self.xdg.surface.send_enter(binding.id);
}

View file

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

View file

@ -11,7 +11,23 @@
clippy::needless_lifetimes,
clippy::enum_variant_names,
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};

View file

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

View file

@ -28,9 +28,9 @@ pub mod display;
pub mod image;
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> {
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"));

View file

@ -19,6 +19,7 @@ use crate::theme::Color;
use crate::tree::{ContainerNode, FloatNode, Node, OutputNode, WorkspaceNode};
use std::ops::Deref;
use std::rc::Rc;
use crate::utils::rc_eq::rc_eq;
pub struct Renderer<'a> {
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) {
assert!(Rc::ptr_eq(&self.ctx.ctx, &texture.ctx.ctx));
assert!(rc_eq(&self.ctx.ctx, &texture.ctx.ctx));
unsafe {
glActiveTexture(GL_TEXTURE0);

View file

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

View file

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

View file

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

View file

@ -65,7 +65,7 @@ impl OutBufferSwapchain {
pub fn commit(&mut self) {
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);
self.pending.push_back(old);
}

View file

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

View file

@ -5,7 +5,7 @@ use uapi::c::c_int;
use uapi::{c, Errno};
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::ENOTSUP, "Not supported"),
(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 bstr::BStr;

View file

@ -257,7 +257,7 @@ struct AsyncReplyHandler<T: Message<'static>> {
}
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() {
slot.data.set(Some(res));
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())
}
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..]) {
Ok(v) => {
self.pos += mem::size_of::<T>();

View file

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

View file

@ -326,8 +326,8 @@ impl Wm {
c,
atoms,
never_focus,
root: root,
xwin: xwin,
root,
xwin,
client,
windows: Default::default(),
windows_by_surface_id: Default::default(),
@ -687,7 +687,7 @@ impl Wm {
{
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>) {
@ -838,7 +838,7 @@ impl Wm {
}
data.info
.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
@ -852,7 +852,7 @@ impl Wm {
log::error!("The xwindow has already been constructed");
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() {
log::error!(
"Could not attach the xwindow to the surface: {}",
@ -912,7 +912,7 @@ impl Wm {
async fn handle_event(&mut self, event: &Event) {
match event.ext() {
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>) {
let res = false
|| data.info.modal.get()
let res = data.info.modal.get()
|| data
.info
.window_types