[idle;lock] Switches to swaylock
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
enable = true;
|
||||
settings = {
|
||||
general = {
|
||||
lock_cmd = "pidof hyprlock || hyprlock"; # avoid starting multiple hyprlock instances.
|
||||
lock_cmd = "pidof swaylock || swaylock"; # avoid starting multiple lock instances.
|
||||
before_sleep_cmd = "loginctl lock-session"; # lock before suspend.
|
||||
after_sleep_cmd = "hyprctl dispatch dpms on"; # to avoid having to press a key twice to turn on the display.
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [
|
||||
./swaylock.nix
|
||||
./hypr/hypridle.nix
|
||||
];
|
||||
|
||||
@@ -426,7 +427,7 @@
|
||||
};
|
||||
|
||||
programs.hyprlock = {
|
||||
enable = true;
|
||||
enable = false;
|
||||
settings = {
|
||||
general = {
|
||||
disable_loading_bar = true;
|
||||
|
||||
@@ -11,7 +11,7 @@ dir="${HOME}/.config/rofi/powermenu"
|
||||
|
||||
# CMDs
|
||||
uptime="$(uptime | awk -F ' ' '{print $2}' | sed -e 's/,//g')"
|
||||
host=`hostname`
|
||||
host=$(hostname)
|
||||
|
||||
# Options
|
||||
shutdown=''
|
||||
@@ -24,89 +24,94 @@ no=''
|
||||
|
||||
# Rofi CMD
|
||||
rofi_cmd() {
|
||||
rofi -dmenu \
|
||||
-p "Uptime: $uptime" \
|
||||
-mesg "Uptime: $uptime" \
|
||||
-theme ${dir}/style.rasi
|
||||
rofi -dmenu \
|
||||
-p "Uptime: $uptime" \
|
||||
-mesg "Uptime: $uptime" \
|
||||
-theme ${dir}/style.rasi
|
||||
}
|
||||
|
||||
# Confirmation CMD
|
||||
confirm_cmd() {
|
||||
rofi -theme-str 'window {location: center; anchor: center; fullscreen: false; width: 350px;}' \
|
||||
-theme-str 'mainbox {children: [ "message", "listview" ];}' \
|
||||
-theme-str 'listview {columns: 2; lines: 1;}' \
|
||||
-theme-str 'element-text {horizontal-align: 0.5;}' \
|
||||
-theme-str 'textbox {horizontal-align: 0.5;}' \
|
||||
-dmenu \
|
||||
-p 'Confirmation' \
|
||||
-mesg 'Are you Sure?' \
|
||||
-theme ${dir}/style.rasi
|
||||
rofi -theme-str 'window {location: center; anchor: center; fullscreen: false; width: 350px;}' \
|
||||
-theme-str 'mainbox {children: [ "message", "listview" ];}' \
|
||||
-theme-str 'listview {columns: 2; lines: 1;}' \
|
||||
-theme-str 'element-text {horizontal-align: 0.5;}' \
|
||||
-theme-str 'textbox {horizontal-align: 0.5;}' \
|
||||
-dmenu \
|
||||
-p 'Confirmation' \
|
||||
-mesg 'Are you Sure?' \
|
||||
-theme ${dir}/style.rasi
|
||||
}
|
||||
|
||||
# Ask for confirmation
|
||||
confirm_exit() {
|
||||
echo -e "$yes\n$no" | confirm_cmd
|
||||
echo -e "$yes\n$no" | confirm_cmd
|
||||
}
|
||||
|
||||
# Pass variables to rofi dmenu
|
||||
run_rofi() {
|
||||
echo -e "$lock\n$suspend\n$logout\n$reboot\n$shutdown" | rofi_cmd
|
||||
echo -e "$lock\n$suspend\n$logout\n$reboot\n$shutdown" | rofi_cmd
|
||||
}
|
||||
|
||||
# Execute Command
|
||||
run_cmd() {
|
||||
selected="$(confirm_exit)"
|
||||
if [[ "$selected" == "$yes" ]]; then
|
||||
if [[ $1 == '--shutdown' ]]; then
|
||||
systemctl poweroff
|
||||
elif [[ $1 == '--reboot' ]]; then
|
||||
systemctl reboot
|
||||
elif [[ $1 == '--suspend' ]]; then
|
||||
mpc -q pause
|
||||
amixer set Master mute
|
||||
systemctl suspend
|
||||
elif [[ $1 == '--logout' ]]; then
|
||||
if [[ "$DESKTOP_SESSION" == 'openbox' ]]; then
|
||||
openbox --exit
|
||||
elif [[ "$DESKTOP_SESSION" == 'bspwm' ]]; then
|
||||
bspc quit
|
||||
elif [[ "$DESKTOP_SESSION" == 'i3' ]]; then
|
||||
i3-msg exit
|
||||
elif [[ "$DESKTOP_SESSION" == 'plasma' ]]; then
|
||||
qdbus org.kde.ksmserver /KSMServer logout 0 0 0
|
||||
elif [[ "$DESKTOP_SESSION" == 'plasma' ]]; then
|
||||
qdbus org.kde.ksmserver /KSMServer logout 0 0 0
|
||||
elif command -v hyprctl &>/dev/null; then
|
||||
selected="$(confirm_exit)"
|
||||
if [[ "$selected" == "$yes" ]]; then
|
||||
if [[ $1 == '--shutdown' ]]; then
|
||||
systemctl poweroff
|
||||
elif [[ $1 == '--reboot' ]]; then
|
||||
systemctl reboot
|
||||
elif [[ $1 == '--suspend' ]]; then
|
||||
mpc -q pause
|
||||
amixer set Master mute
|
||||
systemctl suspend
|
||||
elif [[ $1 == '--logout' ]]; then
|
||||
if [[ "$DESKTOP_SESSION" == 'openbox' ]]; then
|
||||
openbox --exit
|
||||
elif [[ "$DESKTOP_SESSION" == 'bspwm' ]]; then
|
||||
bspc quit
|
||||
elif [[ "$DESKTOP_SESSION" == 'i3' ]]; then
|
||||
i3-msg exit
|
||||
elif [[ "$DESKTOP_SESSION" == 'plasma' ]]; then
|
||||
qdbus org.kde.ksmserver /KSMServer logout 0 0 0
|
||||
elif [[ "$DESKTOP_SESSION" == 'plasma' ]]; then
|
||||
qdbus org.kde.ksmserver /KSMServer logout 0 0 0
|
||||
elif [[ "$DESKTOP_SESSION" == 'hyprland-uwsm' ]]; then
|
||||
hyprctl dispatch exit
|
||||
fi
|
||||
fi
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
elif [[ "$DESKTOP_SESSION" == 'hyprland' ]]; then
|
||||
hyprctl dispatch exit
|
||||
fi
|
||||
fi
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Actions
|
||||
chosen="$(run_rofi)"
|
||||
case ${chosen} in
|
||||
$shutdown)
|
||||
run_cmd --shutdown
|
||||
;;
|
||||
$reboot)
|
||||
run_cmd --reboot
|
||||
;;
|
||||
$lock)
|
||||
if [[ -x '/usr/bin/betterlockscreen' ]]; then
|
||||
betterlockscreen -l
|
||||
elif [[ -x '/usr/bin/i3lock' ]]; then
|
||||
i3lock
|
||||
elif command -v hyprlock &>/dev/null; then
|
||||
hyprlock
|
||||
fi
|
||||
;;
|
||||
$suspend)
|
||||
run_cmd --suspend
|
||||
;;
|
||||
$logout)
|
||||
run_cmd --logout
|
||||
;;
|
||||
$shutdown)
|
||||
run_cmd --shutdown
|
||||
;;
|
||||
$reboot)
|
||||
run_cmd --reboot
|
||||
;;
|
||||
$lock)
|
||||
loginctl lock-session
|
||||
# if [[ -x '/usr/bin/betterlockscreen' ]]; then
|
||||
# betterlockscreen -l
|
||||
# elif [[ -x '/usr/bin/i3lock' ]]; then
|
||||
# i3lock
|
||||
# elif command -v hyprlock &>/dev/null; then
|
||||
# hyprlock
|
||||
# elif command -v swaylock &>/dev/null; then
|
||||
# swaylock
|
||||
# fi
|
||||
;;
|
||||
$suspend)
|
||||
run_cmd --suspend
|
||||
;;
|
||||
$logout)
|
||||
run_cmd --logout
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
imports = [
|
||||
./swaync.nix
|
||||
];
|
||||
|
||||
home.packages = with pkgs; [
|
||||
hyprlock # lock screen
|
||||
# swayidle # lock on idle
|
||||
# swayosd # volume pop-up
|
||||
# swaynotificationcenter # notifications
|
||||
# hyprpolkitagent # Privilege managent
|
||||
# hyprshot # Screenshot utility
|
||||
./swaylock.nix
|
||||
];
|
||||
|
||||
services.swayosd = {
|
||||
@@ -23,16 +14,6 @@
|
||||
topMargin = 0.7;
|
||||
};
|
||||
|
||||
services.swayidle = {
|
||||
enable = true;
|
||||
events = [
|
||||
{
|
||||
event = "before-sleep";
|
||||
command = "hyprlock";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# Enable sway config generation for home.pointerCursor
|
||||
home.pointerCursor.sway.enable = true;
|
||||
|
||||
|
||||
23
home-manager/features/swaylock.nix
Normal file
23
home-manager/features/swaylock.nix
Normal file
@@ -0,0 +1,23 @@
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
programs.swaylock = {
|
||||
enable = true;
|
||||
package = pkgs.swaylock-effects;
|
||||
settings = {
|
||||
clock = true;
|
||||
indicator = true;
|
||||
effect-pixelate = 10;
|
||||
};
|
||||
};
|
||||
|
||||
home.file.".config/swaylock/swaylock.sh" = {
|
||||
executable = true;
|
||||
text = ''
|
||||
#!/bin/env bash
|
||||
|
||||
image=`fd . ~/Pictures/Wallpaper --type f | sort -R | tail -1`
|
||||
|
||||
swaylock --image "$image"
|
||||
'';
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user