fix(kodi): patch stremio CEF to support HiDPI scaling via env var
CI / check (push) Failing after 12m18s
CI / build-and-cache (push) Has been skipped
CI / Check OpenClaw Changes (push) Has been skipped
CI / Build & Push OpenClaw Image (push) Has been skipped

The beta.13 clap parser ignores unknown --force-device-scale-factor flags
and CEF Args::new() starts empty, so CLI flags never reach the CEF subprocess.
Patch src/webview/mod.rs to read STREMIO_FORCE_DEVICE_SCALE_FACTOR and pass
it to CEF via append_switch_with_value. Remove failed GTK4/master branch
build attempt (requires GTK 4.22 not yet in nixpkgs).
This commit is contained in:
2026-05-12 08:48:50 -07:00
parent 71685f9419
commit da21505667
6 changed files with 71 additions and 160 deletions
+43 -22
View File
@@ -22,7 +22,7 @@ in
stremioScaleFactor = mkOption {
type = types.nullOr types.float;
default = null;
description = "Scale factor for Stremio UI via GDK_BACKEND=x11 + GDK_SCALE (e.g., 2.0 for 200% scaling). Forces XWayland mode since GTK4 ignores GDK_SCALE on native Wayland.";
description = "Scale factor for Stremio UI (e.g., 2.0 for 200% scaling). Sets STREMIO_FORCE_DEVICE_SCALE_FACTOR which passes --force-device-scale-factor to the CEF subprocess via a source patch.";
};
appLauncherServer = {
enable = mkOption {
@@ -70,22 +70,19 @@ in
}
else pkgs.qt-pinned.jellyfin-media-player;
# stremio-linux-shell is a GTK4/libadwaita + WebKitGTK app (not Electron/CEF).
# --force-device-scale-factor is a Chromium flag that it ignores entirely.
# On Wayland, GTK4 reads scale from the compositor via wp_fractional_scale_v1.
# To force a specific scale, we use GDK_BACKEND=x11 + GDK_SCALE which works
# reliably under XWayland. On native Wayland, GDK_SCALE is ignored.
# Format floats cleanly: 2.0 -> "2", 1.5 -> "1.5"
stremioScaleStr = let
sf = cfg.stremioScaleFactor;
# Format float for env var: 2.0 -> "2", 1.5 -> "1.5"
# (Nix's toString 2.0 gives "2.000000" which is unclean)
formatScale = sf: let
intPart = builtins.floor sf;
s = builtins.toString sf;
m = builtins.match "([0-9]+)\\.([0-9]*[1-9])0*" s;
gdkScale = builtins.toString intPart;
in if sf == intPart then builtins.toString intPart
else if m != null then (builtins.elemAt m 0) + "." + (builtins.elemAt m 1)
else s;
else let s = builtins.toString sf;
m = builtins.match "([0-9]+)\\.([0-9]*[1-9])0*" s;
in if m != null then (builtins.elemAt m 0) + "." + (builtins.elemAt m 1)
else s;
# stremio-linux-shell is CEF-based. We patch it (via flake overlay) to read
# STREMIO_FORCE_DEVICE_SCALE_FACTOR and pass it to CEF as
# --force-device-scale-factor, which is the standard Chromium flag for HiDPI.
stremioPkg =
if cfg.stremioScaleFactor != null
then pkgs.symlinkJoin {
@@ -96,15 +93,14 @@ in
mkdir -p $out/bin
rm -f $out/bin/stremio
makeWrapper ${pkgs.stremio-linux-shell}/bin/stremio $out/bin/stremio \
--set GDK_BACKEND x11 \
--set GDK_SCALE ${builtins.toString (builtins.floor cfg.stremioScaleFactor)}
--set STREMIO_FORCE_DEVICE_SCALE_FACTOR ${formatScale cfg.stremioScaleFactor}
# Update .desktop file to force XWayland + GDK_SCALE for scaling
# Update .desktop file to set the env var
mkdir -p $out/share/applications
rm -f $out/share/applications/com.stremio.Stremio.desktop
substitute ${pkgs.stremio-linux-shell}/share/applications/com.stremio.Stremio.desktop \
$out/share/applications/com.stremio.Stremio.desktop \
--replace-fail "Exec=sh -c " "Exec=env GDK_BACKEND=x11 GDK_SCALE=${builtins.toString (builtins.floor cfg.stremioScaleFactor)} sh -c "
--replace-fail "Exec=sh -c " "Exec=env STREMIO_FORCE_DEVICE_SCALE_FACTOR=${formatScale cfg.stremioScaleFactor} sh -c "
'';
}
else pkgs.stremio-linux-shell;
@@ -155,9 +151,34 @@ in
};
services.displayManager = mkIf cfg.autologin {
autoLogin.enable = true;
autoLogin.user = "kodi";
defaultSession = "plasma";
autoLogin = {
enable = true;
user = "kodi";
};
};
# Kodi user home manager configuration
home-manager.users.kodi = {
home.stateVersion = "24.05";
# Auto-start Kodi in fullscreen after login
xsession = mkIf (!cfg.wayland) {
windowManager.command = ''
${kodiPkg}/bin/kodi --fullscreen
'';
};
# Use a simple .xsession for X11 or a wayland startup script
home.file = mkIf cfg.wayland {
".config/autostart/kodi.desktop".text = ''
[Desktop Entry]
Type=Application
Name=Kodi
Exec=${kodiPkg}/bin/kodi --fullscreen
X-GNOME-Autostart-enabled=true
Hidden=false
'';
};
};
};
}
}