1
0
Fork 0
forked from wry/wry

autocommit 2022-03-23 16:23:28 CET

This commit is contained in:
Julian Orth 2022-03-23 16:23:28 +01:00
parent d7f298ab5f
commit a9a4fc04b7
13 changed files with 91 additions and 70 deletions

48
Cargo.lock generated
View file

@ -39,9 +39,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.53" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
[[package]] [[package]]
name = "atty" name = "atty"
@ -105,9 +105,7 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [ dependencies = [
"lazy_static",
"memchr", "memchr",
"regex-automata",
] ]
[[package]] [[package]]
@ -118,9 +116,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.72" version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -208,9 +206,9 @@ dependencies = [
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.4" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"libc", "libc",
@ -290,9 +288,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.117" version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
[[package]] [[package]]
name = "libloading" name = "libloading"
@ -306,9 +304,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.14" version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
@ -370,9 +368,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.9.0" version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]] [[package]]
name = "pin-project" name = "pin-project"
@ -423,9 +421,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.15" version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -462,21 +460,15 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.5.4" version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.25" version = "0.6.25"
@ -518,9 +510,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.86" version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -529,9 +521,9 @@ dependencies = [
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.2" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [ dependencies = [
"winapi-util", "winapi-util",
] ]

View file

@ -24,7 +24,7 @@ num-traits = "0.2.14"
num-derive = "0.3.3" num-derive = "0.3.3"
bitflags = "1.3.2" bitflags = "1.3.2"
libloading = "0.7.2" libloading = "0.7.2"
bstr = "0.2.17" bstr = { version = "0.2.17", default-features = false, features = ["std"] }
isnt = "0.1.0" isnt = "0.1.0"
once_cell = "1.9.0" once_cell = "1.9.0"
rand = "0.8.4" rand = "0.8.4"
@ -40,7 +40,7 @@ pin-project = "1.0.10"
[build-dependencies] [build-dependencies]
repc = "0.1.1" repc = "0.1.1"
anyhow = "1.0.52" anyhow = "1.0.52"
bstr = "0.2.17" bstr = { version = "0.2.17", default-features = false, features = ["std"] }
#[profile.dev.build-override] #[profile.dev.build-override]
#opt-level = 3 #opt-level = 3

View file

@ -8,6 +8,7 @@ use crate::drm::drm::{
}; };
use crate::utils::bitflags::BitflagsExt; use crate::utils::bitflags::BitflagsExt;
use crate::utils::oserror::OsError; use crate::utils::oserror::OsError;
use crate::utils::trim::AsciiTrim;
use ahash::AHashMap; use ahash::AHashMap;
use bstr::ByteSlice; use bstr::ByteSlice;
use std::ffi::CString; use std::ffi::CString;

View file

@ -19,6 +19,7 @@ use crate::libinput::sys::{
use crate::udev::UdevError; use crate::udev::UdevError;
use crate::utils::oserror::OsError; use crate::utils::oserror::OsError;
use crate::utils::ptr_ext::PtrExt; use crate::utils::ptr_ext::PtrExt;
use crate::utils::trim::AsciiTrim;
use crate::utils::vasprintf::vasprintf_; use crate::utils::vasprintf::vasprintf_;
use crate::ErrorFmt; use crate::ErrorFmt;
use bstr::ByteSlice; use bstr::ByteSlice;

View file

@ -80,6 +80,7 @@ mod ifs;
mod libinput; mod libinput;
mod logind; mod logind;
mod object; mod object;
mod pango;
mod pixman; mod pixman;
mod rect; mod rect;
mod render; mod render;
@ -99,7 +100,6 @@ mod wire_xcon;
mod xcon; mod xcon;
mod xkbcommon; mod xkbcommon;
mod xwayland; mod xwayland;
mod pango;
fn main() { fn main() {
env_logger::builder() env_logger::builder()

View file

@ -1,17 +1,17 @@
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
use crate::pango::consts::{CairoFormat, CairoOperator, PangoEllipsizeMode};
use std::cell::Cell; use std::cell::Cell;
use std::rc::Rc; use std::rc::Rc;
use thiserror::Error; use thiserror::Error;
use uapi::{c, IntoUstr}; use uapi::{c, IntoUstr};
use crate::pango::consts::{CairoFormat, CairoOperator, PangoEllipsizeMode};
pub mod consts; pub mod consts;
include!(concat!(env!("OUT_DIR"), "/pango_tys.rs")); include!(concat!(env!("OUT_DIR"), "/pango_tys.rs"));
#[link(name = "cairo")] #[link(name = "cairo")]
extern { extern "C" {
type cairo_surface_t; type cairo_surface_t;
type cairo_t; type cairo_t;
@ -33,18 +33,12 @@ extern {
fn cairo_destroy(cairo: *mut cairo_t); fn cairo_destroy(cairo: *mut cairo_t);
fn cairo_set_operator(cr: *mut cairo_t, op: cairo_operator_t); fn cairo_set_operator(cr: *mut cairo_t, op: cairo_operator_t);
fn cairo_set_source_rgba( fn cairo_set_source_rgba(cr: *mut cairo_t, red: f64, green: f64, blue: f64, alpha: f64);
cr: *mut cairo_t,
red: f64,
green: f64,
blue: f64,
alpha: f64,
);
fn cairo_move_to(cr: *mut cairo_t, x: f64, y: f64); fn cairo_move_to(cr: *mut cairo_t, x: f64, y: f64);
} }
#[link(name = "pangocairo-1.0")] #[link(name = "pangocairo-1.0")]
extern { extern "C" {
type PangoContext_; type PangoContext_;
fn pango_cairo_create_context(cr: *mut cairo_t) -> *mut PangoContext_; fn pango_cairo_create_context(cr: *mut cairo_t) -> *mut PangoContext_;
@ -52,14 +46,14 @@ extern {
} }
#[link(name = "gobject-2.0")] #[link(name = "gobject-2.0")]
extern { extern "C" {
type GObject; type GObject;
fn g_object_unref(object: *mut GObject); fn g_object_unref(object: *mut GObject);
} }
#[link(name = "pango-1.0")] #[link(name = "pango-1.0")]
extern { extern "C" {
type PangoFontDescription_; type PangoFontDescription_;
type PangoLayout_; type PangoLayout_;
@ -100,16 +94,18 @@ pub struct CairoImageSurface {
} }
impl CairoImageSurface { impl CairoImageSurface {
pub fn new_image_surface(format: CairoFormat, width: i32, height: i32) -> Result<Rc<Self>, PangoError> { pub fn new_image_surface(
format: CairoFormat,
width: i32,
height: i32,
) -> Result<Rc<Self>, PangoError> {
unsafe { unsafe {
let s = cairo_image_surface_create(format.raw() as _, width as _, height as _); let s = cairo_image_surface_create(format.raw() as _, width as _, height as _);
let status = cairo_surface_status(s); let status = cairo_surface_status(s);
if status != 0 { if status != 0 {
return Err(PangoError::CreateSurface(status as _)); return Err(PangoError::CreateSurface(status as _));
} }
Ok(Rc::new(Self { Ok(Rc::new(Self { s }))
s,
}))
} }
} }
@ -134,15 +130,11 @@ impl CairoImageSurface {
} }
pub fn height(&self) -> i32 { pub fn height(&self) -> i32 {
unsafe { unsafe { cairo_image_surface_get_height(self.s) as _ }
cairo_image_surface_get_height(self.s) as _
}
} }
pub fn stride(&self) -> i32 { pub fn stride(&self) -> i32 {
unsafe { unsafe { cairo_image_surface_get_stride(self.s) as _ }
cairo_image_surface_get_stride(self.s) as _
}
} }
pub fn data(&self) -> Result<&[Cell<u8>], PangoError> { pub fn data(&self) -> Result<&[Cell<u8>], PangoError> {
@ -177,10 +169,7 @@ impl CairoContext {
if p.is_null() { if p.is_null() {
return Err(PangoError::CreatePangoCairo); return Err(PangoError::CreatePangoCairo);
} }
Ok(Rc::new(PangoCairoContext { Ok(Rc::new(PangoCairoContext { c: self.clone(), p }))
c: self.clone(),
p,
}))
} }
} }
@ -247,9 +236,7 @@ impl PangoFontDescription {
pub fn from_string<'a>(s: impl IntoUstr<'a>) -> Self { pub fn from_string<'a>(s: impl IntoUstr<'a>) -> Self {
let s = s.into_ustr(); let s = s.into_ustr();
Self { Self {
s: unsafe { s: unsafe { pango_font_description_from_string(s.as_ptr()) },
pango_font_description_from_string(s.as_ptr())
},
} }
} }
} }

View file

@ -1,6 +1,7 @@
use crate::render::egl::sys::{eglQueryString, EGLDeviceEXT, EGLDisplay, EGL_EXTENSIONS}; use crate::render::egl::sys::{eglQueryString, EGLDeviceEXT, EGLDisplay, EGL_EXTENSIONS};
use crate::render::egl::PROCS; use crate::render::egl::PROCS;
use crate::render::gl::sys::{glGetString, GL_EXTENSIONS}; use crate::render::gl::sys::{glGetString, GL_EXTENSIONS};
use crate::utils::trim::AsciiTrim;
use ahash::AHashSet; use ahash::AHashSet;
use bstr::ByteSlice; use bstr::ByteSlice;
use std::ffi::CStr; use std::ffi::CStr;

View file

@ -1,11 +1,13 @@
use crate::format::ARGB8888; use crate::format::ARGB8888;
use crate::pango::consts::{
CAIRO_FORMAT_ARGB32, CAIRO_OPERATOR_SOURCE, PANGO_ELLIPSIZE_END, PANGO_SCALE,
};
use crate::pango::{CairoImageSurface, PangoError, PangoFontDescription};
use crate::render::{RenderContext, Texture}; use crate::render::{RenderContext, Texture};
use crate::theme::Color; use crate::theme::Color;
use crate::RenderError; use crate::RenderError;
use std::rc::Rc; use std::rc::Rc;
use thiserror::Error; use thiserror::Error;
use crate::pango::{CairoImageSurface, PangoError, PangoFontDescription};
use crate::pango::consts::{CAIRO_FORMAT_ARGB32, CAIRO_OPERATOR_SOURCE, PANGO_ELLIPSIZE_END, PANGO_SCALE};
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum TextError { pub enum TextError {

View file

@ -21,6 +21,7 @@ pub mod smallmap;
pub mod stack; pub mod stack;
pub mod syncqueue; pub mod syncqueue;
pub mod tri; pub mod tri;
pub mod trim;
pub mod vasprintf; pub mod vasprintf;
pub mod vec_ext; pub mod vec_ext;
pub mod vecstorage; pub mod vecstorage;

33
src/utils/trim.rs Normal file
View file

@ -0,0 +1,33 @@
pub trait AsciiTrim {
fn trim(&self) -> &[u8];
fn trim_start(&self) -> &[u8];
fn trim_end(&self) -> &[u8];
}
impl AsciiTrim for [u8] {
fn trim(&self) -> &[u8] {
self.trim_start().trim_end()
}
fn trim_start(&self) -> &[u8] {
let mut s = self;
while let Some((b, r)) = s.split_first() {
if !matches!(*b, b' ' | b'\t' | b'\n') {
break;
}
s = r;
}
s
}
fn trim_end(&self) -> &[u8] {
let mut s = self;
while let Some((b, r)) = s.split_last() {
if !matches!(*b, b' ' | b'\t' | b'\n') {
break;
}
s = r;
}
s
}
}

View file

@ -13,6 +13,7 @@ use std::ptr;
use std::rc::Rc; use std::rc::Rc;
use crate::utils::ptr_ext::PtrExt; use crate::utils::ptr_ext::PtrExt;
use crate::utils::trim::AsciiTrim;
use thiserror::Error; use thiserror::Error;
use uapi::{c, OwnedFd}; use uapi::{c, OwnedFd};

View file

@ -5,6 +5,7 @@ use crate::client::ClientError;
use crate::forker::ForkerProxy; use crate::forker::ForkerProxy;
use crate::ifs::wl_surface::xwindow::Xwindow; use crate::ifs::wl_surface::xwindow::Xwindow;
use crate::ifs::wl_surface::WlSurface; use crate::ifs::wl_surface::WlSurface;
use crate::utils::oserror::OsError;
use crate::utils::tri::Try; use crate::utils::tri::Try;
use crate::wire::WlSurfaceId; use crate::wire::WlSurfaceId;
use crate::xcon::XconError; use crate::xcon::XconError;
@ -16,7 +17,6 @@ use std::num::ParseIntError;
use std::rc::Rc; use std::rc::Rc;
use thiserror::Error; use thiserror::Error;
use uapi::{c, pipe2, Errno, OwnedFd}; use uapi::{c, pipe2, Errno, OwnedFd};
use crate::utils::oserror::OsError;
#[derive(Debug, Error)] #[derive(Debug, Error)]
enum XWaylandError { enum XWaylandError {
@ -128,7 +128,11 @@ async fn run(
Ok(p) => p, Ok(p) => p,
Err(e) => return Err(XWaylandError::Pipe(e.into())), Err(e) => return Err(XWaylandError::Pipe(e.into())),
}; };
let wm = uapi::socketpair(c::AF_UNIX, c::SOCK_STREAM | c::SOCK_CLOEXEC | c::SOCK_NONBLOCK, 0); let wm = uapi::socketpair(
c::AF_UNIX,
c::SOCK_STREAM | c::SOCK_CLOEXEC | c::SOCK_NONBLOCK,
0,
);
let (wm1, wm2) = match wm { let (wm1, wm2) = match wm {
Ok(w) => w, Ok(w) => w,
Err(e) => return Err(XWaylandError::Socketpair(e.into())), Err(e) => return Err(XWaylandError::Socketpair(e.into())),

View file

@ -6,20 +6,18 @@ use crate::wire::WlSurfaceId;
use crate::wire_xcon::{ use crate::wire_xcon::{
ChangeWindowAttributes, ClientMessage, CompositeRedirectSubwindows, ConfigureNotify, ChangeWindowAttributes, ClientMessage, CompositeRedirectSubwindows, ConfigureNotify,
ConfigureRequest, ConfigureWindow, ConfigureWindowValues, CreateGC, CreateNotify, CreatePixmap, ConfigureRequest, ConfigureWindow, ConfigureWindowValues, CreateGC, CreateNotify, CreatePixmap,
CreateWindow, CreateWindowValues, DestroyNotify, FreeGC, FreePixmap, InternAtom, CreateWindow, CreateWindowValues, DestroyNotify, FreeGC, FreePixmap, InternAtom, MapRequest,
MapRequest, MapWindow, PutImage, RenderCreateCursor, RenderCreatePicture, MapWindow, PutImage, RenderCreateCursor, RenderCreatePicture, SetSelectionOwner,
SetSelectionOwner,
}; };
use crate::xcon::consts::{ use crate::xcon::consts::{
COMPOSITE_REDIRECT_MANUAL, EVENT_MASK_PROPERTY_CHANGE, EVENT_MASK_SUBSTRUCTURE_NOTIFY, COMPOSITE_REDIRECT_MANUAL, EVENT_MASK_PROPERTY_CHANGE, EVENT_MASK_SUBSTRUCTURE_NOTIFY,
EVENT_MASK_SUBSTRUCTURE_REDIRECT, IMAGE_FORMAT_Z_PIXMAP, EVENT_MASK_SUBSTRUCTURE_REDIRECT, IMAGE_FORMAT_Z_PIXMAP, WINDOW_CLASS_INPUT_OUTPUT,
WINDOW_CLASS_INPUT_OUTPUT,
}; };
use crate::xcon::{Event, XEvent, Xcon}; use crate::xcon::{Event, XEvent, Xcon};
use crate::xwayland::{XWaylandError, XWaylandEvent}; use crate::xwayland::{XWaylandError, XWaylandEvent};
use crate::{AsyncQueue, ErrorFmt, State}; use crate::{AsyncQueue, ErrorFmt, State};
use ahash::AHashMap; use ahash::AHashMap;
use futures_util::{FutureExt, select}; use futures_util::{select, FutureExt};
use std::mem; use std::mem;
use std::rc::Rc; use std::rc::Rc;
use uapi::OwnedFd; use uapi::OwnedFd;