Skip to content

Commit

Permalink
fix(Input): enable InputPlumber management of all supported devices i…
Browse files Browse the repository at this point in the history
…n full session
  • Loading branch information
ShadowApex committed Dec 28, 2024
1 parent c89e4a3 commit 8ab96c0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/ui/card_ui/card_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions extensions/core/src/dbus/inputplumber/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>;
#[zbus(property)]
fn set_manage_all_devices(&self, value: bool) -> zbus::Result<()>;

/// InterceptMode property
#[zbus(property)]
fn intercept_mode(&self) -> zbus::Result<String>;
Expand Down
34 changes: 34 additions & 0 deletions extensions/core/src/input/inputplumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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<InputManagerProxyBlocking> {
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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
};
}

Expand All @@ -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
Expand Down

0 comments on commit 8ab96c0

Please sign in to comment.