mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 22:45:41 +00:00
Linux: session-native GDK/WebKit mitigations and in-page browse scroll (#731)
* feat(linux): session GDK defaults, nvidia-quirk, optional x11-legacy wrap Ship PSYSONIC_ALLOW_NATIVE_GDK from Nix/AUR instead of pinning WEBKIT_DISABLE_* and GDK x11. Add flake psysonic-x11-legacy for the old wrap; alias gdk-session to psysonic. Startup uses webkit2gtk-nvidia-quirk and Wayland-aware compositing; refresh Help (a45) and nixos-install docs. * fix(linux): session GDK and nvidia-quirk only; drop wrapper env heuristics Remove PSYSONIC_ALLOW_NATIVE_GDK and devShell GDK/WEBKIT exports; stop synthesizing GDK/WebKit vars in main.rs. Update Nix/AUR wrappers, install docs, CHANGELOG, and help FAQ with practical user-facing workarounds. * fix(linux): X11-pinned GDK uses DMABUF quirk path, not Wayland explicit-sync When GDK_BACKEND is forced to x11 on a wayland user session, webkit2gtk-nvidia-quirk would still apply __NV_DISABLE_EXPLICIT_SYNC and gray out the webview. Map that case to WEBKIT_DISABLE_DMABUF_RENDERER like native X11. * fix(ui): stabilize WebKitGTK/Wayland hover paint for nav and media cards Sidebar nav links avoid transition:all and promote icons with translateZ(0). Artist rows and album/artist/song cards use compositing hints; card shadows and borders no longer interpolate so cover zoom can stay smooth without jitter. * fix(ui): isolate artist/album card text and cover paint on WebKitGTK Promote cover blocks with contain/paint and text stacks with translateZ(0); use artist-card-info on the artists grid for the same layout as other cards. * feat(artists): in-page overlay scroll and locked main viewport Move list/grid into an inner OverlayScrollArea, stop sticky toolbar from owning the route scroll, align the rail with the main panel edge, and skip the main-route overlay thumb when the viewport cannot scroll vertically. * feat(browse): extend in-page overlay scroll to more library routes Reuse the locked main viewport pattern from Artists for Albums, Composers, Lossless albums, and New releases; wire VirtualCardGrid and scroll chrome to the matching in-page viewport ids. * fix(linux): improve Wayland GPU compositing text clarity in WebKitGTK Use on-demand hardware acceleration on main and mini webviews when the session is Wayland and compositing stays on; gate subpixel body AA on the same conditions via new Tauri probes. Document PSYSONIC_SKIP_WAYLAND_FONT_TUNING for opt-out and changelog. * fix(rust): satisfy clippy needless_return in Linux webkit helpers * fix(linux): tune Wayland text rendering with HW policy env and CSS Allow PSYSONIC_WEBKIT_WAYLAND_HW_POLICY to select WebKit hardware acceleration policy (never/always vs default on-demand). Extend Wayland font CSS to #root with geometricPrecision and text-size-adjust on html. * feat(linux): Wayland text presets in settings, safe WebKit apply, CPU default Persist profile to app config; apply WebKit policy at startup/mini only to avoid WebKitGTK hangs on live toggles. UI + CSS preview stays live; default preset is sharp (CPU-friendly). * fix(linux): map Wayland sharp preset to OnDemand WebKit policy HardwareAccelerationPolicy::Never at startup broke main-viewport wheel scrolling on WebKitGTK+Wayland; sharp vs balanced remains a CSS AA path. Use PSYSONIC_WEBKIT_WAYLAND_HW_POLICY for a true Never policy. * fix(rust): gate Linux-only Wayland WebKit helpers for Windows builds Re-export startup helpers only under cfg(linux) and drop non-Linux stubs so Windows compiles without unused-import and dead-code warnings. * chore(release): CHANGELOG + credits for Linux session/WebKit work (PR #731) Consolidate scattered incremental changelog notes into two [1.47.0] entries with PR link; remove duplicate Linux blocks from [1.46.0] Fixed. Append settings credit line for cucadmuh.
This commit is contained in:
+25
-59
@@ -2,75 +2,41 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
enum GpuVendor {
|
||||
Nvidia,
|
||||
Intel,
|
||||
Amd,
|
||||
}
|
||||
use webkit2gtk_nvidia_quirk::{
|
||||
apply_workaround_with_options, needs_workaround, set_webkit_disable_dmabuf_renderer,
|
||||
ApplyWorkaroundOptions, WorkaroundKind,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn detect_gpu_vendor() -> Option<GpuVendor> {
|
||||
use std::fs;
|
||||
|
||||
if fs::metadata("/proc/driver/nvidia/version").is_ok() {
|
||||
return Some(GpuVendor::Nvidia);
|
||||
fn apply_linux_webkit_nvidia_quirk() {
|
||||
if std::env::var("PSYSONIC_WEBKIT_GPU_ACCEL").is_ok() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterate every `/sys/class/drm/card*` — hybrid laptops expose multiple
|
||||
// cards, and some systems have no `card0` at all.
|
||||
let entries = fs::read_dir("/sys/class/drm").ok()?;
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name();
|
||||
let Some(name) = name.to_str() else { continue };
|
||||
if !name.starts_with("card") || name.contains('-') {
|
||||
continue;
|
||||
}
|
||||
let Ok(vendor_id) = fs::read_to_string(entry.path().join("device/vendor")) else {
|
||||
continue;
|
||||
};
|
||||
match vendor_id.trim() {
|
||||
"0x10de" => return Some(GpuVendor::Nvidia),
|
||||
"0x8086" => return Some(GpuVendor::Intel),
|
||||
"0x1002" => return Some(GpuVendor::Amd),
|
||||
_ => {}
|
||||
// dev.sh gpu-x11 / nix psysonic-x11-legacy: WebKit uses the X11 GDK path while the session
|
||||
// may still be `XDG_SESSION_TYPE=wayland`. The quirk maps that to `__NV_DISABLE_EXPLICIT_SYNC`,
|
||||
// which mismatches a real X11 EGL stack and can leave the webview gray — mirror the native-X11
|
||||
// branch (`WEBKIT_DISABLE_DMABUF_RENDERER` only) whenever GDK is pinned to x11 first in the list.
|
||||
let forced_x11_gdk = std::env::var("GDK_BACKEND").ok().is_some_and(|s| {
|
||||
matches!(s.split(',').next().map(str::trim), Some("x11"))
|
||||
});
|
||||
if forced_x11_gdk {
|
||||
match needs_workaround() {
|
||||
WorkaroundKind::None => {}
|
||||
WorkaroundKind::DisableWebkitDmabufRenderer | WorkaroundKind::DisableNvExplicitSync => {
|
||||
set_webkit_disable_dmabuf_renderer();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
apply_workaround_with_options(ApplyWorkaroundOptions::default());
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// WebKitGTK on Wayland can be unstable — default to X11 when GDK_BACKEND is unset,
|
||||
// except when PSYSONIC_ALLOW_NATIVE_GDK is set (e.g. Nix psysonic-gdk-session wrapper).
|
||||
// Users can still override by setting GDK_BACKEND before launch.
|
||||
//
|
||||
// Safety: set_var modifies global process state. These calls are safe here
|
||||
// because we're in main() before the Tauri runtime starts — no other threads
|
||||
// exist yet. If this code moves to lazy init or a plugin context, it would
|
||||
// need synchronization or marking as unsafe (Rust 2024+).
|
||||
// Linux GTK/WebKit: `webkit2gtk-nvidia-quirk` (skipped when `PSYSONIC_WEBKIT_GPU_ACCEL` is set).
|
||||
// Forced `GDK_BACKEND=x11` uses the X11-only mitigation path — see `apply_linux_webkit_nvidia_quirk`.
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
// Nix `psysonic-gdk-session` sets this so we do not pin X11 when the packager asked for
|
||||
// session-native GDK (e.g. Wayland). Local dev can export the same var before `tauri dev`.
|
||||
let allow_native_gdk = std::env::var("PSYSONIC_ALLOW_NATIVE_GDK").is_ok();
|
||||
if std::env::var("GDK_BACKEND").is_err() && !allow_native_gdk {
|
||||
std::env::set_var("GDK_BACKEND", "x11");
|
||||
}
|
||||
if std::env::var("WEBKIT_DISABLE_COMPOSITING_MODE").is_err() {
|
||||
std::env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
|
||||
}
|
||||
|
||||
// NVIDIA proprietary adds a small but reproducible overhead on the
|
||||
// DMA-BUF renderer path (blind A/B confirmed on NVIDIA + proprietary).
|
||||
// Unknown GPUs keep the WebKitGTK default — VMs, ARM SBCs and anything
|
||||
// exotic should not be regressed by a guess.
|
||||
if std::env::var("WEBKIT_DISABLE_DMABUF_RENDERER").is_err()
|
||||
&& matches!(detect_gpu_vendor(), Some(GpuVendor::Nvidia))
|
||||
{
|
||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
||||
}
|
||||
}
|
||||
apply_linux_webkit_nvidia_quirk();
|
||||
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
if psysonic_lib::cli::wants_version(&args) {
|
||||
|
||||
Reference in New Issue
Block a user