Update to udev 0.4
This commit is contained in:
parent
6a7d933553
commit
b43c0db115
10
Cargo.toml
10
Cargo.toml
|
@ -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 }
|
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"] }
|
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 }
|
glium = { version = "0.23.0", optional = true, default-features = false }
|
||||||
input = { version = "0.4.1", optional = true }
|
input = { version = "0.5", default-features = false, optional = true }
|
||||||
udev = { version = "0.2.0", optional = true }
|
udev = { version = "0.4", optional = true }
|
||||||
dbus = { version = "0.8", optional = true }
|
dbus = { version = "0.8", optional = true }
|
||||||
systemd = { version = "0.4.0", optional = true }
|
systemd = { version = "0.4.0", optional = true }
|
||||||
wayland-protocols = { version = "0.25.0", features = ["unstable_protocols", "server"], 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"
|
lazy_static = "1.0.0"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
# TODO: remove as soon as drm-rs provides an error implementing Error
|
# TODO: remove as soon as drm-rs provides an error implementing Error
|
||||||
failure = "0.1"
|
failure = { version = "0.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
slog-term = "2.3"
|
slog-term = "2.3"
|
||||||
|
@ -47,8 +47,8 @@ gl_generator = { version = "0.10", optional = true }
|
||||||
|
|
||||||
[features]
|
[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"]
|
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_winit = ["winit", "wayland-server/dlopen", "wayland-client/dlopen", "backend_egl", "wayland-egl", "renderer_gl", "use_system_lib"]
|
||||||
backend_drm = ["drm"]
|
backend_drm = ["drm", "failure"]
|
||||||
backend_drm_legacy = ["backend_drm"]
|
backend_drm_legacy = ["backend_drm"]
|
||||||
backend_drm_gbm = ["backend_drm", "gbm", "image"]
|
backend_drm_gbm = ["backend_drm", "gbm", "image"]
|
||||||
backend_drm_egl = ["backend_drm", "backend_egl"]
|
backend_drm_egl = ["backend_drm", "backend_egl"]
|
||||||
|
|
|
@ -15,6 +15,7 @@ glium = { version = "0.23.0", default-features = false }
|
||||||
wayland-server = "0.25.0"
|
wayland-server = "0.25.0"
|
||||||
xkbcommon = "0.4.0"
|
xkbcommon = "0.4.0"
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
|
input = { version = "0.5.0", features = ["udev"], optional = true }
|
||||||
|
|
||||||
[dependencies.smithay]
|
[dependencies.smithay]
|
||||||
path = ".."
|
path = ".."
|
||||||
|
@ -28,5 +29,5 @@ gl_generator = "0.10"
|
||||||
default = [ "winit", "egl", "udev", "logind" ]
|
default = [ "winit", "egl", "udev", "logind" ]
|
||||||
egl = [ "smithay/use_system_lib" ]
|
egl = [ "smithay/use_system_lib" ]
|
||||||
winit = [ "smithay/backend_winit" ]
|
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" ]
|
logind = [ "smithay/backend_session_logind" ]
|
||||||
|
|
|
@ -118,14 +118,12 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
|
||||||
/*
|
/*
|
||||||
* Initialize the udev backend
|
* Initialize the udev backend
|
||||||
*/
|
*/
|
||||||
let context = ::smithay::reexports::udev::Context::new().map_err(|_| ())?;
|
|
||||||
let seat = session.seat();
|
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 bytes = include_bytes!("../resources/cursor2.rgba");
|
||||||
let udev_backend = UdevBackend::new(
|
let udev_backend = UdevBackend::new(
|
||||||
&context,
|
|
||||||
UdevHandlerImpl {
|
UdevHandlerImpl {
|
||||||
compositor_token,
|
compositor_token,
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
|
@ -223,7 +221,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
|
||||||
* Initialize libinput backend
|
* Initialize libinput backend
|
||||||
*/
|
*/
|
||||||
let mut libinput_context =
|
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());
|
let libinput_session_id = notifier.register(libinput_context.observer());
|
||||||
libinput_context.udev_assign_seat(&seat).unwrap();
|
libinput_context.udev_assign_seat(&seat).unwrap();
|
||||||
let mut libinput_backend = LibinputInputBackend::new(libinput_context, log.clone());
|
let mut libinput_backend = LibinputInputBackend::new(libinput_context, log.clone());
|
||||||
|
|
|
@ -66,7 +66,7 @@ use std::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "backend_udev")]
|
#[cfg(feature = "backend_udev")]
|
||||||
use udev::Context;
|
use udev::Device as UdevDevice;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod tty {
|
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 {
|
fn is_tty_device(dev: dev_t, path: Option<&Path>) -> bool {
|
||||||
match path {
|
match path {
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
let udev = match Context::new() {
|
let device = match UdevDevice::from_syspath(path) {
|
||||||
Ok(context) => context,
|
|
||||||
Err(_) => return major(dev) == TTY_MAJOR || minor(dev) != 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let device = match udev.device_from_syspath(path) {
|
|
||||||
Ok(device) => device,
|
Ok(device) => device,
|
||||||
Err(_) => return major(dev) == TTY_MAJOR || minor(dev) != 0,
|
Err(_) => return major(dev) == TTY_MAJOR || minor(dev) != 0,
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,10 +13,11 @@ use nix::sys::stat::{dev_t, stat};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
|
io::Result as IoResult,
|
||||||
os::unix::io::{AsRawFd, RawFd},
|
os::unix::io::{AsRawFd, RawFd},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use udev::{Context, Enumerator, EventType, MonitorBuilder, MonitorSocket, Result as UdevResult};
|
use udev::{Enumerator, EventType, MonitorBuilder, MonitorSocket};
|
||||||
|
|
||||||
use calloop::{
|
use calloop::{
|
||||||
generic::{Generic, SourceFd},
|
generic::{Generic, SourceFd},
|
||||||
|
@ -46,22 +47,16 @@ impl<T: UdevHandler + 'static> UdevBackend<T> {
|
||||||
/// Creates a new [`UdevBackend`]
|
/// Creates a new [`UdevBackend`]
|
||||||
///
|
///
|
||||||
/// ## Arguments
|
/// ## Arguments
|
||||||
/// `context` - An initialized udev context
|
|
||||||
/// `handler` - User-provided handler to respond to any detected changes
|
/// `handler` - User-provided handler to respond to any detected changes
|
||||||
/// `seat` -
|
/// `seat` -
|
||||||
/// `logger` - slog Logger to be used by the backend and its `DrmDevices`.
|
/// `logger` - slog Logger to be used by the backend and its `DrmDevices`.
|
||||||
pub fn new<L, S: AsRef<str>>(
|
pub fn new<L, S: AsRef<str>>(mut handler: T, seat: S, logger: L) -> IoResult<UdevBackend<T>>
|
||||||
context: &Context,
|
|
||||||
mut handler: T,
|
|
||||||
seat: S,
|
|
||||||
logger: L,
|
|
||||||
) -> UdevResult<UdevBackend<T>>
|
|
||||||
where
|
where
|
||||||
L: Into<Option<::slog::Logger>>,
|
L: Into<Option<::slog::Logger>>,
|
||||||
{
|
{
|
||||||
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_udev"));
|
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()
|
.into_iter()
|
||||||
// Create devices
|
// Create devices
|
||||||
.flat_map(|path| match stat(&path) {
|
.flat_map(|path| match stat(&path) {
|
||||||
|
@ -76,9 +71,7 @@ impl<T: UdevHandler + 'static> UdevBackend<T> {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut builder = MonitorBuilder::new(context)?;
|
let monitor = MonitorBuilder::new()?.match_subsystem("drm")?.listen()?;
|
||||||
builder.match_subsystem("drm")?;
|
|
||||||
let monitor = builder.listen()?;
|
|
||||||
|
|
||||||
Ok(UdevBackend {
|
Ok(UdevBackend {
|
||||||
devices,
|
devices,
|
||||||
|
@ -173,8 +166,8 @@ pub trait UdevHandler {
|
||||||
///
|
///
|
||||||
/// Might be used for filtering in [`UdevHandler::device_added`] or for manual
|
/// Might be used for filtering in [`UdevHandler::device_added`] or for manual
|
||||||
/// [`LegacyDrmDevice`](::backend::drm::legacy::LegacyDrmDevice) initialization.
|
/// [`LegacyDrmDevice`](::backend::drm::legacy::LegacyDrmDevice) initialization.
|
||||||
pub fn primary_gpu<S: AsRef<str>>(context: &Context, seat: S) -> UdevResult<Option<PathBuf>> {
|
pub fn primary_gpu<S: AsRef<str>>(seat: S) -> IoResult<Option<PathBuf>> {
|
||||||
let mut enumerator = Enumerator::new(context)?;
|
let mut enumerator = Enumerator::new()?;
|
||||||
enumerator.match_subsystem("drm")?;
|
enumerator.match_subsystem("drm")?;
|
||||||
enumerator.match_sysname("card[0-9]*")?;
|
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)
|
/// Might be used for manual [`LegacyDrmDevice`](::backend::drm::legacy::LegacyDrmDevice)
|
||||||
/// initialization.
|
/// initialization.
|
||||||
pub fn all_gpus<S: AsRef<str>>(context: &Context, seat: S) -> UdevResult<Vec<PathBuf>> {
|
pub fn all_gpus<S: AsRef<str>>(seat: S) -> IoResult<Vec<PathBuf>> {
|
||||||
let mut enumerator = Enumerator::new(context)?;
|
let mut enumerator = Enumerator::new()?;
|
||||||
enumerator.match_subsystem("drm")?;
|
enumerator.match_subsystem("drm")?;
|
||||||
enumerator.match_sysname("card[0-9]*")?;
|
enumerator.match_sysname("card[0-9]*")?;
|
||||||
Ok(enumerator
|
Ok(enumerator
|
||||||
|
|
Loading…
Reference in New Issue