Update to udev 0.4

This commit is contained in:
Victor Brekenfeld 2020-04-11 19:45:45 +02:00
parent 6a7d933553
commit b43c0db115
5 changed files with 20 additions and 33 deletions

View File

@ -28,8 +28,8 @@ winit = { version = "0.22.0", optional = true }
drm = { version = "^0.4.0", git = "https://github.com/drakulix/drm-rs", branch = "develop", optional = true }
gbm = { version = "^0.6.0", git = "https://github.com/drakulix/gbm.rs", branch = "develop", optional = true, default-features = false, features = ["drm-support"] }
glium = { version = "0.23.0", optional = true, default-features = false }
input = { version = "0.4.1", optional = true }
udev = { version = "0.2.0", optional = true }
input = { version = "0.5", default-features = false, optional = true }
udev = { version = "0.4", optional = true }
dbus = { version = "0.8", optional = true }
systemd = { version = "0.4.0", optional = true }
wayland-protocols = { version = "0.25.0", features = ["unstable_protocols", "server"], optional = true }
@ -37,7 +37,7 @@ image = { version = "0.21.0", optional = true }
lazy_static = "1.0.0"
thiserror = "1"
# TODO: remove as soon as drm-rs provides an error implementing Error
failure = "0.1"
failure = { version = "0.1", optional = true }
[dev-dependencies]
slog-term = "2.3"
@ -47,8 +47,8 @@ gl_generator = { version = "0.10", optional = true }
[features]
default = ["backend_winit", "backend_drm_legacy", "backend_drm_gbm", "backend_drm_egl", "backend_libinput", "backend_udev", "backend_session_logind", "renderer_glium", "xwayland", "wayland_frontend"]
backend_winit = ["winit", "wayland-server/dlopen", "wayland-client/dlopen", "wayland-egl", "backend_egl", "renderer_gl", "use_system_lib"]
backend_drm = ["drm"]
backend_winit = ["winit", "wayland-server/dlopen", "wayland-client/dlopen", "backend_egl", "wayland-egl", "renderer_gl", "use_system_lib"]
backend_drm = ["drm", "failure"]
backend_drm_legacy = ["backend_drm"]
backend_drm_gbm = ["backend_drm", "gbm", "image"]
backend_drm_egl = ["backend_drm", "backend_egl"]

View File

@ -15,6 +15,7 @@ glium = { version = "0.23.0", default-features = false }
wayland-server = "0.25.0"
xkbcommon = "0.4.0"
bitflags = "1.2.1"
input = { version = "0.5.0", features = ["udev"], optional = true }
[dependencies.smithay]
path = ".."
@ -28,5 +29,5 @@ gl_generator = "0.10"
default = [ "winit", "egl", "udev", "logind" ]
egl = [ "smithay/use_system_lib" ]
winit = [ "smithay/backend_winit" ]
udev = [ "smithay/backend_libinput", "smithay/backend_drm_legacy", "smithay/backend_drm_gbm", "smithay/backend_drm_egl", "smithay/backend_udev", "smithay/backend_session" ]
udev = [ "smithay/backend_libinput", "smithay/backend_udev", "smithay/backend_drm_legacy", "smithay/backend_drm_gbm", "smithay/backend_drm_egl", "smithay/backend_session", "input" ]
logind = [ "smithay/backend_session_logind" ]

View File

@ -118,14 +118,12 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
/*
* Initialize the udev backend
*/
let context = ::smithay::reexports::udev::Context::new().map_err(|_| ())?;
let seat = session.seat();
let primary_gpu = primary_gpu(&context, &seat).unwrap_or_default();
let primary_gpu = primary_gpu(&seat).unwrap_or_default();
let bytes = include_bytes!("../resources/cursor2.rgba");
let udev_backend = UdevBackend::new(
&context,
UdevHandlerImpl {
compositor_token,
#[cfg(feature = "egl")]
@ -223,7 +221,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
* Initialize libinput backend
*/
let mut libinput_context =
Libinput::new_from_udev::<LibinputSessionInterface<AutoSession>>(session.clone().into(), &context);
Libinput::new_with_udev::<LibinputSessionInterface<AutoSession>>(session.clone().into());
let libinput_session_id = notifier.register(libinput_context.observer());
libinput_context.udev_assign_seat(&seat).unwrap();
let mut libinput_backend = LibinputInputBackend::new(libinput_context, log.clone());

View File

@ -66,7 +66,7 @@ use std::{
},
};
#[cfg(feature = "backend_udev")]
use udev::Context;
use udev::Device as UdevDevice;
#[allow(dead_code)]
mod tty {
@ -126,12 +126,7 @@ fn is_tty_device(dev: dev_t, _path: Option<&Path>) -> bool {
fn is_tty_device(dev: dev_t, path: Option<&Path>) -> bool {
match path {
Some(path) => {
let udev = match Context::new() {
Ok(context) => context,
Err(_) => return major(dev) == TTY_MAJOR || minor(dev) != 0,
};
let device = match udev.device_from_syspath(path) {
let device = match UdevDevice::from_syspath(path) {
Ok(device) => device,
Err(_) => return major(dev) == TTY_MAJOR || minor(dev) != 0,
};

View File

@ -13,10 +13,11 @@ use nix::sys::stat::{dev_t, stat};
use std::{
collections::HashSet,
ffi::OsString,
io::Result as IoResult,
os::unix::io::{AsRawFd, RawFd},
path::{Path, PathBuf},
};
use udev::{Context, Enumerator, EventType, MonitorBuilder, MonitorSocket, Result as UdevResult};
use udev::{Enumerator, EventType, MonitorBuilder, MonitorSocket};
use calloop::{
generic::{Generic, SourceFd},
@ -46,22 +47,16 @@ impl<T: UdevHandler + 'static> UdevBackend<T> {
/// Creates a new [`UdevBackend`]
///
/// ## Arguments
/// `context` - An initialized udev context
/// `handler` - User-provided handler to respond to any detected changes
/// `seat` -
/// `logger` - slog Logger to be used by the backend and its `DrmDevices`.
pub fn new<L, S: AsRef<str>>(
context: &Context,
mut handler: T,
seat: S,
logger: L,
) -> UdevResult<UdevBackend<T>>
pub fn new<L, S: AsRef<str>>(mut handler: T, seat: S, logger: L) -> IoResult<UdevBackend<T>>
where
L: Into<Option<::slog::Logger>>,
{
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_udev"));
let devices = all_gpus(context, seat)?
let devices = all_gpus(seat)?
.into_iter()
// Create devices
.flat_map(|path| match stat(&path) {
@ -76,9 +71,7 @@ impl<T: UdevHandler + 'static> UdevBackend<T> {
})
.collect();
let mut builder = MonitorBuilder::new(context)?;
builder.match_subsystem("drm")?;
let monitor = builder.listen()?;
let monitor = MonitorBuilder::new()?.match_subsystem("drm")?.listen()?;
Ok(UdevBackend {
devices,
@ -173,8 +166,8 @@ pub trait UdevHandler {
///
/// Might be used for filtering in [`UdevHandler::device_added`] or for manual
/// [`LegacyDrmDevice`](::backend::drm::legacy::LegacyDrmDevice) initialization.
pub fn primary_gpu<S: AsRef<str>>(context: &Context, seat: S) -> UdevResult<Option<PathBuf>> {
let mut enumerator = Enumerator::new(context)?;
pub fn primary_gpu<S: AsRef<str>>(seat: S) -> IoResult<Option<PathBuf>> {
let mut enumerator = Enumerator::new()?;
enumerator.match_subsystem("drm")?;
enumerator.match_sysname("card[0-9]*")?;
@ -204,8 +197,8 @@ pub fn primary_gpu<S: AsRef<str>>(context: &Context, seat: S) -> UdevResult<Opti
///
/// Might be used for manual [`LegacyDrmDevice`](::backend::drm::legacy::LegacyDrmDevice)
/// initialization.
pub fn all_gpus<S: AsRef<str>>(context: &Context, seat: S) -> UdevResult<Vec<PathBuf>> {
let mut enumerator = Enumerator::new(context)?;
pub fn all_gpus<S: AsRef<str>>(seat: S) -> IoResult<Vec<PathBuf>> {
let mut enumerator = Enumerator::new()?;
enumerator.match_subsystem("drm")?;
enumerator.match_sysname("card[0-9]*")?;
Ok(enumerator