keyboard shift mode
This commit is contained in:
@@ -7,13 +7,16 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
backend::overlay::{OverlayData, OverlayState},
|
||||
backend::{
|
||||
input::PointerMode,
|
||||
overlay::{OverlayData, OverlayState},
|
||||
},
|
||||
config,
|
||||
gui::{color_parse, CanvasBuilder, Control},
|
||||
hid::{KeyModifier, VirtualKey, ALT, CTRL, KEYS_TO_MODS, META, SHIFT, SUPER},
|
||||
state::{AppSession, AppState},
|
||||
};
|
||||
use glam::{vec2, vec3a, Affine2};
|
||||
use glam::{vec2, vec3a, Affine2, Vec4};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use rodio::{Decoder, OutputStream, OutputStreamHandle, Source};
|
||||
@@ -130,10 +133,17 @@ fn key_press(
|
||||
control: &mut Control<KeyboardData, KeyButtonData>,
|
||||
data: &mut KeyboardData,
|
||||
app: &mut AppState,
|
||||
mode: PointerMode,
|
||||
) {
|
||||
match control.state.as_mut() {
|
||||
Some(KeyButtonData::Key { vk, pressed }) => {
|
||||
data.key_click(&app.session);
|
||||
|
||||
if let PointerMode::Right = mode {
|
||||
data.modifiers = data.modifiers | SHIFT;
|
||||
app.hid_provider.set_modifiers(data.modifiers);
|
||||
}
|
||||
|
||||
app.hid_provider.send_key(*vk as _, true);
|
||||
*pressed = true;
|
||||
}
|
||||
@@ -190,15 +200,23 @@ fn key_release(
|
||||
}
|
||||
}
|
||||
|
||||
static PRESS_COLOR: Vec4 = Vec4::new(1.0, 1.0, 1.0, 0.5);
|
||||
|
||||
fn test_highlight(
|
||||
control: &Control<KeyboardData, KeyButtonData>,
|
||||
data: &mut KeyboardData,
|
||||
_app: &mut AppState,
|
||||
) -> bool {
|
||||
match control.state.as_ref() {
|
||||
) -> Option<Vec4> {
|
||||
let pressed = match control.state.as_ref() {
|
||||
Some(KeyButtonData::Key { pressed, .. }) => *pressed,
|
||||
Some(KeyButtonData::Modifier { modifier, .. }) => data.modifiers & *modifier != 0,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
if pressed {
|
||||
Some(PRESS_COLOR)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,12 +55,12 @@ where
|
||||
canvas.fg_color = color_parse("#353535");
|
||||
|
||||
let vol_up = canvas.button(327., 116., 46., 32., "+".into());
|
||||
vol_up.on_press = Some(|_control, _data, _app| {
|
||||
vol_up.on_press = Some(|_control, _data, _app, _| {
|
||||
println!("Volume up!"); //TODO
|
||||
});
|
||||
|
||||
let vol_dn = canvas.button(327., 52., 46., 32., "-".into());
|
||||
vol_dn.on_press = Some(|_control, _data, _app| {
|
||||
vol_dn.on_press = Some(|_control, _data, _app, _| {
|
||||
println!("Volume down!"); //TODO
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ where
|
||||
canvas.fg_color = color_parse("#353535");
|
||||
|
||||
let settings = canvas.button(2., 162., 36., 36., "☰".into());
|
||||
settings.on_press = Some(|_control, _data, _app| {
|
||||
settings.on_press = Some(|_control, _data, _app, _| {
|
||||
println!("Settings!"); //TODO
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@ where
|
||||
scr_idx: 0,
|
||||
});
|
||||
|
||||
keyboard.on_press = Some(|control, _data, _app| {
|
||||
keyboard.on_press = Some(|control, _data, _app, _| {
|
||||
if let Some(state) = control.state.as_mut() {
|
||||
state.pressed_at = Instant::now();
|
||||
}
|
||||
@@ -131,7 +131,7 @@ where
|
||||
scr_idx: screen.state.id,
|
||||
});
|
||||
|
||||
button.on_press = Some(|control, _data, _app| {
|
||||
button.on_press = Some(|control, _data, _app, _| {
|
||||
if let Some(state) = control.state.as_mut() {
|
||||
state.pressed_at = Instant::now();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user