Skip to content

Commit

Permalink
Add cosmic_atspi_v1 protocol
Browse files Browse the repository at this point in the history
Used to provide a backend for `AtspiDevice` in `at-spi2-core`, so Orca
keybindings can work.
  • Loading branch information
ids1024 committed Oct 31, 2024
1 parent eb64fda commit 2545b76
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ wayland-scanner = "0.31.1"
xcursor = "0.3.3"
xdg = "^2.1"
xdg-user = "0.2.1"
xkbcommon = "0.7"
xkbcommon = "0.8"
zbus = "4.4.0"
profiling = { version = "1.0" }
rustix = { version = "0.38.32", features = ["process"] }
smallvec = "1.13.2"
rand = "0.8.5"
reis = { version = "0.4", features = ["calloop"] }
drm-ffi = "0.8.0"

[dependencies.id_tree]
Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
}
}
}
state.common.atspi_ei.update_keymap(value.clone());
state.common.config.cosmic_conf.xkb_config = value;
}
"input_default" => {
Expand Down
67 changes: 67 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,13 @@ impl State {
.unwrap_or(false)
});

self.common.atspi_ei.input(
modifiers,
&handle,
event.state(),
event.time() as u64 * 1000,
);

// Leave move overview mode, if any modifier was released
if let Some(Trigger::KeyboardMove(action_modifiers)) =
shell.overview_mode().0.active_trigger()
Expand Down Expand Up @@ -1625,6 +1632,57 @@ impl State {
)));
}

if event.state() == KeyState::Released {
let removed = self
.common
.atspi_ei
.active_virtual_mods
.remove(&event.key_code());
// If `Caps_Lock` is a virtual modifier, and is in locked state, clear it
if removed && handle.modified_sym() == Keysym::Caps_Lock {
if (modifiers.serialized.locked & 2) != 0 {
let serial = SERIAL_COUNTER.next_serial();
let time = self.common.clock.now().as_millis();
keyboard.input(
self,
event.key_code(),
KeyState::Pressed,
serial,
time,
|_, _, _| FilterResult::<()>::Forward,
);
let serial = SERIAL_COUNTER.next_serial();
keyboard.input(
self,
event.key_code(),
KeyState::Released,
serial,
time,
|_, _, _| FilterResult::<()>::Forward,
);
}
}
} else if event.state() == KeyState::Pressed
&& self
.common
.atspi_ei
.virtual_mods
.contains(&event.key_code())
{
self.common
.atspi_ei
.active_virtual_mods
.insert(event.key_code());

tracing::debug!(
"active virtual mods: {:?}",
self.common.atspi_ei.active_virtual_mods
);
seat.supressed_keys().add(&handle, None);

return FilterResult::Intercept(None);
}

// Skip released events for initially surpressed keys
if event.state() == KeyState::Released {
if let Some(tokens) = seat.supressed_keys().filter(&handle) {
Expand All @@ -1649,6 +1707,15 @@ impl State {
return FilterResult::Intercept(None);
}

if self.common.atspi_ei.has_keyboard_grab()
|| self
.common
.atspi_ei
.has_key_grab(modifiers.serialized.layout_effective, event.key_code())
{
return FilterResult::Intercept(None);
}

// handle the rest of the global shortcuts
let mut clear_queue = true;
if !shortcuts_inhibited {
Expand Down
10 changes: 10 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
shell::{grabs::SeatMoveGrabState, CosmicSurface, SeatExt, Shell},
utils::prelude::OutputExt,
wayland::protocols::{
atspi::AtspiState,
drm::WlDrmState,
image_source::ImageSourceState,
output_configuration::OutputConfigurationState,
Expand Down Expand Up @@ -229,6 +230,9 @@ pub struct Common {
pub xwayland_state: Option<XWaylandState>,
pub xwayland_shell_state: XWaylandShellState,
pub pointer_focus_state: Option<PointerFocusState>,

pub atspi_state: AtspiState,
pub atspi_ei: crate::wayland::handlers::atspi::AtspiEiState,
}

#[derive(Debug)]
Expand Down Expand Up @@ -559,6 +563,9 @@ impl State {
tracing::warn!(?err, "Failed to initialize dbus handlers");
}

// TODO: Restrict to only specific client?
let atspi_state = AtspiState::new::<State, _>(dh, client_is_privileged);

State {
common: Common {
config,
Expand Down Expand Up @@ -615,6 +622,9 @@ impl State {
xwayland_state: None,
xwayland_shell_state,
pointer_focus_state: None,

atspi_state,
atspi_ei: Default::default(),
},
backend: BackendData::Unset,
ready: Once::new(),
Expand Down
Loading

0 comments on commit 2545b76

Please sign in to comment.