Skip to content

Commit

Permalink
feat(Keyboard): add keyboard event support and support for sending ke…
Browse files Browse the repository at this point in the history
…ys over DBus
  • Loading branch information
ShadowApex committed Feb 16, 2024
1 parent cc63584 commit e621ae0
Show file tree
Hide file tree
Showing 5 changed files with 570 additions and 16 deletions.
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.

163 changes: 162 additions & 1 deletion src/input/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,165 @@ pub enum GamepadTrigger {
}

#[derive(Clone, Debug)]
pub enum Keyboard {}
pub enum Keyboard {
KeyEsc,
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
Key0,
KeyMinus,
KeyEqual,
KeyBackspace,
KeyTab,
KeyQ,
KeyW,
KeyE,
KeyR,
KeyT,
KeyY,
KeyU,
KeyI,
KeyO,
KeyP,
KeyLeftBrace,
KeyRightBrace,
KeyEnter,
KeyLeftCtrl,
KeyA,
KeyS,
KeyD,
KeyF,
KeyG,
KeyH,
KeyJ,
KeyK,
KeyL,
KeySemicolon,
KeyApostrophe,
KeyGrave,
KeyLeftShift,
KeyBackslash,
KeyZ,
KeyX,
KeyC,
KeyV,
KeyB,
KeyN,
KeyM,
KeyComma,
KeyDot,
KeySlash,
KeyRightshift,
KeyKpasterisk,
KeyLeftAlt,
KeySpace,
KeyCapslock,
KeyF1,
KeyF2,
KeyF3,
KeyF4,
KeyF5,
KeyF6,
KeyF7,
KeyF8,
KeyF9,
KeyF10,
KeyNumlock,
KeyScrolllock,
KeyKp7,
KeyKp8,
KeyKp9,
KeyKpminus,
KeyKp4,
KeyKp5,
KeyKp6,
KeyKpplus,
KeyKp1,
KeyKp2,
KeyKp3,
KeyKp0,
KeyKpdot,
KeyZenkakuhankaku,
Key102nd,
KeyF11,
KeyF12,
KeyRo,
KeyKatakana,
KeyHiragana,
KeyHenkan,
KeyKatakanahiragana,
KeyMuhenkan,
KeyKpjpcomma,
KeyKpenter,
KeyRightctrl,
KeyKpslash,
KeySysrq,
KeyRightalt,
KeyHome,
KeyUp,
KeyPageup,
KeyLeft,
KeyRight,
KeyEnd,
KeyDown,
KeyPagedown,
KeyInsert,
KeyDelete,
KeyMute,
KeyVolumeDown,
KeyVolumeUp,
KeyPower,
KeyKpequal,
KeyPause,
KeyKpcomma,
KeyHanja,
KeyYen,
KeyLeftmeta,
KeyRightmeta,
KeyCompose,
KeyStop,
KeyAgain,
KeyProps,
KeyUndo,
KeyFront,
KeyCopy,
KeyOpen,
KeyPaste,
KeyFind,
KeyCut,
KeyHelp,
KeyCalc,
KeySleep,
KeyWww,
KeyBack,
KeyForward,
KeyEjectcd,
KeyNextsong,
KeyPlaypause,
KeyPrevioussong,
KeyStopcd,
KeyRefresh,
KeyEdit,
KeyScrollUp,
KeyScrollDown,
KeyKpleftparen,
KeyKprightparen,
KeyF13,
KeyF14,
KeyF15,
KeyF16,
KeyF17,
KeyF18,
KeyF19,
KeyF20,
KeyF21,
KeyF22,
KeyF23,
KeyF24,
}
44 changes: 41 additions & 3 deletions src/input/composite_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub enum Command {
SetInterceptMode(InterceptMode),
GetInterceptMode(mpsc::Sender<InterceptMode>),
GetSourceDevicePaths(mpsc::Sender<Vec<String>>),
GetTargetDevicePaths(mpsc::Sender<Vec<String>>),
GetDBusDevicePaths(mpsc::Sender<Vec<String>>),
SourceDeviceAdded,
SourceDeviceStopped(String),
Stop,
Expand Down Expand Up @@ -116,9 +118,33 @@ impl DBusInterface {
Ok(())
}

/// Emitted when an input event occurs when the device is in intercept mode
#[dbus_interface(signal)]
async fn input_event(ctxt: &SignalContext<'_>, event: String, value: f64) -> zbus::Result<()>;
/// Target devices that this [CompositeDevice] is managing
#[dbus_interface(property)]
async fn target_devices(&self) -> fdo::Result<Vec<String>> {
let (sender, mut receiver) = mpsc::channel::<Vec<String>>(1);
self.tx
.send(Command::GetTargetDevicePaths(sender))
.map_err(|e| fdo::Error::Failed(e.to_string()))?;
let Some(paths) = receiver.recv().await else {
return Ok(Vec::new());
};

Ok(paths)
}

/// Target dbus devices that this [CompositeDevice] is managing
#[dbus_interface(property)]
async fn dbus_devices(&self) -> fdo::Result<Vec<String>> {
let (sender, mut receiver) = mpsc::channel::<Vec<String>>(1);
self.tx
.send(Command::GetDBusDevicePaths(sender))
.map_err(|e| fdo::Error::Failed(e.to_string()))?;
let Some(paths) = receiver.recv().await else {
return Ok(Vec::new());
};

Ok(paths)
}
}

/// Defines a handle to a [CompositeDevice] for communication
Expand Down Expand Up @@ -284,6 +310,18 @@ impl CompositeDevice {
log::error!("Failed to send source device paths: {:?}", e);
}
}
Command::GetTargetDevicePaths(sender) => {
let paths = self.target_devices.keys().cloned().collect();
if let Err(e) = sender.send(paths).await {
log::error!("Failed to send target device paths: {:?}", e);
}
}
Command::GetDBusDevicePaths(sender) => {
let paths = self.target_dbus_devices.keys().cloned().collect();
if let Err(e) = sender.send(paths).await {
log::error!("Failed to send dbus device paths: {:?}", e);
}
}
Command::SourceDeviceAdded => todo!(),
Command::SourceDeviceStopped(device_id) => {
log::debug!("Detected source device removal: {}", device_id);
Expand Down
Loading

0 comments on commit e621ae0

Please sign in to comment.