Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb6476a864 | ||
|
|
17a09e08a5 | ||
|
|
eb9f35968e | ||
|
|
55eaf98e75 | ||
|
|
a698c54c66 | ||
|
|
c9cfc479dc | ||
|
|
fd2368058f | ||
|
|
fba3fb9604 |
No files matched your search
@@ -20,6 +20,8 @@ jobs:
|
||||
cargo test --locked --all-targets
|
||||
cc -std=c11 -O2 -Wall -Wextra -Werror tests/frame-protocol.c -o /tmp/frame-protocol
|
||||
/tmp/frame-protocol
|
||||
cc -std=c11 -O2 -Wall -Wextra -Werror tests/cursor-overlay.c -o /tmp/cursor-overlay
|
||||
/tmp/cursor-overlay
|
||||
- name: Build
|
||||
run: cargo build --locked --release
|
||||
|
||||
|
||||
Generated
+1
-1
@@ -1413,7 +1413,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "uur"
|
||||
version = "0.1.1"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"ashpd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "uur"
|
||||
version = "0.1.1"
|
||||
version = "0.1.3"
|
||||
edition = "2021"
|
||||
description = "Native Linux companion for NetEase UU Remote: X11/Wayland input and capture, packaged as a regular desktop app"
|
||||
license = "MIT"
|
||||
|
||||
@@ -69,7 +69,7 @@ recipes and release artifacts share one version and filesystem layout.
|
||||
Install a downloaded release package with pacman:
|
||||
|
||||
```bash
|
||||
sudo pacman -U ./dist/uur-0.1.1-1-x86_64.pkg.tar.zst
|
||||
sudo pacman -U ./dist/uur-0.1.3-1-x86_64.pkg.tar.zst
|
||||
```
|
||||
|
||||
### AUR
|
||||
@@ -83,13 +83,13 @@ paru -S uur
|
||||
### Debian and Ubuntu package family
|
||||
|
||||
```bash
|
||||
sudo apt install ./uur_0.1.1_amd64.deb
|
||||
sudo apt install ./uur_0.1.3_amd64.deb
|
||||
```
|
||||
|
||||
### Fedora and compatible RPM systems
|
||||
|
||||
```bash
|
||||
sudo dnf install ./uur-0.1.1-1.x86_64.rpm
|
||||
sudo dnf install ./uur-0.1.3-1.x86_64.rpm
|
||||
```
|
||||
|
||||
On systems with different RPM dependency names, install the dependencies
|
||||
@@ -98,7 +98,7 @@ manually or use the portable archive.
|
||||
### Portable archive
|
||||
|
||||
```bash
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.1-linux-x86_64.tar.zst
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.3-linux-x86_64.tar.zst
|
||||
```
|
||||
|
||||
### Nix and NixOS
|
||||
|
||||
+4
-4
@@ -66,7 +66,7 @@ uur run
|
||||
使用 pacman 安装下载的正式发布包:
|
||||
|
||||
```bash
|
||||
sudo pacman -U ./dist/uur-0.1.1-1-x86_64.pkg.tar.zst
|
||||
sudo pacman -U ./dist/uur-0.1.3-1-x86_64.pkg.tar.zst
|
||||
```
|
||||
|
||||
### AUR
|
||||
@@ -80,13 +80,13 @@ paru -S uur
|
||||
### Debian、Ubuntu 及兼容发行版
|
||||
|
||||
```bash
|
||||
sudo apt install ./uur_0.1.1_amd64.deb
|
||||
sudo apt install ./uur_0.1.3_amd64.deb
|
||||
```
|
||||
|
||||
### Fedora 及兼容 RPM 发行版
|
||||
|
||||
```bash
|
||||
sudo dnf install ./uur-0.1.1-1.x86_64.rpm
|
||||
sudo dnf install ./uur-0.1.3-1.x86_64.rpm
|
||||
```
|
||||
|
||||
如果发行版的 RPM 依赖名称不同,请手动安装依赖或使用通用压缩包。
|
||||
@@ -94,7 +94,7 @@ sudo dnf install ./uur-0.1.1-1.x86_64.rpm
|
||||
### 通用压缩包
|
||||
|
||||
```bash
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.1-linux-x86_64.tar.zst
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.3-linux-x86_64.tar.zst
|
||||
```
|
||||
|
||||
### Nix 与 NixOS
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 539 KiB After Width: | Height: | Size: 993 KiB |
@@ -12,13 +12,13 @@ needed for system-wide package installation.
|
||||
paru -S uur
|
||||
|
||||
# Downloaded release package
|
||||
sudo pacman -U ./uur-0.1.1-1-x86_64.pkg.tar.zst
|
||||
sudo pacman -U ./uur-0.1.3-1-x86_64.pkg.tar.zst
|
||||
```
|
||||
|
||||
## Debian, Ubuntu, and derivatives
|
||||
|
||||
```bash
|
||||
sudo apt install ./uur_0.1.1_amd64.deb
|
||||
sudo apt install ./uur_0.1.3_amd64.deb
|
||||
```
|
||||
|
||||
The same release artifact covers Debian, Ubuntu, Linux Mint, Pop!_OS, KDE neon,
|
||||
@@ -28,10 +28,10 @@ derivatives.
|
||||
## Fedora, RHEL, and openSUSE families
|
||||
|
||||
```bash
|
||||
sudo dnf install ./uur-0.1.1-1.x86_64.rpm
|
||||
sudo dnf install ./uur-0.1.3-1.x86_64.rpm
|
||||
|
||||
# openSUSE
|
||||
sudo zypper install ./uur-0.1.1-1.x86_64.rpm
|
||||
sudo zypper install ./uur-0.1.3-1.x86_64.rpm
|
||||
```
|
||||
|
||||
This format also covers Fedora derivatives and RPM systems whose repositories
|
||||
@@ -42,7 +42,7 @@ provide the declared Wine, GLib, PipeWire, and portal dependencies.
|
||||
The portable archive targets conventional glibc/FHS systems:
|
||||
|
||||
```bash
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.1-linux-x86_64.tar.zst
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.3-linux-x86_64.tar.zst
|
||||
```
|
||||
|
||||
## Nix and NixOS
|
||||
|
||||
@@ -46,7 +46,7 @@ paru -S uur
|
||||
From a downloaded Arch package:
|
||||
|
||||
```bash
|
||||
sudo pacman -U ./uur-0.1.1-1-x86_64.pkg.tar.zst
|
||||
sudo pacman -U ./uur-0.1.3-1-x86_64.pkg.tar.zst
|
||||
```
|
||||
|
||||
Install the portal backend supplied or recommended by the selected desktop.
|
||||
@@ -60,7 +60,7 @@ Zorin OS, elementary OS, KDE neon, TUXEDO OS, Kali Linux, MX Linux, and other
|
||||
compatible derivatives:
|
||||
|
||||
```bash
|
||||
sudo apt install ./uur_0.1.1_amd64.deb
|
||||
sudo apt install ./uur_0.1.3_amd64.deb
|
||||
```
|
||||
|
||||
The package manager resolves Wine, PipeWire, and the portal frontend. Install
|
||||
@@ -74,10 +74,10 @@ dependency names. Install it with the native frontend:
|
||||
|
||||
```bash
|
||||
# Fedora and compatible systems
|
||||
sudo dnf install ./uur-0.1.1-1.x86_64.rpm
|
||||
sudo dnf install ./uur-0.1.3-1.x86_64.rpm
|
||||
|
||||
# openSUSE family
|
||||
sudo zypper install ./uur-0.1.1-1.x86_64.rpm
|
||||
sudo zypper install ./uur-0.1.3-1.x86_64.rpm
|
||||
```
|
||||
|
||||
RHEL, CentOS Stream, Rocky Linux, AlmaLinux, Oracle Linux, Nobara, Ultramarine,
|
||||
@@ -91,7 +91,7 @@ PCLinuxOS, and similar mutable/FHS systems can use the portable archive when
|
||||
they provide compatible glibc, Wine, PipeWire, and portal libraries:
|
||||
|
||||
```bash
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.1-linux-x86_64.tar.zst
|
||||
sudo tar --zstd -C / -xf ./uur-0.1.3-linux-x86_64.tar.zst
|
||||
```
|
||||
|
||||
Alternatively, build and install for one user:
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#ifndef UUR_CURSOR_OVERLAY_H
|
||||
#define UUR_CURSOR_OVERLAY_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct uur_cursor_rect {
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
} uur_cursor_rect;
|
||||
|
||||
typedef struct uur_cursor_shape {
|
||||
/* The hotspot is in the same screen coordinates as the GDI source DC. */
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
int hotspot_x;
|
||||
int hotspot_y;
|
||||
} uur_cursor_shape;
|
||||
|
||||
static inline int uur_cursor_bitmap_height(int mask_height, int has_color)
|
||||
{
|
||||
return has_color ? mask_height : mask_height / 2;
|
||||
}
|
||||
|
||||
static inline int uur_map_cursor_overlay(const uur_cursor_rect *source,
|
||||
const uur_cursor_rect *destination,
|
||||
const uur_cursor_shape *cursor,
|
||||
uur_cursor_rect *overlay)
|
||||
{
|
||||
int64_t left;
|
||||
int64_t top;
|
||||
int64_t scaled_hotspot_x;
|
||||
int64_t scaled_hotspot_y;
|
||||
int64_t scaled_width;
|
||||
int64_t scaled_height;
|
||||
int64_t mapped_x;
|
||||
int64_t mapped_y;
|
||||
|
||||
if (source->width <= 0 || source->height <= 0 ||
|
||||
destination->width <= 0 || destination->height <= 0 ||
|
||||
cursor->width <= 0 || cursor->height <= 0)
|
||||
return 0;
|
||||
|
||||
left = (int64_t)cursor->x - cursor->hotspot_x;
|
||||
top = (int64_t)cursor->y - cursor->hotspot_y;
|
||||
/* Keep partially visible cursors at the edges of the captured region. */
|
||||
if (left >= (int64_t)source->x + source->width ||
|
||||
top >= (int64_t)source->y + source->height ||
|
||||
left + cursor->width <= source->x ||
|
||||
top + cursor->height <= source->y)
|
||||
return 0;
|
||||
|
||||
scaled_hotspot_x = ((int64_t)cursor->hotspot_x * destination->width +
|
||||
source->width / 2) / source->width;
|
||||
scaled_hotspot_y = ((int64_t)cursor->hotspot_y * destination->height +
|
||||
source->height / 2) / source->height;
|
||||
scaled_width = ((int64_t)cursor->width * destination->width +
|
||||
source->width / 2) / source->width;
|
||||
scaled_height = ((int64_t)cursor->height * destination->height +
|
||||
source->height / 2) / source->height;
|
||||
|
||||
mapped_x = (int64_t)destination->x +
|
||||
(((int64_t)cursor->x - source->x) * destination->width) /
|
||||
source->width - scaled_hotspot_x;
|
||||
mapped_y = (int64_t)destination->y +
|
||||
(((int64_t)cursor->y - source->y) * destination->height) /
|
||||
source->height - scaled_hotspot_y;
|
||||
if (mapped_x < INT_MIN || mapped_x > INT_MAX || mapped_y < INT_MIN ||
|
||||
mapped_y > INT_MAX || scaled_width > INT_MAX ||
|
||||
scaled_height > INT_MAX)
|
||||
return 0;
|
||||
overlay->x = (int)mapped_x;
|
||||
overlay->y = (int)mapped_y;
|
||||
overlay->width = scaled_width > 0 ? (int)scaled_width : 1;
|
||||
overlay->height = scaled_height > 0 ? (int)scaled_height : 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
+73
-4
@@ -26,6 +26,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "cursor-overlay.h"
|
||||
#include "frame-protocol.h"
|
||||
|
||||
#define UUR_MAGIC 0x50495555u
|
||||
@@ -328,6 +329,63 @@ static BOOL source_is_screen_dc(HDC source)
|
||||
GetDeviceCaps(source, TECHNOLOGY) == DT_RASDISPLAY;
|
||||
}
|
||||
|
||||
/* GDI screen captures do not include the X11 hardware cursor. Keep the
|
||||
* cursor visible in the fallback path used on X11 by compositing Wine's
|
||||
* current cursor onto the capture destination after the desktop blit. */
|
||||
static void draw_cursor_overlay(HDC hdc_dest, int x, int y, int width, int height,
|
||||
int source_x, int source_y, int source_width,
|
||||
int source_height)
|
||||
{
|
||||
CURSORINFO cursor;
|
||||
ICONINFO icon;
|
||||
BITMAP mask;
|
||||
POINT position;
|
||||
uur_cursor_rect source = {source_x, source_y, source_width, source_height};
|
||||
uur_cursor_rect destination = {x, y, width, height};
|
||||
uur_cursor_rect overlay;
|
||||
uur_cursor_shape shape;
|
||||
|
||||
if (hdc_dest == NULL || width <= 0 || height <= 0 || source_width <= 0 ||
|
||||
source_height <= 0 || source_is_screen_dc(hdc_dest))
|
||||
return;
|
||||
ZeroMemory(&cursor, sizeof(cursor));
|
||||
cursor.cbSize = sizeof(cursor);
|
||||
if (!GetCursorInfo(&cursor) || !(cursor.flags & CURSOR_SHOWING) ||
|
||||
!GetCursorPos(&position))
|
||||
return;
|
||||
/* Wine can report a visible cursor with a null handle until the first
|
||||
* real window has selected a class cursor. A generic arrow is preferable
|
||||
* to dropping the cursor from the remote frame altogether. */
|
||||
if (cursor.hCursor == NULL)
|
||||
cursor.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
if (cursor.hCursor == NULL)
|
||||
return;
|
||||
|
||||
ZeroMemory(&icon, sizeof(icon));
|
||||
if (!GetIconInfo(cursor.hCursor, &icon))
|
||||
return;
|
||||
|
||||
/* GetIconInfo's mask holds the cursor's actual bitmap dimensions. For a
|
||||
* monochrome cursor the AND/XOR masks are stacked vertically. */
|
||||
if (icon.hbmMask != NULL &&
|
||||
GetObjectW(icon.hbmMask, sizeof(mask), &mask) == sizeof(mask)) {
|
||||
shape.x = position.x;
|
||||
shape.y = position.y;
|
||||
shape.width = mask.bmWidth;
|
||||
shape.height = uur_cursor_bitmap_height(mask.bmHeight,
|
||||
icon.hbmColor != NULL);
|
||||
shape.hotspot_x = (int)icon.xHotspot;
|
||||
shape.hotspot_y = (int)icon.yHotspot;
|
||||
if (uur_map_cursor_overlay(&source, &destination, &shape, &overlay))
|
||||
DrawIconEx(hdc_dest, overlay.x, overlay.y, cursor.hCursor,
|
||||
overlay.width, overlay.height, 0, NULL, DI_NORMAL);
|
||||
}
|
||||
if (icon.hbmColor != NULL)
|
||||
DeleteObject(icon.hbmColor);
|
||||
if (icon.hbmMask != NULL)
|
||||
DeleteObject(icon.hbmMask);
|
||||
}
|
||||
|
||||
/* Feed the newest desktop frame into the capture destination by drawing
|
||||
* our shared-memory frame with StretchDIBits. Works regardless of the
|
||||
* destination bitmap type (DDB or DIB section). */
|
||||
@@ -436,21 +494,32 @@ static BOOL try_capture_feed(HDC hdc_dest, int x, int y, DWORD rop,
|
||||
BOOL WINAPI hook_bit_blt(HDC hdc_dest, int x, int y, int width, int height,
|
||||
HDC hdc_src, int x_src, int y_src, DWORD rop)
|
||||
{
|
||||
BOOL result;
|
||||
if (try_capture_feed(hdc_dest, x, y, rop, hdc_src, width, height, x_src,
|
||||
y_src, width, height))
|
||||
return TRUE;
|
||||
return original_bit_blt(hdc_dest, x, y, width, height, hdc_src, x_src,
|
||||
y_src, rop);
|
||||
result = original_bit_blt(hdc_dest, x, y, width, height, hdc_src, x_src,
|
||||
y_src, rop);
|
||||
if (result && (rop & 0x00ffffffu) == SRCCOPY && hdc_src != NULL &&
|
||||
source_is_screen_dc(hdc_src))
|
||||
draw_cursor_overlay(hdc_dest, x, y, width, height, x_src, y_src,
|
||||
width, height);
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL WINAPI hook_stretch_blt(HDC hdc_dest, int x, int y, int w, int h,
|
||||
HDC hdc_src, int xs, int ys, int sw, int sh,
|
||||
DWORD rop)
|
||||
{
|
||||
BOOL result;
|
||||
if (try_capture_feed(hdc_dest, x, y, rop, hdc_src, w, h, xs, ys, sw, sh))
|
||||
return TRUE;
|
||||
return original_stretch_blt(hdc_dest, x, y, w, h, hdc_src, xs, ys, sw,
|
||||
sh, rop);
|
||||
result = original_stretch_blt(hdc_dest, x, y, w, h, hdc_src, xs, ys, sw,
|
||||
sh, rop);
|
||||
if (result && (rop & 0x00ffffffu) == SRCCOPY && hdc_src != NULL &&
|
||||
source_is_screen_dc(hdc_src))
|
||||
draw_cursor_overlay(hdc_dest, x, y, w, h, xs, ys, sw, sh);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ---- diagnostics ------------------------------------------------------ */
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ let
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "uur";
|
||||
version = "0.1.1";
|
||||
version = "0.1.3";
|
||||
|
||||
src = lib.cleanSource ../.;
|
||||
cargoLock.lockFile = ../Cargo.lock;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Contributor: uur contributors
|
||||
# Maintainer: uur contributors
|
||||
pkgname=uur
|
||||
pkgver=0.1.1
|
||||
pkgver=0.1.3
|
||||
pkgrel=0
|
||||
pkgdesc="Native Linux companion for NetEase UU Remote"
|
||||
url="https://github.com/panxuc/uur"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pkgbase = uur
|
||||
pkgdesc = Native Linux companion for NetEase UU Remote (X11/Wayland input and capture bridge)
|
||||
pkgver = 0.1.1
|
||||
pkgver = 0.1.3
|
||||
pkgrel = 1
|
||||
url = https://github.com/panxuc/uur
|
||||
install = uur.install
|
||||
@@ -31,7 +31,7 @@ pkgbase = uur
|
||||
optdepends = libva-utils: VA-API capability diagnostics
|
||||
optdepends = vulkan-tools: Vulkan and Vulkan Video capability diagnostics
|
||||
optdepends = nvidia-utils: NVENC and NVDEC capability diagnostics on NVIDIA GPUs
|
||||
source = uur-0.1.1.tar.gz::https://github.com/panxuc/uur/archive/refs/tags/v0.1.1.tar.gz
|
||||
source = uur-0.1.3.tar.gz::https://github.com/panxuc/uur/archive/refs/tags/v0.1.3.tar.gz
|
||||
sha256sums = SKIP
|
||||
|
||||
pkgname = uur
|
||||
@@ -8,7 +8,7 @@
|
||||
# `uur setup` (it is never redistributed by this package).
|
||||
|
||||
pkgname=uur
|
||||
pkgver=0.1.1
|
||||
pkgver=0.1.3
|
||||
pkgrel=1
|
||||
pkgdesc="Native Linux companion for NetEase UU Remote (X11/Wayland input and capture bridge)"
|
||||
arch=('x86_64')
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 57 KiB |
@@ -12,5 +12,8 @@ cargo test --manifest-path "$project_root/Cargo.toml" --all-targets
|
||||
cc -std=c11 -O2 -Wall -Wextra -Werror \
|
||||
"$project_root/tests/frame-protocol.c" -o "$temporary/frame-protocol"
|
||||
"$temporary/frame-protocol"
|
||||
cc -std=c11 -O2 -Wall -Wextra -Werror \
|
||||
"$project_root/tests/cursor-overlay.c" -o "$temporary/cursor-overlay"
|
||||
"$temporary/cursor-overlay"
|
||||
"$project_root/hook/build.sh"
|
||||
"$project_root/capture/build.sh"
|
||||
+277
-7
@@ -1,12 +1,122 @@
|
||||
use anyhow::{Context, Result};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io::Read;
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::input;
|
||||
use crate::protocol::{self, RECORD_BYTES, RECORD_HELLO};
|
||||
|
||||
struct SharedInput {
|
||||
backend: Box<dyn input::InputBackend>,
|
||||
keys: HashMap<u16, usize>,
|
||||
buttons: HashMap<u16, usize>,
|
||||
}
|
||||
|
||||
struct ConnectionInput {
|
||||
shared: Arc<Mutex<SharedInput>>,
|
||||
name: &'static str,
|
||||
keys: HashSet<u16>,
|
||||
buttons: HashSet<u16>,
|
||||
}
|
||||
|
||||
impl ConnectionInput {
|
||||
fn press(&mut self, code: u16, down: bool, keyboard: bool) -> Result<()> {
|
||||
let mut shared = self.shared.lock().unwrap();
|
||||
let held = if keyboard {
|
||||
&mut self.keys
|
||||
} else {
|
||||
&mut self.buttons
|
||||
};
|
||||
let owners = if keyboard {
|
||||
&shared.keys
|
||||
} else {
|
||||
&shared.buttons
|
||||
};
|
||||
let count = owners.get(&code).copied().unwrap_or(0);
|
||||
if !down && !held.contains(&code) {
|
||||
return Ok(());
|
||||
}
|
||||
if down || count <= 1 {
|
||||
if keyboard {
|
||||
shared.backend.key(code, down)?;
|
||||
} else {
|
||||
shared.backend.button(code, down)?;
|
||||
}
|
||||
}
|
||||
let owners = if keyboard {
|
||||
&mut shared.keys
|
||||
} else {
|
||||
&mut shared.buttons
|
||||
};
|
||||
if down {
|
||||
if held.insert(code) {
|
||||
*owners.entry(code).or_default() += 1;
|
||||
}
|
||||
} else {
|
||||
held.remove(&code);
|
||||
if count <= 1 {
|
||||
owners.remove(&code);
|
||||
} else {
|
||||
owners.insert(code, count - 1);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl input::InputBackend for ConnectionInput {
|
||||
fn name(&self) -> &'static str {
|
||||
self.name
|
||||
}
|
||||
fn key(&mut self, code: u16, down: bool) -> Result<()> {
|
||||
self.press(code, down, true)
|
||||
}
|
||||
fn button(&mut self, code: u16, down: bool) -> Result<()> {
|
||||
self.press(code, down, false)
|
||||
}
|
||||
fn motion(&mut self, absolute: bool, x: i32, y: i32) -> Result<()> {
|
||||
self.shared.lock().unwrap().backend.motion(absolute, x, y)
|
||||
}
|
||||
fn wheel(&mut self, horizontal: bool, delta: i32) -> Result<()> {
|
||||
self.shared.lock().unwrap().backend.wheel(horizontal, delta)
|
||||
}
|
||||
fn release_all(&mut self) -> Result<()> {
|
||||
let mut error = None;
|
||||
for code in self.keys.clone() {
|
||||
if let Err(e) = self.key(code, false) {
|
||||
error = Some(e);
|
||||
}
|
||||
}
|
||||
for code in self.buttons.clone() {
|
||||
if let Err(e) = self.button(code, false) {
|
||||
error = Some(e);
|
||||
}
|
||||
}
|
||||
// A disconnected client must not retain ownership if a release fails.
|
||||
let mut shared = self.shared.lock().unwrap();
|
||||
for code in self.keys.drain() {
|
||||
if let Some(count) = shared.keys.get_mut(&code) {
|
||||
*count -= 1;
|
||||
if *count == 0 {
|
||||
shared.keys.remove(&code);
|
||||
}
|
||||
}
|
||||
}
|
||||
for code in self.buttons.drain() {
|
||||
if let Some(count) = shared.buttons.get_mut(&code) {
|
||||
*count -= 1;
|
||||
if *count == 0 {
|
||||
shared.buttons.remove(&code);
|
||||
}
|
||||
}
|
||||
}
|
||||
error.map_or(Ok(()), Err)
|
||||
}
|
||||
}
|
||||
|
||||
/// Print the X11 pointer position — the before/after observable for hook
|
||||
/// verification.
|
||||
pub fn print_pointer() -> Result<()> {
|
||||
@@ -19,8 +129,8 @@ pub fn print_pointer() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Serve the in-client hook: one authenticated loopback connection at a
|
||||
/// time, records dispatched to the selected input backend.
|
||||
/// Serve authenticated loopback hook connections, serializing individual
|
||||
/// input events without holding the backend lock while waiting for records.
|
||||
pub fn serve() -> Result<()> {
|
||||
let config = Config::load()?;
|
||||
let preferred =
|
||||
@@ -29,7 +139,12 @@ pub fn serve() -> Result<()> {
|
||||
if let Some(path) = std::env::var_os("UUR_BACKEND_STATUS") {
|
||||
std::fs::write(path, selected.name()).context("writing backend status")?;
|
||||
}
|
||||
let backend = std::sync::Arc::new(std::sync::Mutex::new(selected));
|
||||
let backend_name = selected.name();
|
||||
let backend = Arc::new(Mutex::new(SharedInput {
|
||||
backend: selected,
|
||||
keys: HashMap::new(),
|
||||
buttons: HashMap::new(),
|
||||
}));
|
||||
let backend_handle = backend.clone();
|
||||
let addr = format!("127.0.0.1:{}", config.bridge_port);
|
||||
let listener = TcpListener::bind(&addr).with_context(|| format!("binding {addr}"))?;
|
||||
@@ -52,9 +167,16 @@ pub fn serve() -> Result<()> {
|
||||
Ok(false) => return,
|
||||
Err(_) => return,
|
||||
}
|
||||
let mut guard = backend_handle.lock().unwrap();
|
||||
println!("{}", t!("bridge.connected", backend = guard.name()));
|
||||
match pump(&mut stream, guard.as_mut()) {
|
||||
use input::InputBackend;
|
||||
// Read sockets without holding the shared desktop input lock.
|
||||
let mut connection = ConnectionInput {
|
||||
shared: backend_handle,
|
||||
name: backend_name,
|
||||
keys: HashSet::new(),
|
||||
buttons: HashSet::new(),
|
||||
};
|
||||
println!("{}", t!("bridge.connected", backend = connection.name()));
|
||||
match pump(&mut stream, &mut connection) {
|
||||
Ok(count) => {
|
||||
println!("{}", t!("bridge.session_summary", count = count));
|
||||
println!("{}", t!("bridge.disconnected_clean"));
|
||||
@@ -66,7 +188,7 @@ pub fn serve() -> Result<()> {
|
||||
);
|
||||
}
|
||||
}
|
||||
let _ = guard.release_all();
|
||||
let _ = connection.release_all();
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
@@ -165,3 +287,151 @@ fn tokens_differ(a: &[u8; 32], b: &[u8; 32]) -> bool {
|
||||
}
|
||||
diff != 0
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::input::InputBackend;
|
||||
use std::io::Write;
|
||||
use std::sync::mpsc;
|
||||
use std::time::Duration;
|
||||
|
||||
struct Recorder(mpsc::Sender<String>);
|
||||
impl InputBackend for Recorder {
|
||||
fn name(&self) -> &'static str {
|
||||
"test"
|
||||
}
|
||||
fn key(&mut self, code: u16, down: bool) -> Result<()> {
|
||||
self.0.send(format!("key {code} {down}"))?;
|
||||
Ok(())
|
||||
}
|
||||
fn button(&mut self, code: u16, down: bool) -> Result<()> {
|
||||
self.0.send(format!("button {code} {down}"))?;
|
||||
Ok(())
|
||||
}
|
||||
fn motion(&mut self, _: bool, _: i32, _: i32) -> Result<()> {
|
||||
self.0.send("motion".into())?;
|
||||
Ok(())
|
||||
}
|
||||
fn wheel(&mut self, _: bool, _: i32) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn release_all(&mut self) -> Result<()> {
|
||||
panic!("must release only owned inputs")
|
||||
}
|
||||
}
|
||||
|
||||
fn connection(shared: &Arc<Mutex<SharedInput>>) -> ConnectionInput {
|
||||
ConnectionInput {
|
||||
shared: shared.clone(),
|
||||
name: "test",
|
||||
keys: HashSet::new(),
|
||||
buttons: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn shared() -> (Arc<Mutex<SharedInput>>, mpsc::Receiver<String>) {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
(
|
||||
Arc::new(Mutex::new(SharedInput {
|
||||
backend: Box::new(Recorder(tx)),
|
||||
keys: HashMap::new(),
|
||||
buttons: HashMap::new(),
|
||||
})),
|
||||
rx,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idle_connection_does_not_block_another_connections_motion() {
|
||||
let (shared, events) = shared();
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let mut client = TcpStream::connect(listener.local_addr().unwrap()).unwrap();
|
||||
let (mut server, _) = listener.accept().unwrap();
|
||||
let mut idle = connection(&shared);
|
||||
let thread = thread::spawn(move || pump(&mut server, &mut idle).unwrap());
|
||||
let mut packet = Vec::new();
|
||||
for value in [
|
||||
protocol::MAGIC,
|
||||
1,
|
||||
protocol::RECORD_MOUSE,
|
||||
16,
|
||||
protocol::RECORD_MOUSE,
|
||||
] {
|
||||
packet.extend_from_slice(&value.to_le_bytes());
|
||||
}
|
||||
packet.extend_from_slice(&0xffffu16.to_le_bytes());
|
||||
packet.extend_from_slice(&0u16.to_le_bytes());
|
||||
packet.extend_from_slice(&1i32.to_le_bytes());
|
||||
packet.extend_from_slice(&0i32.to_le_bytes());
|
||||
client.write_all(&packet).unwrap();
|
||||
assert_eq!(
|
||||
events.recv_timeout(Duration::from_secs(2)).unwrap(),
|
||||
"motion"
|
||||
);
|
||||
let mut other = connection(&shared);
|
||||
let other_thread = thread::spawn(move || other.motion(false, 1, 0).unwrap());
|
||||
let delivered = events.recv_timeout(Duration::from_secs(2));
|
||||
drop(client);
|
||||
thread.join().unwrap();
|
||||
other_thread.join().unwrap();
|
||||
assert_eq!(delivered.unwrap(), "motion");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disconnect_preserves_keys_and_buttons_held_by_another_connection() {
|
||||
let (shared, events) = shared();
|
||||
let mut first = connection(&shared);
|
||||
let mut second = connection(&shared);
|
||||
first.key(65, true).unwrap();
|
||||
second.key(65, true).unwrap();
|
||||
first.button(1, true).unwrap();
|
||||
second.button(1, true).unwrap();
|
||||
first.release_all().unwrap();
|
||||
assert_eq!(
|
||||
events.try_iter().collect::<Vec<_>>(),
|
||||
[
|
||||
"key 65 true",
|
||||
"key 65 true",
|
||||
"button 1 true",
|
||||
"button 1 true"
|
||||
]
|
||||
);
|
||||
second.release_all().unwrap();
|
||||
assert_eq!(
|
||||
events.try_iter().collect::<Vec<_>>(),
|
||||
["key 65 false", "button 1 false"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disconnect_forgets_ownership_when_backend_release_fails() {
|
||||
let (shared, events) = shared();
|
||||
let mut client = connection(&shared);
|
||||
client.key(65, true).unwrap();
|
||||
client.button(1, true).unwrap();
|
||||
drop(events);
|
||||
assert!(client.release_all().is_err());
|
||||
assert!(client.keys.is_empty());
|
||||
assert!(client.buttons.is_empty());
|
||||
let shared = shared.lock().unwrap();
|
||||
assert!(shared.keys.is_empty());
|
||||
assert!(shared.buttons.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_press_is_released_once_and_unowned_release_is_ignored() {
|
||||
let (shared, events) = shared();
|
||||
let mut first = connection(&shared);
|
||||
let mut second = connection(&shared);
|
||||
first.key(65, true).unwrap();
|
||||
first.key(65, true).unwrap();
|
||||
second.key(65, false).unwrap();
|
||||
first.release_all().unwrap();
|
||||
assert_eq!(
|
||||
events.try_iter().collect::<Vec<_>>(),
|
||||
["key 65 true", "key 65 true", "key 65 false"]
|
||||
);
|
||||
assert!(shared.lock().unwrap().keys.is_empty());
|
||||
}
|
||||
}
|
||||
+31
-5
@@ -171,6 +171,22 @@ fn deploy_terminal_proxy(install_dir: &Path) -> Result<PathBuf> {
|
||||
|
||||
/// The client UI needs the Evergreen WebView2 runtime; the official
|
||||
/// bootstrapper ships inside the client's bin directory.
|
||||
const WEBVIEW2_DLL_OVERRIDES: &str = "wtsapi32=b,wevtapi=b";
|
||||
|
||||
fn webview2_install_command(prefix: &Path, bootstrapper: &Path) -> Command {
|
||||
let mut command = Command::new("wine");
|
||||
command
|
||||
.env("WINEPREFIX", prefix)
|
||||
.env("WINEDEBUG", wine_debug())
|
||||
// The bootstrapper is a 32-bit process. uur's native preload DLLs are
|
||||
// 64-bit, so inherited global native-only overrides make its updater
|
||||
// unable to load WTSAPI32.dll under WoW64.
|
||||
.env("WINEDLLOVERRIDES", WEBVIEW2_DLL_OVERRIDES)
|
||||
.arg(bootstrapper)
|
||||
.args(["/silent", "/install"]);
|
||||
command
|
||||
}
|
||||
|
||||
fn ensure_webview2(prefix: &Path, install_dir: &Path) -> Result<()> {
|
||||
let marker = prefix.join("drive_c/Program Files (x86)/Microsoft/EdgeWebView/Application");
|
||||
if marker.exists() {
|
||||
@@ -183,11 +199,7 @@ fn ensure_webview2(prefix: &Path, install_dir: &Path) -> Result<()> {
|
||||
anyhow::bail!("{}", t!("session.webview_missing"));
|
||||
}
|
||||
println!("{}", t!("session.installing_webview"));
|
||||
let status = Command::new("wine")
|
||||
.env("WINEPREFIX", prefix)
|
||||
.env("WINEDEBUG", wine_debug())
|
||||
.arg(bootstrapper.to_string_lossy().as_ref())
|
||||
.args(["/silent", "/install"])
|
||||
let status = webview2_install_command(prefix, &bootstrapper)
|
||||
.status()
|
||||
.context("running the WebView2 bootstrapper")?;
|
||||
if !status.success() {
|
||||
@@ -716,6 +728,20 @@ fn wine_debug() -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::ffi::OsStr;
|
||||
|
||||
#[test]
|
||||
fn webview2_installer_uses_builtin_wow64_dlls() {
|
||||
let command = webview2_install_command(
|
||||
Path::new("/tmp/uur-wine-prefix"),
|
||||
Path::new("/tmp/MicrosoftEdgeWebview2Setup.exe"),
|
||||
);
|
||||
let overrides = command
|
||||
.get_envs()
|
||||
.find_map(|(name, value)| (name == OsStr::new("WINEDLLOVERRIDES")).then_some(value))
|
||||
.flatten();
|
||||
assert_eq!(overrides, Some(OsStr::new(WEBVIEW2_DLL_OVERRIDES)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tasklist_parser_matches_the_exact_image() {
|
||||
|
||||
+35
-5
@@ -141,13 +141,15 @@ pub fn setup(accept_eula: bool) -> Result<()> {
|
||||
/// - GameViewerServer.exe sees Windows 10 because current UU terminal builds
|
||||
/// gate their ConPTY transport on the OS version. Native input and display
|
||||
/// adapters handle the hardware capabilities separately;
|
||||
/// - the UU client and service prefer their bundled msvcp140 runtime. Wine 10's
|
||||
/// builtin implementation can stall UU 4.41 before the WebView starts;
|
||||
/// - the service must auto-start;
|
||||
/// - X11 focus/XIM tuning and CJK font substitution keep the controller
|
||||
/// usable.
|
||||
type RegistryEntry = (String, Vec<(&'static str, &'static str, &'static str)>);
|
||||
|
||||
pub fn apply_registry_compat(prefix: &Path) -> Result<()> {
|
||||
let entries: Vec<RegistryEntry> = vec![
|
||||
fn registry_compat_entries() -> Vec<RegistryEntry> {
|
||||
vec![
|
||||
(
|
||||
r#"Software\Wine\AppDefaults\msedgewebview2.exe"#.to_string(),
|
||||
vec![("Version", "REG_SZ", "win8")],
|
||||
@@ -156,6 +158,14 @@ pub fn apply_registry_compat(prefix: &Path) -> Result<()> {
|
||||
r#"Software\Wine\AppDefaults\GameViewerServer.exe"#.to_string(),
|
||||
vec![("Version", "REG_SZ", "win10")],
|
||||
),
|
||||
(
|
||||
r#"Software\Wine\AppDefaults\gameviewer.exe\DllOverrides"#.to_string(),
|
||||
vec![("msvcp140", "REG_SZ", "native,builtin")],
|
||||
),
|
||||
(
|
||||
r#"Software\Wine\AppDefaults\GameViewerServer.exe\DllOverrides"#.to_string(),
|
||||
vec![("msvcp140", "REG_SZ", "native,builtin")],
|
||||
),
|
||||
(
|
||||
r"System\CurrentControlSet\Services\GameViewerService".to_string(),
|
||||
vec![("Start", "REG_DWORD", "2")],
|
||||
@@ -175,15 +185,17 @@ pub fn apply_registry_compat(prefix: &Path) -> Result<()> {
|
||||
("MS Shell Dlg 2", "REG_SZ", "Noto Sans CJK SC"),
|
||||
],
|
||||
),
|
||||
];
|
||||
]
|
||||
}
|
||||
|
||||
for (key, values) in &entries {
|
||||
pub fn apply_registry_compat(prefix: &Path) -> Result<()> {
|
||||
for (key, values) in registry_compat_entries() {
|
||||
let full = if key.starts_with("System") {
|
||||
format!("HKLM\\{key}")
|
||||
} else {
|
||||
format!("HKCU\\{key}")
|
||||
};
|
||||
for (value, reg_type, data) in values {
|
||||
for (value, reg_type, data) in &values {
|
||||
let _ = Command::new("wine")
|
||||
.env("WINEPREFIX", prefix)
|
||||
.env("WINEDEBUG", wine_debug())
|
||||
@@ -407,3 +419,21 @@ fn purge_wine_shortcuts() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::registry_compat_entries;
|
||||
|
||||
#[test]
|
||||
fn bundled_cpp_runtime_is_preferred_for_both_uu_processes() {
|
||||
let entries = registry_compat_entries();
|
||||
for executable in ["gameviewer.exe", "GameViewerServer.exe"] {
|
||||
let key = format!(r"Software\Wine\AppDefaults\{executable}\DllOverrides");
|
||||
let values = entries
|
||||
.iter()
|
||||
.find_map(|(entry, values)| (entry == &key).then_some(values))
|
||||
.unwrap_or_else(|| panic!("missing DLL overrides for {executable}"));
|
||||
assert!(values.contains(&("msvcp140", "REG_SZ", "native,builtin")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "../hook/cursor-overlay.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uur_cursor_rect source = {0, 0, 1920, 1080};
|
||||
uur_cursor_rect destination = {0, 0, 1920, 1080};
|
||||
uur_cursor_rect overlay;
|
||||
uur_cursor_shape cursor = {100, 200, 64, 48, 16, 8};
|
||||
|
||||
/* A negative virtual-screen origin must not shift a primary-screen blit. */
|
||||
assert(uur_map_cursor_overlay(&source, &destination, &cursor, &overlay));
|
||||
assert(overlay.x == 84 && overlay.y == 192);
|
||||
assert(overlay.width == 64 && overlay.height == 48);
|
||||
|
||||
source.x = -1920;
|
||||
cursor.x = -1820;
|
||||
assert(uur_map_cursor_overlay(&source, &destination, &cursor, &overlay));
|
||||
assert(overlay.x == 84);
|
||||
|
||||
/* StretchBlt scales the cursor bitmap and hotspot together. */
|
||||
destination.width = 960;
|
||||
destination.height = 540;
|
||||
assert(uur_map_cursor_overlay(&source, &destination, &cursor, &overlay));
|
||||
assert(overlay.x == 42 && overlay.y == 96);
|
||||
assert(overlay.width == 32 && overlay.height == 24);
|
||||
|
||||
/* A cursor overlapping the capture edge remains partially visible. */
|
||||
cursor.x = -1925;
|
||||
assert(uur_map_cursor_overlay(&source, &destination, &cursor, &overlay));
|
||||
cursor.x = -2000;
|
||||
assert(!uur_map_cursor_overlay(&source, &destination, &cursor, &overlay));
|
||||
|
||||
assert(uur_cursor_bitmap_height(48, 1) == 48);
|
||||
assert(uur_cursor_bitmap_height(96, 0) == 48);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user