Skip to content

Commit

Permalink
WayVR: Display auto-hide support (Fixes #98), keyboard settings in co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
olekolek1000 authored and galister committed Nov 5, 2024
1 parent d212098 commit 502cf5d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 16 deletions.
30 changes: 27 additions & 3 deletions src/backend/wayvr/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ use smithay::{
wayland::shell::xdg::ToplevelSurface,
};

use crate::{backend::overlay::OverlayID, gen_id};
use crate::{
backend::{overlay::OverlayID, wayvr::time::get_millis},
gen_id,
};

use super::{
client::WayVRManager, comp::send_frames_surface_tree, egl_data, event_queue::SyncEventQueue,
process, smithay_wrapper, time, window,
process, smithay_wrapper, time, window, WayVRSignal,
};

fn generate_auth_key() -> String {
Expand Down Expand Up @@ -55,6 +58,7 @@ pub struct Display {
pub displayed_windows: Vec<DisplayWindow>,
wayland_env: super::WaylandEnv,
last_pressed_time_ms: u64,
pub no_windows_since: Option<u64>,

// Render data stuff
gles_texture: GlesTexture, // TODO: drop texture
Expand Down Expand Up @@ -123,6 +127,7 @@ impl Display {
overlay_id: None,
tasks: SyncEventQueue::new(),
last_pressed_time_ms: 0,
no_windows_since: None,
})
}

Expand Down Expand Up @@ -158,7 +163,24 @@ impl Display {
}
}

pub fn tick(&mut self) {
pub fn tick(
&mut self,
config: &super::Config,
handle: &DisplayHandle,
signals: &mut SyncEventQueue<WayVRSignal>,
) {
if self.visible {
if !self.displayed_windows.is_empty() {
self.no_windows_since = None;
} else if let Some(auto_hide_delay) = config.auto_hide_delay {
if let Some(s) = self.no_windows_since {
if s + (auto_hide_delay as u64) < get_millis() {
signals.send(WayVRSignal::DisplayHideRequest(*handle));
}
}
}
}

while let Some(task) = self.tasks.read() {
match task {
DisplayTask::ProcessCleanup(process_handle) => {
Expand All @@ -169,6 +191,7 @@ impl Display {
self.name,
self.displayed_windows.len()
);
self.no_windows_since = Some(get_millis());

self.reposition_windows();
}
Expand Down Expand Up @@ -248,6 +271,7 @@ impl Display {
self.visible = visible;
if visible {
self.wants_redraw = true;
self.no_windows_since = None;
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/backend/wayvr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ pub enum WayVRTask {
ProcessTerminationRequest(process::ProcessHandle),
}

#[derive(Clone)]
pub enum WayVRSignal {
DisplayHideRequest(display::DisplayHandle),
}

pub struct Config {
pub click_freeze_time_ms: u32,
pub keyboard_repeat_delay_ms: u32,
pub keyboard_repeat_rate: u32,
pub auto_hide_delay: Option<u32>, // if None, auto-hide is disabled
}

#[allow(dead_code)]
Expand All @@ -83,6 +89,7 @@ pub struct WayVR {
config: Config,

tasks: SyncEventQueue<WayVRTask>,
pub signals: SyncEventQueue<WayVRSignal>,
}

pub enum MouseIndex {
Expand Down Expand Up @@ -140,6 +147,7 @@ impl WayVR {
processes: ProcessVec::new(),
egl_data: Rc::new(egl_data),
wm: Rc::new(RefCell::new(window::WindowManager::new())),
signals: SyncEventQueue::new(),
tasks,
config,
})
Expand Down Expand Up @@ -206,9 +214,9 @@ impl WayVR {
}
}

for display in self.displays.vec.iter_mut().flatten() {
display.obj.tick();
}
self.displays.iter_mut(&mut |handle, display| {
display.tick(&self.config, &handle, &mut self.signals);
});

while let Some(task) = self.tasks.read() {
match task {
Expand Down
46 changes: 41 additions & 5 deletions src/config_wayvr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,40 @@ impl WayVRCatalog {
}
}

fn def_true() -> bool {
true
}

fn def_autohide_delay() -> u32 {
750
}

fn def_keyboard_repeat_delay() -> u32 {
200
}

fn def_keyboard_repeat_rate() -> u32 {
50
}

#[derive(Deserialize, Serialize)]
pub struct WayVRConfig {
pub version: u32,
pub run_compositor_at_start: bool,
pub catalogs: HashMap<String, WayVRCatalog>,
pub displays: BTreeMap<String, WayVRDisplay>, // sorted alphabetically

#[serde(default = "def_true")]
pub auto_hide: bool,

#[serde(default = "def_autohide_delay")]
pub auto_hide_delay: u32,

#[serde(default = "def_keyboard_repeat_delay")]
pub keyboard_repeat_delay: u32,

#[serde(default = "def_keyboard_repeat_rate")]
pub keyboard_repeat_rate: u32,
}

impl WayVRConfig {
Expand All @@ -106,11 +134,19 @@ impl WayVRConfig {
None
}

pub fn get_wayvr_config(config: &crate::config::GeneralConfig) -> wayvr::Config {
pub fn get_wayvr_config(
config_general: &crate::config::GeneralConfig,
config_wayvr: &crate::config_wayvr::WayVRConfig,
) -> wayvr::Config {
wayvr::Config {
click_freeze_time_ms: config.click_freeze_time_ms,
keyboard_repeat_delay_ms: 200,
keyboard_repeat_rate: 50,
click_freeze_time_ms: config_general.click_freeze_time_ms,
keyboard_repeat_delay_ms: config_wayvr.keyboard_repeat_delay,
keyboard_repeat_rate: config_wayvr.keyboard_repeat_rate,
auto_hide_delay: if config_wayvr.auto_hide {
Some(config_wayvr.auto_hide_delay)
} else {
None
},
}
}

Expand Down Expand Up @@ -147,7 +183,7 @@ impl WayVRConfig {
if self.run_compositor_at_start {
// Start Wayland server instantly
Ok(Some(Rc::new(RefCell::new(WayVRState::new(
Self::get_wayvr_config(config),
Self::get_wayvr_config(config, &self),
)?))))
} else {
// Lazy-init WayVR later if the user requested
Expand Down
28 changes: 24 additions & 4 deletions src/overlays/wayvr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use wlx_capture::frame::{DmabufFrame, FourCC, FrameFormat, FramePlane};

use crate::{
backend::{
common::OverlayContainer,
common::{OverlayContainer, OverlaySelector},
input::{self, InteractionHandler},
overlay::{
ui_transform, OverlayData, OverlayID, OverlayRenderer, OverlayState,
SplitOverlayBackend,
},
task::TaskType,
wayvr::{self, display, WayVR},
},
graphics::WlxGraphics,
Expand Down Expand Up @@ -213,8 +214,27 @@ pub fn tick_events<O>(app: &mut AppState, overlays: &mut OverlayContainer<O>) ->
where
O: Default,
{
if let Some(wayvr) = app.wayvr.clone() {
let res = wayvr.borrow_mut().state.tick_events()?;
if let Some(r_wayvr) = app.wayvr.clone() {
let mut wayvr = r_wayvr.borrow_mut();
while let Some(signal) = wayvr.state.signals.read() {
match signal {
wayvr::WayVRSignal::DisplayHideRequest(display_handle) => {
if let Some(overlay_id) = wayvr.display_handle_map.get(&display_handle) {
let overlay_id = *overlay_id;
wayvr.state.set_display_visible(display_handle, false);
app.tasks.enqueue(TaskType::Overlay(
OverlaySelector::Id(overlay_id),
Box::new(move |_app, o| {
o.want_visible = false;
}),
));
}
}
}
}

let res = wayvr.state.tick_events()?;
drop(wayvr);

for result in res {
match result {
Expand All @@ -232,7 +252,7 @@ where
};

if let Some(disp_name) = disp_name {
let mut wayvr = wayvr.borrow_mut();
let mut wayvr = r_wayvr.borrow_mut();

log::info!("Registering external process with PID {}", req.pid);

Expand Down
13 changes: 13 additions & 0 deletions src/res/wayvr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ version: 1
# (used for remote starting external processes)
run_compositor_at_start: false

# Automatically close overlays with zero window count?
auto_hide: true

# For how long an overlay should be visible in case if there are no windows present? (in milliseconds, auto_hide needs to be enabled)
# This value shouldn't be set at 0, because some programs could re-initialize a window during startup (splash screens for example)
auto_hide_delay: 750

# In milliseconds
keyboard_repeat_delay: 200

# Chars per second
keyboard_repeat_rate: 50

displays:
Watch:
width: 400
Expand Down
2 changes: 1 addition & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl AppState {
Ok(wvr.clone())
} else {
let wayvr = Rc::new(RefCell::new(WayVRState::new(
WayVRConfig::get_wayvr_config(&self.session.config),
WayVRConfig::get_wayvr_config(&self.session.config, &self.session.wayvr_config),
)?));
self.wayvr = Some(wayvr.clone());
Ok(wayvr)
Expand Down

0 comments on commit 502cf5d

Please sign in to comment.