From 269d117e0eedf245d4c0097162284bde89d13165 Mon Sep 17 00:00:00 2001 From: William Edwards Date: Sat, 28 Dec 2024 10:07:11 -0800 Subject: [PATCH] fix(Input): enable InputPlumber management of all supported devices in full session --- core/ui/card_ui/card_ui.gd | 3 ++ .../src/dbus/inputplumber/input_manager.rs | 6 ++++ extensions/core/src/input/inputplumber.rs | 34 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/core/ui/card_ui/card_ui.gd b/core/ui/card_ui/card_ui.gd index 057c7f16..3f4058ed 100644 --- a/core/ui/card_ui/card_ui.gd +++ b/core/ui/card_ui/card_ui.gd @@ -143,6 +143,9 @@ func _ready() -> void: get_viewport().gui_focus_changed.connect(_on_focus_changed) library_manager.reload_library() + # Enable InputPlumber management of all supported input devices + input_plumber.manage_all_devices = true + # Setup inputplumber to receive guide presses. input_plumber.set_intercept_mode(InputPlumberInstance.INTERCEPT_MODE_ALL) input_plumber.set_intercept_activation(PackedStringArray(["Gamepad:Button:Guide"]), "Gamepad:Button:Guide") diff --git a/extensions/core/src/dbus/inputplumber/input_manager.rs b/extensions/core/src/dbus/inputplumber/input_manager.rs index 49b1c383..1e78f432 100644 --- a/extensions/core/src/dbus/inputplumber/input_manager.rs +++ b/extensions/core/src/dbus/inputplumber/input_manager.rs @@ -38,6 +38,12 @@ trait InputManager { /// StopTargetDevice method fn stop_target_device(&self, path: &str) -> zbus::Result<()>; + /// ManageAllDevices property + #[zbus(property)] + fn manage_all_devices(&self) -> zbus::Result; + #[zbus(property)] + fn set_manage_all_devices(&self, value: bool) -> zbus::Result<()>; + /// InterceptMode property #[zbus(property)] fn intercept_mode(&self) -> zbus::Result; diff --git a/extensions/core/src/input/inputplumber.rs b/extensions/core/src/input/inputplumber.rs index e0a570d2..0a990ee1 100644 --- a/extensions/core/src/input/inputplumber.rs +++ b/extensions/core/src/input/inputplumber.rs @@ -17,6 +17,7 @@ use godot::classes::{Engine, Resource}; use zbus::fdo::ObjectManagerProxy; use zbus::names::BusName; +use crate::dbus::inputplumber::input_manager::InputManagerProxyBlocking; use crate::dbus::RunError; use crate::{get_dbus_system, get_dbus_system_blocking, RUNTIME}; @@ -101,6 +102,10 @@ pub struct InputPlumberInstance { /// The current target event for intercept mode #[var(get = get_intercept_target, set = set_intercept_target)] intercept_target: GString, + /// Whether or not to automatically manage all supported input devices + #[allow(dead_code)] + #[var(get = get_manage_all_devices, set = set_manage_all_devices)] + manage_all_devices: bool, } #[godot_api] @@ -128,6 +133,15 @@ impl InputPlumberInstance { #[signal] fn composite_device_removed(dbus_path: GString); + /// Return a proxy instance to the input manager + fn get_proxy(&self) -> Option { + if let Some(conn) = self.conn.as_ref() { + InputManagerProxyBlocking::builder(conn).build().ok() + } else { + None + } + } + /// Returns true if the InputPlumber service is currently running #[func] fn is_running(&self) -> bool { @@ -259,6 +273,24 @@ impl InputPlumberInstance { } } + /// Gets whether or not InputPlumber should automatically manage all supported devices + #[func] + fn get_manage_all_devices(&self) -> bool { + let Some(proxy) = self.get_proxy() else { + return false; + }; + proxy.manage_all_devices().unwrap_or_default() + } + + /// Sets whether or not InputPlumber should automatically manage all supported devices + #[func] + fn set_manage_all_devices(&self, value: bool) { + let Some(proxy) = self.get_proxy() else { + return; + }; + proxy.set_manage_all_devices(value).unwrap_or_default() + } + /// Gets the current intercept mode for all composite devices #[func] fn get_intercept_mode(&self) -> i64 { @@ -408,6 +440,7 @@ impl IResource for InputPlumberInstance { intercept_mode: Default::default(), intercept_triggers: Default::default(), intercept_target: Default::default(), + manage_all_devices: Default::default(), }; } @@ -428,6 +461,7 @@ impl IResource for InputPlumberInstance { intercept_mode: 0, intercept_triggers: PackedStringArray::from(&["Gamepad:Button:Guide".into()]), intercept_target: "Gamepad:Button:Guide".into(), + manage_all_devices: Default::default(), }; // Do initial device discovery