mirror of https://github.com/wayvr-org/wayvr.git
Port changes from -x repo
This commit is contained in:
parent
979969d8a2
commit
41a5bebb1d
|
|
@ -4205,6 +4205,7 @@ dependencies = [
|
|||
"vulkano-shaders",
|
||||
"winit",
|
||||
"wlx-capture",
|
||||
"xdg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4256,6 +4257,12 @@ version = "0.3.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a0ccd7b4a5345edfcd0c3535718a4e9ff7798ffc536bb5b5a0e26ff84732911"
|
||||
|
||||
[[package]]
|
||||
name = "xdg"
|
||||
version = "2.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
|
||||
|
||||
[[package]]
|
||||
name = "xdg-home"
|
||||
version = "1.0.0"
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ vulkano = { git = "https://github.com/vulkano-rs/vulkano", rev = "94f50f1" }
|
|||
vulkano-shaders = { git = "https://github.com/vulkano-rs/vulkano", rev = "94f50f1" }
|
||||
winit = "0.29.10"
|
||||
wlx-capture = { git = "https://github.com/galister/wlx-capture" }
|
||||
xdg = "2.5.2"
|
||||
|
||||
[features]
|
||||
openvr = ["dep:ovr_overlay"]
|
||||
|
|
|
|||
|
|
@ -232,8 +232,10 @@ impl OverlayData<OpenVrOverlayData> {
|
|||
texture.m_nWidth,
|
||||
texture.m_nHeight,
|
||||
image.usage()
|
||||
);
|
||||
if let Err(e) = overlay.set_image_vulkan(handle, &mut texture) {
|
||||
panic!("Failed to set overlay texture: {}", e);
|
||||
}
|
||||
log::info!("{}: Uploaded texture", self.state.name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,6 @@ pub fn def_pw_tokens() -> Vec<(String, String)> {
|
|||
Vec::new()
|
||||
}
|
||||
|
||||
fn def_grab_threshold() -> f32 {
|
||||
0.6
|
||||
}
|
||||
|
||||
fn def_trigger_threshold() -> f32 {
|
||||
0.65
|
||||
}
|
||||
|
||||
fn def_click_freeze_time_ms() -> u32 {
|
||||
300
|
||||
}
|
||||
|
|
@ -32,12 +24,6 @@ fn def_one() -> f32 {
|
|||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct GeneralConfig {
|
||||
#[serde(default = "def_grab_threshold")]
|
||||
pub grab_threshold: f32,
|
||||
|
||||
#[serde(default = "def_trigger_threshold")]
|
||||
pub trigger_threshold: f32,
|
||||
|
||||
#[serde(default = "def_click_freeze_time_ms")]
|
||||
pub click_freeze_time_ms: u32,
|
||||
|
||||
|
|
@ -74,8 +60,6 @@ impl GeneralConfig {
|
|||
}
|
||||
|
||||
fn post_load(&self) {
|
||||
GeneralConfig::sanitize_range("grab_threshold", self.grab_threshold, 0.0, 1.0);
|
||||
GeneralConfig::sanitize_range("trigger_threshold", self.trigger_threshold, 0.0, 1.0);
|
||||
GeneralConfig::sanitize_range("keyboard_scale", self.keyboard_scale, 0.0, 5.0);
|
||||
GeneralConfig::sanitize_range("desktop_view_scale", self.desktop_view_scale, 0.0, 5.0);
|
||||
GeneralConfig::sanitize_range("watch_scale", self.watch_scale, 0.0, 5.0);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use std::{
|
|||
|
||||
use ash::vk::{self, SubmitInfo};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use vulkano::instance::InstanceCreateFlags;
|
||||
use vulkano::{
|
||||
buffer::{
|
||||
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
|
||||
|
|
@ -25,6 +26,8 @@ use vulkano::{
|
|||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::physical::PhysicalDeviceType,
|
||||
device::Features,
|
||||
device::{
|
||||
physical::PhysicalDevice, Device, DeviceCreateInfo, DeviceExtensions, Queue,
|
||||
QueueCreateInfo, QueueFlags,
|
||||
|
|
@ -37,6 +40,7 @@ use vulkano::{
|
|||
Image, ImageCreateInfo, ImageLayout, ImageTiling, ImageType, ImageUsage, SampleCount,
|
||||
SubresourceLayout,
|
||||
},
|
||||
instance::InstanceExtensions,
|
||||
instance::{Instance, InstanceCreateInfo},
|
||||
memory::{
|
||||
allocator::{
|
||||
|
|
@ -72,6 +76,7 @@ use vulkano::{
|
|||
},
|
||||
DeviceSize, VulkanLibrary, VulkanObject,
|
||||
};
|
||||
|
||||
use wlx_capture::frame::{
|
||||
DmabufFrame, FourCC, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR8888,
|
||||
DRM_FORMAT_XRGB8888,
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ use crate::{
|
|||
config,
|
||||
gui::{color_parse, CanvasBuilder, Control},
|
||||
hid::{KeyModifier, VirtualKey, KEYS_TO_MODS},
|
||||
state::AppState,
|
||||
state::{AppSession, AppState},
|
||||
};
|
||||
use glam::{vec2, vec3a, Affine2};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use rodio::{Decoder, OutputStream, Source};
|
||||
use rodio::{Decoder, OutputStream, OutputStreamHandle, Source};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const PIXELS_PER_UNIT: f32 = 80.;
|
||||
|
|
@ -35,6 +35,8 @@ where
|
|||
modifiers: 0,
|
||||
processes: vec![],
|
||||
audio_stream: None,
|
||||
first_try: true,
|
||||
audio_handle: None,
|
||||
};
|
||||
|
||||
let mut canvas = CanvasBuilder::new(
|
||||
|
|
@ -107,7 +109,7 @@ where
|
|||
let interaction_transform = Affine2::from_translation(vec2(0.5, 0.5))
|
||||
* Affine2::from_scale(vec2(1., -size.x as f32 / size.y as f32));
|
||||
|
||||
let width = LAYOUT.row_size * 0.05;
|
||||
let width = LAYOUT.row_size * 0.05 * app.session.config.keyboard_scale;
|
||||
|
||||
OverlayData {
|
||||
state: OverlayState {
|
||||
|
|
@ -132,7 +134,7 @@ fn key_press(
|
|||
) {
|
||||
match control.state.as_mut() {
|
||||
Some(KeyButtonData::Key { vk, pressed }) => {
|
||||
data.key_click();
|
||||
data.key_click(&app.session);
|
||||
app.hid_provider.send_key(*vk as _, true);
|
||||
*pressed = true;
|
||||
}
|
||||
|
|
@ -143,12 +145,12 @@ fn key_press(
|
|||
}) => {
|
||||
*sticky = data.modifiers & *modifier == 0;
|
||||
data.modifiers |= *modifier;
|
||||
data.key_click();
|
||||
data.key_click(&app.session);
|
||||
app.hid_provider.set_modifiers(data.modifiers);
|
||||
*pressed = true;
|
||||
}
|
||||
Some(KeyButtonData::Macro { verbs }) => {
|
||||
data.key_click();
|
||||
data.key_click(&app.session);
|
||||
for (vk, press) in verbs {
|
||||
app.hid_provider.send_key(*vk as _, *press);
|
||||
}
|
||||
|
|
@ -158,7 +160,7 @@ fn key_press(
|
|||
data.processes
|
||||
.retain_mut(|child| !matches!(child.try_wait(), Ok(Some(_))));
|
||||
|
||||
data.key_click();
|
||||
data.key_click(&app.session);
|
||||
if let Ok(child) = Command::new(program).args(args).spawn() {
|
||||
data.processes.push(child);
|
||||
}
|
||||
|
|
@ -208,19 +210,31 @@ struct KeyboardData {
|
|||
modifiers: KeyModifier,
|
||||
processes: Vec<Child>,
|
||||
audio_stream: Option<OutputStream>,
|
||||
audio_handle: Option<OutputStreamHandle>,
|
||||
first_try: bool,
|
||||
}
|
||||
|
||||
impl KeyboardData {
|
||||
fn key_click(&mut self) {
|
||||
let wav = include_bytes!("../res/421581.wav");
|
||||
let cursor = Cursor::new(wav);
|
||||
let source = Decoder::new_wav(cursor).unwrap();
|
||||
self.audio_stream = None;
|
||||
if let Ok((stream, handle)) = OutputStream::try_default() {
|
||||
fn key_click(&mut self, session: &AppSession) {
|
||||
if !session.config.keyboard_sound_enabled {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.audio_stream.is_none() && self.first_try {
|
||||
self.first_try = false;
|
||||
if let Ok((stream, handle)) = OutputStream::try_default() {
|
||||
self.audio_stream = Some(stream);
|
||||
self.audio_handle = Some(handle);
|
||||
} else {
|
||||
log::error!("Failed to open audio stream");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(handle) = &self.audio_handle {
|
||||
let wav = include_bytes!("../res/421581.wav");
|
||||
let cursor = Cursor::new(wav);
|
||||
let source = Decoder::new_wav(cursor).unwrap();
|
||||
let _ = handle.play_raw(source.convert_samples());
|
||||
self.audio_stream = Some(stream);
|
||||
} else {
|
||||
log::error!("Failed to play key click");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use core::slice;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
collections::HashMap,
|
||||
error::Error,
|
||||
f32::consts::PI,
|
||||
ops::Deref,
|
||||
|
|
@ -84,9 +84,6 @@ impl InteractionHandler for ScreenInteractionHandler {
|
|||
}
|
||||
}
|
||||
fn on_pointer(&mut self, app: &mut AppState, hit: &PointerHit, pressed: bool) {
|
||||
let pos = self.mouse_transform.transform_point2(hit.uv);
|
||||
app.hid_provider.mouse_move(pos);
|
||||
|
||||
let btn = match hit.mode {
|
||||
PointerMode::Right => MOUSE_RIGHT,
|
||||
PointerMode::Middle => MOUSE_MIDDLE,
|
||||
|
|
@ -94,11 +91,14 @@ impl InteractionHandler for ScreenInteractionHandler {
|
|||
};
|
||||
|
||||
if pressed {
|
||||
self.next_move =
|
||||
Instant::now() + Duration::from_millis(app.session.click_freeze_time_ms);
|
||||
self.next_move = Instant::now()
|
||||
+ Duration::from_millis(app.session.config.click_freeze_time_ms as u64);
|
||||
}
|
||||
|
||||
app.hid_provider.send_button(btn, pressed);
|
||||
|
||||
let pos = self.mouse_transform.transform_point2(hit.uv);
|
||||
app.hid_provider.mouse_move(pos);
|
||||
}
|
||||
fn on_scroll(&mut self, app: &mut AppState, _hit: &PointerHit, delta: f32) {
|
||||
let millis = (1. - delta.abs()) * delta;
|
||||
|
|
@ -350,7 +350,7 @@ impl OverlayRenderer for ScreenRenderer {
|
|||
fn try_create_screen<O>(
|
||||
wl: &WlxClient,
|
||||
id: u32,
|
||||
pw_token_store: &mut BTreeMap<String, String>,
|
||||
pw_token_store: &mut HashMap<String, String>,
|
||||
session: &AppSession,
|
||||
) -> Option<OverlayData<O>>
|
||||
where
|
||||
|
|
@ -435,7 +435,7 @@ where
|
|||
want_visible: session.show_screens.iter().any(|s| s == &*output.name),
|
||||
show_hide: true,
|
||||
grabbable: true,
|
||||
spawn_scale: 1.5,
|
||||
spawn_scale: 1.5 * session.config.desktop_view_scale,
|
||||
spawn_point: vec3a(0., 0.5, -1.),
|
||||
spawn_rotation: Quat::from_axis_angle(axis, angle),
|
||||
interaction_transform,
|
||||
|
|
@ -462,7 +462,7 @@ fn get_pw_token_path() -> PathBuf {
|
|||
path
|
||||
}
|
||||
|
||||
pub fn save_pw_token_config(tokens: &BTreeMap<String, String>) -> Result<(), Box<dyn Error>> {
|
||||
pub fn save_pw_token_config(tokens: &HashMap<String, String>) -> Result<(), Box<dyn Error>> {
|
||||
let mut conf = TokenConf::default();
|
||||
|
||||
for (name, token) in tokens {
|
||||
|
|
@ -475,8 +475,8 @@ pub fn save_pw_token_config(tokens: &BTreeMap<String, String>) -> Result<(), Box
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_pw_token_config() -> Result<BTreeMap<String, String>, Box<dyn Error>> {
|
||||
let mut map: BTreeMap<String, String> = BTreeMap::new();
|
||||
pub fn load_pw_token_config() -> Result<HashMap<String, String>, Box<dyn Error>> {
|
||||
let mut map: HashMap<String, String> = HashMap::new();
|
||||
|
||||
let yaml = std::fs::read_to_string(get_pw_token_path())?;
|
||||
let conf: TokenConf = serde_yaml::from_str(yaml.as_str())?;
|
||||
|
|
@ -496,10 +496,10 @@ where
|
|||
let wl = WlxClient::new().unwrap();
|
||||
|
||||
// Load existing Pipewire tokens from file
|
||||
let mut pw_tokens: BTreeMap<String, String> = if let Ok(conf) = load_pw_token_config() {
|
||||
let mut pw_tokens: HashMap<String, String> = if let Ok(conf) = load_pw_token_config() {
|
||||
conf
|
||||
} else {
|
||||
BTreeMap::new()
|
||||
HashMap::new()
|
||||
};
|
||||
|
||||
let pw_tokens_copy = pw_tokens.clone();
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ where
|
|||
name: "Watch".into(),
|
||||
size: (400, 200),
|
||||
want_visible: true,
|
||||
spawn_scale: 0.065,
|
||||
spawn_scale: 0.065 * state.session.config.watch_scale,
|
||||
spawn_point: state.session.watch_pos.into(),
|
||||
spawn_rotation: state.session.watch_rot,
|
||||
interaction_transform,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,3 @@
|
|||
# Grab threshold for changing position of overlays
|
||||
# Allowed values: 0.0 - 1.0
|
||||
# Default - 0.6
|
||||
#
|
||||
# 1.0 - The hand must grab tighter to start dragging, recommended on Index controller
|
||||
grab_threshold: 0.6
|
||||
|
||||
# Threshold for registering trigger (click) event
|
||||
# Allowed values: 0.0 - 1.0
|
||||
# Default - 0.65
|
||||
trigger_threshold: 0.65
|
||||
|
||||
# For how much time mouse motion events should be stopped after clicking?
|
||||
# Prevents accidental dragging various GUI elements or links, making it easier to click
|
||||
# Default: 300
|
||||
|
|
|
|||
16
src/state.rs
16
src/state.rs
|
|
@ -80,13 +80,6 @@ pub struct AppSession {
|
|||
pub config: GeneralConfig,
|
||||
|
||||
pub show_screens: Vec<String>,
|
||||
pub show_keyboard: bool,
|
||||
pub keyboard_volume: f32,
|
||||
|
||||
pub screen_flip_h: bool,
|
||||
pub screen_flip_v: bool,
|
||||
pub screen_invert_color: bool,
|
||||
pub screen_max_res: [u32; 2],
|
||||
|
||||
pub watch_hand: usize,
|
||||
pub watch_pos: Vec3,
|
||||
|
|
@ -100,8 +93,6 @@ pub struct AppSession {
|
|||
pub color_shift: Vec3,
|
||||
pub color_alt: Vec3,
|
||||
pub color_grab: Vec3,
|
||||
|
||||
pub click_freeze_time_ms: u64,
|
||||
}
|
||||
|
||||
impl AppSession {
|
||||
|
|
@ -114,12 +105,6 @@ impl AppSession {
|
|||
config_root_path,
|
||||
config,
|
||||
show_screens: vec!["DP-3".to_string()],
|
||||
keyboard_volume: 0.5,
|
||||
show_keyboard: false,
|
||||
screen_flip_h: false,
|
||||
screen_flip_v: false,
|
||||
screen_invert_color: false,
|
||||
screen_max_res: [2560, 1440],
|
||||
capture_method: "auto".to_string(),
|
||||
primary_hand: 1,
|
||||
watch_hand: 0,
|
||||
|
|
@ -145,7 +130,6 @@ impl AppSession {
|
|||
y: 0.,
|
||||
z: 0.,
|
||||
},
|
||||
click_freeze_time_ms: 300,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue