Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP atspi: add_virtual_modifier #982

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion src/backend/kms/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}

Expand Down
28 changes: 22 additions & 6 deletions src/wayland/handlers/atspi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use reis::{
use smithay::{
backend::input::{KeyState, Keycode},
input::keyboard::ModifiersState,
reexports::wayland_server::Resource,
utils::SealedFile,
};
use std::{
Expand All @@ -35,6 +36,7 @@ pub struct AtspiKeyGrab {
#[derive(Debug, Default)]
struct AtspiClient {
key_grabs: Vec<AtspiKeyGrab>,
virtual_mods: HashSet<Keycode>,
has_keyboard_grab: bool,
// TODO: purge old instances
keyboards: Vec<(Connection, Device, eis::Keyboard)>,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 17 additions & 1 deletion src/wayland/protocols/atspi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,7 +58,7 @@ impl AtspiState {
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
{
let global = dh.create_global::<D, cosmic_atspi_manager_v1::CosmicAtspiManagerV1, _>(
1,
2,
AtspiGlobalData {
filter: Box::new(client_filter),
},
Expand Down Expand Up @@ -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!(),
}
Expand Down
Loading