diff --git a/Cargo.lock b/Cargo.lock index 0785c86..b295328 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,9 +42,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" [[package]] name = "anstyle-parse" @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "async-io" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb41eb19024a91746eba0773aa5e16036045bbf45733766661099e182ea6a744" +checksum = "8f97ab0c5b00a7cdbe5a371b9a782ee7be1316095885c8a4ea1daf490eb0ef65" dependencies = [ "async-lock 3.3.0", "cfg-if", @@ -145,7 +145,7 @@ dependencies = [ "futures-lite 2.2.0", "parking", "polling 3.3.2", - "rustix 0.38.30", + "rustix 0.38.31", "slab", "tracing", "windows-sys 0.52.0", @@ -184,7 +184,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.30", + "rustix 0.38.31", "windows-sys 0.48.0", ] @@ -205,13 +205,13 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" dependencies = [ - "async-io 2.3.0", + "async-io 2.3.1", "async-lock 2.8.0", "atomic-waker", "cfg-if", "futures-core", "futures-io", - "rustix 0.38.30", + "rustix 0.38.31", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -300,9 +300,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.14.0" +version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +checksum = "ed2490600f404f2b94c167e31d3ed1d5f3c225a0f3b80230053b3e0b7b962bd9" dependencies = [ "bytemuck_derive", ] @@ -340,7 +340,7 @@ dependencies = [ "log", "nix 0.26.4", "polling 3.3.2", - "rustix 0.38.30", + "rustix 0.38.31", "slab", "thiserror", ] @@ -362,7 +362,7 @@ dependencies = [ "tracing", "tracing-log", "tracing-subscriber", - "udev 0.8.0", + "udev", "zbus", ] @@ -558,7 +558,7 @@ dependencies = [ "bytemuck", "drm-ffi", "drm-fourcc", - "rustix 0.38.30", + "rustix 0.38.31", ] [[package]] @@ -568,7 +568,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41334f8405792483e32ad05fbb9c5680ff4e84491883d2947a4757dc54cb2ac6" dependencies = [ "drm-sys", - "rustix 0.38.30", + "rustix 0.38.31", ] [[package]] @@ -828,9 +828,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" dependencies = [ "equivalent", "hashbrown", @@ -838,25 +838,22 @@ dependencies = [ [[package]] name = "input" -version = "0.8.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e74cd82cedcd66db78742a8337bdc48f188c4d2c12742cbc5cd85113f0b059" +checksum = "7911ce3db9c10c5ab4a35c49af778a5f9a827bd0f7371d9be56175d8dd2740d0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "input-sys", "io-lifetimes 1.0.11", "libc", - "udev 0.7.0", + "udev", ] [[package]] name = "input-sys" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f6c2a17e8aba7217660e32863af87b0febad811d4b8620ef76b386603fddc2" -dependencies = [ - "libc", -] +checksum = "bd4f5b4d1c00331c5245163aacfe5f20be75b564c7112d45893d4ae038119eb0" [[package]] name = "instant" @@ -904,9 +901,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" @@ -1184,7 +1181,7 @@ dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", - "rustix 0.38.30", + "rustix 0.38.31", "tracing", "windows-sys 0.52.0", ] @@ -1207,27 +1204,27 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "profiling" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d135ede8821cf6376eb7a64148901e1690b788c11ae94dc297ae917dbc91dc0e" +checksum = "0f0f7f43585c34e4fdd7497d746bc32e14458cf11c69341cc0587b1d825dde42" dependencies = [ "profiling-procmacros", ] [[package]] name = "profiling-procmacros" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b322d7d65c1ab449be3c890fcbd0db6e1092d0dd05d79dba2dd28032cebeb05" +checksum = "ce97fecd27bc49296e5e20518b5a1bb54a14f7d5fe6228bc9686ee2a74915cc8" dependencies = [ "quote", "syn 2.0.48", @@ -1235,9 +1232,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.30.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" dependencies = [ "memchr", ] @@ -1303,13 +1300,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.2" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.3", + "regex-automata 0.4.5", "regex-syntax 0.8.2", ] @@ -1324,9 +1321,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -1367,9 +1364,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.30" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ "bitflags 2.4.2", "errno", @@ -1398,18 +1395,18 @@ checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] name = "serde" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", @@ -1418,9 +1415,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" dependencies = [ "itoa", "ryu", @@ -1478,14 +1475,14 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b187f0231d56fe41bfb12034819dd2bf336422a5866de41bc3fec4b2e3883e8" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smithay" version = "0.3.0" -source = "git+https://github.com/smithay/smithay#b7284bc6ca6afc782bd55a5c34ef3f902005951f" +source = "git+https://github.com/smithay/smithay#3af1e3c6a5d8e890619f3f398ad02f5ce04b3ef7" dependencies = [ "appendlist", "bitflags 2.4.2", @@ -1510,13 +1507,13 @@ dependencies = [ "pkg-config", "profiling", "rand", - "rustix 0.38.30", + "rustix 0.38.31", "scan_fmt", "smallvec", "tempfile", "thiserror", "tracing", - "udev 0.8.0", + "udev", "wayland-backend", "wayland-protocols", "wayland-protocols-misc", @@ -1589,7 +1586,7 @@ dependencies = [ "cfg-if", "fastrand 2.0.1", "redox_syscall", - "rustix 0.38.30", + "rustix 0.38.31", "windows-sys 0.52.0", ] @@ -1599,7 +1596,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "rustix 0.38.30", + "rustix 0.38.31", "windows-sys 0.48.0", ] @@ -1734,17 +1731,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "udev" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebdbbd670373442a12fe9ef7aeb53aec4147a5a27a00bbc3ab639f08f48191a" -dependencies = [ - "libc", - "libudev-sys", - "pkg-config", -] - [[package]] name = "udev" version = "0.8.0" @@ -1806,13 +1792,13 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wayland-backend" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19152ddd73f45f024ed4534d9ca2594e0ef252c1847695255dae47f34df9fbe4" +checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" dependencies = [ "cc", "downcast-rs", - "nix 0.26.4", + "rustix 0.38.31", "scoped-tls", "smallvec", "wayland-sys", @@ -1820,9 +1806,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e253d7107ba913923dc253967f35e8561a3c65f914543e46843c88ddd729e21c" +checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" dependencies = [ "bitflags 2.4.2", "wayland-backend", @@ -1858,9 +1844,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8e28403665c9f9513202b7e1ed71ec56fde5c107816843fb14057910b2c09c" +checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283" dependencies = [ "proc-macro2", "quick-xml", @@ -1869,14 +1855,14 @@ dependencies = [ [[package]] name = "wayland-server" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f3f0c52a445936ca1184c98f1a69cf4ad9c9130788884531ef04428468cb1ce" +checksum = "00e6e4d5c285bc24ba4ed2d5a4bd4febd5fd904451f465973225c8e99772fdb7" dependencies = [ "bitflags 2.4.2", "downcast-rs", "io-lifetimes 2.0.3", - "nix 0.26.4", + "rustix 0.38.31", "wayland-backend", "wayland-scanner", ] @@ -2050,9 +2036,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.34" +version = "0.5.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" +checksum = "818ce546a11a9986bc24f93d0cdf38a8a1a400f1473ea8c82e59f6e0ffab9249" dependencies = [ "memchr", ] diff --git a/src/catacomb.rs b/src/catacomb.rs index d29e8e5..a35740a 100644 --- a/src/catacomb.rs +++ b/src/catacomb.rs @@ -41,7 +41,7 @@ use smithay::wayland::input_method::{ use smithay::wayland::keyboard_shortcuts_inhibit::{ KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, KeyboardShortcutsInhibitor, }; -use smithay::wayland::output::OutputManagerState; +use smithay::wayland::output::{OutputHandler, OutputManagerState}; use smithay::wayland::presentation::PresentationState; use smithay::wayland::selection::data_device::{ self, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler, @@ -669,6 +669,8 @@ delegate_virtual_keyboard_manager!(Catacomb); delegate_input_method_manager!(Catacomb); delegate_text_input_manager!(Catacomb); +impl OutputHandler for Catacomb {} + delegate_output!(Catacomb); impl XdgDecorationHandler for Catacomb { diff --git a/src/udev.rs b/src/udev.rs index d4f806a..246af92 100644 --- a/src/udev.rs +++ b/src/udev.rs @@ -13,7 +13,7 @@ use smithay::backend::allocator::gbm::{GbmAllocator, GbmBuffer, GbmBufferFlags, use smithay::backend::allocator::{Format, Fourcc}; use smithay::backend::drm::compositor::{DrmCompositor as SmithayDrmCompositor, RenderFrameResult}; use smithay::backend::drm::gbm::GbmFramebuffer; -use smithay::backend::drm::{DrmDevice, DrmDeviceFd, DrmEvent}; +use smithay::backend::drm::{DrmDevice, DrmDeviceFd, DrmEvent, DrmSurface}; use smithay::backend::egl::context::EGLContext; use smithay::backend::egl::display::EGLDisplay; use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface}; @@ -33,11 +33,11 @@ use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; use smithay::reexports::calloop::{ Dispatcher, EventLoop, Interest, LoopHandle, Mode as TriggerMode, PostAction, RegistrationToken, }; -use smithay::reexports::drm::control::connector::State as ConnectorState; +use smithay::reexports::drm::control::connector::{Info as ConnectorInfo, State as ConnectorState}; use smithay::reexports::drm::control::property::{ Handle as PropertyHandle, Value as PropertyValue, }; -use smithay::reexports::drm::control::Device; +use smithay::reexports::drm::control::{Device, Mode as DrmMode, ResourceHandles}; use smithay::reexports::input::Libinput; use smithay::reexports::rustix::fs::OFlags; use smithay::reexports::wayland_protocols::wp::linux_dmabuf as _linux_dmabuf; @@ -172,7 +172,7 @@ impl Udev { SessionEvent::PauseSession => { context.suspend(); - if let Some(output_device) = &catacomb.backend.output_device { + if let Some(output_device) = &mut catacomb.backend.output_device { output_device.drm.pause(); } }, @@ -317,10 +317,10 @@ impl Udev { let fd = self.session.open(&path, open_flags)?; let device_fd = DrmDeviceFd::new(DeviceFd::from(fd)); - let (drm, drm_notifier) = DrmDevice::new(device_fd.clone(), true)?; + let (mut drm, drm_notifier) = DrmDevice::new(device_fd.clone(), true)?; let gbm = GbmDevice::new(device_fd)?; - let display = EGLDisplay::new(gbm.clone())?; + let display = unsafe { EGLDisplay::new(gbm.clone())? }; let context = EGLContext::new(&display)?; let mut gles = unsafe { @@ -339,7 +339,7 @@ impl Udev { // Create the DRM compositor. let drm_compositor = self - .create_drm_compositor(display_handle, windows, &gles, &drm, &gbm) + .create_drm_compositor(display_handle, windows, &gles, &mut drm, &gbm) .ok_or("drm compositor")?; // Listen for VBlanks. @@ -426,7 +426,7 @@ impl Udev { display: &DisplayHandle, windows: &mut Windows, gles: &GlesRenderer, - drm: &DrmDevice, + drm: &mut DrmDevice, gbm: &GbmDevice, ) -> Option { let formats = Bind::::supported_formats(gles)?; @@ -440,25 +440,8 @@ impl Udev { })?; let connector_mode = *connector.modes().first()?; - let surface = connector - // Get all available encoders. - .encoders() - .iter() - .flat_map(|handle| drm.get_encoder(*handle)) - // Find the ideal CRTC. - .flat_map(|encoder| { - // Get all CRTCs compatible with the encoder. - let mut crtcs = resources.filter_crtcs(encoder.possible_crtcs()); - - // Sort by maximum number of overlay planes. - crtcs.sort_by_cached_key(|crtc| { - drm.planes(crtc).map_or(0, |planes| -(planes.overlay.len() as isize)) - }); - - crtcs - }) - // Try to create a DRM surface. - .find_map(|crtc| drm.create_surface(crtc, connector_mode, &[connector.handle()]).ok())?; + // Create DRM surface. + let surface = Self::create_surface(drm, resources, &connector, connector_mode)?; // Create GBM allocator. let gbm_flags = GbmBufferFlags::RENDERING | GbmBufferFlags::SCANOUT; @@ -497,6 +480,38 @@ impl Udev { ) .ok() } + + /// Create DRM surface on the ideal CRTC. + fn create_surface( + drm: &mut DrmDevice, + resources: ResourceHandles, + connector: &ConnectorInfo, + mode: DrmMode, + ) -> Option { + for encoder in connector.encoders() { + let encoder = match drm.get_encoder(*encoder) { + Ok(encoder) => encoder, + Err(_) => continue, + }; + + // Get all CRTCs compatible with the encoder. + let mut crtcs = resources.filter_crtcs(encoder.possible_crtcs()); + + // Sort CRTCs by maximum number of overlay planes. + crtcs.sort_by_cached_key(|crtc| { + drm.planes(crtc).map_or(0, |planes| -(planes.overlay.len() as isize)) + }); + + // Get first CRTC allowing for successful surface creation. + for crtc in crtcs { + if let Ok(drm_surface) = drm.create_surface(crtc, mode, &[connector.handle()]) { + return Some(drm_surface); + } + } + } + + None + } } /// Target device for rendering. @@ -568,12 +583,9 @@ impl OutputDevice { self.drm_compositor.set_output_mode_source(windows.canvas().into()); let textures = windows.textures(&mut self.gles, &mut self.graphics); - let mut frame_result = self.drm_compositor.render_frame::<_, _, GlesRenderbuffer>( - &mut self.gles, - textures, - CLEAR_COLOR, - )?; - let rendered = frame_result.damage.is_some(); + let mut frame_result = + self.drm_compositor.render_frame(&mut self.gles, textures, CLEAR_COLOR)?; + let rendered = !frame_result.is_empty; // Update last render states. self.last_render_states = mem::take(&mut frame_result.states);