From f6de6356f7637a731e342aa2d812917c83a41c11 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 7 Nov 2024 12:31:46 -0800 Subject: [PATCH] WIP atspi: `add_virtual_modifier` --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/backend/kms/device.rs | 4 +++- src/wayland/handlers/atspi.rs | 28 ++++++++++++++++++++++------ src/wayland/protocols/atspi.rs | 18 +++++++++++++++++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aebb3e94..e02ee519 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -899,7 +899,7 @@ dependencies = [ [[package]] name = "cosmic-protocols" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-protocols?branch=main#ec1616b90fa6b4568709cfe2c0627b1e8cc887e0" +source = "git+https://github.com/pop-os/cosmic-protocols?branch=virtual-mods#604f50abccb91583567555ebe4377cd02f8360ce" dependencies = [ "bitflags 2.6.0", "wayland-backend", diff --git a/Cargo.toml b/Cargo.toml index 6aa22761..2f7b80d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ bytemuck = "1.12" calloop = {version = "0.14.1", features = ["executor"]} cosmic-comp-config = {path = "cosmic-comp-config"} cosmic-config = {git = "https://github.com/pop-os/libcosmic/", features = ["calloop", "macro"]} -cosmic-protocols = {git = "https://github.com/pop-os/cosmic-protocols", branch = "main", default-features = false, features = ["server"]} +cosmic-protocols = {git = "https://github.com/pop-os/cosmic-protocols", branch = "virtual-mods", default-features = false, features = ["server"]} cosmic-settings-config = { git = "https://github.com/pop-os/cosmic-settings-daemon" } edid-rs = {version = "0.1"} egui = {version = "0.29.0", optional = true} diff --git a/src/backend/kms/device.rs b/src/backend/kms/device.rs index df3fec77..687e3b89 100644 --- a/src/backend/kms/device.rs +++ b/src/backend/kms/device.rs @@ -307,7 +307,9 @@ impl State { let surface = device.surfaces.remove(&crtc).unwrap(); if surface.output.mirroring().is_none() { // TODO: move up later outputs? - w = w.saturating_sub(surface.output.config().transformed_size().w as u32); + w = w.saturating_sub( + surface.output.config().transformed_size().w as u32, + ); } } diff --git a/src/wayland/handlers/atspi.rs b/src/wayland/handlers/atspi.rs index 277e0ef4..93a1d21e 100644 --- a/src/wayland/handlers/atspi.rs +++ b/src/wayland/handlers/atspi.rs @@ -10,6 +10,7 @@ use reis::{ use smithay::{ backend::input::{KeyState, Keycode}, input::keyboard::ModifiersState, + reexports::wayland_server::Resource, utils::SealedFile, }; use std::{ @@ -35,6 +36,7 @@ pub struct AtspiKeyGrab { #[derive(Debug, Default)] struct AtspiClient { key_grabs: Vec, + virtual_mods: HashSet, has_keyboard_grab: bool, // TODO: purge old instances keyboards: Vec<(Connection, Device, eis::Keyboard)>, @@ -148,12 +150,14 @@ impl AtspiEiState { fn update_virtual_mods(&mut self) { self.virtual_mods.clear(); - self.virtual_mods.extend( - self.clients - .values() - .flat_map(|client| &client.key_grabs) - .flat_map(|grab| &grab.virtual_mods), - ); + for (manager, client) in self.clients.iter() { + if manager.version() >= 2 { + self.virtual_mods.extend(&client.virtual_mods); + } else { + self.virtual_mods + .extend(client.key_grabs.iter().flat_map(|grab| &grab.virtual_mods)); + } + } } pub fn update_keymap(&mut self, xkb_config: XkbConfig) { @@ -192,6 +196,18 @@ impl AtspiHandler for State { self.common.atspi_ei.update_virtual_mods(); } + fn add_virtual_modifier(&mut self, manager: &CosmicAtspiManagerV1, key: Keycode) { + let client = self.common.atspi_ei.clients.get_mut(manager).unwrap(); + client.virtual_mods.insert(key); + self.common.atspi_ei.update_virtual_mods(); + } + + fn remove_virtual_modifier(&mut self, manager: &CosmicAtspiManagerV1, key: Keycode) { + let client = self.common.atspi_ei.clients.get_mut(manager).unwrap(); + client.virtual_mods.remove(&key); + self.common.atspi_ei.update_virtual_mods(); + } + fn add_key_grab( &mut self, manager: &CosmicAtspiManagerV1, diff --git a/src/wayland/protocols/atspi.rs b/src/wayland/protocols/atspi.rs index c4f73ee7..a1597151 100644 --- a/src/wayland/protocols/atspi.rs +++ b/src/wayland/protocols/atspi.rs @@ -18,6 +18,16 @@ pub trait AtspiHandler { key_event_socket: UnixStream, ); fn client_disconnected(&mut self, manager: &cosmic_atspi_manager_v1::CosmicAtspiManagerV1); + fn add_virtual_modifier( + &mut self, + manager: &cosmic_atspi_manager_v1::CosmicAtspiManagerV1, + key: Keycode, + ); + fn remove_virtual_modifier( + &mut self, + manager: &cosmic_atspi_manager_v1::CosmicAtspiManagerV1, + key: Keycode, + ); fn add_key_grab( &mut self, manager: &cosmic_atspi_manager_v1::CosmicAtspiManagerV1, @@ -48,7 +58,7 @@ impl AtspiState { F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static, { let global = dh.create_global::( - 1, + 2, AtspiGlobalData { filter: Box::new(client_filter), }, @@ -134,6 +144,12 @@ where cosmic_atspi_manager_v1::Request::UngrabKeyboard => { state.ungrab_keyboard(manager); } + cosmic_atspi_manager_v1::Request::AddVirtualModifier { key } => { + state.add_virtual_modifier(manager, (key + 8).into()); + } + cosmic_atspi_manager_v1::Request::RemoveVirtualModifier { key } => { + state.remove_virtual_modifier(manager, (key + 8).into()); + } cosmic_atspi_manager_v1::Request::Destroy => {} _ => unreachable!(), }