mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a91f0024d3 | ||
|
|
68ad9759bd | ||
|
|
169edf2224 |
No files matched your search
Generated
+1
-1
@@ -2741,7 +2741,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
edition = "2021"
|
||||
default-run = "uuremote-server"
|
||||
authors = ["uu-remote-linux contributors"]
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#define SESSION_DEST "org.gnome.SessionManager"
|
||||
#define SESSION_PATH "/org/gnome/SessionManager"
|
||||
#define SESSION_IFACE "org.gnome.SessionManager"
|
||||
#define SCREENSAVER_DEST "org.freedesktop.ScreenSaver"
|
||||
#define SCREENSAVER_PATH "/org/freedesktop/ScreenSaver"
|
||||
|
||||
enum {
|
||||
UU_POWER_OK = 0,
|
||||
@@ -17,6 +19,7 @@ enum {
|
||||
struct uu_idle_inhibitor {
|
||||
GDBusConnection *connection;
|
||||
guint32 cookie;
|
||||
int freedesktop; /* org.freedesktop.ScreenSaver (KDE) instead of org.gnome.SessionManager */
|
||||
};
|
||||
|
||||
struct setup_timeout {
|
||||
@@ -138,13 +141,45 @@ struct uu_idle_inhibitor *uu_desktop_idle_inhibitor_acquire(int *error_code) {
|
||||
return inhibitor;
|
||||
}
|
||||
|
||||
/* KDE (and other desktops implementing the freedesktop idle-inhibition spec): the inhibition is
|
||||
also dropped by the screensaver when this private connection closes. */
|
||||
struct uu_idle_inhibitor *uu_desktop_screensaver_inhibitor_acquire(int *error_code) {
|
||||
if (!error_code) return NULL;
|
||||
*error_code = UU_POWER_OK;
|
||||
GDBusConnection *connection = private_session_bus(error_code);
|
||||
if (!connection) return NULL;
|
||||
GError *error = NULL;
|
||||
GVariant *reply = g_dbus_connection_call_sync(
|
||||
connection, SCREENSAVER_DEST, SCREENSAVER_PATH, SCREENSAVER_DEST, "Inhibit",
|
||||
g_variant_new("(ss)", "uu-remote-linux", "Remote desktop session is active"),
|
||||
G_VARIANT_TYPE("(u)"), G_DBUS_CALL_FLAGS_NONE, CALL_TIMEOUT_MS, NULL, &error);
|
||||
g_clear_error(&error);
|
||||
struct uu_idle_inhibitor *inhibitor = reply ? calloc(1, sizeof(*inhibitor)) : NULL;
|
||||
if (!inhibitor) {
|
||||
*error_code = UU_POWER_CALL_FAILED;
|
||||
if (reply) g_variant_unref(reply);
|
||||
close_private_bus(connection);
|
||||
return NULL;
|
||||
}
|
||||
g_variant_get(reply, "(u)", &inhibitor->cookie);
|
||||
g_variant_unref(reply);
|
||||
inhibitor->connection = connection;
|
||||
inhibitor->freedesktop = 1;
|
||||
return inhibitor;
|
||||
}
|
||||
|
||||
void uu_desktop_idle_inhibitor_release(struct uu_idle_inhibitor *inhibitor) {
|
||||
if (!inhibitor) return;
|
||||
GError *error = NULL;
|
||||
GVariant *reply = g_dbus_connection_call_sync(
|
||||
inhibitor->connection, SESSION_DEST, SESSION_PATH, SESSION_IFACE, "Uninhibit",
|
||||
g_variant_new("(u)", inhibitor->cookie), G_VARIANT_TYPE("()"),
|
||||
G_DBUS_CALL_FLAGS_NONE, CALL_TIMEOUT_MS, NULL, &error);
|
||||
GVariant *reply = inhibitor->freedesktop
|
||||
? g_dbus_connection_call_sync(
|
||||
inhibitor->connection, SCREENSAVER_DEST, SCREENSAVER_PATH, SCREENSAVER_DEST, "UnInhibit",
|
||||
g_variant_new("(u)", inhibitor->cookie), G_VARIANT_TYPE("()"),
|
||||
G_DBUS_CALL_FLAGS_NONE, CALL_TIMEOUT_MS, NULL, &error)
|
||||
: g_dbus_connection_call_sync(
|
||||
inhibitor->connection, SESSION_DEST, SESSION_PATH, SESSION_IFACE, "Uninhibit",
|
||||
g_variant_new("(u)", inhibitor->cookie), G_VARIANT_TYPE("()"),
|
||||
G_DBUS_CALL_FLAGS_NONE, CALL_TIMEOUT_MS, NULL, &error);
|
||||
if (reply) g_variant_unref(reply);
|
||||
g_clear_error(&error);
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
# Unofficial UU Remote Linux host in a container, for NAS boxes (Synology DSM, etc.) without a desktop.
|
||||
# Headless mode: file transfer, terminal and port mapping; no remote desktop. Uses the published release binary.
|
||||
FROM ubuntu:24.04
|
||||
ARG VERSION=v0.2.15
|
||||
ARG VERSION=v0.2.16
|
||||
LABEL org.opencontainers.image.source="https://github.com/VallierDev/uu-remote-linux" \
|
||||
org.opencontainers.image.description="Unofficial UU Remote Linux host, headless (file transfer, terminal, port mapping)" \
|
||||
org.opencontainers.image.licenses="GPL-3.0"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
KDE 远程期间不再自动锁屏;锁屏和黑屏原因写进日志。/ No idle lock on KDE during remote sessions; lock and black-screen hints.
|
||||
|
||||
### 修复 / Fixed
|
||||
- **KDE Wayland 远程操作中途自动锁屏**(#61,感谢 @coolxll):桌面连接期间通过 `org.freedesktop.ScreenSaver.Inhibit` 阻止空闲锁屏,
|
||||
断开后释放(GNOME 沿用 SessionManager 的空闲抑制)。尚未在 KDE 真机上验证。
|
||||
- **`inproc-av` 奇数尺寸桌面**(#60,感谢 @ferstar):进程内编码路径同样补齐为偶数尺寸(#53 只修了默认 FFmpeg 管线)。
|
||||
`inproc-av` 不在预编译包里;未在奇数尺寸真机上验证。
|
||||
|
||||
### 改进 / Improved
|
||||
- 桌面锁屏时日志提示「控制端在解锁前只会看到黑屏」,并给出解锁方式(控制端「自动解锁被控端」或本机 `loginctl unlock-session`)。
|
||||
- 检测到 Wayland 会话却选中了 X11 后端时给出警告(此时采集 XWayland 只会得到全黑画面且没有报错)。
|
||||
- KDE sessions hold a freedesktop ScreenSaver inhibitor while connected (not yet tested on real KDE); the log now explains lock-screen
|
||||
black frames and warns when X11 capture is used inside a Wayland session; `inproc-av` pads odd sizes too.
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux-v0.2.16-x86_64-linux.tar.gz` / `uu-remote-linux-v0.2.16-aarch64-linux.tar.gz`,或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.16`(x86_64)。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
@@ -6,6 +6,16 @@ pub enum DesktopBackend { X11, Wayland, Portal, Kms }
|
||||
/// port mapping stay available (servers without a monitor or logged-in session).
|
||||
pub fn headless() -> bool { std::env::var("UU_DESKTOP_BACKEND").is_ok_and(|v| v == "none") }
|
||||
|
||||
/// A Wayland compositor socket exists for this user or the environment says so, even when this
|
||||
/// process (e.g. a systemd unit with only DISPLAY set) would select X11.
|
||||
pub fn wayland_session_running() -> bool {
|
||||
std::env::var("XDG_SESSION_TYPE").is_ok_and(|v| v == "wayland")
|
||||
|| std::env::var("WAYLAND_DISPLAY").is_ok_and(|v| !v.is_empty())
|
||||
|| std::env::var_os("XDG_RUNTIME_DIR").and_then(|dir| std::fs::read_dir(dir).ok())
|
||||
.is_some_and(|entries| entries.flatten().any(|e| e.file_name().to_str()
|
||||
.is_some_and(|n| n.starts_with("wayland-") && !n.ends_with(".lock"))))
|
||||
}
|
||||
|
||||
pub fn detect() -> Result<DesktopBackend, String> {
|
||||
let backend=select(std::env::var("UU_DESKTOP_BACKEND").ok().as_deref(),
|
||||
std::env::var("XDG_SESSION_TYPE").ok().as_deref(),
|
||||
|
||||
+15
-9
@@ -8,6 +8,7 @@ mod native {
|
||||
fn uu_desktop_power_wake() -> i32;
|
||||
fn uu_desktop_idle_inhibitor_acquire(error: *mut i32) -> *mut c_void;
|
||||
fn uu_desktop_idle_inhibitor_release(inhibitor: *mut c_void);
|
||||
fn uu_desktop_screensaver_inhibitor_acquire(error: *mut i32) -> *mut c_void;
|
||||
}
|
||||
|
||||
pub struct Handle(NonNull<c_void>);
|
||||
@@ -16,9 +17,9 @@ mod native {
|
||||
unsafe impl Send for Handle {}
|
||||
|
||||
impl Handle {
|
||||
pub fn acquire() -> Result<Self, String> {
|
||||
pub fn acquire(gnome: bool) -> Result<Self, String> {
|
||||
let mut error = 0;
|
||||
let pointer = unsafe { uu_desktop_idle_inhibitor_acquire(&mut error) };
|
||||
let pointer = unsafe { if gnome { uu_desktop_idle_inhibitor_acquire(&mut error) } else { uu_desktop_screensaver_inhibitor_acquire(&mut error) } };
|
||||
NonNull::new(pointer).map(Self).ok_or_else(|| super::error("idle inhibition", error))
|
||||
}
|
||||
|
||||
@@ -50,7 +51,9 @@ pub fn wake() -> Result<(), String> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Holds a GNOME SessionManager idle-only inhibitor until dropped.
|
||||
/// Holds an idle-only inhibitor until dropped: GNOME SessionManager on GNOME, the freedesktop
|
||||
/// ScreenSaver interface on KDE (remote input through the portal does not count as activity
|
||||
/// there, so the session locked mid-session, #61).
|
||||
///
|
||||
/// Acquire and drop perform blocking D-Bus work. Session-bus setup and each method call are
|
||||
/// bounded to three seconds. Callers on an async runtime should move both operations to a
|
||||
@@ -62,7 +65,8 @@ pub struct IdleInhibitor {
|
||||
|
||||
impl IdleInhibitor {
|
||||
pub fn acquire() -> Result<Self, String> {
|
||||
if !gnome_portal_active() {
|
||||
let kde = portal_desktop_is("kde");
|
||||
if !gnome_portal_active() && !kde {
|
||||
return Ok(Self {
|
||||
#[cfg(all(target_os = "linux", feature = "portal"))]
|
||||
_handle: None,
|
||||
@@ -70,7 +74,7 @@ impl IdleInhibitor {
|
||||
}
|
||||
#[cfg(all(target_os = "linux", feature = "portal"))]
|
||||
{
|
||||
native::Handle::acquire().map(|handle| Self { _handle: Some(handle) })
|
||||
native::Handle::acquire(!kde).map(|handle| Self { _handle: Some(handle) })
|
||||
}
|
||||
#[cfg(not(all(target_os = "linux", feature = "portal")))]
|
||||
{
|
||||
@@ -79,10 +83,12 @@ impl IdleInhibitor {
|
||||
}
|
||||
}
|
||||
|
||||
fn gnome_portal_active() -> bool {
|
||||
let gnome = std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default().split(':')
|
||||
.any(|desktop| desktop.eq_ignore_ascii_case("gnome"));
|
||||
gnome && crate::desktop_backend::detect().is_ok_and(|backend| backend == crate::desktop_backend::DesktopBackend::Portal)
|
||||
fn gnome_portal_active() -> bool { portal_desktop_is("gnome") }
|
||||
|
||||
fn portal_desktop_is(name: &str) -> bool {
|
||||
let matches = std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default().split(':')
|
||||
.any(|desktop| desktop.eq_ignore_ascii_case(name));
|
||||
matches && crate::desktop_backend::detect().is_ok_and(|backend| backend == crate::desktop_backend::DesktopBackend::Portal)
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", feature = "portal"))]
|
||||
|
||||
@@ -101,7 +101,9 @@ fn drain(encoder: &mut encoder::Video, packet: &mut Packet, units: &mpsc::Sender
|
||||
|
||||
/// Opens the selected video encoder for `config`. Returns the encoder, its input pixel format and output size.
|
||||
fn open_encoder(config: &Config) -> Result<(encoder::Video, Pixel, u32, u32), String> {
|
||||
// H.264/HEVC 4:2:0 and NVENC need even dimensions; an odd native capture is padded (see run_damage).
|
||||
let (width, height) = config.output.unwrap_or(config.input);
|
||||
let (width, height) = (width + width % 2, height + height % 2);
|
||||
let codec = encoder::find_by_name(config.encoder.name_for(config.codec))
|
||||
.ok_or_else(|| format!("{} is not available in this FFmpeg build", config.encoder.name_for(config.codec)))?;
|
||||
// Allocate for this codec so FFmpeg fills its defaults; libx264 rejects a context allocated without one.
|
||||
@@ -278,7 +280,11 @@ pub fn run(config: Config, units: mpsc::Sender<EncodedUnit>, stop: Arc<AtomicBoo
|
||||
fn run_damage(config: Config, mut capture: DamageCapture, units: mpsc::Sender<EncodedUnit>, stop: Arc<AtomicBool>, idr: Arc<AtomicBool>, budget: Arc<Semaphore>) -> Result<(), String> {
|
||||
let (mut encoder, pixel, width, height) = open_encoder(&config)?;
|
||||
let (cap_width, cap_height) = capture.size();
|
||||
let mut captured = frame::Video::new(Pixel::BGRZ, cap_width, cap_height);
|
||||
// Native size uses the even encoder size. The extra row/column is never overwritten, so it stays black.
|
||||
let native = config.output.is_none();
|
||||
let (frame_width, frame_height) = if native { (width, height) } else { (cap_width, cap_height) };
|
||||
let mut captured = frame::Video::new(Pixel::BGRZ, frame_width, frame_height);
|
||||
if native { captured.data_mut(0).fill(0); }
|
||||
let mut converted = frame::Video::empty();
|
||||
let mut scaler = None;
|
||||
let mut packet = Packet::empty();
|
||||
@@ -324,11 +330,11 @@ fn run_damage(config: Config, mut capture: DamageCapture, units: mpsc::Sender<En
|
||||
let slot = slot.max(last_slot + 1);
|
||||
last_slot = slot;
|
||||
|
||||
let frame = if pixel == Pixel::BGRZ && width == cap_width && height == cap_height {
|
||||
let frame = if pixel == Pixel::BGRZ && width == captured.width() && height == captured.height() {
|
||||
&mut captured
|
||||
} else {
|
||||
if scaler.is_none() {
|
||||
scaler = Some(scaling::Context::get(Pixel::BGRZ, cap_width, cap_height, pixel, width, height, scaling::Flags::BILINEAR).map_err(text)?);
|
||||
scaler = Some(scaling::Context::get(Pixel::BGRZ, captured.width(), captured.height(), pixel, width, height, scaling::Flags::BILINEAR).map_err(text)?);
|
||||
}
|
||||
if dirty {
|
||||
if let Some(context) = scaler.as_mut() { context.run(&captured, &mut converted).map_err(text)?; }
|
||||
|
||||
@@ -410,6 +410,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let _audio_cleanup=virtual_audio::Cleanup;
|
||||
log::info!("Starting uu-remote-linux host v{}...", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
if !desktop_backend::headless() && desktop_backend::detect()? == desktop_backend::DesktopBackend::X11 && desktop_backend::wayland_session_running() {
|
||||
// X11 capture inside a Wayland session reads XWayland's root window: all black, no error (#61).
|
||||
log::warn!("A Wayland session is running but the X11 backend is selected: the picture will be black. Run inside the Wayland session (WAYLAND_DISPLAY set, UU_DESKTOP_BACKEND=auto) or log in to the Xorg session");
|
||||
}
|
||||
let capture = Arc::new((if desktop_backend::headless() {
|
||||
Err("headless mode (UU_DESKTOP_BACKEND=none)".to_owned())
|
||||
} else if desktop_backend::detect()?==desktop_backend::DesktopBackend::Portal {
|
||||
|
||||
@@ -92,6 +92,8 @@ pub fn watch_locked() -> watch::Receiver<Option<bool>> {
|
||||
if locked.is_none() { session = None; } // session ended or changed: look it up again
|
||||
sender.send_if_modified(|current| if *current != locked {
|
||||
log::info!("Desktop lock state: {}", match locked { Some(true) => "locked", Some(false) => "unlocked", None => "unknown" });
|
||||
// The viewer only sees black frames while locked and gives no hint (#61).
|
||||
if locked == Some(true) { log::info!("Desktop is locked: viewers see a black screen until it is unlocked (viewer 自动解锁被控端, or `loginctl unlock-session` on the host)"); }
|
||||
*current = locked; true
|
||||
} else { false });
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
|
||||
Reference in new issue
Block a user