From 1865b2548c8e022020fd28127d9e483ad03703d6 Mon Sep 17 00:00:00 2001 From: stjet <49297268+stjet@users.noreply.github.com> Date: Mon, 10 Feb 2025 01:22:30 +0000 Subject: [PATCH] try this --- Cargo.toml | 1 + src/essential/onscreen_keyboard.rs | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9c64742..938185b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,4 @@ serde = { version = "1", features = ["derive"] } audiotags = "0.5.0" bmp-rust = "0.4.1" dirs = "5.0.1" +uinput = "0.1.3" diff --git a/src/essential/onscreen_keyboard.rs b/src/essential/onscreen_keyboard.rs index fdc51b8..523f76a 100644 --- a/src/essential/onscreen_keyboard.rs +++ b/src/essential/onscreen_keyboard.rs @@ -2,6 +2,9 @@ use std::vec; use std::vec::Vec; use std::collections::HashMap; +use uinput::Device; +use uinput::event::keyboard; + use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType, KeyChar }; use crate::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest }; use crate::framebuffer::Dimensions; @@ -47,13 +50,13 @@ enum KeyResponse { //if alt is true and ctrl is true, only alt will be sent. //because I don't care about ctrl+alt stuff, and won't use it. //(and probably not supported by this with a real keyboard anyways) -#[derive(Default)] pub struct OnscreenKeyboard { dimensions: Dimensions, components: Vec>>, alt: bool, ctrl: bool, board: Board, + device: Device, } impl WindowLike for OnscreenKeyboard { @@ -71,6 +74,12 @@ impl WindowLike for OnscreenKeyboard { if let Some(returned) = returned { return match returned { KeyResponse::Key(ch) => { + //for now just send a random keypress to see if it refreshes the framebuffer + //(with just touch event fb doesn't seem to be written to screen, needs key... or stdin?) + self.device.click(&keyboard::Key::Down).unwrap(); + //sync to indicate the events were at the same time + //(so alt+key, ctrl+key is possible) + self.device.synchronize().unwrap(); WindowMessageResponse::Request(WindowManagerRequest::DoKeyChar(if self.alt { KeyChar::Alt(ch) } else if self.ctrl { @@ -120,7 +129,14 @@ impl WindowLike for OnscreenKeyboard { impl OnscreenKeyboard { pub fn new() -> Self { - Self::default() + Self { + dimensions: [0, 0], + components: Vec::new(), + alt: false, + ctrl: false, + board: Board::default(), + device: uinput::default().unwrap().name("uinput").unwrap().event(uinput::event::Keyboard::All).unwrap().create().unwrap(), + } } fn set_key_components(&mut self) {