sxmo: auto-scale the environment to accomodate non-mobile-friendly apps
this is hacky, but it hopefully makes gnome-maps usable, quickly. an alternative fix would be to theme gnome-maps. it's likely also that it becomes more mobile-friendly in the gnome 45 release.
This commit is contained in:
@@ -67,6 +67,7 @@
|
|||||||
./stepmania.nix
|
./stepmania.nix
|
||||||
./sublime-music.nix
|
./sublime-music.nix
|
||||||
./supertuxkart.nix
|
./supertuxkart.nix
|
||||||
|
./sway-autoscaler
|
||||||
./swaynotificationcenter.nix
|
./swaynotificationcenter.nix
|
||||||
./tangram.nix
|
./tangram.nix
|
||||||
./tor-browser-bundle-bin.nix
|
./tor-browser-bundle-bin.nix
|
||||||
|
44
hosts/common/programs/sway-autoscaler/default.nix
Normal file
44
hosts/common/programs/sway-autoscaler/default.nix
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.sane.programs.sway-autoscaler;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
sane.programs.sway-autoscaler = {
|
||||||
|
configOption = with lib; mkOption {
|
||||||
|
default = {};
|
||||||
|
type = types.submodule {
|
||||||
|
options.autostart = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
options.defaultScale = mkOption {
|
||||||
|
type = types.number;
|
||||||
|
default = 1;
|
||||||
|
};
|
||||||
|
options.interval = mkOption {
|
||||||
|
type = types.number;
|
||||||
|
default = 5;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
package = pkgs.static-nix-shell.mkBash {
|
||||||
|
pname = "sway-autoscaler";
|
||||||
|
pkgs = [ "jq" "sway" ];
|
||||||
|
src = ./.;
|
||||||
|
};
|
||||||
|
|
||||||
|
services.sway-autoscaler = {
|
||||||
|
description = "adjust global desktop scale to match the activate application";
|
||||||
|
wantedBy = lib.mkIf cfg.config.autostart [ "default.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${cfg.package}/bin/sway-autoscaler --loop-sec ${builtins.toString cfg.config.interval}";
|
||||||
|
Type = "simple";
|
||||||
|
Restart = "always";
|
||||||
|
RestartSec = "10s";
|
||||||
|
};
|
||||||
|
environment.SWAY_DEFAULT_SCALE = builtins.toString cfg.config.defaultScale;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
69
hosts/common/programs/sway-autoscaler/sway-autoscaler
Executable file
69
hosts/common/programs/sway-autoscaler/sway-autoscaler
Executable file
@@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#!nix-shell -i bash -p jq -p sway
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo "queries the focused window and apply an appropriate display-wide scale."
|
||||||
|
echo "this should be considered a temporary workaround until more apps support small displays."
|
||||||
|
echo ""
|
||||||
|
echo "args:"
|
||||||
|
echo " -v | --verbose"
|
||||||
|
echo " --loop-sec N re-compute the scale every N seconds. else, run once and exit."
|
||||||
|
echo ""
|
||||||
|
echo "environment variables:"
|
||||||
|
echo " SWAY_DEFAULT_SCALE=N scale to apply when no known window is selected."
|
||||||
|
# TODO: could use map-style environment variables to allow external per-app config
|
||||||
|
# - SWAY_SCALE_org.gnome.Maps=1 ; ...
|
||||||
|
}
|
||||||
|
|
||||||
|
options=$(getopt -l verbose,loop-sec: -o v -- "" "${@}")
|
||||||
|
eval "set -- ${options}"
|
||||||
|
|
||||||
|
verbose=false
|
||||||
|
loop=false
|
||||||
|
loop_sec=
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
(-v|--verbose)
|
||||||
|
verbose=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
(--loop-sec)
|
||||||
|
shift
|
||||||
|
loop=true
|
||||||
|
loop_sec="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
(--)
|
||||||
|
shift
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
echo "invalid arguments: '$1'"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
autoscale() {
|
||||||
|
focused=$(swaymsg -t get_tree | jq --raw-output '.. | select(.type?) | select(.focused==true) | .app_id')
|
||||||
|
$verbose && echo "focused: '$focused'"
|
||||||
|
|
||||||
|
scale=${SWAY_DEFAULT_SCALE:-1}
|
||||||
|
case "$focused" in
|
||||||
|
org.gnome.Maps) scale=1
|
||||||
|
esac
|
||||||
|
|
||||||
|
$verbose && echo "scaling to $scale"
|
||||||
|
swaymsg -q -- output '*' scale "$scale"
|
||||||
|
}
|
||||||
|
|
||||||
|
if $loop; then
|
||||||
|
while true; do
|
||||||
|
autoscale
|
||||||
|
sleep "$loop_sec"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
autoscale
|
||||||
|
fi
|
@@ -236,6 +236,7 @@ in
|
|||||||
# SXMO_WM = mkSettingsOpt "sway" "sway or dwm. ordinarily initialized by sxmo_{x,w}init.sh";
|
# SXMO_WM = mkSettingsOpt "sway" "sway or dwm. ordinarily initialized by sxmo_{x,w}init.sh";
|
||||||
SXMO_NO_AUDIO = mkSettingsOpt "1" "don't start pipewire/pulseaudio in sxmo_hook_start.sh";
|
SXMO_NO_AUDIO = mkSettingsOpt "1" "don't start pipewire/pulseaudio in sxmo_hook_start.sh";
|
||||||
SXMO_STATES = mkSettingsOpt "unlock screenoff" "list of states the device should support (unlock, lock, screenoff)";
|
SXMO_STATES = mkSettingsOpt "unlock screenoff" "list of states the device should support (unlock, lock, screenoff)";
|
||||||
|
SXMO_SWAY_SCALE = mkSettingsOpt "1" "sway output scale";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
default = {};
|
default = {};
|
||||||
@@ -265,6 +266,7 @@ in
|
|||||||
"bemenu" # specifically to import its theming
|
"bemenu" # specifically to import its theming
|
||||||
"sfeed" # want this here so that the user's ~/.sfeed/sfeedrc gets created
|
"sfeed" # want this here so that the user's ~/.sfeed/sfeedrc gets created
|
||||||
# "superd" # make superctl (used by sxmo) be on PATH
|
# "superd" # make superctl (used by sxmo) be on PATH
|
||||||
|
"sway-autoscaler"
|
||||||
];
|
];
|
||||||
|
|
||||||
persist.byStore.cryptClearOnBoot = [
|
persist.byStore.cryptClearOnBoot = [
|
||||||
@@ -382,6 +384,8 @@ in
|
|||||||
|
|
||||||
sane.programs.sxmoApps.enableFor.user.colin = true;
|
sane.programs.sxmoApps.enableFor.user.colin = true;
|
||||||
|
|
||||||
|
sane.programs.sway-autoscaler.config.defaultScale = builtins.fromJSON cfg.settings.SXMO_SWAY_SCALE;
|
||||||
|
|
||||||
# sxmo internally uses doas instead of sudo
|
# sxmo internally uses doas instead of sudo
|
||||||
security.doas.enable = true;
|
security.doas.enable = true;
|
||||||
security.doas.wheelNeedsPassword = false;
|
security.doas.wheelNeedsPassword = false;
|
||||||
|
Reference in New Issue
Block a user