Sway : Move mon/vrr controls to swayscript.
This commit is contained in:
parent
5fde1f7dd8
commit
ab46247efa
|
@ -8,8 +8,8 @@
|
|||
offMax = "95";
|
||||
|
||||
script = pkgs.writeShellScriptBin "powerlimit" ''
|
||||
function _toggle() {
|
||||
if _status; then
|
||||
function toggle() {
|
||||
if status; then
|
||||
echo ${offMax} > ${controlFileMax}
|
||||
echo ${offMin} > ${controlFileMin}
|
||||
else
|
||||
|
@ -20,18 +20,18 @@
|
|||
true
|
||||
}
|
||||
|
||||
function _waybar() {
|
||||
_status || echo -n ""
|
||||
function waybar() {
|
||||
status || echo -n ""
|
||||
}
|
||||
|
||||
function _status() {
|
||||
function status() {
|
||||
local current=$(cat ${controlFileMax})
|
||||
local enabled="${onMax}"
|
||||
|
||||
[[ "''${current}" = "''${enabled}" ]]
|
||||
}
|
||||
|
||||
_''${1}
|
||||
''${@}
|
||||
'';
|
||||
in {
|
||||
systemd = {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ pkgs, lib, wallpaper, style, ... } @args: let
|
||||
sway = import ./sway args;
|
||||
config = pkgs.writeText "swayConfig" sway.config;
|
||||
script = pkgs.writeShellScriptBin "swayscript" sway.script;
|
||||
in {
|
||||
imports = [
|
||||
./desktop/App.nix
|
||||
|
@ -15,6 +16,7 @@ in {
|
|||
];
|
||||
|
||||
services.gnome.gnome-keyring.enable = lib.mkForce false;
|
||||
systemd.services.keyd.path = [ script ];
|
||||
environment.systemPackages = with pkgs; [
|
||||
gnome.adwaita-icon-theme # GTK icons.
|
||||
grim slurp # Screenshot.
|
||||
|
@ -23,6 +25,7 @@ in {
|
|||
pamixer pavucontrol pulseaudio # Audio.
|
||||
playerctl # Multimedia controls.
|
||||
wl-clipboard # Clipboard.
|
||||
script
|
||||
];
|
||||
|
||||
programs.sway = {
|
||||
|
|
|
@ -45,11 +45,13 @@
|
|||
};
|
||||
|
||||
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)";
|
||||
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 = {};
|
||||
|
@ -61,6 +63,8 @@
|
|||
users.groups.keyd = {};
|
||||
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.ProtectHome = lib.mkForce false;
|
||||
# systemd.services.keyd.environment.KEYD_DEBUG = "1";
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{ style, util, pkgs, ... } @args: let
|
||||
modules = util.catAllText ./module args;
|
||||
modules = util.catText (util.ls ./module) args;
|
||||
modulesFile = pkgs.writeText "bashModules" modules;
|
||||
in {
|
||||
inherit modules;
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
'';
|
||||
}
|
|
@ -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
|
||||
}
|
||||
'';
|
||||
}
|
|
@ -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'
|
||||
}
|
||||
'';
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
{ style, key, util, setting, ... } @args: {
|
||||
config = util.catAllText ./module args;
|
||||
config = util.catText (util.ls ./module) args;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ util, ... } @args: {
|
||||
config = (import ./config args).text;
|
||||
style = util.catAllText ./style args;
|
||||
style = util.catText (util.ls ./style) args;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{ controlFile, enable, disable, ... }: {
|
||||
script = ''
|
||||
function _toggle() {
|
||||
if _status; then
|
||||
function toggle() {
|
||||
if status; then
|
||||
echo ${disable} > ${controlFile}
|
||||
else
|
||||
echo ${enable} > ${controlFile}
|
||||
|
@ -10,17 +10,17 @@
|
|||
true
|
||||
}
|
||||
|
||||
function _waybar() {
|
||||
_status || echo -n ""
|
||||
function waybar() {
|
||||
status || echo -n ""
|
||||
}
|
||||
|
||||
function _status() {
|
||||
function status() {
|
||||
local current=$(cat ${controlFile})
|
||||
local enabled="${enable}"
|
||||
|
||||
[[ "''${current}" = "''${enabled}" ]]
|
||||
}
|
||||
|
||||
_''${1}
|
||||
''${@}
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -1,36 +1,32 @@
|
|||
{ pkgs, wallpaper, style, util, setting, ... } @args: let
|
||||
mkConfig = { modules }: builtins.foldl' (acc: mod:
|
||||
acc + util.trimTabs((import mod args).text)
|
||||
) "" modules;
|
||||
|
||||
swayRc = mkConfig {
|
||||
modules = [
|
||||
./module/Style.nix
|
||||
./module/Display.nix
|
||||
./module/Input.nix
|
||||
./module/Mod.nix
|
||||
./module/Font.nix
|
||||
./module/Launcher.nix
|
||||
./module/Terminal.nix
|
||||
./module/TitleBar.nix
|
||||
./module/Brightness.nix
|
||||
./module/Navigation.nix
|
||||
./module/Notification.nix
|
||||
./module/Resize.nix
|
||||
./module/ScratchPad.nix
|
||||
./module/Screenshot.nix
|
||||
./module/Sound.nix
|
||||
./module/Tiling.nix
|
||||
./module/Workspace.nix
|
||||
./module/Session.nix
|
||||
./module/Keyd.nix
|
||||
./module/Waybar.nix
|
||||
];
|
||||
};
|
||||
swayRc = util.catText [
|
||||
./module/Style.nix
|
||||
./module/Display.nix
|
||||
./module/Input.nix
|
||||
./module/Mod.nix
|
||||
./module/Font.nix
|
||||
./module/Launcher.nix
|
||||
./module/Terminal.nix
|
||||
./module/TitleBar.nix
|
||||
./module/Brightness.nix
|
||||
./module/Navigation.nix
|
||||
./module/Notification.nix
|
||||
./module/Resize.nix
|
||||
./module/ScratchPad.nix
|
||||
./module/Screenshot.nix
|
||||
./module/Sound.nix
|
||||
./module/Tiling.nix
|
||||
./module/Workspace.nix
|
||||
./module/Session.nix
|
||||
./module/Keyd.nix
|
||||
./module/Waybar.nix
|
||||
] args;
|
||||
in {
|
||||
config = (util.trimTabs ''
|
||||
# Read `man 5 sway` for a complete reference.
|
||||
include /etc/sway/config.d/*
|
||||
'') + swayRc;
|
||||
|
||||
script = util.catText (util.ls ./script) args + "\${@}";
|
||||
}
|
||||
|
||||
|
|
38
module/sway/script/Monitor.nix
Normal file
38
module/sway/script/Monitor.nix
Normal 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
|
||||
}
|
||||
'';
|
||||
}
|
13
module/sway/script/Scratchpad.nix
Normal file
13
module/sway/script/Scratchpad.nix
Normal 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
|
||||
}
|
||||
'';
|
||||
}
|
19
module/sway/script/Util.nix
Normal file
19
module/sway/script/Util.nix
Normal 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
|
||||
}
|
||||
'';
|
||||
}
|
38
module/sway/script/Vrr.nix
Normal file
38
module/sway/script/Vrr.nix
Normal 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
|
||||
}
|
||||
'';
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
ls = path: map (f: "${path}/${f}") (builtins.attrNames (builtins.readDir path));
|
||||
|
||||
# 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)
|
||||
) "" (ls path);
|
||||
) "" files;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{ util, setting, ... } @args: {
|
||||
config = util.catAllText ./module args;
|
||||
config = util.catText (util.ls ./module) args;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue