Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99a4a336ad | ||
|
|
df45c0bfeb | ||
|
|
faad8ce26a | ||
|
|
e378b2e33b | ||
|
|
96e41de1b1 | ||
|
|
5c888f8357 | ||
|
|
074f004227 | ||
|
|
2d22036930 |
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
All notable changes to PeerSpeak are documented here.
|
All notable changes to PeerSpeak are documented here.
|
||||||
|
|
||||||
|
## [0.6.3] — 2026-07-06
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **In-app screen-sharing controls.** A new **Screen sharing** section in Settings, plus a per-call **quality picker** on the Share control, put the whole share pipeline under your control without editing config files. Encode side: quality preset, bitrate, framerate, maximum resolution, maximum viewers, a force-software-encode switch, and an escape hatch for extra pixelpass arguments. Playback side: choose **mpv or VLC**, toggle **hardware decoding**, pick a buffering posture (low-latency vs. smooth), set the demuxer cache, and pass extra mpv arguments. Everything is stored locally in your config and defaults are unchanged, so existing setups keep working as-is.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- **Shared video no longer freezes on the first frame while audio keeps playing.** Hardware decoding now defaults **off**; forcing `--hwdec=auto` stalled some viewers' hardware decoder on frame 1. You can re-enable hardware decoding from the new Screen sharing settings if your machine handles it well.
|
||||||
|
- **The per-call quality picker is now honored.** The inline quality dropdown next to the Share button was being reset to the saved default before a share started, so every share silently used the default quality regardless of what you picked.
|
||||||
|
- **VLC now respects your playback settings.** VLC hardware-decodes by default, so a VLC viewer previously ignored the hardware-decode toggle (and could hit the same frame-1 freeze) and the buffering posture. VLC viewers now map both settings onto VLC's own options.
|
||||||
|
|
||||||
|
[0.6.3]: https://gitbutter.xyz/mollusk/peerspeak/releases/tag/v0.6.3
|
||||||
|
|
||||||
## [0.6.2] — 2026-07-03
|
## [0.6.2] — 2026-07-03
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
Generated
+1
-1
@@ -4871,7 +4871,7 @@ checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peerspeak"
|
name = "peerspeak"
|
||||||
version = "0.6.2"
|
version = "0.6.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "peerspeak"
|
name = "peerspeak"
|
||||||
version = "0.6.2"
|
version = "0.6.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "Decentralized peer-to-peer voice chat (Rust/iroh/PipeWire/Opus/iced)"
|
description = "Decentralized peer-to-peer voice chat (Rust/iroh/PipeWire/Opus/iced)"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
# Maintainer: mollusk <jitty+lc1iz0dc@protonmail.com>
|
# Maintainer: mollusk <jitty+lc1iz0dc@protonmail.com>
|
||||||
pkgname=peerspeak-git
|
pkgname=peerspeak-git
|
||||||
_pkgname=peerspeak
|
_pkgname=peerspeak
|
||||||
pkgver=0.6.1.r315.ga78860d
|
pkgver=0.6.2.r319.g8014edf
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Decentralized peer-to-peer voice chat (Rust/iroh/PipeWire/Opus/iced)"
|
pkgdesc="Decentralized peer-to-peer voice chat (Rust/iroh/PipeWire/Opus/iced)"
|
||||||
arch=('x86_64')
|
arch=('x86_64')
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
; (x86_64-pc-windows-gnu, statically linked -- no extra DLLs needed).
|
; (x86_64-pc-windows-gnu, statically linked -- no extra DLLs needed).
|
||||||
|
|
||||||
#define MyAppName "PeerSpeak"
|
#define MyAppName "PeerSpeak"
|
||||||
#define MyAppVersion "0.6.2"
|
#define MyAppVersion "0.6.3"
|
||||||
#define MyAppPublisher "mollusk"
|
#define MyAppPublisher "mollusk"
|
||||||
#define MyAppExeName "peerspeak.exe"
|
#define MyAppExeName "peerspeak.exe"
|
||||||
|
|
||||||
|
|||||||
+493
-7
@@ -4,7 +4,10 @@ use crate::audio::clip_player::{
|
|||||||
};
|
};
|
||||||
use crate::audio::eq::{EQ_GAIN_DB_MAX, EQ_GAIN_DB_MIN, EqSettings};
|
use crate::audio::eq::{EQ_GAIN_DB_MAX, EQ_GAIN_DB_MIN, EqSettings};
|
||||||
use crate::audio::{AudioDevice, enumerate_audio_devices};
|
use crate::audio::{AudioDevice, enumerate_audio_devices};
|
||||||
use crate::config::{AppConfig, AudioProfile, NetworkMode, RecordingMode, RoomLayout};
|
use crate::config::{
|
||||||
|
AppConfig, AudioProfile, NetworkMode, RecordingMode, RoomLayout, ShareBuffering, SharePlayer,
|
||||||
|
ShareQuality,
|
||||||
|
};
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
CoreController,
|
CoreController,
|
||||||
messages::{CoreCommand, UiEvent},
|
messages::{CoreCommand, UiEvent},
|
||||||
@@ -60,18 +63,20 @@ pub enum SettingsCategory {
|
|||||||
Profile,
|
Profile,
|
||||||
Appearance,
|
Appearance,
|
||||||
Network,
|
Network,
|
||||||
|
Advanced,
|
||||||
Notifications,
|
Notifications,
|
||||||
Games,
|
Games,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SettingsCategory {
|
impl SettingsCategory {
|
||||||
const ALL: [SettingsCategory; 8] = [
|
const ALL: [SettingsCategory; 9] = [
|
||||||
SettingsCategory::Audio,
|
SettingsCategory::Audio,
|
||||||
SettingsCategory::Hotkeys,
|
SettingsCategory::Hotkeys,
|
||||||
SettingsCategory::Recording,
|
SettingsCategory::Recording,
|
||||||
SettingsCategory::Profile,
|
SettingsCategory::Profile,
|
||||||
SettingsCategory::Appearance,
|
SettingsCategory::Appearance,
|
||||||
SettingsCategory::Network,
|
SettingsCategory::Network,
|
||||||
|
SettingsCategory::Advanced,
|
||||||
SettingsCategory::Notifications,
|
SettingsCategory::Notifications,
|
||||||
SettingsCategory::Games,
|
SettingsCategory::Games,
|
||||||
];
|
];
|
||||||
@@ -84,6 +89,7 @@ impl SettingsCategory {
|
|||||||
SettingsCategory::Profile => "Profile",
|
SettingsCategory::Profile => "Profile",
|
||||||
SettingsCategory::Appearance => "Appearance",
|
SettingsCategory::Appearance => "Appearance",
|
||||||
SettingsCategory::Network => "Network",
|
SettingsCategory::Network => "Network",
|
||||||
|
SettingsCategory::Advanced => "Advanced",
|
||||||
SettingsCategory::Notifications => "Notifications",
|
SettingsCategory::Notifications => "Notifications",
|
||||||
SettingsCategory::Games => "Games",
|
SettingsCategory::Games => "Games",
|
||||||
}
|
}
|
||||||
@@ -97,6 +103,7 @@ impl SettingsCategory {
|
|||||||
SettingsCategory::Profile => "Avatar and identity",
|
SettingsCategory::Profile => "Avatar and identity",
|
||||||
SettingsCategory::Appearance => "Layout and theme",
|
SettingsCategory::Appearance => "Layout and theme",
|
||||||
SettingsCategory::Network => "Relay and privacy mode",
|
SettingsCategory::Network => "Relay and privacy mode",
|
||||||
|
SettingsCategory::Advanced => "Screen sharing",
|
||||||
SettingsCategory::Notifications => "Chimes and sounds",
|
SettingsCategory::Notifications => "Chimes and sounds",
|
||||||
SettingsCategory::Games => "Detection, presence, backgrounds",
|
SettingsCategory::Games => "Detection, presence, backgrounds",
|
||||||
}
|
}
|
||||||
@@ -109,6 +116,176 @@ impl std::fmt::Display for SettingsCategory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum ShareMaxHeightChoice {
|
||||||
|
Source,
|
||||||
|
P720,
|
||||||
|
P1080,
|
||||||
|
P1440,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShareMaxHeightChoice {
|
||||||
|
const ALL: [ShareMaxHeightChoice; 4] = [
|
||||||
|
ShareMaxHeightChoice::Source,
|
||||||
|
ShareMaxHeightChoice::P720,
|
||||||
|
ShareMaxHeightChoice::P1080,
|
||||||
|
ShareMaxHeightChoice::P1440,
|
||||||
|
];
|
||||||
|
|
||||||
|
fn from_config(value: Option<u32>) -> Self {
|
||||||
|
match value {
|
||||||
|
Some(720) => ShareMaxHeightChoice::P720,
|
||||||
|
Some(1080) => ShareMaxHeightChoice::P1080,
|
||||||
|
Some(1440) => ShareMaxHeightChoice::P1440,
|
||||||
|
_ => ShareMaxHeightChoice::Source,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_config(self) -> Option<u32> {
|
||||||
|
match self {
|
||||||
|
ShareMaxHeightChoice::Source => None,
|
||||||
|
ShareMaxHeightChoice::P720 => Some(720),
|
||||||
|
ShareMaxHeightChoice::P1080 => Some(1080),
|
||||||
|
ShareMaxHeightChoice::P1440 => Some(1440),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ShareMaxHeightChoice {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
ShareMaxHeightChoice::Source => "Source",
|
||||||
|
ShareMaxHeightChoice::P720 => "720p",
|
||||||
|
ShareMaxHeightChoice::P1080 => "1080p",
|
||||||
|
ShareMaxHeightChoice::P1440 => "1440p",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum ShareFramerateChoice {
|
||||||
|
Preset,
|
||||||
|
Fps15,
|
||||||
|
Fps24,
|
||||||
|
Fps30,
|
||||||
|
Fps60,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShareFramerateChoice {
|
||||||
|
const ALL: [ShareFramerateChoice; 5] = [
|
||||||
|
ShareFramerateChoice::Preset,
|
||||||
|
ShareFramerateChoice::Fps15,
|
||||||
|
ShareFramerateChoice::Fps24,
|
||||||
|
ShareFramerateChoice::Fps30,
|
||||||
|
ShareFramerateChoice::Fps60,
|
||||||
|
];
|
||||||
|
|
||||||
|
fn from_config(value: Option<u32>) -> Self {
|
||||||
|
match value {
|
||||||
|
Some(15) => ShareFramerateChoice::Fps15,
|
||||||
|
Some(24) => ShareFramerateChoice::Fps24,
|
||||||
|
Some(30) => ShareFramerateChoice::Fps30,
|
||||||
|
Some(60) => ShareFramerateChoice::Fps60,
|
||||||
|
_ => ShareFramerateChoice::Preset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_config(self) -> Option<u32> {
|
||||||
|
match self {
|
||||||
|
ShareFramerateChoice::Preset => None,
|
||||||
|
ShareFramerateChoice::Fps15 => Some(15),
|
||||||
|
ShareFramerateChoice::Fps24 => Some(24),
|
||||||
|
ShareFramerateChoice::Fps30 => Some(30),
|
||||||
|
ShareFramerateChoice::Fps60 => Some(60),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ShareFramerateChoice {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
ShareFramerateChoice::Preset => "Preset default",
|
||||||
|
ShareFramerateChoice::Fps15 => "15 fps",
|
||||||
|
ShareFramerateChoice::Fps24 => "24 fps",
|
||||||
|
ShareFramerateChoice::Fps30 => "30 fps",
|
||||||
|
ShareFramerateChoice::Fps60 => "60 fps",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum ShareMaxViewersChoice {
|
||||||
|
Auto,
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
Three,
|
||||||
|
Four,
|
||||||
|
Five,
|
||||||
|
Six,
|
||||||
|
Seven,
|
||||||
|
Eight,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShareMaxViewersChoice {
|
||||||
|
const ALL: [ShareMaxViewersChoice; 9] = [
|
||||||
|
ShareMaxViewersChoice::Auto,
|
||||||
|
ShareMaxViewersChoice::One,
|
||||||
|
ShareMaxViewersChoice::Two,
|
||||||
|
ShareMaxViewersChoice::Three,
|
||||||
|
ShareMaxViewersChoice::Four,
|
||||||
|
ShareMaxViewersChoice::Five,
|
||||||
|
ShareMaxViewersChoice::Six,
|
||||||
|
ShareMaxViewersChoice::Seven,
|
||||||
|
ShareMaxViewersChoice::Eight,
|
||||||
|
];
|
||||||
|
|
||||||
|
fn from_config(value: Option<u32>) -> Self {
|
||||||
|
match value {
|
||||||
|
Some(1) => ShareMaxViewersChoice::One,
|
||||||
|
Some(2) => ShareMaxViewersChoice::Two,
|
||||||
|
Some(3) => ShareMaxViewersChoice::Three,
|
||||||
|
Some(4) => ShareMaxViewersChoice::Four,
|
||||||
|
Some(5) => ShareMaxViewersChoice::Five,
|
||||||
|
Some(6) => ShareMaxViewersChoice::Six,
|
||||||
|
Some(7) => ShareMaxViewersChoice::Seven,
|
||||||
|
Some(8) => ShareMaxViewersChoice::Eight,
|
||||||
|
_ => ShareMaxViewersChoice::Auto,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_config(self) -> Option<u32> {
|
||||||
|
match self {
|
||||||
|
ShareMaxViewersChoice::Auto => None,
|
||||||
|
ShareMaxViewersChoice::One => Some(1),
|
||||||
|
ShareMaxViewersChoice::Two => Some(2),
|
||||||
|
ShareMaxViewersChoice::Three => Some(3),
|
||||||
|
ShareMaxViewersChoice::Four => Some(4),
|
||||||
|
ShareMaxViewersChoice::Five => Some(5),
|
||||||
|
ShareMaxViewersChoice::Six => Some(6),
|
||||||
|
ShareMaxViewersChoice::Seven => Some(7),
|
||||||
|
ShareMaxViewersChoice::Eight => Some(8),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ShareMaxViewersChoice {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
ShareMaxViewersChoice::Auto => "Auto",
|
||||||
|
ShareMaxViewersChoice::One => "1",
|
||||||
|
ShareMaxViewersChoice::Two => "2",
|
||||||
|
ShareMaxViewersChoice::Three => "3",
|
||||||
|
ShareMaxViewersChoice::Four => "4",
|
||||||
|
ShareMaxViewersChoice::Five => "5",
|
||||||
|
ShareMaxViewersChoice::Six => "6",
|
||||||
|
ShareMaxViewersChoice::Seven => "7",
|
||||||
|
ShareMaxViewersChoice::Eight => "8",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const SHARE_CACHE_MB_OPTIONS: [u32; 8] = [1, 2, 4, 8, 16, 32, 64, 128];
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
enum HomeLayoutMode {
|
enum HomeLayoutMode {
|
||||||
FocusedEmpty,
|
FocusedEmpty,
|
||||||
@@ -379,6 +556,18 @@ pub enum AppMessage {
|
|||||||
NetworkModeSelected(NetworkMode),
|
NetworkModeSelected(NetworkMode),
|
||||||
AudioProfileSelected(AudioProfile),
|
AudioProfileSelected(AudioProfile),
|
||||||
RecordingModeSelected(RecordingMode),
|
RecordingModeSelected(RecordingMode),
|
||||||
|
ScreenShareQualitySelected(ShareQuality),
|
||||||
|
ScreenSharePlayerSelected(SharePlayer),
|
||||||
|
ScreenShareBufferingSelected(ShareBuffering),
|
||||||
|
ScreenShareMaxHeightSelected(ShareMaxHeightChoice),
|
||||||
|
ScreenShareFramerateSelected(ShareFramerateChoice),
|
||||||
|
ScreenShareMaxViewersSelected(ShareMaxViewersChoice),
|
||||||
|
ScreenShareCacheMbSelected(u32),
|
||||||
|
ScreenShareBitrateChanged(String),
|
||||||
|
ToggleScreenShareForceSoftwareEncode(bool),
|
||||||
|
ToggleScreenShareHardwareDecode(bool),
|
||||||
|
ScreenShareExtraMpvArgsChanged(String),
|
||||||
|
ScreenShareExtraHostArgsChanged(String),
|
||||||
/// Choose the friends presence posture (W7): invisible / normal / discoverable.
|
/// Choose the friends presence posture (W7): invisible / normal / discoverable.
|
||||||
PresenceModeSelected(PresenceMode),
|
PresenceModeSelected(PresenceMode),
|
||||||
/// Friends list (W7 P5): add-form edits, add, remove, and local rename.
|
/// Friends list (W7 P5): add-form edits, add, remove, and local rename.
|
||||||
@@ -537,6 +726,8 @@ pub enum AppMessage {
|
|||||||
/// Select which app's audio to share in the picker: `Some(name)` for one app,
|
/// Select which app's audio to share in the picker: `Some(name)` for one app,
|
||||||
/// `None` for the whole desktop ("All system audio").
|
/// `None` for the whole desktop ("All system audio").
|
||||||
SelectShareAudioApp(Option<String>),
|
SelectShareAudioApp(Option<String>),
|
||||||
|
/// Session-only quality preset for the next share start.
|
||||||
|
SelectShareQualityOverride(ShareQuality),
|
||||||
/// Confirm the picker: start the share with the currently selected audio app.
|
/// Confirm the picker: start the share with the currently selected audio app.
|
||||||
ConfirmShareScreen,
|
ConfirmShareScreen,
|
||||||
/// Watch a peer's screen share, identified by their pixelpass ticket.
|
/// Watch a peer's screen share, identified by their pixelpass ticket.
|
||||||
@@ -761,6 +952,8 @@ pub struct AppState {
|
|||||||
/// The picker's current selection: `Some(name)` = capture that app's audio,
|
/// The picker's current selection: `Some(name)` = capture that app's audio,
|
||||||
/// `None` = "All system audio" (whole desktop; may echo the call).
|
/// `None` = "All system audio" (whole desktop; may echo the call).
|
||||||
share_audio_selection: Option<String>,
|
share_audio_selection: Option<String>,
|
||||||
|
/// Session-only quality override for the next screen-share start.
|
||||||
|
share_quality_selection: ShareQuality,
|
||||||
/// A share start is in flight: `ConfirmShareScreen` was sent but the core
|
/// A share start is in flight: `ConfirmShareScreen` was sent but the core
|
||||||
/// hasn't yet replied with `ScreenShareStarted`/an error. Blocks reopening
|
/// hasn't yet replied with `ScreenShareStarted`/an error. Blocks reopening
|
||||||
/// the picker (and re-confirming) during that startup window. Cleared on
|
/// the picker (and re-confirming) during that startup window. Cleared on
|
||||||
@@ -871,6 +1064,7 @@ impl AppState {
|
|||||||
self.share_picker_open = false;
|
self.share_picker_open = false;
|
||||||
self.share_audio_apps.clear();
|
self.share_audio_apps.clear();
|
||||||
self.share_audio_selection = None;
|
self.share_audio_selection = None;
|
||||||
|
self.share_quality_selection = self.config.screen_share.quality;
|
||||||
self.share_starting = false;
|
self.share_starting = false;
|
||||||
self.share_audio_dropped = false;
|
self.share_audio_dropped = false;
|
||||||
self.share_audio_app_active = false;
|
self.share_audio_app_active = false;
|
||||||
@@ -975,6 +1169,7 @@ impl Default for AppState {
|
|||||||
let (clip_player, clip_status) = ClipPlayer::new(config.clip_volume);
|
let (clip_player, clip_status) = ClipPlayer::new(config.clip_volume);
|
||||||
let (music_player, music_status) = ClipPlayer::new(config.music_volume);
|
let (music_player, music_status) = ClipPlayer::new(config.music_volume);
|
||||||
let music_broadcasting = config.music_broadcast;
|
let music_broadcasting = config.music_broadcast;
|
||||||
|
let share_quality_selection = config.screen_share.quality;
|
||||||
let music_playlist = config
|
let music_playlist = config
|
||||||
.music_playlist
|
.music_playlist
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1049,6 +1244,7 @@ impl Default for AppState {
|
|||||||
share_picker_open: false,
|
share_picker_open: false,
|
||||||
share_audio_apps: Vec::new(),
|
share_audio_apps: Vec::new(),
|
||||||
share_audio_selection: None,
|
share_audio_selection: None,
|
||||||
|
share_quality_selection,
|
||||||
share_starting: false,
|
share_starting: false,
|
||||||
share_audio_dropped: false,
|
share_audio_dropped: false,
|
||||||
share_audio_app_active: false,
|
share_audio_app_active: false,
|
||||||
@@ -1563,6 +1759,11 @@ fn update(state: &mut AppState, message: AppMessage) -> Task<AppMessage> {
|
|||||||
// so the picker can't be reopened during the startup window.
|
// so the picker can't be reopened during the startup window.
|
||||||
state.share_picker_open = true;
|
state.share_picker_open = true;
|
||||||
state.share_audio_selection = None;
|
state.share_audio_selection = None;
|
||||||
|
// NB: do NOT reset `share_quality_selection` here. It is the
|
||||||
|
// per-call override set by the inline quality dropdown next to
|
||||||
|
// the Share button, and the picker has no quality control of its
|
||||||
|
// own — resetting it would silently discard the user's pick
|
||||||
|
// before `ConfirmShareScreen` reads it.
|
||||||
state.share_audio_apps.clear();
|
state.share_audio_apps.clear();
|
||||||
let _ = state.controller.send(CoreCommand::ListAudioApps);
|
let _ = state.controller.send(CoreCommand::ListAudioApps);
|
||||||
}
|
}
|
||||||
@@ -1573,6 +1774,9 @@ fn update(state: &mut AppState, message: AppMessage) -> Task<AppMessage> {
|
|||||||
AppMessage::SelectShareAudioApp(app) => {
|
AppMessage::SelectShareAudioApp(app) => {
|
||||||
state.share_audio_selection = app;
|
state.share_audio_selection = app;
|
||||||
}
|
}
|
||||||
|
AppMessage::SelectShareQualityOverride(quality) => {
|
||||||
|
state.share_quality_selection = quality;
|
||||||
|
}
|
||||||
AppMessage::ConfirmShareScreen => {
|
AppMessage::ConfirmShareScreen => {
|
||||||
// Only a confirm from an open picker starts a share; a stray confirm
|
// Only a confirm from an open picker starts a share; a stray confirm
|
||||||
// (or one arriving while a start is already in flight) is ignored, so
|
// (or one arriving while a start is already in flight) is ignored, so
|
||||||
@@ -1581,14 +1785,21 @@ fn update(state: &mut AppState, message: AppMessage) -> Task<AppMessage> {
|
|||||||
state.share_picker_open = false;
|
state.share_picker_open = false;
|
||||||
state.share_starting = true;
|
state.share_starting = true;
|
||||||
let audio_app = state.share_audio_selection.clone();
|
let audio_app = state.share_audio_selection.clone();
|
||||||
let _ = state
|
let settings = state.config.screen_share.clone();
|
||||||
.controller
|
let quality = state.share_quality_selection;
|
||||||
.send(CoreCommand::StartScreenShare { audio_app });
|
let _ = state.controller.send(CoreCommand::StartScreenShare {
|
||||||
|
audio_app,
|
||||||
|
settings,
|
||||||
|
quality,
|
||||||
|
});
|
||||||
state.status_message = "Starting screen share…".to_string();
|
state.status_message = "Starting screen share…".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AppMessage::WatchShare(ticket) => {
|
AppMessage::WatchShare(ticket) => {
|
||||||
let _ = state.controller.send(CoreCommand::ViewShare(ticket));
|
let settings = state.config.screen_share.clone();
|
||||||
|
let _ = state
|
||||||
|
.controller
|
||||||
|
.send(CoreCommand::ViewShare { ticket, settings });
|
||||||
state.status_message = "Opening screen share…".to_string();
|
state.status_message = "Opening screen share…".to_string();
|
||||||
}
|
}
|
||||||
AppMessage::ToggleMutePressed => {
|
AppMessage::ToggleMutePressed => {
|
||||||
@@ -2064,6 +2275,61 @@ fn update(state: &mut AppState, message: AppMessage) -> Task<AppMessage> {
|
|||||||
// Takes effect on the next recording start.
|
// Takes effect on the next recording start.
|
||||||
let _ = state.controller.send(CoreCommand::SetRecordingMode(mode));
|
let _ = state.controller.send(CoreCommand::SetRecordingMode(mode));
|
||||||
}
|
}
|
||||||
|
AppMessage::ScreenShareQualitySelected(quality) => {
|
||||||
|
state.config.screen_share.quality = quality;
|
||||||
|
state.share_quality_selection = quality;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenSharePlayerSelected(player) => {
|
||||||
|
state.config.screen_share.player = player;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareBufferingSelected(buffering) => {
|
||||||
|
state.config.screen_share.buffering = buffering;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareMaxHeightSelected(choice) => {
|
||||||
|
state.config.screen_share.max_height = choice.to_config();
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareFramerateSelected(choice) => {
|
||||||
|
state.config.screen_share.framerate = choice.to_config();
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareMaxViewersSelected(choice) => {
|
||||||
|
state.config.screen_share.max_viewers = choice.to_config();
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareCacheMbSelected(cache_mb) => {
|
||||||
|
state.config.screen_share.cache_mb = cache_mb;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareBitrateChanged(value) => {
|
||||||
|
let trimmed = value.trim();
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
state.config.screen_share.bitrate_mbps = None;
|
||||||
|
state.config.save();
|
||||||
|
} else if let Ok(mbps) = trimmed.parse::<u32>() {
|
||||||
|
state.config.screen_share.bitrate_mbps = Some(mbps);
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AppMessage::ToggleScreenShareForceSoftwareEncode(enabled) => {
|
||||||
|
state.config.screen_share.force_software_encode = enabled;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ToggleScreenShareHardwareDecode(enabled) => {
|
||||||
|
state.config.screen_share.hardware_decode = enabled;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareExtraMpvArgsChanged(args) => {
|
||||||
|
state.config.screen_share.extra_mpv_args = args;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
|
AppMessage::ScreenShareExtraHostArgsChanged(args) => {
|
||||||
|
state.config.screen_share.extra_host_args = args;
|
||||||
|
state.config.save();
|
||||||
|
}
|
||||||
AppMessage::PresenceModeSelected(mode) => {
|
AppMessage::PresenceModeSelected(mode) => {
|
||||||
state.config.presence_mode = mode;
|
state.config.presence_mode = mode;
|
||||||
state.config.save();
|
state.config.save();
|
||||||
@@ -3166,6 +3432,30 @@ fn presence_mode_hint(mode: PresenceMode) -> &'static str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn share_quality_hint(quality: ShareQuality) -> &'static str {
|
||||||
|
match quality {
|
||||||
|
ShareQuality::Auto => "Use pixelpass bandwidth pre-flight; falls back to Medium.",
|
||||||
|
ShareQuality::Low => "Lower bandwidth: up to 480p, about 1 Mbps.",
|
||||||
|
ShareQuality::Medium => "Balanced preset: up to 720p, about 2.5 Mbps.",
|
||||||
|
ShareQuality::High => "Sharper preset: up to 1080p, about 4 Mbps.",
|
||||||
|
ShareQuality::Source => "Native source resolution, about 6 Mbps.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn share_player_hint(player: SharePlayer) -> &'static str {
|
||||||
|
match player {
|
||||||
|
SharePlayer::Mpv => "Try mpv first, then VLC if mpv is unavailable.",
|
||||||
|
SharePlayer::Vlc => "Try VLC first, then mpv if VLC is unavailable.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn share_buffering_hint(buffering: ShareBuffering) -> &'static str {
|
||||||
|
match buffering {
|
||||||
|
ShareBuffering::LowLatency => "Small buffers for interactive screen sharing.",
|
||||||
|
ShareBuffering::Smooth => "Larger cache/readahead for steadier playback.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Formats a call duration as `m:ss` (or `h:mm:ss` past an hour).
|
/// Formats a call duration as `m:ss` (or `h:mm:ss` past an hour).
|
||||||
fn format_duration(total_secs: u64) -> String {
|
fn format_duration(total_secs: u64) -> String {
|
||||||
let h = total_secs / 3600;
|
let h = total_secs / 3600;
|
||||||
@@ -4759,6 +5049,135 @@ fn view(state: &AppState) -> Element<'_, AppMessage> {
|
|||||||
// Spacing between one category and the next.
|
// Spacing between one category and the next.
|
||||||
let section_gap = 18.0;
|
let section_gap = 18.0;
|
||||||
|
|
||||||
|
let screen_share = &state.config.screen_share;
|
||||||
|
let screen_share_bitrate = screen_share
|
||||||
|
.bitrate_mbps
|
||||||
|
.map(|v| v.to_string())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let screen_share_section = column![
|
||||||
|
column![
|
||||||
|
text("Host encoding").size(13).color(color_subtext),
|
||||||
|
row![
|
||||||
|
column![
|
||||||
|
text("Quality").size(12).color(color_subtext),
|
||||||
|
pick_list(
|
||||||
|
&ShareQuality::ALL[..],
|
||||||
|
Some(screen_share.quality),
|
||||||
|
AppMessage::ScreenShareQualitySelected,
|
||||||
|
).width(iced::Length::Fill),
|
||||||
|
text(share_quality_hint(screen_share.quality)).size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
column![
|
||||||
|
text("Max resolution").size(12).color(color_subtext),
|
||||||
|
pick_list(
|
||||||
|
&ShareMaxHeightChoice::ALL[..],
|
||||||
|
Some(ShareMaxHeightChoice::from_config(screen_share.max_height)),
|
||||||
|
AppMessage::ScreenShareMaxHeightSelected,
|
||||||
|
).width(iced::Length::Fill),
|
||||||
|
text("Source keeps the captured display height.").size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
].spacing(16).width(iced::Length::Fill),
|
||||||
|
row![
|
||||||
|
column![
|
||||||
|
text("Framerate").size(12).color(color_subtext),
|
||||||
|
pick_list(
|
||||||
|
&ShareFramerateChoice::ALL[..],
|
||||||
|
Some(ShareFramerateChoice::from_config(screen_share.framerate)),
|
||||||
|
AppMessage::ScreenShareFramerateSelected,
|
||||||
|
).width(iced::Length::Fill),
|
||||||
|
text("Preset default lets pixelpass choose.").size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
column![
|
||||||
|
text("Bitrate Mbps").size(12).color(color_subtext),
|
||||||
|
context_input("preset default", &screen_share_bitrate)
|
||||||
|
.on_input(AppMessage::ScreenShareBitrateChanged)
|
||||||
|
.style(t_style)
|
||||||
|
.padding(8)
|
||||||
|
.width(iced::Length::Fill),
|
||||||
|
text("Blank uses the quality preset.").size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
].spacing(16).width(iced::Length::Fill),
|
||||||
|
row![
|
||||||
|
column![
|
||||||
|
text("Max viewers").size(12).color(color_subtext),
|
||||||
|
pick_list(
|
||||||
|
&ShareMaxViewersChoice::ALL[..],
|
||||||
|
Some(ShareMaxViewersChoice::from_config(screen_share.max_viewers)),
|
||||||
|
AppMessage::ScreenShareMaxViewersSelected,
|
||||||
|
).width(iced::Length::Fill),
|
||||||
|
text("Auto uses pixelpass' connection-aware recommendation.").size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
column![
|
||||||
|
checkbox(screen_share.force_software_encode)
|
||||||
|
.label("Force software encode")
|
||||||
|
.on_toggle(AppMessage::ToggleScreenShareForceSoftwareEncode),
|
||||||
|
text("Passes --no-hwencode to pixelpass.").size(11).color(color_subtext),
|
||||||
|
].spacing(8).width(iced::Length::Fill),
|
||||||
|
].spacing(16).width(iced::Length::Fill),
|
||||||
|
].spacing(10).width(iced::Length::Fill),
|
||||||
|
vertical_space(section_gap),
|
||||||
|
column![
|
||||||
|
text("Viewer playback").size(13).color(color_subtext),
|
||||||
|
row![
|
||||||
|
column![
|
||||||
|
text("Player").size(12).color(color_subtext),
|
||||||
|
pick_list(
|
||||||
|
&SharePlayer::ALL[..],
|
||||||
|
Some(screen_share.player),
|
||||||
|
AppMessage::ScreenSharePlayerSelected,
|
||||||
|
).width(iced::Length::Fill),
|
||||||
|
text(share_player_hint(screen_share.player)).size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
column![
|
||||||
|
text("Buffering").size(12).color(color_subtext),
|
||||||
|
pick_list(
|
||||||
|
&ShareBuffering::ALL[..],
|
||||||
|
Some(screen_share.buffering),
|
||||||
|
AppMessage::ScreenShareBufferingSelected,
|
||||||
|
).width(iced::Length::Fill),
|
||||||
|
text(share_buffering_hint(screen_share.buffering)).size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
].spacing(16).width(iced::Length::Fill),
|
||||||
|
row![
|
||||||
|
column![
|
||||||
|
text("Cache MB").size(12).color(color_subtext),
|
||||||
|
pick_list(
|
||||||
|
&SHARE_CACHE_MB_OPTIONS[..],
|
||||||
|
Some(screen_share.cache_mb),
|
||||||
|
AppMessage::ScreenShareCacheMbSelected,
|
||||||
|
).width(iced::Length::Fill),
|
||||||
|
text("mpv demuxer cache size (mpv only).").size(11).color(color_subtext),
|
||||||
|
].spacing(4).width(iced::Length::Fill),
|
||||||
|
column![
|
||||||
|
checkbox(screen_share.hardware_decode)
|
||||||
|
.label("Hardware video decode")
|
||||||
|
.on_toggle(AppMessage::ToggleScreenShareHardwareDecode),
|
||||||
|
text("GPU decode (mpv --hwdec=auto / VLC hardware decode). Off avoids the known frame-freeze bug.").size(11).color(color_subtext),
|
||||||
|
].spacing(8).width(iced::Length::Fill),
|
||||||
|
].spacing(16).width(iced::Length::Fill),
|
||||||
|
].spacing(10).width(iced::Length::Fill),
|
||||||
|
vertical_space(section_gap),
|
||||||
|
column![
|
||||||
|
text("Extra mpv args").size(12).color(color_subtext),
|
||||||
|
context_input("--no-osc --vd-lavc-threads=2", &screen_share.extra_mpv_args)
|
||||||
|
.on_input(AppMessage::ScreenShareExtraMpvArgsChanged)
|
||||||
|
.style(t_style)
|
||||||
|
.padding(8)
|
||||||
|
.width(iced::Length::Fill),
|
||||||
|
text("⚠ Advanced — may break playback").size(11).color(color_yellow),
|
||||||
|
text("Extra pixelpass args").size(12).color(color_subtext),
|
||||||
|
context_input("--relay https://relay.example/", &screen_share.extra_host_args)
|
||||||
|
.on_input(AppMessage::ScreenShareExtraHostArgsChanged)
|
||||||
|
.style(t_style)
|
||||||
|
.padding(8)
|
||||||
|
.width(iced::Length::Fill),
|
||||||
|
text("⚠ Advanced — may break playback").size(11).color(color_yellow),
|
||||||
|
].spacing(6).width(iced::Length::Fill),
|
||||||
|
text("Applies the next time you start or watch a screen share. These are local preferences only.").size(11).color(color_subtext),
|
||||||
|
]
|
||||||
|
.spacing(10)
|
||||||
|
.width(iced::Length::Fill);
|
||||||
|
|
||||||
// One recording-mode radio with a hover tooltip explaining it. (iced's
|
// One recording-mode radio with a hover tooltip explaining it. (iced's
|
||||||
// pick_list can't host per-option tooltips, so the modes are radios.)
|
// pick_list can't host per-option tooltips, so the modes are radios.)
|
||||||
let mode_radio = |mode: RecordingMode, label: &'static str| -> Element<'_, AppMessage> {
|
let mode_radio = |mode: RecordingMode, label: &'static str| -> Element<'_, AppMessage> {
|
||||||
@@ -5082,6 +5501,13 @@ fn view(state: &AppState) -> Element<'_, AppMessage> {
|
|||||||
.spacing(10)
|
.spacing(10)
|
||||||
.width(iced::Length::Fill)
|
.width(iced::Length::Fill)
|
||||||
.into(),
|
.into(),
|
||||||
|
SettingsCategory::Advanced => column![
|
||||||
|
section_header("Screen sharing"),
|
||||||
|
screen_share_section,
|
||||||
|
]
|
||||||
|
.spacing(10)
|
||||||
|
.width(iced::Length::Fill)
|
||||||
|
.into(),
|
||||||
SettingsCategory::Notifications => column![
|
SettingsCategory::Notifications => column![
|
||||||
section_header("Notifications & Sounds"),
|
section_header("Notifications & Sounds"),
|
||||||
column![
|
column![
|
||||||
@@ -6479,11 +6905,29 @@ fn view(state: &AppState) -> Element<'_, AppMessage> {
|
|||||||
} else {
|
} else {
|
||||||
AppMessage::OpenPixelpassHelp
|
AppMessage::OpenPixelpassHelp
|
||||||
};
|
};
|
||||||
button(btn_content(share_kind, share_label, share_fg))
|
let share_button = button(btn_content(share_kind, share_label, share_fg))
|
||||||
.on_press(share_press)
|
.on_press(share_press)
|
||||||
.style(b_style(share_bg, share_hover, share_fg, 8.0))
|
.style(b_style(share_bg, share_hover, share_fg, 8.0))
|
||||||
.padding(14)
|
.padding(14)
|
||||||
|
.width(iced::Length::Fill);
|
||||||
|
let share_control: Element<'_, AppMessage> = if state.self_sharing {
|
||||||
|
share_button.into()
|
||||||
|
} else {
|
||||||
|
row![
|
||||||
|
share_button,
|
||||||
|
pick_list(
|
||||||
|
&ShareQuality::ALL[..],
|
||||||
|
Some(state.share_quality_selection),
|
||||||
|
AppMessage::SelectShareQualityOverride,
|
||||||
|
)
|
||||||
|
.width(iced::Length::Fixed(112.0)),
|
||||||
|
]
|
||||||
|
.spacing(8)
|
||||||
|
.align_y(iced::alignment::Vertical::Center)
|
||||||
.width(iced::Length::Fill)
|
.width(iced::Length::Fill)
|
||||||
|
.into()
|
||||||
|
};
|
||||||
|
share_control
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -8703,6 +9147,10 @@ mod tests {
|
|||||||
assert!(!state.share_picker_open);
|
assert!(!state.share_picker_open);
|
||||||
assert!(state.share_audio_apps.is_empty());
|
assert!(state.share_audio_apps.is_empty());
|
||||||
assert!(state.share_audio_selection.is_none());
|
assert!(state.share_audio_selection.is_none());
|
||||||
|
assert_eq!(
|
||||||
|
state.share_quality_selection,
|
||||||
|
state.config.screen_share.quality
|
||||||
|
);
|
||||||
assert!(!state.share_starting);
|
assert!(!state.share_starting);
|
||||||
assert!(!state.share_audio_dropped);
|
assert!(!state.share_audio_dropped);
|
||||||
assert!(!state.share_audio_app_active);
|
assert!(!state.share_audio_app_active);
|
||||||
@@ -8827,6 +9275,42 @@ mod tests {
|
|||||||
assert!(!state.share_picker_open);
|
assert!(!state.share_picker_open);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inline_quality_override_survives_opening_the_picker() {
|
||||||
|
// The inline quality dropdown (next to the Share button) sets a
|
||||||
|
// per-call `share_quality_selection`. Opening the audio picker via
|
||||||
|
// ToggleScreenShare must NOT reset it back to the saved config default,
|
||||||
|
// or the override the user just made is silently discarded before
|
||||||
|
// ConfirmShareScreen reads it into StartScreenShare.
|
||||||
|
use crate::config::ShareQuality;
|
||||||
|
let mut state = AppState::default();
|
||||||
|
// Saved default is Auto; the user picks a different per-call quality.
|
||||||
|
assert_eq!(state.config.screen_share.quality, ShareQuality::Auto);
|
||||||
|
let _ = update(
|
||||||
|
&mut state,
|
||||||
|
AppMessage::SelectShareQualityOverride(ShareQuality::High),
|
||||||
|
);
|
||||||
|
assert_eq!(state.share_quality_selection, ShareQuality::High);
|
||||||
|
|
||||||
|
// Clicking Share opens the picker — the override must be preserved.
|
||||||
|
let _ = update(&mut state, AppMessage::ToggleScreenShare);
|
||||||
|
assert!(state.share_picker_open);
|
||||||
|
assert_eq!(
|
||||||
|
state.share_quality_selection,
|
||||||
|
ShareQuality::High,
|
||||||
|
"opening the picker must not clobber the inline per-call override"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Confirming reads that same override into the share start.
|
||||||
|
let _ = update(&mut state, AppMessage::ConfirmShareScreen);
|
||||||
|
assert!(state.share_starting);
|
||||||
|
assert_eq!(
|
||||||
|
state.share_quality_selection,
|
||||||
|
ShareQuality::High,
|
||||||
|
"the override the picker preserved must still be what ConfirmShareScreen sends"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn share_start_failure_clears_in_flight_flag() {
|
fn share_start_failure_clears_in_flight_flag() {
|
||||||
// A failed spawn surfaces as UiEvent::Error (not ScreenShareStopped); the
|
// A failed spawn surfaces as UiEvent::Error (not ScreenShareStopped); the
|
||||||
@@ -9198,12 +9682,14 @@ mod tests {
|
|||||||
"Profile",
|
"Profile",
|
||||||
"Appearance",
|
"Appearance",
|
||||||
"Network",
|
"Network",
|
||||||
|
"Advanced",
|
||||||
"Notifications",
|
"Notifications",
|
||||||
"Games"
|
"Games"
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
assert_eq!(SettingsCategory::Audio.hint(), "Devices, mic gate, echo");
|
assert_eq!(SettingsCategory::Audio.hint(), "Devices, mic gate, echo");
|
||||||
assert_eq!(SettingsCategory::Profile.hint(), "Avatar and identity");
|
assert_eq!(SettingsCategory::Profile.hint(), "Avatar and identity");
|
||||||
|
assert_eq!(SettingsCategory::Advanced.hint(), "Screen sharing");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
SettingsCategory::Games.hint(),
|
SettingsCategory::Games.hint(),
|
||||||
"Detection, presence, backgrounds"
|
"Detection, presence, backgrounds"
|
||||||
|
|||||||
+145
@@ -168,6 +168,139 @@ impl std::fmt::Display for NetworkMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pixelpass host quality preset for screen shares. `Auto` leaves pixelpass free
|
||||||
|
/// to choose from its bandwidth pre-flight; fixed presets are passed as CLI flags.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum ShareQuality {
|
||||||
|
#[default]
|
||||||
|
Auto,
|
||||||
|
Low,
|
||||||
|
Medium,
|
||||||
|
High,
|
||||||
|
Source,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShareQuality {
|
||||||
|
pub const ALL: [ShareQuality; 5] = [
|
||||||
|
ShareQuality::Auto,
|
||||||
|
ShareQuality::Low,
|
||||||
|
ShareQuality::Medium,
|
||||||
|
ShareQuality::High,
|
||||||
|
ShareQuality::Source,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ShareQuality {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
ShareQuality::Auto => "Auto",
|
||||||
|
ShareQuality::Low => "Low",
|
||||||
|
ShareQuality::Medium => "Medium",
|
||||||
|
ShareQuality::High => "High",
|
||||||
|
ShareQuality::Source => "Source",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Preferred local player for watching a peer's screen share.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum SharePlayer {
|
||||||
|
#[default]
|
||||||
|
Mpv,
|
||||||
|
Vlc,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SharePlayer {
|
||||||
|
pub const ALL: [SharePlayer; 2] = [SharePlayer::Mpv, SharePlayer::Vlc];
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for SharePlayer {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
SharePlayer::Mpv => "mpv",
|
||||||
|
SharePlayer::Vlc => "VLC",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Local player buffering posture for screen-share playback.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum ShareBuffering {
|
||||||
|
#[default]
|
||||||
|
LowLatency,
|
||||||
|
Smooth,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShareBuffering {
|
||||||
|
pub const ALL: [ShareBuffering; 2] = [ShareBuffering::LowLatency, ShareBuffering::Smooth];
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ShareBuffering {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
ShareBuffering::LowLatency => "Low latency",
|
||||||
|
ShareBuffering::Smooth => "Smooth",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_screen_share_cache_mb() -> u32 {
|
||||||
|
2
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Local-only screen-share preferences. Host fields become pixelpass host CLI
|
||||||
|
/// flags; viewer fields shape local mpv/VLC launch. None/empty/default values
|
||||||
|
/// deliberately let pixelpass/player defaults stand.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
|
pub struct ScreenShareSettings {
|
||||||
|
#[serde(default)]
|
||||||
|
pub quality: ShareQuality,
|
||||||
|
#[serde(default)]
|
||||||
|
pub bitrate_mbps: Option<u32>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub framerate: Option<u32>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub max_height: Option<u32>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub max_viewers: Option<u32>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub force_software_encode: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub extra_host_args: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub player: SharePlayer,
|
||||||
|
#[serde(default)]
|
||||||
|
pub hardware_decode: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub buffering: ShareBuffering,
|
||||||
|
#[serde(default = "default_screen_share_cache_mb")]
|
||||||
|
pub cache_mb: u32,
|
||||||
|
#[serde(default)]
|
||||||
|
pub extra_mpv_args: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ScreenShareSettings {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
quality: ShareQuality::default(),
|
||||||
|
bitrate_mbps: None,
|
||||||
|
framerate: None,
|
||||||
|
max_height: None,
|
||||||
|
max_viewers: None,
|
||||||
|
force_software_encode: false,
|
||||||
|
extra_host_args: String::new(),
|
||||||
|
player: SharePlayer::default(),
|
||||||
|
hardware_decode: false,
|
||||||
|
buffering: ShareBuffering::default(),
|
||||||
|
cache_mb: default_screen_share_cache_mb(),
|
||||||
|
extra_mpv_args: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn default_true() -> bool {
|
fn default_true() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -369,6 +502,9 @@ pub struct AppConfig {
|
|||||||
/// Empty / unset = look it up on `$PATH`. Hand-editable; no Settings UI yet.
|
/// Empty / unset = look it up on `$PATH`. Hand-editable; no Settings UI yet.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub pixelpass_path: Option<String>,
|
pub pixelpass_path: Option<String>,
|
||||||
|
/// Local-only host/player controls for screen sharing.
|
||||||
|
#[serde(default)]
|
||||||
|
pub screen_share: ScreenShareSettings,
|
||||||
/// Recently-joined rooms (W7), most-recent-first. Purely local UI state for a
|
/// Recently-joined rooms (W7), most-recent-first. Purely local UI state for a
|
||||||
/// one-click rejoin; never sent over the wire. De-duped by room topic and
|
/// one-click rejoin; never sent over the wire. De-duped by room topic and
|
||||||
/// capped (see `recents`). Defaulted empty so older configs upgrade cleanly.
|
/// capped (see `recents`). Defaulted empty so older configs upgrade cleanly.
|
||||||
@@ -474,6 +610,7 @@ impl Default for AppConfig {
|
|||||||
sound_mic_toggle_enabled: true,
|
sound_mic_toggle_enabled: true,
|
||||||
sound_reconnect_failed_enabled: true,
|
sound_reconnect_failed_enabled: true,
|
||||||
pixelpass_path: None,
|
pixelpass_path: None,
|
||||||
|
screen_share: ScreenShareSettings::default(),
|
||||||
recents: Vec::new(),
|
recents: Vec::new(),
|
||||||
peer_eq: HashMap::new(),
|
peer_eq: HashMap::new(),
|
||||||
peer_pan: HashMap::new(),
|
peer_pan: HashMap::new(),
|
||||||
@@ -803,6 +940,14 @@ mod tests {
|
|||||||
assert!(deserialized.custom_sound_self_leave.is_none());
|
assert!(deserialized.custom_sound_self_leave.is_none());
|
||||||
assert!(deserialized.custom_sound_mic_toggle.is_none());
|
assert!(deserialized.custom_sound_mic_toggle.is_none());
|
||||||
assert!(deserialized.custom_sound_reconnect_failed.is_none());
|
assert!(deserialized.custom_sound_reconnect_failed.is_none());
|
||||||
|
assert_eq!(deserialized.screen_share, ScreenShareSettings::default());
|
||||||
|
assert_eq!(deserialized.screen_share.quality, ShareQuality::Auto);
|
||||||
|
assert_eq!(deserialized.screen_share.player, SharePlayer::Mpv);
|
||||||
|
assert_eq!(
|
||||||
|
deserialized.screen_share.buffering,
|
||||||
|
ShareBuffering::LowLatency
|
||||||
|
);
|
||||||
|
assert_eq!(deserialized.screen_share.cache_mb, 2);
|
||||||
// Configs predating the per-sound flags (W6) enable every chime, so an
|
// Configs predating the per-sound flags (W6) enable every chime, so an
|
||||||
// upgrade is silent-change-free.
|
// upgrade is silent-change-free.
|
||||||
for sound in Sound::ALL {
|
for sound in Sound::ALL {
|
||||||
|
|||||||
+25
-6
@@ -1,4 +1,4 @@
|
|||||||
use crate::config::{AudioProfile, NetworkMode, RecordingMode};
|
use crate::config::{AudioProfile, NetworkMode, RecordingMode, ScreenShareSettings, ShareQuality};
|
||||||
use crate::friends::Friend;
|
use crate::friends::Friend;
|
||||||
use crate::network::PeerState;
|
use crate::network::PeerState;
|
||||||
use crate::presence::{FriendPresence, PresenceMode};
|
use crate::presence::{FriendPresence, PresenceMode};
|
||||||
@@ -119,13 +119,18 @@ pub enum CoreCommand {
|
|||||||
/// whole desktop audio (the legacy behavior).
|
/// whole desktop audio (the legacy behavior).
|
||||||
StartScreenShare {
|
StartScreenShare {
|
||||||
audio_app: Option<String>,
|
audio_app: Option<String>,
|
||||||
|
settings: ScreenShareSettings,
|
||||||
|
quality: ShareQuality,
|
||||||
},
|
},
|
||||||
/// Stop sharing our screen: kill the pixelpass host and clear the presence
|
/// Stop sharing our screen: kill the pixelpass host and clear the presence
|
||||||
/// ticket. No-op when not sharing.
|
/// ticket. No-op when not sharing.
|
||||||
StopScreenShare,
|
StopScreenShare,
|
||||||
/// Watch a peer's screen share: spawn a pixelpass viewer for `ticket` and
|
/// Watch a peer's screen share: spawn a pixelpass viewer for `ticket` and
|
||||||
/// open it in a local player.
|
/// open it in a local player.
|
||||||
ViewShare(String),
|
ViewShare {
|
||||||
|
ticket: String,
|
||||||
|
settings: ScreenShareSettings,
|
||||||
|
},
|
||||||
/// Mint a fresh persistent identity (W7), discarding the old one. Takes effect
|
/// Mint a fresh persistent identity (W7), discarding the old one. Takes effect
|
||||||
/// on the next room join (the endpoint is rebuilt then). The core replies with
|
/// on the next room join (the endpoint is rebuilt then). The core replies with
|
||||||
/// an updated [`UiEvent::IdentityStatus`].
|
/// an updated [`UiEvent::IdentityStatus`].
|
||||||
@@ -244,9 +249,16 @@ pub fn delivery_class(cmd: &CoreCommand) -> DeliveryClass {
|
|||||||
}
|
}
|
||||||
| CoreCommand::SetPixelpassPath(_)
|
| CoreCommand::SetPixelpassPath(_)
|
||||||
| CoreCommand::ListAudioApps
|
| CoreCommand::ListAudioApps
|
||||||
| CoreCommand::StartScreenShare { audio_app: _ }
|
| CoreCommand::StartScreenShare {
|
||||||
|
audio_app: _,
|
||||||
|
settings: _,
|
||||||
|
quality: _,
|
||||||
|
}
|
||||||
| CoreCommand::StopScreenShare
|
| CoreCommand::StopScreenShare
|
||||||
| CoreCommand::ViewShare(_)
|
| CoreCommand::ViewShare {
|
||||||
|
ticket: _,
|
||||||
|
settings: _,
|
||||||
|
}
|
||||||
| CoreCommand::RegenerateIdentity
|
| CoreCommand::RegenerateIdentity
|
||||||
| CoreCommand::AddFriend {
|
| CoreCommand::AddFriend {
|
||||||
id: _,
|
id: _,
|
||||||
@@ -325,9 +337,16 @@ pub fn coalesce_key(cmd: &CoreCommand) -> Option<CoalesceKey> {
|
|||||||
}
|
}
|
||||||
| CoreCommand::SetPixelpassPath(_)
|
| CoreCommand::SetPixelpassPath(_)
|
||||||
| CoreCommand::ListAudioApps
|
| CoreCommand::ListAudioApps
|
||||||
| CoreCommand::StartScreenShare { audio_app: _ }
|
| CoreCommand::StartScreenShare {
|
||||||
|
audio_app: _,
|
||||||
|
settings: _,
|
||||||
|
quality: _,
|
||||||
|
}
|
||||||
| CoreCommand::StopScreenShare
|
| CoreCommand::StopScreenShare
|
||||||
| CoreCommand::ViewShare(_)
|
| CoreCommand::ViewShare {
|
||||||
|
ticket: _,
|
||||||
|
settings: _,
|
||||||
|
}
|
||||||
| CoreCommand::RegenerateIdentity
|
| CoreCommand::RegenerateIdentity
|
||||||
| CoreCommand::AddFriend {
|
| CoreCommand::AddFriend {
|
||||||
id: _,
|
id: _,
|
||||||
|
|||||||
+64
-12
@@ -662,9 +662,11 @@ struct ActiveSession {
|
|||||||
/// Our pixelpass screen-share host child while sharing (`kill_on_drop`, so it
|
/// Our pixelpass screen-share host child while sharing (`kill_on_drop`, so it
|
||||||
/// also dies if the session is dropped without an explicit stop).
|
/// also dies if the session is dropped without an explicit stop).
|
||||||
screenshare_host: Option<tokio::process::Child>,
|
screenshare_host: Option<tokio::process::Child>,
|
||||||
/// pixelpass viewer children we spawned to watch peers' shares; killed on
|
/// pixelpass viewer children we spawned to watch peers' shares, each paired
|
||||||
/// session teardown (each also self-exits when its player window closes).
|
/// with the share ticket it's viewing so a re-watch of the same share can
|
||||||
screenshare_viewers: Vec<tokio::process::Child>,
|
/// replace (not stack) its player. Killed on session teardown (each also
|
||||||
|
/// self-exits when its player window closes).
|
||||||
|
screenshare_viewers: Vec<(String, tokio::process::Child)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveSession {
|
impl ActiveSession {
|
||||||
@@ -676,7 +678,7 @@ impl ActiveSession {
|
|||||||
if let Some(mut host) = self.screenshare_host.take() {
|
if let Some(mut host) = self.screenshare_host.take() {
|
||||||
let _ = host.kill().await;
|
let _ = host.kill().await;
|
||||||
}
|
}
|
||||||
for mut viewer in self.screenshare_viewers.drain(..) {
|
for (_, mut viewer) in self.screenshare_viewers.drain(..) {
|
||||||
let _ = viewer.kill().await;
|
let _ = viewer.kill().await;
|
||||||
}
|
}
|
||||||
self.datagram_task.abort();
|
self.datagram_task.abort();
|
||||||
@@ -2497,7 +2499,7 @@ async fn run_core_loop(
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
echo_cancel: echo_cancel_guard,
|
echo_cancel: echo_cancel_guard,
|
||||||
screenshare_host: None,
|
screenshare_host: None,
|
||||||
screenshare_viewers: Vec::new(),
|
screenshare_viewers: Vec::<(String, tokio::process::Child)>::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let self_id = endpoint.id().to_string();
|
let self_id = endpoint.id().to_string();
|
||||||
@@ -3121,7 +3123,11 @@ async fn run_core_loop(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreCommand::StartScreenShare { audio_app } => {
|
CoreCommand::StartScreenShare {
|
||||||
|
audio_app,
|
||||||
|
settings,
|
||||||
|
quality,
|
||||||
|
} => {
|
||||||
let Some(session) = &mut active_session else {
|
let Some(session) = &mut active_session else {
|
||||||
let _ = ui_tx
|
let _ = ui_tx
|
||||||
.send(UiEvent::Error(
|
.send(UiEvent::Error(
|
||||||
@@ -3171,7 +3177,15 @@ async fn run_core_loop(
|
|||||||
});
|
});
|
||||||
tx
|
tx
|
||||||
});
|
});
|
||||||
match crate::screenshare::spawn_host(&bin, audio_app.as_deref(), notices).await {
|
match crate::screenshare::spawn_host(
|
||||||
|
&bin,
|
||||||
|
audio_app.as_deref(),
|
||||||
|
&settings,
|
||||||
|
quality,
|
||||||
|
notices,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok((child, ticket)) => {
|
Ok((child, ticket)) => {
|
||||||
crate::log_msg("Screen share host started");
|
crate::log_msg("Screen share host started");
|
||||||
session.screenshare_host = Some(child);
|
session.screenshare_host = Some(child);
|
||||||
@@ -3209,7 +3223,7 @@ async fn run_core_loop(
|
|||||||
let _ = ui_tx.send(UiEvent::ScreenShareStopped).await;
|
let _ = ui_tx.send(UiEvent::ScreenShareStopped).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreCommand::ViewShare(ticket) => {
|
CoreCommand::ViewShare { ticket, settings } => {
|
||||||
let bin = match crate::screenshare::pixelpass_path(pixelpass_override.as_deref()) {
|
let bin = match crate::screenshare::pixelpass_path(pixelpass_override.as_deref()) {
|
||||||
Some(b) => b,
|
Some(b) => b,
|
||||||
None => {
|
None => {
|
||||||
@@ -3221,11 +3235,27 @@ async fn run_core_loop(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match crate::screenshare::spawn_viewer(&bin, &ticket).await {
|
if let Some(session) = &mut active_session {
|
||||||
|
// Drop viewers whose player window has already closed so the
|
||||||
|
// list only tracks live players.
|
||||||
|
session
|
||||||
|
.screenshare_viewers
|
||||||
|
.retain_mut(|(_, child)| !matches!(child.try_wait(), Ok(Some(_))));
|
||||||
|
// One player per share: a second Watch click on a share we're
|
||||||
|
// already viewing is a retry (usually because the first window
|
||||||
|
// froze), so replace the existing player rather than stacking a
|
||||||
|
// second mpv — two players would double the shared audio.
|
||||||
|
if let Some(pos) = replace_viewer_index(&session.screenshare_viewers, &ticket) {
|
||||||
|
let (_, mut old) = session.screenshare_viewers.remove(pos);
|
||||||
|
let _ = old.kill().await;
|
||||||
|
crate::log_msg("Screen share viewer replaced (re-watch)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match crate::screenshare::spawn_viewer(&bin, &ticket, &settings).await {
|
||||||
Ok(child) => {
|
Ok(child) => {
|
||||||
crate::log_msg("Screen share viewer started");
|
crate::log_msg("Screen share viewer started");
|
||||||
if let Some(session) = &mut active_session {
|
if let Some(session) = &mut active_session {
|
||||||
session.screenshare_viewers.push(child);
|
session.screenshare_viewers.push((ticket, child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -3241,14 +3271,23 @@ async fn run_core_loop(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Index of an existing viewer for `ticket` in the live-viewers list, if any.
|
||||||
|
/// A re-watch of the same share replaces that player instead of stacking a
|
||||||
|
/// second one — two players decoding the same stream would double the shared
|
||||||
|
/// audio. Generic over the child value so the dedup rule is unit-testable
|
||||||
|
/// without spawning real player processes.
|
||||||
|
fn replace_viewer_index<T>(viewers: &[(String, T)], ticket: &str) -> Option<usize> {
|
||||||
|
viewers.iter().position(|(t, _)| t == ticket)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
KnownPeers, MAX_OPUS_PAYLOAD, MAX_RETAINED_PEERS, MIC_LEVEL_REPORT_SAMPLES, MicLevelMeter,
|
KnownPeers, MAX_OPUS_PAYLOAD, MAX_RETAINED_PEERS, MIC_LEVEL_REPORT_SAMPLES, MicLevelMeter,
|
||||||
PLAYBACK_HANDOFF_QUEUE_FRAMES, PeerSpeakTicket, admit_retained, apply_peer_volume,
|
PLAYBACK_HANDOFF_QUEUE_FRAMES, PeerSpeakTicket, admit_retained, apply_peer_volume,
|
||||||
apply_volume, audio_datagram_len_ok, coalesce_insert, coalesce_pop, frame_level,
|
apply_volume, audio_datagram_len_ok, coalesce_insert, coalesce_pop, frame_level,
|
||||||
mix_frames, mix_stereo_frames, next_game_change, send_playback_frame, should_auto_fetch,
|
mix_frames, mix_stereo_frames, next_game_change, replace_viewer_index, send_playback_frame,
|
||||||
stereo_to_mono,
|
should_auto_fetch, stereo_to_mono,
|
||||||
};
|
};
|
||||||
use crate::core::messages::{CoalesceKey, CoreCommand, coalesce_key};
|
use crate::core::messages::{CoalesceKey, CoreCommand, coalesce_key};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
@@ -3259,6 +3298,19 @@ mod tests {
|
|||||||
iroh::SecretKey::generate().public()
|
iroh::SecretKey::generate().public()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn re_watch_replaces_existing_viewer_for_same_ticket() {
|
||||||
|
// The value type stands in for a viewer Child; only the ticket matters.
|
||||||
|
let viewers = vec![("ticket-A".to_string(), 0u8), ("ticket-B".to_string(), 1u8)];
|
||||||
|
// Re-watching an already-open share finds the existing player to replace.
|
||||||
|
assert_eq!(replace_viewer_index(&viewers, "ticket-A"), Some(0));
|
||||||
|
assert_eq!(replace_viewer_index(&viewers, "ticket-B"), Some(1));
|
||||||
|
// A different (new) share has nothing to replace — it opens fresh.
|
||||||
|
assert_eq!(replace_viewer_index(&viewers, "ticket-C"), None);
|
||||||
|
// Empty list: first watch of anything opens fresh.
|
||||||
|
assert_eq!(replace_viewer_index::<u8>(&[], "ticket-A"), None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn admit_retained_rejects_only_new_ids_at_the_cap() {
|
fn admit_retained_rejects_only_new_ids_at_the_cap() {
|
||||||
// Below the cap, a brand-new identity is retained.
|
// Below the cap, a brand-new identity is retained.
|
||||||
|
|||||||
+265
-30
@@ -21,6 +21,8 @@ use std::time::Duration;
|
|||||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||||
use tokio::process::{Child, Command};
|
use tokio::process::{Child, Command};
|
||||||
|
|
||||||
|
use crate::config::{ScreenShareSettings, ShareBuffering, SharePlayer, ShareQuality};
|
||||||
|
|
||||||
/// The binary we shell out to. Looked up on `$PATH` unless a config override
|
/// The binary we shell out to. Looked up on `$PATH` unless a config override
|
||||||
/// points elsewhere.
|
/// points elsewhere.
|
||||||
const PIXELPASS_BIN: &str = "pixelpass";
|
const PIXELPASS_BIN: &str = "pixelpass";
|
||||||
@@ -139,7 +141,11 @@ fn json_u32(v: &serde_json::Value, key: &str) -> u32 {
|
|||||||
/// otherwise rejects hyphen-leading option values). The name is locally chosen
|
/// otherwise rejects hyphen-leading option values). The name is locally chosen
|
||||||
/// (our own enumeration / the user's pick), not peer-supplied, but is still
|
/// (our own enumeration / the user's pick), not peer-supplied, but is still
|
||||||
/// sanitized via [`sanitize_app_name`] before reaching here. Pure: no I/O.
|
/// sanitized via [`sanitize_app_name`] before reaching here. Pure: no I/O.
|
||||||
pub fn host_args(audio_app: Option<&str>) -> Vec<String> {
|
pub fn host_args(
|
||||||
|
audio_app: Option<&str>,
|
||||||
|
settings: &ScreenShareSettings,
|
||||||
|
quality: ShareQuality,
|
||||||
|
) -> Vec<String> {
|
||||||
let mut args = vec![
|
let mut args = vec![
|
||||||
"--host".to_string(),
|
"--host".to_string(),
|
||||||
"--output".to_string(),
|
"--output".to_string(),
|
||||||
@@ -149,9 +155,44 @@ pub fn host_args(audio_app: Option<&str>) -> Vec<String> {
|
|||||||
args.push(format!("--app={name}"));
|
args.push(format!("--app={name}"));
|
||||||
args.push("--strict-audio".to_string());
|
args.push("--strict-audio".to_string());
|
||||||
}
|
}
|
||||||
|
if quality != ShareQuality::Auto {
|
||||||
|
args.push(format!("--quality={}", pixelpass_quality(quality)));
|
||||||
|
}
|
||||||
|
if let Some(height) = settings.max_height {
|
||||||
|
args.push(format!("--max-height={height}"));
|
||||||
|
}
|
||||||
|
if let Some(mbps) = settings.bitrate_mbps {
|
||||||
|
args.push(format!("--bitrate={}", mbps.saturating_mul(1000)));
|
||||||
|
}
|
||||||
|
if let Some(fps) = settings.framerate {
|
||||||
|
args.push(format!("--framerate={fps}"));
|
||||||
|
}
|
||||||
|
if settings.force_software_encode {
|
||||||
|
args.push("--no-hwencode".to_string());
|
||||||
|
}
|
||||||
|
if let Some(max) = settings.max_viewers {
|
||||||
|
args.push(format!("--max-viewers={max}"));
|
||||||
|
}
|
||||||
|
args.extend(split_extra_args(&settings.extra_host_args));
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pixelpass_quality(quality: ShareQuality) -> &'static str {
|
||||||
|
match quality {
|
||||||
|
ShareQuality::Auto => "auto",
|
||||||
|
ShareQuality::Low => "low",
|
||||||
|
ShareQuality::Medium => "medium",
|
||||||
|
ShareQuality::High => "high",
|
||||||
|
ShareQuality::Source => "source",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Split user-supplied advanced argv text into separate tokens. Peerspeak does
|
||||||
|
/// not depend on a shell lexer, so quoted values are not interpreted here.
|
||||||
|
fn split_extra_args(raw: &str) -> impl Iterator<Item = String> + '_ {
|
||||||
|
raw.split_whitespace().map(str::to_string)
|
||||||
|
}
|
||||||
|
|
||||||
/// Validate a locally-chosen audio app name before it becomes a `--app` value:
|
/// Validate a locally-chosen audio app name before it becomes a `--app` value:
|
||||||
/// trim, reject empty / overlong, and reject names carrying control characters
|
/// trim, reject empty / overlong, and reject names carrying control characters
|
||||||
/// (newlines etc.) that have no place in a real `application.name`. `None` means
|
/// (newlines etc.) that have no place in a real `application.name`. `None` means
|
||||||
@@ -320,15 +361,22 @@ pub fn is_available(config_override: Option<&str>) -> bool {
|
|||||||
/// whole desktop sink, which avoids the call-loopback echo (A23). The child keeps
|
/// whole desktop sink, which avoids the call-loopback echo (A23). The child keeps
|
||||||
/// running (streaming to viewers) until killed or dropped; remaining stdout is
|
/// running (streaming to viewers) until killed or dropped; remaining stdout is
|
||||||
/// drained in a background task so a full pipe can't stall the host. We do
|
/// drained in a background task so a full pipe can't stall the host. We do
|
||||||
/// **not** pass `--max-viewers`: pixelpass bandwidth-measures its own safe cap,
|
/// not pass encode/viewer overrides unless the local settings explicitly ask for
|
||||||
/// protecting the sharer's uplink, and refuses extras with `viewer_refused`.
|
/// them, so pixelpass keeps its own defaults in the common case.
|
||||||
pub async fn spawn_host(
|
pub async fn spawn_host(
|
||||||
bin: &Path,
|
bin: &Path,
|
||||||
audio_app: Option<&str>,
|
audio_app: Option<&str>,
|
||||||
|
settings: &ScreenShareSettings,
|
||||||
|
quality: ShareQuality,
|
||||||
notices: Option<tokio::sync::mpsc::UnboundedSender<PixelpassEvent>>,
|
notices: Option<tokio::sync::mpsc::UnboundedSender<PixelpassEvent>>,
|
||||||
) -> std::io::Result<(Child, String)> {
|
) -> std::io::Result<(Child, String)> {
|
||||||
|
let args = host_args(audio_app, settings, quality);
|
||||||
|
// Log the exact argv we hand pixelpass so a field log can confirm which
|
||||||
|
// encode/quality flags (e.g. --bitrate) actually reached the host — these
|
||||||
|
// are local flags with no ticket/secret, so logging them verbatim is safe.
|
||||||
|
crate::log_msg(&format!("pixelpass host spawn: {} {}", bin.display(), args.join(" ")));
|
||||||
let mut child = Command::new(bin)
|
let mut child = Command::new(bin)
|
||||||
.args(host_args(audio_app))
|
.args(&args)
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
// Capture stderr (not null): pixelpass prints its startup precondition
|
// Capture stderr (not null): pixelpass prints its startup precondition
|
||||||
@@ -428,10 +476,14 @@ pub fn pixelpass_failure_detail(stderr: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a pixelpass viewer for `ticket`, wait for it to connect, and open the
|
/// Spawn a pixelpass viewer for `ticket`, wait for it to connect, and open the
|
||||||
/// stream in a local player (mpv, falling back to vlc). Returns the live viewer
|
/// stream in a local player (mpv/VLC in the configured order, then fallback).
|
||||||
/// child so the caller can kill it on room-leave; it also self-exits when the
|
/// Returns the live viewer child so the caller can kill it on room-leave; it also
|
||||||
/// player window closes (its tunnel ends).
|
/// self-exits when the player window closes (its tunnel ends).
|
||||||
pub async fn spawn_viewer(bin: &Path, ticket: &str) -> std::io::Result<Child> {
|
pub async fn spawn_viewer(
|
||||||
|
bin: &Path,
|
||||||
|
ticket: &str,
|
||||||
|
settings: &ScreenShareSettings,
|
||||||
|
) -> std::io::Result<Child> {
|
||||||
let mut child = Command::new(bin)
|
let mut child = Command::new(bin)
|
||||||
.args(viewer_args(ticket))
|
.args(viewer_args(ticket))
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
@@ -465,7 +517,7 @@ pub async fn spawn_viewer(bin: &Path, ticket: &str) -> std::io::Result<Child> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = launch_player(&url) {
|
if let Err(e) = launch_player(&url, settings) {
|
||||||
let _ = child.kill().await;
|
let _ = child.kill().await;
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
@@ -547,23 +599,33 @@ fn event_for_log(ev: &PixelpassEvent) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open the viewer stream URL in a media player. Mirrors pixelpass's own
|
/// Open the viewer stream URL in a media player, then fall back to vlc. The
|
||||||
/// low-latency mpv invocation; falls back to vlc. The player is reaped in a
|
/// player is reaped in a background task so it doesn't linger as a zombie when
|
||||||
/// background task so it doesn't linger as a zombie when its window closes.
|
/// its window closes.
|
||||||
fn launch_player(url: &str) -> std::io::Result<()> {
|
///
|
||||||
const MPV_ARGS: &[&str] = &[
|
/// The flags keep latency low while preserving A/V sync. We deliberately do
|
||||||
"--profile=low-latency",
|
/// NOT pass mpv's `--untimed`: that displays each video frame the instant it
|
||||||
"--untimed",
|
/// decodes, ignoring audio timestamps, which makes a shared *video* drift
|
||||||
"--hwdec=auto",
|
/// progressively out of sync with its audio. Pacing to the audio clock costs a
|
||||||
"--audio-buffer=0.2",
|
/// little latency (negligible for pointing at a desktop) and keeps a shared
|
||||||
"--demuxer-max-bytes=2M",
|
/// video in sync. We also leave hwdec at the `low-latency` default (software
|
||||||
"--demuxer-readahead-secs=0.5",
|
/// decode): forcing `--hwdec=auto` froze some viewers on frame 1 while audio
|
||||||
];
|
/// kept playing.
|
||||||
const VLC_ARGS: &[&str] = &["--network-caching=200", "--live-caching=200"];
|
fn launch_player(url: &str, settings: &ScreenShareSettings) -> std::io::Result<()> {
|
||||||
|
let mpv_args = mpv_args(settings);
|
||||||
|
let vlc_args = vlc_args(settings);
|
||||||
|
let first = match settings.player {
|
||||||
|
SharePlayer::Mpv => ("mpv", &mpv_args),
|
||||||
|
SharePlayer::Vlc => ("vlc", &vlc_args),
|
||||||
|
};
|
||||||
|
let second = match settings.player {
|
||||||
|
SharePlayer::Mpv => ("vlc", &vlc_args),
|
||||||
|
SharePlayer::Vlc => ("mpv", &mpv_args),
|
||||||
|
};
|
||||||
|
|
||||||
let child = match spawn_player("mpv", MPV_ARGS, url) {
|
let child = match spawn_player(first.0, first.1, url) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(_) => spawn_player("vlc", VLC_ARGS, url).map_err(|_| {
|
Err(_) => spawn_player(second.0, second.1, url).map_err(|_| {
|
||||||
std::io::Error::new(
|
std::io::Error::new(
|
||||||
std::io::ErrorKind::NotFound,
|
std::io::ErrorKind::NotFound,
|
||||||
"no media player found — install mpv or vlc to watch screen shares",
|
"no media player found — install mpv or vlc to watch screen shares",
|
||||||
@@ -577,7 +639,64 @@ fn launch_player(url: &str) -> std::io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_player(bin: &str, args: &[&str], url: &str) -> std::io::Result<Child> {
|
pub fn mpv_args(settings: &ScreenShareSettings) -> Vec<String> {
|
||||||
|
let mut args = Vec::new();
|
||||||
|
match settings.buffering {
|
||||||
|
ShareBuffering::LowLatency => {
|
||||||
|
args.push("--profile=low-latency".to_string());
|
||||||
|
args.push("--audio-buffer=0.2".to_string());
|
||||||
|
args.push("--demuxer-readahead-secs=0.5".to_string());
|
||||||
|
}
|
||||||
|
ShareBuffering::Smooth => {
|
||||||
|
args.push("--cache=yes".to_string());
|
||||||
|
args.push("--demuxer-readahead-secs=2".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args.push(format!("--demuxer-max-bytes={}M", settings.cache_mb));
|
||||||
|
if settings.hardware_decode {
|
||||||
|
args.push("--hwdec=auto".to_string());
|
||||||
|
}
|
||||||
|
args.extend(split_extra_args(&settings.extra_mpv_args));
|
||||||
|
args
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build the argv for a VLC viewer. VLC honors the subset of viewer settings
|
||||||
|
/// that map cleanly onto its option set: the buffering posture (network/live
|
||||||
|
/// caching, in ms) and hardware decoding. The rest of the viewer knobs are
|
||||||
|
/// mpv-specific — `cache_mb` is an mpv demuxer *byte* cache (VLC's caching is
|
||||||
|
/// time-based, already covered by `buffering`) and `extra_mpv_args` is literally
|
||||||
|
/// mpv flags — so they are deliberately not mapped here; the Settings UI labels
|
||||||
|
/// them as mpv-only. Pure: no I/O.
|
||||||
|
///
|
||||||
|
/// The hardware-decode mapping is the load-bearing one: VLC hardware-decodes by
|
||||||
|
/// default, so without an explicit `--avcodec-hw=none` a VLC viewer would ignore
|
||||||
|
/// the (default-off) hardware-decode toggle and could hit the frame-1 freeze
|
||||||
|
/// that default exists to avoid — the same A-bug that made us drop mpv's forced
|
||||||
|
/// `--hwdec=auto`.
|
||||||
|
fn vlc_args(settings: &ScreenShareSettings) -> Vec<String> {
|
||||||
|
let caching_ms = match settings.buffering {
|
||||||
|
ShareBuffering::LowLatency => 200,
|
||||||
|
ShareBuffering::Smooth => 1500,
|
||||||
|
};
|
||||||
|
let hw = if settings.hardware_decode {
|
||||||
|
"--avcodec-hw=any"
|
||||||
|
} else {
|
||||||
|
"--avcodec-hw=none"
|
||||||
|
};
|
||||||
|
vec![
|
||||||
|
format!("--network-caching={caching_ms}"),
|
||||||
|
format!("--live-caching={caching_ms}"),
|
||||||
|
hw.to_string(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_player(bin: &str, args: &[String], url: &str) -> std::io::Result<Child> {
|
||||||
|
// Log the player + its flags (mpv/vlc, incl. hardware-decode: --hwdec /
|
||||||
|
// --avcodec-hw) so a field log can confirm the viewer settings reached the
|
||||||
|
// player. The `url` is omitted deliberately — it is the local stream address
|
||||||
|
// and is not needed to verify the flags. Logged on each attempt, so a
|
||||||
|
// fallback from the preferred player to the other one is visible too.
|
||||||
|
crate::log_msg(&format!("player spawn: {bin} {}", args.join(" ")));
|
||||||
Command::new(bin)
|
Command::new(bin)
|
||||||
.args(args)
|
.args(args)
|
||||||
.arg(url)
|
.arg(url)
|
||||||
@@ -621,7 +740,11 @@ mod tests {
|
|||||||
fn host_args_without_app_shares_whole_desktop() {
|
fn host_args_without_app_shares_whole_desktop() {
|
||||||
// No app selected → no --app flag → pixelpass keeps its default
|
// No app selected → no --app flag → pixelpass keeps its default
|
||||||
// (whole-desktop) audio capture.
|
// (whole-desktop) audio capture.
|
||||||
assert_eq!(host_args(None), vec!["--host", "--output", "json"]);
|
let settings = ScreenShareSettings::default();
|
||||||
|
assert_eq!(
|
||||||
|
host_args(None, &settings, ShareQuality::Auto),
|
||||||
|
vec!["--host", "--output", "json"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -629,8 +752,9 @@ mod tests {
|
|||||||
// The chosen app rides in the `--app=<name>` single-token form so a
|
// The chosen app rides in the `--app=<name>` single-token form so a
|
||||||
// name beginning with `-` can never be reparsed as a flag (A23), plus
|
// name beginning with `-` can never be reparsed as a flag (A23), plus
|
||||||
// `--strict-audio` so pixelpass never falls back to whole-desktop audio.
|
// `--strict-audio` so pixelpass never falls back to whole-desktop audio.
|
||||||
|
let settings = ScreenShareSettings::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
host_args(Some("Firefox")),
|
host_args(Some("Firefox"), &settings, ShareQuality::Auto),
|
||||||
vec![
|
vec![
|
||||||
"--host",
|
"--host",
|
||||||
"--output",
|
"--output",
|
||||||
@@ -641,7 +765,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
// The hyphen-leading name is still bound to --app as a single token;
|
// The hyphen-leading name is still bound to --app as a single token;
|
||||||
// --strict-audio is the trailing flag.
|
// --strict-audio is the trailing flag.
|
||||||
let args = host_args(Some("-rm -rf"));
|
let args = host_args(Some("-rm -rf"), &settings, ShareQuality::Auto);
|
||||||
assert_eq!(args[3], "--app=-rm -rf");
|
assert_eq!(args[3], "--app=-rm -rf");
|
||||||
assert_eq!(args[4], "--strict-audio");
|
assert_eq!(args[4], "--strict-audio");
|
||||||
}
|
}
|
||||||
@@ -650,11 +774,122 @@ mod tests {
|
|||||||
fn host_args_blank_or_control_app_is_dropped() {
|
fn host_args_blank_or_control_app_is_dropped() {
|
||||||
// An empty / whitespace / control-laden selection is sanitized away,
|
// An empty / whitespace / control-laden selection is sanitized away,
|
||||||
// falling back to whole-desktop capture rather than a broken flag.
|
// falling back to whole-desktop capture rather than a broken flag.
|
||||||
assert_eq!(host_args(Some(" ")), vec!["--host", "--output", "json"]);
|
let settings = ScreenShareSettings::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
host_args(Some("bad\nname")),
|
host_args(Some(" "), &settings, ShareQuality::Auto),
|
||||||
vec!["--host", "--output", "json"]
|
vec!["--host", "--output", "json"]
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
host_args(Some("bad\nname"), &settings, ShareQuality::Auto),
|
||||||
|
vec!["--host", "--output", "json"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn host_args_apply_screen_share_settings_and_extra_args_last() {
|
||||||
|
let settings = ScreenShareSettings {
|
||||||
|
bitrate_mbps: Some(5),
|
||||||
|
framerate: Some(60),
|
||||||
|
max_height: Some(1080),
|
||||||
|
max_viewers: Some(4),
|
||||||
|
force_software_encode: true,
|
||||||
|
extra_host_args: "--relay https://relay.example --verbose".to_string(),
|
||||||
|
..ScreenShareSettings::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
host_args(Some("Firefox"), &settings, ShareQuality::High),
|
||||||
|
vec![
|
||||||
|
"--host",
|
||||||
|
"--output",
|
||||||
|
"json",
|
||||||
|
"--app=Firefox",
|
||||||
|
"--strict-audio",
|
||||||
|
"--quality=high",
|
||||||
|
"--max-height=1080",
|
||||||
|
"--bitrate=5000",
|
||||||
|
"--framerate=60",
|
||||||
|
"--no-hwencode",
|
||||||
|
"--max-viewers=4",
|
||||||
|
"--relay",
|
||||||
|
"https://relay.example",
|
||||||
|
"--verbose",
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mpv_args_default_matches_low_latency_software_decode() {
|
||||||
|
assert_eq!(
|
||||||
|
mpv_args(&ScreenShareSettings::default()),
|
||||||
|
vec![
|
||||||
|
"--profile=low-latency",
|
||||||
|
"--audio-buffer=0.2",
|
||||||
|
"--demuxer-readahead-secs=0.5",
|
||||||
|
"--demuxer-max-bytes=2M",
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mpv_args_smooth_hwdecode_and_extra_args_last() {
|
||||||
|
let settings = ScreenShareSettings {
|
||||||
|
hardware_decode: true,
|
||||||
|
buffering: ShareBuffering::Smooth,
|
||||||
|
cache_mb: 16,
|
||||||
|
extra_mpv_args: "--no-osc --vd-lavc-threads=2".to_string(),
|
||||||
|
..ScreenShareSettings::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
mpv_args(&settings),
|
||||||
|
vec![
|
||||||
|
"--cache=yes",
|
||||||
|
"--demuxer-readahead-secs=2",
|
||||||
|
"--demuxer-max-bytes=16M",
|
||||||
|
"--hwdec=auto",
|
||||||
|
"--no-osc",
|
||||||
|
"--vd-lavc-threads=2",
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn vlc_args_default_disables_hardware_decode() {
|
||||||
|
// The A-bug fix default (hardware_decode = false) must reach VLC too:
|
||||||
|
// VLC hardware-decodes by default, so without an explicit
|
||||||
|
// `--avcodec-hw=none` a VLC viewer would ignore the toggle and could hit
|
||||||
|
// the frame-1 freeze. Low-latency buffering keeps the 200 ms caches.
|
||||||
|
assert_eq!(
|
||||||
|
vlc_args(&ScreenShareSettings::default()),
|
||||||
|
vec![
|
||||||
|
"--network-caching=200",
|
||||||
|
"--live-caching=200",
|
||||||
|
"--avcodec-hw=none",
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn vlc_args_smooth_buffering_and_hwdecode() {
|
||||||
|
// Enabling hardware decode flips VLC to `--avcodec-hw=any`; Smooth
|
||||||
|
// buffering raises the network/live caches. cache_mb / extra_mpv_args are
|
||||||
|
// mpv-only and must NOT leak into the VLC argv.
|
||||||
|
let settings = ScreenShareSettings {
|
||||||
|
hardware_decode: true,
|
||||||
|
buffering: ShareBuffering::Smooth,
|
||||||
|
cache_mb: 16,
|
||||||
|
extra_mpv_args: "--no-osc".to_string(),
|
||||||
|
..ScreenShareSettings::default()
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
vlc_args(&settings),
|
||||||
|
vec![
|
||||||
|
"--network-caching=1500",
|
||||||
|
"--live-caching=1500",
|
||||||
|
"--avcodec-hw=any",
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -70,6 +70,13 @@ pub fn paste(value: &str, start: usize, end: usize, clip: &str) -> Edit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Strip control characters (e.g. a trailing newline on an X11 PRIMARY
|
||||||
|
/// selection) from clipboard text before it is pasted. Shared by the
|
||||||
|
/// right-click menu Paste and the middle-click PRIMARY paste.
|
||||||
|
pub fn sanitize_clip(raw: &str) -> String {
|
||||||
|
raw.chars().filter(|c| !c.is_control()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn select_all_range(value: &str) -> (usize, usize) {
|
pub fn select_all_range(value: &str) -> (usize, usize) {
|
||||||
let value = text_input::Value::new(value);
|
let value = text_input::Value::new(value);
|
||||||
|
|
||||||
@@ -362,6 +369,48 @@ where
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Middle-click pastes the X11 PRIMARY selection at the cursor. iced's
|
||||||
|
// base text_input only wires Ctrl+V to the Standard (CLIPBOARD)
|
||||||
|
// selection, so without this the common "select text, middle-click to
|
||||||
|
// paste" workflow does nothing on X11.
|
||||||
|
let middle_click_on_input = matches!(
|
||||||
|
event,
|
||||||
|
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Middle))
|
||||||
|
) && cursor.is_over(layout.bounds());
|
||||||
|
|
||||||
|
if middle_click_on_input && !self.locked {
|
||||||
|
let clip = sanitize_clip(&clipboard.read(clipboard::Kind::Primary).unwrap_or_default());
|
||||||
|
|
||||||
|
if !clip.is_empty() {
|
||||||
|
let value = text_input::Value::new(&self.value);
|
||||||
|
let input_state = tree.children[0]
|
||||||
|
.state
|
||||||
|
.downcast_mut::<text_input::State<Renderer::Paragraph>>();
|
||||||
|
let (start, end) = match input_state.cursor().state(&value) {
|
||||||
|
text_input::cursor::State::Index(index) => {
|
||||||
|
let index = index.min(value.len());
|
||||||
|
(index, index)
|
||||||
|
}
|
||||||
|
text_input::cursor::State::Selection { start, end } => {
|
||||||
|
normalized_range(&value, start, end)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let edit = paste(&self.value, start, end, &clip);
|
||||||
|
input_state.move_cursor_to(edit.cursor);
|
||||||
|
|
||||||
|
if let Some(on_paste) = &self.on_paste {
|
||||||
|
shell.publish(on_paste.as_ref()(edit.value));
|
||||||
|
} else if let Some(on_input) = &self.on_input {
|
||||||
|
shell.publish(on_input.as_ref()(edit.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.capture_event();
|
||||||
|
shell.request_redraw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Widget::update(
|
Widget::update(
|
||||||
&mut self.input,
|
&mut self.input,
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
@@ -717,12 +766,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MenuAction::Paste => {
|
MenuAction::Paste => {
|
||||||
let clip = clipboard
|
let clip = sanitize_clip(&clipboard.read(clipboard::Kind::Standard).unwrap_or_default());
|
||||||
.read(clipboard::Kind::Standard)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.chars()
|
|
||||||
.filter(|c| !c.is_control())
|
|
||||||
.collect::<String>();
|
|
||||||
let edit = paste(self.value, start, end, &clip);
|
let edit = paste(self.value, start, end, &clip);
|
||||||
|
|
||||||
self.publish_paste(edit, shell);
|
self.publish_paste(edit, shell);
|
||||||
@@ -842,6 +886,16 @@ mod tests {
|
|||||||
assert_eq!(clip, None);
|
assert_eq!(clip, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sanitize_clip_strips_control_chars_keeps_text() {
|
||||||
|
// An X11 PRIMARY selection commonly carries a trailing newline.
|
||||||
|
assert_eq!(sanitize_clip("pixelpassF1:abc\n"), "pixelpassF1:abc");
|
||||||
|
assert_eq!(sanitize_clip("a\tb\r\nc"), "abc");
|
||||||
|
// Non-control unicode is preserved.
|
||||||
|
assert_eq!(sanitize_clip("héllo🦀"), "héllo🦀");
|
||||||
|
assert_eq!(sanitize_clip(""), "");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn paste_replaces_selection_or_inserts_at_cursor() {
|
fn paste_replaces_selection_or_inserts_at_cursor() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
Reference in New Issue
Block a user