Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ curl -LO https://github.com/MemerGamer/LinuxFiles/releases/download/nightly/Linu
- [Showcase](../docs/linux-port/SHOWCASE.md): screenshots and the feature checklist
- [Packaging details](../docs/linux-port/packaging.md) and the [roadmap](../docs/linux-port/PLAN.md)

## Troubleshooting

**Soft text or icons on niri / xwayland-satellite:** Enable **Detect display scale from the compositor (experimental)** in Settings > Appearance and restart Files to use niri's focused output scale when no Uno, Xft, GDK or Qt scale hint is present and both `NIRI_SOCKET` and `WAYLAND_DISPLAY` are set. Check stderr for `[display-scale]` to see whether IPC or CLI detection succeeded. Detection defaults off and may double-scale on some setups. `FILES_NIRI_SCALE=1` forces it on and `FILES_NIRI_SCALE=0` forces it off, overriding the saved preference. Launch with `UNO_DISPLAY_SCALE_OVERRIDE=1.25 files` to select a scale manually (replace `1.25` with your output scale). The scale is chosen at startup. See [display scale details](../docs/linux-port/appearance-transparency.md#display-scale-on-niri).

## Reporting bugs

- **Linux bugs and Linux feature requests:** open an issue in [this fork](https://github.com/MemerGamer/LinuxFiles/issues).
Expand Down
8 changes: 8 additions & 0 deletions docs/linux-port/appearance-transparency.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ Settings > Appearance > Backdrop (`BackdropMode`) with Background opacity (`Back
## Not offered
- **Native Wayland / org_kde_kwin_blur.** The Skia host is X11 only.
- **Backdrop material (Mica/Acrylic).** Not implemented on Linux; the Backdrop material card is hidden.

## Display scale on niri

On niri with xwayland-satellite, Files can render at 1x when XWayland publishes no DPI, leaving text and icons soft after compositor scaling. Enable **Detect display scale from the compositor (experimental)** in Settings > Appearance to detect the output scale at startup as a last resort. The boolean `DetectCompositorDisplayScale` defaults to false and is read directly from the XDG user settings file before Uno/window creation, without DI. Missing, non-regular or malformed settings leave detection off. The saved preference is read only when niri detection is eligible and no environment override is set. **Restart required; some setups may double-scale.** Existing scale hints retain precedence: `UNO_DISPLAY_SCALE_OVERRIDE`, any `Xft.dpi` resource, `GDK_SCALE`/`GDK_DPI_SCALE`, or `QT_SCALE_FACTOR`/`QT_SCREEN_SCALE_FACTORS` take precedence, including an explicit 1x or malformed hint. Both `NIRI_SOCKET` and `WAYLAND_DISPLAY` must be set.

The fallback queries the Unix socket named by `NIRI_SOCKET` for `Outputs` and `FocusedOutput`. The [niri IPC protocol](https://github.com/YaLTeR/niri/blob/main/niri-ipc/src/lib.rs) encodes these unit requests as JSON strings (`"Outputs"` and `"FocusedOutput"`), each terminated by a newline. It reads `logical.scale` from the focused output, or the first output if focus is unavailable. If socket detection fails, it resolves `niri` through the existing absolute-directory PATH lookup and runs `niri msg --json outputs` (and `focused-output`) without a shell. Socket detection and the CLI fallback each have a 500 ms budget, with up to another 500 ms to reap a terminated CLI process; replies are capped at 256 KiB. Errors, timeouts and invalid output scales leave the existing detection unchanged. Valid scales are clamped to 1–4, and the selected IPC/CLI source is logged once to stderr as `[display-scale]`.

After the display/toolkit hints, `FILES_NIRI_SCALE=1` forces this fallback on and `FILES_NIRI_SCALE=0` forces it off, overriding the saved setting. Unset or other values use the setting. Neither value overrides display/toolkit hints. To choose a scale manually, launch with e.g. `UNO_DISPLAY_SCALE_OVERRIDE=1.25 files` (use your output's scale). Detection runs once before Uno starts; moving the window between outputs does not update the scale. A sandbox that cannot access the niri socket or executable may still need the manual override.
8 changes: 4 additions & 4 deletions docs/linux-port/investigations/pixelation-findings.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pixelated / soft text and icons on Wayland (niri + xwayland-satellite, fractional scale)

Status: diagnosis only; no app change was justified by the measurements. Follows `ui-frameworks-wayland.md`.
Status: original headless diagnosis below; the missing-scale niri case is now addressed by the [startup IPC fallback](../appearance-transparency.md#display-scale-on-niri). Follows `ui-frameworks-wayland.md`.

## Method
Headless only (`scripts/linux/headless-run.sh`, private Xvfb, sandbox HOME, `FILES_SANDBOX_DRIVES=scripts/linux/showcase-drives.txt`, 1600x1000), debug build of main (5 Oct). The scale is driven by `FILES_HEADLESS_XFT_DPI` (writes `Xft.dpi` to the private display): 96 = 1x, 144 = 1.5x, 192 = 2x. Uno reads `Xft.dpi` itself; `UNO_DISPLAY_SCALE_OVERRIDE=<factor>` (e.g. `1.5`, not a DPI) also works, `DisplayScaleResolver` falls back to `QT_SCALE_FACTOR`/`GDK_SCALE`. At 1.5x/2x the window is the same 1280x800 physical size, so fewer logical pixels fit (at 2x the sidebar collapses). Pixel crops were taken with ImageMagick (nearest-neighbour zoom).
Expand All @@ -12,12 +12,12 @@ Headless only (`scripts/linux/headless-run.sh`, private Xvfb, sandbox HOME, `FIL
- **DPI reporting is correct when `Xft.dpi` is an integer** (`DisplayScaleResolver` already converts fractional `Xft.dpi` and the Qt/GDK variables to an override). Icon caches (`IconCacheService`, `LinuxIconThemeProvider`) key on logical size, not scale; only a live scale change (moving between monitors) would serve stale-resolution bitmaps. Not observed, not fixed.

## Cause breakdown for the reported blur
1. **XWayland upscaling (dominant, not fixable in-app).** If the compositor/xwayland-satellite does not publish a fractional scale (no `Xft.dpi`, no `GDK_SCALE`), Uno renders at 1.0 and the compositor stretches the whole buffer by 1.5. Everything (text and icons) is then uniformly soft regardless of how well the app rasterises. Only a native Wayland host (fractional-scale-v1 + viewporter, see `ui-frameworks-wayland.md`) removes this. This could not be reproduced here: Xvfb has no compositor resampling.
1. **XWayland upscaling (dominant in the original report).** If the compositor/xwayland-satellite does not publish a fractional scale (no `Xft.dpi`, no `GDK_SCALE`), Uno renders at 1.0 and the compositor stretches the whole buffer by 1.5. Everything (text and icons) is then uniformly soft regardless of how well the app rasterises. The reporter subsequently confirmed that `UNO_DISPLAY_SCALE_OVERRIDE=1.25` renders crisply at the correct size on their niri + xwayland-satellite setup. The experimental opt-in startup IPC fallback supplies that missing scale when enabled in Settings > Appearance; native Wayland (fractional-scale-v1 + viewporter, see `ui-frameworks-wayland.md`) remains a separate host improvement. This could not be reproduced here: Xvfb has no compositor resampling.
2. **Hinting at 1x (small, upstream).** `Normal` hinting on Selawik gives the blocky look at 100%. Needs Uno to expose `SKFont.Hinting` (Slight/None); no supported switch.
3. **Icons/DPI plumbing (no defect found).**

## What a user can do today (no code change)
## Manual scale override
Make the X11 side advertise the real scale so Uno renders at device resolution: launch with `UNO_DISPLAY_SCALE_OVERRIDE=1.5` (match the output scale) or export `Xft.dpi: 144` into the XWayland session. Whether xwayland-satellite then also rescales the surface (double scaling) depends on its version and was not verifiable without the real display; check on the real session.

## Not done
No code was changed because every app-side lever either already behaves correctly (icons, DPI) or is unreachable without patching Uno (hinting). Candidate follow-ups: ask/patch Uno for `SKFontHinting.Slight`; read the real output scale from niri IPC (`NIRI_SOCKET`) or the portal when `Xft.dpi` is absent (unverified without a real compositor); native Wayland host.
The original investigation made no code changes. The niri missing-scale fallback is now implemented; visual confirmation on the reporter's compositor and live scale changes between monitors remain unverified. Candidate follow-ups: ask/patch Uno for `SKFontHinting.Slight`; native Wayland host.
1 change: 1 addition & 0 deletions src/Files.App/Data/Contracts/IAppearanceSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public interface IAppearanceSettingsService : IBaseSettingsService, INotifyPrope
ColourSource ColourSource { get; set; }
BackdropMode BackdropMode { get; set; }
float BackgroundOpacity { get; set; }
bool DetectCompositorDisplayScale { get; set; }

/// <summary>
/// Gets or sets a value for the app theme background color.
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Services/Settings/AppearanceSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public BackdropMode BackdropMode
set => Set(value.ToString());
}

public bool DetectCompositorDisplayScale
{
get => Get(false);
set => Set(value);
}

public float BackgroundOpacity
{
get => AppearancePreferences.ClampOpacity(Get(0.85f), 0);
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -5126,4 +5126,10 @@
<data name="LinuxOpacityHighContrast" xml:space="preserve">
<value>High contrast keeps the window opaque. Your opacity choice is retained.</value>
</data>
<data name="LinuxDetectCompositorDisplayScale" xml:space="preserve">
<value>Detect display scale from the compositor (experimental)</value>
</data>
<data name="LinuxDetectCompositorDisplayScaleDescription" xml:space="preserve">
<value>Requires a restart. Uses the niri output scale when no display or toolkit scale is configured. May double-scale on some setups.</value>
</data>
</root>
9 changes: 9 additions & 0 deletions src/Files.App/ViewModels/Settings/AppearanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public int SelectedBackdropMode
OnPropertyChanged(nameof(IsBackgroundOpacityEnabled));
}
}
public bool DetectCompositorDisplayScale
{
get => UserSettingsService.AppearanceSettingsService.DetectCompositorDisplayScale;
set
{
UserSettingsService.AppearanceSettingsService.DetectCompositorDisplayScale = value;
OnPropertyChanged();
}
}
public float BackgroundOpacity
{
get => UserSettingsService.AppearanceSettingsService.BackgroundOpacity;
Expand Down
9 changes: 9 additions & 0 deletions src/Files.App/Views/Settings/AppearancePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@
Value="{x:Bind ViewModel.BackgroundOpacity, Mode=TwoWay}" />
</wctcontrols:SettingsCard>

<wctcontrols:SettingsCard
Visibility="{x:Bind ViewModel.LinuxAppearanceVisibility}"
Header="{helpers:ResourceString Key=LinuxDetectCompositorDisplayScale}"
Description="{helpers:ResourceString Key=LinuxDetectCompositorDisplayScaleDescription}">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Key=LinuxDetectCompositorDisplayScale}"
IsOn="{x:Bind ViewModel.DetectCompositorDisplayScale, Mode=TwoWay}" />
</wctcontrols:SettingsCard>

<!-- Whole-window opacity -->
<wctcontrols:SettingsCard
x:Name="WindowOpacityCard"
Expand Down
41 changes: 41 additions & 0 deletions src/Files.Platform.Linux/Windowing/CompositorScaleSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.Platform.Linux.Previews;
using System;
using System.IO;
using System.Text.Json;

namespace Files.Platform.Linux.Windowing
{
/// <summary>Reads the startup scale preference without constructing the app's settings services.</summary>
public static class CompositorScaleSettings
{
public const string SettingName = "DetectCompositorDisplayScale";
private const int MaxSettingsLength = 1024 * 1024;

public static bool Read(string settingsPath)
{
try
{
using var stream = PreviewFile.OpenRead(settingsPath);
var fileLength = stream.Length;
if (fileLength > MaxSettingsLength)
return false;
// Limit the actual read as well, in case a concurrent writer grows the file.
var buffer = new byte[(int)fileLength + 1];
var length = stream.ReadAtLeast(buffer, buffer.Length, throwOnEndOfStream: false);
if (length == buffer.Length)
return false;
var offset = length >= 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF ? 3 : 0;
using var document = JsonDocument.Parse(buffer.AsMemory(offset, length - offset));
return document.RootElement.ValueKind == JsonValueKind.Object &&
document.RootElement.TryGetProperty(SettingName, out var value) && value.ValueKind == JsonValueKind.True;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException or NotSupportedException or ArgumentException)
{
return false;
}
}
}
}
116 changes: 112 additions & 4 deletions src/Files.Platform.Linux/Windowing/DisplayScaleResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
using System;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Threading;

namespace Files.Platform.Linux.Windowing
{
/// <summary>
/// Works out the display scale to hand to Uno. Uno's X11 host reads <c>Xft.dpi</c> (set by KDE and GNOME on X11) and honours
/// <c>UNO_DISPLAY_SCALE_OVERRIDE</c>; this fills the gap when <c>Xft.dpi</c> is absent (some XWayland sessions) from toolkit variables.
/// <c>UNO_DISPLAY_SCALE_OVERRIDE</c>; this fills the gap when <c>Xft.dpi</c> is absent (some XWayland sessions) from toolkit variables or niri IPC.
/// </summary>
public static class DisplayScaleResolver
{
public const string OverrideVariable = "UNO_DISPLAY_SCALE_OVERRIDE";

private static int niriSourceLogged;

/// <summary>
/// Returns the value to assign to <see cref="OverrideVariable"/>, or null when Uno's own detection should be used.
/// </summary>
public static string? Resolve(Func<string, string?> getEnv, string? xResources)
public static string? Resolve(Func<string, string?> getEnv, string? xResources, Func<double?>? readNiriScale = null,
bool detectCompositorDisplayScale = false, Func<bool>? readCompositorScaleSetting = null)
{
if (!string.IsNullOrWhiteSpace(getEnv(OverrideVariable)))
return null;
Expand All @@ -38,7 +43,100 @@ public static class DisplayScaleResolver
double? scale = global is null && screen is null ? null : (global ?? 1.0) * (screen ?? 1.0);
scale ??= ParseScale(getEnv("GDK_SCALE"));

return scale is { } s && s > 1.0 ? Math.Min(s, 4.0).ToString("0.##", CultureInfo.InvariantCulture) : null;
if (scale is { } s && s > 1.0)
return Math.Min(s, 4.0).ToString("0.##", CultureInfo.InvariantCulture);

if (string.IsNullOrWhiteSpace(getEnv("NIRI_SOCKET")) || string.IsNullOrWhiteSpace(getEnv("WAYLAND_DISPLAY")) ||
GetXftDpiText(xResources) is not null)
return null;

foreach (var variable in new[] { OverrideVariable, "GDK_SCALE", "GDK_DPI_SCALE", "QT_SCALE_FACTOR", "QT_SCREEN_SCALE_FACTORS" })
if (!string.IsNullOrEmpty(getEnv(variable)))
return null;

try
{
if (!(getEnv("FILES_NIRI_SCALE") switch
{
"1" => true,
"0" => false,
_ => readCompositorScaleSetting?.Invoke() ?? detectCompositorDisplayScale,
}))
return null;

return readNiriScale?.Invoke() is { } niri && double.IsFinite(niri) && niri > 0
? Math.Clamp(niri, 1.0, 4.0).ToString("0.###", CultureInfo.InvariantCulture) : null;
}
catch (Exception)
{
return null;
}
}

/// <summary>
/// Reads niri's socket reply or CLI output, preferring the separately queried focused output.
/// </summary>
public static double? ParseNiriOutputs(string? outputsJson, string? focusedOutputJson = null)
{
if (string.IsNullOrWhiteSpace(outputsJson) || outputsJson.Length > NiriScaleClient.MaxResponseLength)
return null;

try
{
using var document = JsonDocument.Parse(outputsJson);
var outputs = UnwrapNiriReply(document.RootElement, "Outputs");
if (outputs.ValueKind != JsonValueKind.Object)
return null;

var focusedName = ParseNiriFocusedName(focusedOutputJson);
JsonElement? first = null;
foreach (var output in outputs.EnumerateObject())
{
first ??= output.Value;
if (output.Name == focusedName)
return ParseNiriOutputScale(output.Value);
}
return first is { } fallback ? ParseNiriOutputScale(fallback) : null;
}
catch (JsonException)
{
return null;
}
}

private static JsonElement UnwrapNiriReply(JsonElement root, string response)
{
if (root.ValueKind == JsonValueKind.Object && root.TryGetProperty("Err", out _))
return default;
if (root.ValueKind == JsonValueKind.Object && root.TryGetProperty("Ok", out var ok))
return ok.ValueKind == JsonValueKind.Object && ok.TryGetProperty(response, out var result) ? result : default;
return root;
}

private static string? ParseNiriFocusedName(string? json)
{
if (string.IsNullOrWhiteSpace(json) || json.Length > NiriScaleClient.MaxResponseLength)
return null;
try
{
using var document = JsonDocument.Parse(json);
var output = UnwrapNiriReply(document.RootElement, "FocusedOutput");
return output.ValueKind == JsonValueKind.Object && output.TryGetProperty("name", out var name) && name.ValueKind == JsonValueKind.String
? name.GetString() : null;
}
catch (JsonException)
{
return null;
}
}

private static double? ParseNiriOutputScale(JsonElement output)
{
if (output.ValueKind != JsonValueKind.Object || !output.TryGetProperty("logical", out var logical) ||
logical.ValueKind != JsonValueKind.Object || !logical.TryGetProperty("scale", out var value) ||
value.ValueKind != JsonValueKind.Number || !value.TryGetDouble(out var scale) || !double.IsFinite(scale) || scale <= 0)
return null;
return Math.Clamp(scale, 1.0, 4.0);
}

/// <summary>
Expand Down Expand Up @@ -133,9 +231,12 @@ public static void ApplyToProcess()
return;

string? resolved;
string? niriSource = null;
try
{
resolved = Resolve(Environment.GetEnvironmentVariable, ReadXResources());
resolved = Resolve(Environment.GetEnvironmentVariable, ReadXResources(),
() => NiriScaleClient.ReadScale(out niriSource),
readCompositorScaleSetting: () => CompositorScaleSettings.Read(new LinuxAppDataPaths().UserSettingsFilePath));
}
catch (Exception)
{
Expand All @@ -144,7 +245,14 @@ public static void ApplyToProcess()
}

if (resolved is not null)
{
Environment.SetEnvironmentVariable(OverrideVariable, resolved);
if (niriSource is not null && Interlocked.Exchange(ref niriSourceLogged, 1) == 0)
{
try { Console.Error.WriteLine($"[display-scale] Using niri {niriSource}: {resolved}"); }
catch (System.IO.IOException) { }
}
}
}

private static string? ReadXResources()
Expand Down
Loading
Loading