Sway : Move mon/vrr controls to swayscript.

This commit is contained in:
Dmitry Voronin 2024-05-08 18:26:33 +03:00
parent 5fde1f7dd8
commit ab46247efa
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
17 changed files with 162 additions and 87 deletions

View file

@ -8,8 +8,8 @@
offMax = "95"; offMax = "95";
script = pkgs.writeShellScriptBin "powerlimit" '' script = pkgs.writeShellScriptBin "powerlimit" ''
function _toggle() { function toggle() {
if _status; then if status; then
echo ${offMax} > ${controlFileMax} echo ${offMax} > ${controlFileMax}
echo ${offMin} > ${controlFileMin} echo ${offMin} > ${controlFileMin}
else else
@ -20,18 +20,18 @@
true true
} }
function _waybar() { function waybar() {
_status || echo -n "" status || echo -n ""
} }
function _status() { function status() {
local current=$(cat ${controlFileMax}) local current=$(cat ${controlFileMax})
local enabled="${onMax}" local enabled="${onMax}"
[[ "''${current}" = "''${enabled}" ]] [[ "''${current}" = "''${enabled}" ]]
} }
_''${1} ''${@}
''; '';
in { in {
systemd = { systemd = {

View file

@ -1,6 +1,7 @@
{ pkgs, lib, wallpaper, style, ... } @args: let { pkgs, lib, wallpaper, style, ... } @args: let
sway = import ./sway args; sway = import ./sway args;
config = pkgs.writeText "swayConfig" sway.config; config = pkgs.writeText "swayConfig" sway.config;
script = pkgs.writeShellScriptBin "swayscript" sway.script;
in { in {
imports = [ imports = [
./desktop/App.nix ./desktop/App.nix
@ -15,6 +16,7 @@ in {
]; ];
services.gnome.gnome-keyring.enable = lib.mkForce false; services.gnome.gnome-keyring.enable = lib.mkForce false;
systemd.services.keyd.path = [ script ];
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
gnome.adwaita-icon-theme # GTK icons. gnome.adwaita-icon-theme # GTK icons.
grim slurp # Screenshot. grim slurp # Screenshot.
@ -23,6 +25,7 @@ in {
pamixer pavucontrol pulseaudio # Audio. pamixer pavucontrol pulseaudio # Audio.
playerctl # Multimedia controls. playerctl # Multimedia controls.
wl-clipboard # Clipboard. wl-clipboard # Clipboard.
script
]; ];
programs.sway = { programs.sway = {

View file

@ -45,11 +45,13 @@
}; };
layer_system = { layer_system = {
p = "command(powersave toggle)";
l = "command(powerlimit toggle)";
z = "command(systemctl suspend -i)";
x = "command(systemctl poweroff -i)";
c = "command(loginctl kill-user voronind)"; c = "command(loginctl kill-user voronind)";
l = "command(powerlimit toggle)";
# m = "command(swayscript montoggle)";
p = "command(powersave toggle)";
# v = "command(swayscript vrrtoggle)";
x = "command(systemctl poweroff -i)";
z = "command(systemctl suspend -i)";
}; };
layer_macro = {}; layer_macro = {};
@ -61,6 +63,8 @@
users.groups.keyd = {}; users.groups.keyd = {};
systemd.services.keyd.serviceConfig.CapabilityBoundingSet = [ "CAP_SETGID" ]; systemd.services.keyd.serviceConfig.CapabilityBoundingSet = [ "CAP_SETGID" ];
# HACK: Workaround for powersave/powerlimit scripts. # HACK: Workaround for powersave/powerlimit/swayscript scripts.
systemd.services.keyd.serviceConfig.ProtectKernelTunables = lib.mkForce false; systemd.services.keyd.serviceConfig.ProtectKernelTunables = lib.mkForce false;
systemd.services.keyd.serviceConfig.ProtectHome = lib.mkForce false;
# systemd.services.keyd.environment.KEYD_DEBUG = "1";
} }

View file

@ -1,5 +1,5 @@
{ style, util, pkgs, ... } @args: let { style, util, pkgs, ... } @args: let
modules = util.catAllText ./module args; modules = util.catText (util.ls ./module) args;
modulesFile = pkgs.writeText "bashModules" modules; modulesFile = pkgs.writeText "bashModules" modules;
in { in {
inherit modules; inherit modules;

View file

@ -1,13 +0,0 @@
{ ... }: {
text = ''
# Enable monitors.
function monon() {
swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power on'
}
# Disable monitors.
function monoff() {
swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power off'
}
'';
}

View file

@ -1,10 +0,0 @@
{ ... }: {
text = ''
# Kill all windows in Sway scratchpad.
function sway_scratchpad_kill() {
for window in $(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?) | select(.name == "__i3_scratch").floating_nodes[].id'); do
swaymsg [ con_id="$window" ] kill
done
}
'';
}

View file

@ -1,13 +0,0 @@
{ ... }: {
text = ''
# Enable VRR.
function vrron() {
swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync on'
}
# Disable VRR.
function vrroff() {
swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync off'
}
'';
}

View file

@ -1,3 +1,3 @@
{ style, key, util, setting, ... } @args: { { style, key, util, setting, ... } @args: {
config = util.catAllText ./module args; config = util.catText (util.ls ./module) args;
} }

View file

@ -1,4 +1,4 @@
{ util, ... } @args: { { util, ... } @args: {
config = (import ./config args).text; config = (import ./config args).text;
style = util.catAllText ./style args; style = util.catText (util.ls ./style) args;
} }

View file

@ -1,7 +1,7 @@
{ controlFile, enable, disable, ... }: { { controlFile, enable, disable, ... }: {
script = '' script = ''
function _toggle() { function toggle() {
if _status; then if status; then
echo ${disable} > ${controlFile} echo ${disable} > ${controlFile}
else else
echo ${enable} > ${controlFile} echo ${enable} > ${controlFile}
@ -10,17 +10,17 @@
true true
} }
function _waybar() { function waybar() {
_status || echo -n "󰓅" status || echo -n "󰓅"
} }
function _status() { function status() {
local current=$(cat ${controlFile}) local current=$(cat ${controlFile})
local enabled="${enable}" local enabled="${enable}"
[[ "''${current}" = "''${enabled}" ]] [[ "''${current}" = "''${enabled}" ]]
} }
_''${1} ''${@}
''; '';
} }

View file

@ -1,10 +1,5 @@
{ pkgs, wallpaper, style, util, setting, ... } @args: let { pkgs, wallpaper, style, util, setting, ... } @args: let
mkConfig = { modules }: builtins.foldl' (acc: mod: swayRc = util.catText [
acc + util.trimTabs((import mod args).text)
) "" modules;
swayRc = mkConfig {
modules = [
./module/Style.nix ./module/Style.nix
./module/Display.nix ./module/Display.nix
./module/Input.nix ./module/Input.nix
@ -25,12 +20,13 @@
./module/Session.nix ./module/Session.nix
./module/Keyd.nix ./module/Keyd.nix
./module/Waybar.nix ./module/Waybar.nix
]; ] args;
};
in { in {
config = (util.trimTabs '' config = (util.trimTabs ''
# Read `man 5 sway` for a complete reference. # Read `man 5 sway` for a complete reference.
include /etc/sway/config.d/* include /etc/sway/config.d/*
'') + swayRc; '') + swayRc;
script = util.catText (util.ls ./script) args + "\${@}";
} }

View file

@ -0,0 +1,38 @@
{ ... }: {
text = ''
# Enable monitors.
function monon() {
on() {
_monstate on
swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power on'
}
_sway_iterate_sockets on
}
# Disable monitors.
function monoff() {
off() {
_monstate off
swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power off'
}
_sway_iterate_sockets off
}
# Toggle monitors.
function montoggle() {
if [[ "$(_monstate)" = "off" ]]; then
monon
else
monoff
fi
}
function _monstate() {
if [[ "''${1}" = "" ]]; then
cat /tmp/.monstate 2> /dev/null
else
echo "''${*}" > /tmp/.monstate
fi
}
'';
}

View file

@ -0,0 +1,13 @@
{ ... }: {
text = ''
# Kill all windows in Sway scratchpad.
function sway_scratchpad_kill() {
kill() {
for window in $(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?) | select(.name == "__i3_scratch").floating_nodes[].id'); do
swaymsg [ con_id="$window" ] kill
done
}
_sway_iterate_sockets kill
}
'';
}

View file

@ -0,0 +1,19 @@
{ ... }: {
text = ''
# Find currently active SWAYSOCK paths.
function _sway_find_sockets() {
ls /run/user/1000/sway-ipc.1000.*.sock
}
function _sway_iterate_sockets() {
local IFS=$'\n'
for socket in $(_sway_find_sockets); do
SWAYSOCK="''${socket}" ''${1}
done
echo FUCKME | systemd-cat
ls /run/user/ | systemd-cat
ls /run/user/1000 | systemd-cat
}
'';
}

View file

@ -0,0 +1,38 @@
{ ... }: {
text = ''
# Enable VRR.
function vrron() {
on() {
_vrrstate on
swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync on'
}
_sway_iterate_sockets on
}
# Disable VRR.
function vrroff() {
off() {
_vrrstate off
swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync off'
}
_sway_iterate_sockets off
}
# Toggle VRR.
function vrrtoggle() {
if [[ "$(_vrrstate)" = "off" ]]; then
vrron
else
vrroff
fi
}
function _vrrstate() {
if [[ "''${1}" = "" ]]; then
cat /tmp/.vrrstate 2> /dev/null
else
echo "''${*}" > /tmp/.vrrstate
fi
}
'';
}

View file

@ -11,7 +11,7 @@
ls = path: map (f: "${path}/${f}") (builtins.attrNames (builtins.readDir path)); ls = path: map (f: "${path}/${f}") (builtins.attrNames (builtins.readDir path));
# Concat all files by `text` key. # Concat all files by `text` key.
catAllText = path: args: builtins.foldl' (acc: mod: catText = files: args: builtins.foldl' (acc: mod:
acc + trimTabs ((import mod args).text) acc + trimTabs ((import mod args).text)
) "" (ls path); ) "" files;
} }

View file

@ -1,3 +1,3 @@
{ util, setting, ... } @args: { { util, setting, ... } @args: {
config = util.catAllText ./module args; config = util.catText (util.ls ./module) args;
} }