mirror of
https://github.com/lightly-toasted/nix-config.git
synced 2025-10-04 15:45:39 +00:00
feat: add mouse actions
Refs: 302185f6a873209ea51a26b314faa24c45cd03ac
This commit is contained in:
parent
b88d00fe40
commit
45a49b1529
12 changed files with 186 additions and 6 deletions
|
@ -20,6 +20,7 @@
|
||||||
./programs/waybar
|
./programs/waybar
|
||||||
./programs/dunst.nix
|
./programs/dunst.nix
|
||||||
./programs/keepassxc.nix
|
./programs/keepassxc.nix
|
||||||
|
./programs/mouse-actions
|
||||||
];
|
];
|
||||||
|
|
||||||
home = {
|
home = {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
pkgs.tofi
|
pkgs.tofi
|
||||||
];
|
];
|
||||||
|
|
||||||
|
programs.mouse-actions.enable = true;
|
||||||
wayland.windowManager.hyprland = {
|
wayland.windowManager.hyprland = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.hyprland;
|
package = pkgs.hyprland;
|
||||||
|
@ -71,6 +72,9 @@
|
||||||
|
|
||||||
"$mod SHIFT, S, exec, env HYPRSHOT_DIR=/data/Backup/Screenshots hyprshot -m region"
|
"$mod SHIFT, S, exec, env HYPRSHOT_DIR=/data/Backup/Screenshots hyprshot -m region"
|
||||||
"$mod SHIFT, E, exec, ~/bin/powermenu.sh"
|
"$mod SHIFT, E, exec, ~/bin/powermenu.sh"
|
||||||
|
|
||||||
|
"$mod, mouse:277, exec, cycle-mouse-action"
|
||||||
|
", mouse:277, exec, run-mouse-action"
|
||||||
];
|
];
|
||||||
|
|
||||||
bindel = [
|
bindel = [
|
||||||
|
|
40
home/toast/programs/mouse-actions/actions/autoclick.nix
Normal file
40
home/toast/programs/mouse-actions/actions/autoclick.nix
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
script = pkgs.writeShellScriptBin "autoclick-action" ''
|
||||||
|
if ! command -v ydotool >/dev/null 2>&1; then
|
||||||
|
notify-send -r 120000 "Autoclicker" "This tool requires ydotool to be installed on your system."
|
||||||
|
fi
|
||||||
|
|
||||||
|
AUTOCLICK_FILE="/run/user/$(id -u)/autoclick"
|
||||||
|
|
||||||
|
if [ ! -f "$AUTOCLICK_FILE" ]; then
|
||||||
|
echo "1" > "$AUTOCLICK_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
current=$(cat "$AUTOCLICK_FILE")
|
||||||
|
if [ "$current" = "0" ]; then
|
||||||
|
echo "1" > "$AUTOCLICK_FILE"
|
||||||
|
notify-send -r 120000 "Autoclicker" "Stopped"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "0" > "$AUTOCLICK_FILE"
|
||||||
|
notify-send -r 120000 "Autoclicker" "Started"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
line=$(cat "$AUTOCLICK_FILE")
|
||||||
|
if [ "$line" = "0" ]; then
|
||||||
|
ydotool click --next-delay 25 0xC0 > /dev/null 2>&1
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
package = pkgs.symlinkJoin {
|
||||||
|
name = "autoclick-action";
|
||||||
|
paths = [ script pkgs.libnotify ];
|
||||||
|
};
|
||||||
|
}
|
13
home/toast/programs/mouse-actions/actions/deafen.nix
Normal file
13
home/toast/programs/mouse-actions/actions/deafen.nix
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
script = pkgs.writeShellScriptBin "deafen-action" ''
|
||||||
|
hyprctl dispatch sendshortcut CTRL+SHIFT, D, 'class:^(vesktop)$'
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
package = pkgs.symlinkJoin {
|
||||||
|
name = "deafen-action";
|
||||||
|
paths = [ script pkgs.hyprland ];
|
||||||
|
};
|
||||||
|
}
|
7
home/toast/programs/mouse-actions/actions/default.nix
Normal file
7
home/toast/programs/mouse-actions/actions/default.nix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
{
|
||||||
|
autoclick = import ./autoclick.nix { inherit pkgs; };
|
||||||
|
deafen = import ./deafen.nix { inherit pkgs; };
|
||||||
|
sober-lag = import ./sober-lag.nix { inherit pkgs; };
|
||||||
|
}
|
27
home/toast/programs/mouse-actions/actions/sober-lag.nix
Normal file
27
home/toast/programs/mouse-actions/actions/sober-lag.nix
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
script = pkgs.writeShellScriptBin "sober-lag-action" ''
|
||||||
|
roblox_pid=$(ps aux | grep "[s]ober --" | sort -k3 -nr | head -n 1 | awk '{print $2}')
|
||||||
|
if [ -z "$roblox_pid" ]; then
|
||||||
|
notify-send "sober-lag.sh" "Sober is not running."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
pgid=$(ps -o pgid= -p "$roblox_pid" | xargs)
|
||||||
|
if [ -z "$pgid" ]; then
|
||||||
|
notify-send "sober-lag.sh" "Could not find PGID for PID $roblox_pid."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
kill -STOP -- "-$pgid"
|
||||||
|
sleep 0.2
|
||||||
|
kill -CONT -- "-$pgid"
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
package = pkgs.symlinkJoin {
|
||||||
|
name = "sober-lag-action";
|
||||||
|
paths = [ script pkgs.procps pkgs.gawk pkgs.gnugrep pkgs.gnused pkgs.coreutils pkgs.libnotify ];
|
||||||
|
};
|
||||||
|
}
|
29
home/toast/programs/mouse-actions/cycle.nix
Normal file
29
home/toast/programs/mouse-actions/cycle.nix
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
let
|
||||||
|
script = pkgs.writeShellScriptBin "cycle-mouse-action" ''
|
||||||
|
STATE_FILE="$HOME/.config/mouse-actions/state"
|
||||||
|
mkdir -p "$(dirname "$STATE_FILE")"
|
||||||
|
|
||||||
|
if [ -f "$STATE_FILE" ]; then
|
||||||
|
CURRENT_ACTION=$(cat "$STATE_FILE")
|
||||||
|
else
|
||||||
|
CURRENT_ACTION="deafen"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$CURRENT_ACTION" in
|
||||||
|
"deafen") NEW_ACTION="sober-lag" ;;
|
||||||
|
"sober-lag") NEW_ACTION="autoclick" ;;
|
||||||
|
*) NEW_ACTION="deafen"
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "$NEW_ACTION" > "$STATE_FILE.tmp"
|
||||||
|
mv "$STATE_FILE.tmp" "$STATE_FILE"
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
package = pkgs.symlinkJoin {
|
||||||
|
name = "cycle-mouse-action";
|
||||||
|
paths = [ script pkgs.libnotify ];
|
||||||
|
};
|
||||||
|
}
|
18
home/toast/programs/mouse-actions/default.nix
Normal file
18
home/toast/programs/mouse-actions/default.nix
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{ lib, pkgs, config, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
options.programs.mouse-actions.enable = lib.mkEnableOption "mouse-actions";
|
||||||
|
config = lib.mkIf config.programs.mouse-actions.enable
|
||||||
|
(let
|
||||||
|
cfg = config.programs.mouse-actions;
|
||||||
|
actions = import ./actions { inherit pkgs; };
|
||||||
|
|
||||||
|
cycle-script = import ./cycle.nix { inherit pkgs; };
|
||||||
|
run-script = import ./run.nix { inherit pkgs; actions = actions; };
|
||||||
|
in {
|
||||||
|
home.packages = [
|
||||||
|
cycle-script.package
|
||||||
|
run-script.package
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
31
home/toast/programs/mouse-actions/run.nix
Normal file
31
home/toast/programs/mouse-actions/run.nix
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{ pkgs, actions }:
|
||||||
|
|
||||||
|
let
|
||||||
|
script = pkgs.writeShellScriptBin "run-mouse-action" ''
|
||||||
|
STATE_FILE="$HOME/.config/mouse-actions/state"
|
||||||
|
|
||||||
|
if [ ! -f "$STATE_FILE" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
ACTION_NAME=$(<"$STATE_FILE")
|
||||||
|
|
||||||
|
case "$ACTION_NAME" in
|
||||||
|
"deafen")
|
||||||
|
systemd-run --user ${actions.deafen.package}/bin/deafen-action
|
||||||
|
;;
|
||||||
|
"sober-lag")
|
||||||
|
systemd-run --user ${actions.sober-lag.package}/bin/sober-lag-action
|
||||||
|
;;
|
||||||
|
"autoclick")
|
||||||
|
systemd-run --user ${actions.autoclick.package}/bin/autoclick-action
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
package = pkgs.symlinkJoin {
|
||||||
|
name = "run-mouse-action";
|
||||||
|
paths = [ script pkgs.systemd ];
|
||||||
|
};
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
position = "top";
|
position = "top";
|
||||||
height = 5;
|
height = 5;
|
||||||
output = "HDMI-A-1";
|
output = "HDMI-A-1";
|
||||||
modules-left = [ ];
|
modules-left = [ "custom/mouse-actions" ];
|
||||||
modules-center = [ ];
|
modules-center = [ ];
|
||||||
modules-right = [
|
modules-right = [
|
||||||
"pulseaudio"
|
"pulseaudio"
|
||||||
|
@ -61,6 +61,15 @@
|
||||||
system = true;
|
system = true;
|
||||||
user = false;
|
user = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
"custom/mouse-actions" = {
|
||||||
|
format = " {}";
|
||||||
|
exec = "tail -n 1 -F ~/.config/mouse-actions/state 2>/dev/null";
|
||||||
|
on-click = "run-mouse-action";
|
||||||
|
on-scroll-down = "cycle-mouse-action";
|
||||||
|
return-type = "text";
|
||||||
|
restart-interval = false;
|
||||||
|
};
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,5 @@
|
||||||
};
|
};
|
||||||
programs.xfconf.enable = true;
|
programs.xfconf.enable = true;
|
||||||
programs.ssh.startAgent = true;
|
programs.ssh.startAgent = true;
|
||||||
|
programs.ydotool.enable = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
users.users.toast = {
|
users.users.toast = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
description = "toast";
|
description = "toast";
|
||||||
extraGroups = [ "networkmanager" "wheel" ];
|
extraGroups = [ "networkmanager" "wheel" "ydotool" ];
|
||||||
packages = with pkgs; [];
|
packages = with pkgs; [];
|
||||||
shell = pkgs.zsh;
|
shell = pkgs.zsh;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue