From d95808c2d9f8cf100ce5739ec639239c11ed3ce1 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 15 Jul 2022 14:21:20 +0200 Subject: [PATCH 1/4] input: Always add keyboard/pointer to seat --- src/backend/mod.rs | 18 +++++++++-- src/input/mod.rs | 79 ++++++++++++++++++++++------------------------ 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 6a7b62ff..1aa7e6c4 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::state::{Data, State}; -use anyhow::Result; +use anyhow::{Context, Result}; use smithay::reexports::{calloop::EventLoop, wayland_server::DisplayHandle}; pub mod render; @@ -17,7 +17,7 @@ pub fn init_backend_auto( event_loop: &mut EventLoop<'static, Data>, state: &mut State, ) -> Result<()> { - match std::env::var("COSMIC_BACKEND") { + let res = match std::env::var("COSMIC_BACKEND") { Ok(x) if x == "x11" => x11::init_backend(dh, event_loop, state), Ok(x) if x == "winit" => winit::init_backend(dh, event_loop, state), Ok(x) if x == "kms" => kms::init_backend(dh, event_loop, state), @@ -38,5 +38,19 @@ pub fn init_backend_auto( kms::init_backend(dh, event_loop, state) } } + }; + if res.is_ok() { + for seat in &state.common.seats { + let output = state + .common + .shell + .outputs() + .next() + .with_context(|| "Backend initialized without output")? + .clone(); + seat.user_data() + .insert_if_missing(|| crate::input::ActiveOutput(std::cell::RefCell::new(output))); + } } + res } diff --git a/src/input/mod.rs b/src/input/mod.rs index d073f77d..fc10051c 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -99,13 +99,46 @@ impl Devices { } pub fn add_seat(dh: &DisplayHandle, name: String) -> Seat { - let seat = Seat::::new(dh, name, None); + let mut seat = Seat::::new(dh, name, None); let userdata = seat.user_data(); userdata.insert_if_missing(SeatId::default); userdata.insert_if_missing(Devices::default); userdata.insert_if_missing(SupressedKeys::default); userdata.insert_if_missing(SeatMoveGrabState::default); userdata.insert_if_missing(|| RefCell::new(CursorImageStatus::Default)); + + // A lot of clients bind keyboard and pointer unconditionally once on launch.. + // Initial clients might race the compositor on adding periheral and + // end up in a state, where they are not able to receive input. + // Additionally a lot of clients don't handle keyboards/pointer objects being + // removed very well either and we don't want to crash applications, because the + // user is replugging their keyboard or mouse. + // + // So instead of doing the right thing (and initialize these capabilities as matching + // devices appear), we have to surrender to reality and just always expose a keyboard and pointer. + let dh_clone = dh.clone(); + let _ = seat.add_keyboard( + XkbConfig::default(), + 200, + 25, + move |seat, focus| { + if let Some(client) = + focus.and_then(|s| dh_clone.get_client(s.id()).ok()) + { + set_data_device_focus(&dh_clone, seat, Some(client)); + } + }, + ); + + let owned_seat = seat.clone(); + seat.add_pointer(move |status| { + *owned_seat + .user_data() + .get::>() + .unwrap() + .borrow_mut() = status; + }); + seat } @@ -124,40 +157,7 @@ impl State { let devices = userdata.get::().unwrap(); for cap in devices.add_device(&device) { match cap { - DeviceCapability::Keyboard => { - let dh_clone = dh.clone(); - let _ = seat.add_keyboard( - XkbConfig::default(), - 200, - 25, - move |seat, focus| { - if let Some(client) = - focus.and_then(|s| dh_clone.get_client(s.id()).ok()) - { - set_data_device_focus(&dh_clone, seat, Some(client)) - } - }, - ); - } - DeviceCapability::Pointer => { - let output = self - .common - .shell - .outputs() - .next() - .expect("Backend initialized without output") - .clone(); - seat.user_data() - .insert_if_missing(|| ActiveOutput(RefCell::new(output))); - let owned_seat = seat.clone(); - seat.add_pointer(move |status| { - *owned_seat - .user_data() - .get::>() - .unwrap() - .borrow_mut() = status; - }); - } + // TODO: Handle touch, tablet _ => {} } } @@ -174,13 +174,8 @@ impl State { if devices.has_device(&device) { for cap in devices.remove_device(&device) { match cap { - DeviceCapability::Keyboard => { - seat.remove_keyboard(); - } - DeviceCapability::Pointer => { - seat.remove_pointer(); - } - _ => {} + // TODO: Handle touch, tablet + _ => {}, } } break; From fbbbf7612e24535b4c02ea7d0e57d0f4d544126b Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 15 Jul 2022 14:21:39 +0200 Subject: [PATCH 2/4] debug: More info on layer_shell surfaces --- src/debug.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index c24cc77e..673259a0 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -3,7 +3,9 @@ use crate::state::{Common, Fps}; use smithay::{ backend::drm::DrmNode, - utils::{Physical, Rectangle}, + desktop::layer_map_for_output, + reexports::wayland_server::Resource, + utils::{Physical, Rectangle, IsAlive}, }; pub use smithay_egui::EguiFrame; @@ -228,7 +230,9 @@ pub fn debug_ui( { ui.separator(); ui.collapsing(output.name(), |ui| { - ui.label(format!("Output: {:#?}", output)); + ui.label(format!("Mode: {:#?}", output.current_mode())); + ui.label(format!("Scale: {:#?}", output.current_scale())); + ui.label(format!("Transform: {:#?}", output.current_transform())); ui.label(format!("Geometry: {:?}", output.geometry())); ui.label(format!( "Local Geometry: {:?}", @@ -244,6 +248,22 @@ pub fn debug_ui( .shell .space_relative_output_geometry((0i32, 0i32), &output) )); + ui.separator(); + ui.collapsing("Layers:", |ui| { + let map = layer_map_for_output(&output); + for layer in map.layers() { + ui.collapsing(format!("{}/{:?}", layer.wl_surface().id(), layer.wl_surface().client_id()), |ui| { + ui.label(format!("Alive: {:?} {:?} {:?}", layer.alive(), layer.layer_surface().alive(), layer.wl_surface().alive())); + ui.label(format!("Layer: {:?}", layer.layer())); + ui.label(format!("Namespace: {:?}", layer.namespace())); + ui.label(format!("Geometry: {:?}", layer.bbox())); + ui.label(format!("Anchor: {:?}", layer.cached_state().anchor)); + ui.label(format!("Margin: {:?}", layer.cached_state().margin)); + ui.label(format!("Exclusive: {:?}", layer.cached_state().exclusive_zone)); + }); + } + ui.label(format!("{:?}", map)); + }); }); } }); From 7bf7aea06d3b5402a0da3e5f2b6f162fc22cc973 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 15 Jul 2022 14:22:25 +0200 Subject: [PATCH 3/4] chore: Remove left-over dbg-message --- src/shell/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index d8931c85..44fa32c2 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -608,7 +608,7 @@ impl Shell { with_states(surface, |states| { let state = states.cached_state.current::(); matches!(state.layer, Layer::Top | Layer::Overlay) - && dbg!(state.keyboard_interactivity) != KeyboardInteractivity::None + && state.keyboard_interactivity != KeyboardInteractivity::None }) }; From f3881b6c3b9e9fc4b63e82716ed38bfe66d0f844 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 15 Jul 2022 17:28:51 +0200 Subject: [PATCH 4/4] deps: Pin wayland-rs beta version --- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 085c9d75..2066f6be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,9 +114,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" dependencies = [ "addr2line", "cc", @@ -402,9 +402,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5999502d32b9c48d492abe66392408144895020ec4709e549e840799f3bb74c0" +checksum = "2ccfd8c0ee4cce11e45b3fd6f9d5e69e0cc62912aa6a0cb1bf4617b0eba5a12f" dependencies = [ "generic-array", "typenum", @@ -736,9 +736,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" +checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" [[package]] name = "hermit-abi" @@ -1147,9 +1147,9 @@ dependencies = [ [[package]] name = "object" -version = "0.28.4" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" dependencies = [ "memchr", ] @@ -1406,18 +1406,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" +checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" +checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ "proc-macro2", "quote", @@ -1517,7 +1517,7 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "smithay" version = "0.3.0" -source = "git+https://github.com/pop-os/smithay?branch=main#bb4bdc613ff91e06b2205d4021d8c2003e9ef660" +source = "git+https://github.com/pop-os/smithay?branch=main#2a2c55b8cede75d988599e2320c53510dd9fabf6" dependencies = [ "appendlist", "bitflags", diff --git a/Cargo.toml b/Cargo.toml index cb5ba2f4..3878def5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,8 @@ xdg = "^2.1" ron = "0.7" atomic_float = "0.1" libsystemd = "0.5" -wayland-backend = "0.1.0-beta.7" -wayland-scanner = "0.30.0-beta.7" +wayland-backend = "=0.1.0-beta.7" +wayland-scanner = "=0.30.0-beta.7" cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", branch = "main" } [dependencies.smithay]