Add touchscreen support with onscreen keyboard #1

Merged
stjet merged 21 commits from dev into master 2025-02-10 05:03:49 +00:00
3 changed files with 13 additions and 34 deletions
Showing only changes of commit 5998216b19 - Show all commits

View File

@@ -21,7 +21,3 @@ serde = { version = "1", features = ["derive"] }
audiotags = "0.5.0" audiotags = "0.5.0"
bmp-rust = "0.4.1" bmp-rust = "0.4.1"
dirs = "5.0.1" dirs = "5.0.1"
uinput = "0.1.3"
[patch.crates-io]
uinput = { git = 'https://github.com/stjet/rust-uinput.git' }

View File

@@ -2,9 +2,6 @@ use std::vec;
use std::vec::Vec; use std::vec::Vec;
use std::collections::HashMap; use std::collections::HashMap;
use uinput::Device;
use uinput::event::keyboard;
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType, KeyChar }; use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType, KeyChar };
use crate::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest }; use crate::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest };
use crate::framebuffer::Dimensions; use crate::framebuffer::Dimensions;
@@ -13,6 +10,9 @@ use crate::components::Component;
use crate::components::press_button::PressButton; use crate::components::press_button::PressButton;
use crate::utils::point_inside; use crate::utils::point_inside;
//seems like framebuffer only updates if (real) key is pressed...
//on mobile, volume down button seems to work but is annoying
const PADDING_Y: usize = 15; const PADDING_Y: usize = 15;
const PADDING_X: usize = 15; const PADDING_X: usize = 15;
//padding in between keys in the x direction //padding in between keys in the x direction
@@ -50,13 +50,13 @@ enum KeyResponse {
//if alt is true and ctrl is true, only alt will be sent. //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. //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) //(and probably not supported by this with a real keyboard anyways)
#[derive(Default)]
pub struct OnscreenKeyboard { pub struct OnscreenKeyboard {
dimensions: Dimensions, dimensions: Dimensions,
components: Vec<Box<PressButton<KeyResponse>>>, components: Vec<Box<PressButton<KeyResponse>>>,
alt: bool, alt: bool,
ctrl: bool, ctrl: bool,
board: Board, board: Board,
device: Option<Device>,
} }
impl WindowLike for OnscreenKeyboard { impl WindowLike for OnscreenKeyboard {
@@ -74,21 +74,16 @@ impl WindowLike for OnscreenKeyboard {
if let Some(returned) = returned { if let Some(returned) = returned {
return match returned { return match returned {
KeyResponse::Key(ch) => { KeyResponse::Key(ch) => {
if let Some(device) = &mut self.device { let kc = if self.alt {
//for now just send a random keypress to see if it refreshes the framebuffer self.alt = false;
//(with just touch event fb doesn't seem to be written to screen, needs key... or stdin?)
device.click(&keyboard::Key::Down).unwrap();
//sync to indicate the events were at the same time
//(so alt+key, ctrl+key is possible)
device.synchronize().unwrap();
}
WindowMessageResponse::Request(WindowManagerRequest::DoKeyChar(if self.alt {
KeyChar::Alt(ch) KeyChar::Alt(ch)
} else if self.ctrl { } else if self.ctrl {
self.ctrl = false;
KeyChar::Ctrl(ch) KeyChar::Ctrl(ch)
} else { } else {
KeyChar::Press(ch) KeyChar::Press(ch)
})) };
WindowMessageResponse::Request(WindowManagerRequest::DoKeyChar(kc))
}, },
KeyResponse::Alt => { KeyResponse::Alt => {
self.alt = !self.alt; self.alt = !self.alt;
@@ -131,20 +126,7 @@ impl WindowLike for OnscreenKeyboard {
impl OnscreenKeyboard { impl OnscreenKeyboard {
pub fn new() -> Self { pub fn new() -> Self {
let device = if let Ok(builder) = uinput::default() { Default::default()
Some(builder.name("uinput").unwrap().event(uinput::event::Keyboard::All).unwrap().create().unwrap())
} else {
println!("could not open uinput");
None
};
Self {
dimensions: [0, 0],
components: Vec::new(),
alt: false,
ctrl: false,
board: Board::default(),
device,
}
} }
fn set_key_components(&mut self) { fn set_key_components(&mut self) {

View File

@@ -80,15 +80,16 @@ pub fn init(framebuffer: Framebuffer, framebuffer_info: FramebufferInfo) {
let mut wm: WindowManager = WindowManager::new(writer, framebuffer, dimensions, rotate); let mut wm: WindowManager = WindowManager::new(writer, framebuffer, dimensions, rotate);
wm.draw(None, false);
let mut stdout = stdout().into_raw_mode().unwrap(); let mut stdout = stdout().into_raw_mode().unwrap();
write!(stdout, "{}", clear::All).unwrap(); write!(stdout, "{}", clear::All).unwrap();
write!(stdout, "{}", cursor::Hide).unwrap(); write!(stdout, "{}", cursor::Hide).unwrap();
stdout.flush().unwrap(); stdout.flush().unwrap();
wm.draw(None, false);
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let tx1 = tx.clone(); let tx1 = tx.clone();