forked from wayvr-org/wayvr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.rs
More file actions
389 lines (293 loc) · 8.82 KB
/
Copy pathconfig.rs
File metadata and controls
389 lines (293 loc) · 8.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
use std::{collections::HashMap, sync::Arc};
use chrono::Offset;
use idmap::IdMap;
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumProperty, EnumString, VariantArray};
use wayvr_ipc::packet_client::WvrProcessLaunchParams;
use wgui::drawing::{self, HsvColor};
use crate::{
astr_containers::{AStrMap, AStrSet},
locale::{self},
overlays::{BackendAttribValue, ToastDisplayMethod, ToastTopic},
windowing::OverlayWindowState,
};
pub type PwTokenMap = AStrMap<String>;
pub type SerializedWindowStates = HashMap<Arc<str>, OverlayWindowState>;
#[derive(Default, Clone, Copy, Serialize, Deserialize, AsRefStr, EnumString, EnumProperty, VariantArray)]
pub enum CaptureMethod {
#[default]
#[serde(alias = "auto")]
#[strum(props(Translation = "APP_SETTINGS.OPTION.AUTO", Tooltip = "APP_SETTINGS.OPTION.AUTO_HELP"))]
Auto,
#[serde(alias = "pipewire")]
#[strum(props(Text = "PipeWire GPU", Tooltip = "APP_SETTINGS.OPTION.PIPEWIRE_HELP"))]
PipeWire,
#[strum(props(Text = "ScreenCopy GPU", Tooltip = "APP_SETTINGS.OPTION.SCREENCOPY_GPU_HELP"))]
ScreenCopyGpu,
#[serde(alias = "pw-fallback")]
#[strum(props(Text = "PipeWire CPU", Tooltip = "APP_SETTINGS.OPTION.PW_FALLBACK_HELP"))]
PipeWireCpu,
#[serde(alias = "screencopy")]
#[strum(props(Text = "ScreenCopy CPU", Tooltip = "APP_SETTINGS.OPTION.SCREENCOPY_HELP"))]
ScreenCopyCpu,
}
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, AsRefStr, EnumString, EnumProperty, VariantArray)]
pub enum AltModifier {
#[default]
#[strum(props(Translation = "APP_SETTINGS.OPTION.NONE"))]
None,
Shift,
Ctrl,
Alt,
Super,
Meta,
}
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, AsRefStr, EnumString, EnumProperty, VariantArray)]
pub enum HandsfreePointer {
#[strum(props(Translation = "APP_SETTINGS.OPTION.NONE"))]
None,
#[strum(props(Translation = "APP_SETTINGS.OPTION.HMD_PINCH"))]
#[default]
Hmd,
#[strum(props(Translation = "APP_SETTINGS.OPTION.HMD_ONLY"))]
HmdOnly,
#[strum(props(Translation = "APP_SETTINGS.OPTION.EYE_PINCH"))]
EyeTracking,
#[strum(props(Translation = "APP_SETTINGS.OPTION.EYE_ONLY"))]
EyeTrackingOnly,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct ChromaKeyParams {
pub hsv_min: [f32; 3],
pub hsv_max: [f32; 3],
pub curve: f32,
pub despill: f32,
}
fn hsv_green() -> [f32; 3] {
[2.0 / 6.0, 1.0, 1.0]
}
impl Default for ChromaKeyParams {
fn default() -> Self {
Self {
hsv_min: hsv_green(),
hsv_max: hsv_green(),
curve: 0.0, // Monado will ignore chroma keying completely if this value is zero
despill: 0.0,
}
}
}
impl ChromaKeyParams {
pub fn update_hsv_range_from_rgb(&mut self, rgb_color: drawing::Color, range_h: f32, range_s: f32, range_v: f32) {
let hsv = HsvColor::from(rgb_color);
self.hsv_min[0] = hsv.h - range_h / 2.0;
self.hsv_min[1] = hsv.s - range_s / 2.0;
self.hsv_min[2] = hsv.v - range_v / 2.0;
self.hsv_max[0] = hsv.h + range_h / 2.0;
self.hsv_max[1] = hsv.s + range_s / 2.0;
self.hsv_max[2] = hsv.v + range_v / 2.0;
}
// Inverse of `update_hsv_range_from_rgb` function
pub fn get_rgb_and_hsv_ranges(&self) -> (drawing::Color, f32, f32, f32) {
(
HsvColor::new(
(self.hsv_min[0] + self.hsv_max[0]) / 2.0,
(self.hsv_min[1] + self.hsv_max[1]) / 2.0,
(self.hsv_min[2] + self.hsv_max[2]) / 2.0,
1.0,
)
.to_rgb(),
self.hsv_max[0] - self.hsv_min[0],
self.hsv_max[1] - self.hsv_min[1],
self.hsv_max[2] - self.hsv_min[2],
)
}
}
#[derive(Clone, Serialize, Deserialize)]
pub struct SerializedWindowSet {
pub name: Arc<str>,
#[serde(default)]
pub overlays: SerializedWindowStates,
#[serde(default)]
pub hidden_overlays: SerializedWindowStates,
}
pub const fn def_pw_tokens() -> PwTokenMap {
AStrMap::new()
}
const fn def_mouse_move_interval_ms() -> i32 {
10 // 100fps
}
const fn def_click_freeze_time_ms() -> i32 {
300
}
const fn def_true() -> bool {
true
}
const fn def_false() -> bool {
false
}
const fn def_one() -> f32 {
1.0
}
const fn def_half() -> f32 {
0.5
}
const fn def_point7() -> f32 {
0.7
}
const fn def_point3() -> f32 {
0.3
}
const fn def_osc_port() -> u16 {
9000
}
fn def_timezones() -> Vec<String> {
const EMEA: i32 = -60 * 60; // UTC-1
const APAC: i32 = 5 * 60 * 60; // UTC+5
let offset = chrono::Local::now().offset().fix();
match offset.local_minus_utc() {
i32::MIN..EMEA => vec!["Europe/Paris".into(), "Asia/Tokyo".into()],
EMEA..APAC => vec!["America/New_York".into(), "Asia/Tokyo".into()],
APAC..=i32::MAX => vec!["Europe/Paris".into(), "America/New_York".into()],
}
}
fn def_empty() -> Arc<str> {
"".into()
}
fn def_theme_path() -> Arc<str> {
"theme".into()
}
const fn def_max_height() -> u16 {
1440
}
#[derive(Deserialize, Serialize)]
pub struct GeneralConfig {
#[serde(default = "def_theme_path")]
pub theme_path: Arc<str>,
pub color_text: Option<String>,
pub color_accent: Option<String>,
pub color_danger: Option<String>,
pub color_faded: Option<String>,
pub color_background: Option<String>,
pub language: Option<locale::Language>, // auto-detected at runtime if unset
#[serde(default = "def_one")]
#[serde(alias = "ui_animation_speed", alias = "animation_speed" /* old name */)]
pub ui_animation_speed: f32,
#[serde(default = "def_one")]
#[serde(alias = "ui_round_multiplier", alias = "round_multiplier" /* old name */)]
pub ui_round_multiplier: f32,
#[serde(default = "def_point3")]
pub ui_gradient_intensity: f32,
pub default_keymap: Option<String>,
#[serde(default)]
pub attribs: AStrMap<Vec<BackendAttribValue>>,
#[serde(default = "def_click_freeze_time_ms")]
pub click_freeze_time_ms: i32,
#[serde(default = "def_false")]
pub invert_scroll_direction_x: bool,
#[serde(default = "def_false")]
pub invert_scroll_direction_y: bool,
#[serde(default = "def_one")]
pub scroll_speed: f32,
#[serde(default = "def_one")]
pub long_press_duration: f32,
#[serde(default = "def_mouse_move_interval_ms")]
pub mouse_move_interval_ms: i32,
#[serde(default = "def_true")]
pub notifications_enabled: bool,
#[serde(default = "def_true")]
pub notifications_sound_enabled: bool,
#[serde(default)]
pub notification_topics: IdMap<ToastTopic, ToastDisplayMethod>,
#[serde(default = "def_true")]
pub keyboard_sound_enabled: bool,
#[serde(default = "def_one")]
pub keyboard_scale: f32,
#[serde(default = "def_one")]
pub desktop_view_scale: f32,
#[serde(default = "def_half")]
pub watch_view_angle_min: f32,
#[serde(default = "def_point7")]
pub watch_view_angle_max: f32,
#[serde(default = "def_osc_port")]
pub osc_out_port: u16,
#[serde(default = "def_false")]
pub upright_screen_fix: bool,
#[serde(default = "def_false")]
pub double_cursor_fix: bool,
#[serde(default = "def_true")]
pub enable_watch: bool,
#[serde(default = "def_false")]
pub sets_on_watch: bool,
#[serde(default = "def_false")]
pub hide_grab_help: bool,
#[serde(default)]
pub custom_panels: AStrSet,
#[serde(default)]
pub capture_method: CaptureMethod,
#[serde(default = "def_point7")]
pub xr_click_sensitivity: f32,
#[serde(default = "def_half")]
pub xr_click_sensitivity_release: f32,
#[serde(default = "def_true")]
pub allow_sliding: bool,
#[serde(default = "def_false")]
pub focus_follows_mouse_mode: bool,
#[serde(default = "def_false")]
pub left_handed_mouse: bool,
#[serde(default = "def_false")]
pub block_game_input: bool,
#[serde(default = "def_true")]
pub block_game_input_ignore_watch: bool,
#[serde(default = "def_true")]
pub block_poses_on_kbd_interaction: bool,
#[serde(default = "def_one")]
pub space_drag_multiplier: f32,
#[serde(default = "def_empty")]
pub skybox_texture: Arc<str>,
#[serde(default = "def_true")]
pub use_skybox: bool,
#[serde(default = "def_true")]
pub use_passthrough: bool,
#[serde(default = "def_max_height")]
pub screen_max_height: u16,
#[serde(default = "def_false")]
pub screen_render_down: bool,
#[serde(default = "def_point3")]
pub pointer_lerp_factor: f32,
#[serde(default = "def_true")]
pub space_drag_unlocked: bool,
#[serde(default = "def_false")]
pub space_rotate_unlocked: bool,
#[serde(default)]
pub alt_click_down: Vec<String>,
#[serde(default)]
pub alt_click_up: Vec<String>,
#[serde(default = "def_timezones")]
pub timezones: Vec<String>,
#[serde(default = "def_false")]
pub clock_12h: bool,
#[serde(default)]
pub sets: Vec<SerializedWindowSet>,
#[serde(default)]
pub global_set: SerializedWindowStates,
#[serde(default)]
pub autostart_apps: Vec<WvrProcessLaunchParams>,
#[serde(default)]
pub last_set: u32,
#[serde(default)]
pub hide_username: bool,
#[serde(default)]
pub opaque_background: bool,
#[serde(default)]
pub xwayland_by_default: bool,
#[serde(default)]
pub context_menu_hold_and_release: bool,
#[serde(default)]
pub keyboard_middle_click_mode: AltModifier,
#[serde(default)]
pub handsfree_pointer: HandsfreePointer,
#[serde(default = "def_one")]
pub grid_opacity: f32,
#[serde(default)]
pub chroma_key_params: ChromaKeyParams,
}