Use modules folder

This commit is contained in:
Elnu 2023-01-25 20:15:06 -08:00
parent e42f845f09
commit 2903676336
46 changed files with 21 additions and 21 deletions

18
modules/rofi/default.nix Normal file
View file

@ -0,0 +1,18 @@
{ pkgs, ... }:
let
_theme = import ../theme;
theme = _theme.theme; # Theme name
in {
home.packages = with pkgs; [
(pkgs.callPackage ./power.nix { })
wmctrl # TODO: add as dependency of rofi-power
];
programs.rofi = {
enable = true;
inherit theme;
};
home.file.".config/rofi/${theme}.rasi".source = pkgs.substituteAll ({
src = ./theme.rasi;
} // _theme.colors);
}

9
modules/rofi/power.nix Normal file
View file

@ -0,0 +1,9 @@
{ pkgs, substituteAll }:
substituteAll {
name = "rofi-power";
src = ./power.sh;
dir = "bin";
isExecutable = true;
}

67
modules/rofi/power.sh Executable file
View file

@ -0,0 +1,67 @@
POWER_OFF=" Power Off"
REBOOT=" Reboot"
SUSPEND=" Suspend"
LOG_OUT=" Log out"
chosen=`printf "%s\n%s\n%s\n%s" "$POWER_OFF" "$REBOOT" "$SUSPEND" "$LOG_OUT" | rofi -dmenu -i -p ""`
case "$chosen" in
$POWER_OFF) action="power off" ;;
$REBOOT) action="reboot" ;;
$SUSPEND) action="suspend" ;;
$LOG_OUT) action="log out" ;;
*) exit 1 ;;
esac
confirm=`printf "Yes, %s" "$action"`
sure=`printf "%s\nNo, cancel" "$confirm" | rofi -dmenu -i -p "Are you sure"`
if [[ $sure != $confirm ]]; then
exit 1
fi
if [[ $chosen != $SUSPEND ]]; then
# based on https://github.com/ardadem/graceful-shutdown
TIMEOUT=10
APPLIST_TO_TERMINATE=(Discord firefox)
close_windows () {
wmctrl -l | awk '{print $1}' | while read -r wId
do
wmctrl -i -c $wId
done
}
window_timeout_countdown () {
for i in $(seq 1 $TIMEOUT);
do
if [[ -z $(wmctrl -l) ]]; then
return 0
fi
sleep 1
done
exit 1
}
terminate_processes () {
pidof ${APPLIST_TO_TERMINATE[@]} | tr ' ' '\n' | while read -r pId
do
kill -15 $pId
tail --pid=$pId -f /dev/null # wait until terminate it
done
}
close_windows
window_timeout_countdown
terminate_processes
fi
case "$chosen" in
$POWER_OFF) poweroff ;;
$REBOOT) reboot ;;
$SUSPEND) systemctl suspend ;;
$LOG_OUT) i3-msg exit ;;
*) exit 1 ;;
esac

83
modules/rofi/theme.rasi Normal file
View file

@ -0,0 +1,83 @@
/* Modified from https://github.com/undiabler/nord-rofi-theme */
configuration {
font: "Noto Sans Mono 12";
width: 30;
line-margin: 10;
lines: 6;
columns: 2;
display-ssh: "";
display-run: "";
display-drun: "";
display-window: "";
display-combi: "";
show-icons: true;
}
* {
background-color: transparent;
highlight: underline bold @fg1@;
}
window {
location: center;
anchor: center;
transparency: "screenshot";
padding: 0px;
border: 0px;
border-radius: 0px;
spacing: 0;
children: [mainbox];
orientation: horizontal;
}
mainbox {
spacing: 0;
children: [ inputbar, message, listview ];
}
message {
color: @bg0@;
padding: 5;
border-color: @fg0@;
border: 0px 2px 2px 2px;
}
inputbar {
color: @fg0@;
padding: 11px;
background-color: @bg1@;
}
entry, prompt, case-indicator {
text-font: inherit;
text-color: inherit;
}
prompt {
margin: 0px 0.3em 0em 0em;
}
listview {
padding: 8px;
border: 0;
background-color: @bg0@e5;
dynamic: false;
}
element {
padding: 3px;
border-radius: 4px;
text-color: @fg0@;
}
element selected.normal {
background-color: @primary@;
text-color: @bg0@;
}
element-text, element-icon {
background-color: inherit;
text-color: inherit;
}