sway
This commit is contained in:
parent
492f085d52
commit
bb021a1aae
30 changed files with 487 additions and 573 deletions
53
hm/desktop/sway/batteryNotify.sh
Executable file
53
hm/desktop/sway/batteryNotify.sh
Executable file
|
@ -0,0 +1,53 @@
|
|||
BATT="/sys/class/power_supply/BAT0"
|
||||
LOW=10
|
||||
CRIT=3
|
||||
LASTSTATE="$HOME/.cache/batteryState"
|
||||
|
||||
function setState() { # state [...notify-send arguments]
|
||||
state="$1"
|
||||
last="$(cat "$LASTSTATE" 2> /dev/null)"
|
||||
shift
|
||||
|
||||
echo "Battery state: $state"
|
||||
|
||||
if [ "$state" != "$last" ]
|
||||
then
|
||||
notify-send "$@"
|
||||
echo "$state" > "$LASTSTATE"
|
||||
fi
|
||||
}
|
||||
|
||||
function computeState() {
|
||||
acpiStatus="$(cat "$BATT/status")"
|
||||
acpiCapacity="$(cat "$BATT/capacity")"
|
||||
|
||||
if [ "$acpiStatus" == "Discharging" ]
|
||||
then
|
||||
if [ "$acpiCapacity" -le $CRIT ]
|
||||
then
|
||||
setState "CRIT" -u critical -i battery-caution "Battery level is critical" "$acpiCapacity %"
|
||||
elif [ "$acpiCapacity" -le $LOW ]
|
||||
then
|
||||
setState "LOW" -u critical -i battery-low "Battery level is low" "$acpiCapacity %"
|
||||
else
|
||||
setState "DISCHARGING" -i battery-good "Battery is discharging" "$acpiCapacity %"
|
||||
fi
|
||||
elif [ "$acpiStatus" == "Charging" ]
|
||||
then
|
||||
setState "CHARGING" -u normal -i battery-good-charging "Battery is charging" "$acpiCapacity %"
|
||||
elif [ "$acpiStatus" == "Full" ]
|
||||
then
|
||||
setState "FULL" -u low -i battery-full-charged "Battery is full" "$acpiCapacity %"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" == "-d" ]
|
||||
then
|
||||
while true
|
||||
do
|
||||
computeState
|
||||
sleep 10
|
||||
done
|
||||
else
|
||||
computeState
|
||||
fi
|
313
hm/desktop/sway/default.nix
Normal file
313
hm/desktop/sway/default.nix
Normal file
|
@ -0,0 +1,313 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
let
|
||||
# CARDINALS
|
||||
cardinals = [
|
||||
{
|
||||
vi = "h";
|
||||
arrow = "Left";
|
||||
container = "left";
|
||||
workspace = "prev_on_output";
|
||||
output = "left";
|
||||
}
|
||||
{
|
||||
vi = "l";
|
||||
arrow = "Right";
|
||||
container = "right";
|
||||
workspace = "next_on_output";
|
||||
output = "right";
|
||||
}
|
||||
{
|
||||
vi = "j";
|
||||
arrow = "Down";
|
||||
container = "down";
|
||||
workspace = "prev";
|
||||
output = "below";
|
||||
}
|
||||
{
|
||||
vi = "k";
|
||||
arrow = "Up";
|
||||
container = "up";
|
||||
workspace = "next";
|
||||
output = "above";
|
||||
}
|
||||
];
|
||||
forEachCardinal = f: map (c: f c) cardinals;
|
||||
|
||||
# WORKSPACES
|
||||
workspaces_keys = lib.strings.stringToCharacters "1234567890";
|
||||
workspaces = map (i: {
|
||||
id = i;
|
||||
name = builtins.toString (i + 1);
|
||||
key = builtins.elemAt workspaces_keys i;
|
||||
}) (lib.lists.range 0 ((builtins.length workspaces_keys) - 1));
|
||||
forEachWorkspace = f: map (w: f w) workspaces;
|
||||
|
||||
# MISC
|
||||
mod = config.wayland.windowManager.sway.config.modifier;
|
||||
rofi = "exec --no-startup-id ${config.programs.rofi.package}/bin/rofi";
|
||||
modes = config.frogeye.desktop.i3.bindmodes;
|
||||
|
||||
screenCombinations = lib.trivial.pipe config.services.kanshi.settings [
|
||||
# All settings
|
||||
(builtins.map (
|
||||
setting:
|
||||
lib.trivial.pipe setting [
|
||||
# Profile/setting (assumes one profile is defined at most over one setting)
|
||||
(lib.attrsets.attrByPath [ "profile" "outputs" ] [ ])
|
||||
# List of output objects
|
||||
(builtins.filter (output: (lib.attrsets.attrByPath [ "status" ] [ "enable" ] output) != "disable"))
|
||||
# List of output objects that are enabled
|
||||
(builtins.filter (output: (lib.attrsets.attrByPath [ "criteria" ] [ "*" ] output) != "*"))
|
||||
# Lost of outputs objects with a defined criteria
|
||||
# (at this point we could sort by position like we do in frobar, but we can rely on definition order)
|
||||
(builtins.map (output: output.criteria))
|
||||
# List of output names
|
||||
]
|
||||
))
|
||||
# List of list of output name
|
||||
(builtins.filter (outputs: builtins.length outputs >= 2))
|
||||
# List of list of output name with at least two screens
|
||||
];
|
||||
in
|
||||
{
|
||||
config = lib.mkIf config.wayland.windowManager.sway.enable {
|
||||
xdg.configFile = {
|
||||
"rofimoji.rc" = {
|
||||
text = ''
|
||||
skin-tone = neutral
|
||||
files = [emojis, math]
|
||||
action = clipboard
|
||||
'';
|
||||
};
|
||||
};
|
||||
wayland = {
|
||||
systemd.target = "sway-session.target";
|
||||
windowManager.sway.checkConfig = false; # us_qwerty-fr is not in the testing environment
|
||||
};
|
||||
# https://github.com/nix-community/home-manager/issues/5311
|
||||
# Setting a compiled file is not desirable as it depends on the keyboard's, uuuh, key placement
|
||||
wayland.windowManager.sway.config = {
|
||||
input."*".xkb_layout = "us_qwerty-fr";
|
||||
modifier = lib.mkDefault "Mod4";
|
||||
fonts = {
|
||||
names = [ config.stylix.fonts.sansSerif.name ];
|
||||
size = lib.mkForce 8.0;
|
||||
};
|
||||
terminal = "alacritty";
|
||||
colors =
|
||||
let
|
||||
ignore = "#ff00ff";
|
||||
in
|
||||
with config.lib.stylix.colors.withHashtag;
|
||||
lib.mkForce {
|
||||
focused = {
|
||||
border = base0B;
|
||||
background = base0B;
|
||||
text = base00;
|
||||
indicator = base00;
|
||||
childBorder = base0B;
|
||||
};
|
||||
focusedInactive = {
|
||||
border = base02;
|
||||
background = base02;
|
||||
text = base05;
|
||||
indicator = base02;
|
||||
childBorder = base02;
|
||||
};
|
||||
unfocused = {
|
||||
border = base05;
|
||||
background = base04;
|
||||
text = base00;
|
||||
indicator = base04;
|
||||
childBorder = base00;
|
||||
};
|
||||
urgent = {
|
||||
border = base0F;
|
||||
background = base08;
|
||||
text = base00;
|
||||
indicator = base08;
|
||||
childBorder = base0F;
|
||||
};
|
||||
placeholder = {
|
||||
border = ignore;
|
||||
background = base00;
|
||||
text = base05;
|
||||
indicator = ignore;
|
||||
childBorder = base00;
|
||||
};
|
||||
background = base07;
|
||||
# I set the color of the active tab as the the background color of the terminal so they merge together.
|
||||
};
|
||||
focus = {
|
||||
followMouse = false;
|
||||
mouseWarping = "container";
|
||||
};
|
||||
keybindings = lib.mkOptionDefault (
|
||||
{
|
||||
# Compatibility layer for people coming from other backgrounds
|
||||
"Mod1+Tab" = "${rofi} -modi window -show window";
|
||||
"Mod1+F2" = "${rofi} -modi drun -show drun";
|
||||
"Mod1+F4" = "kill";
|
||||
# kill focused window
|
||||
"${mod}+z" = "kill";
|
||||
button2 = "kill";
|
||||
# Rofi
|
||||
"${mod}+i" = "exec --no-startup-id ${pkgs.rofimoji}/bin/rofimoji";
|
||||
# start program launcher
|
||||
"${mod}+d" = "${rofi} -modi run -show run";
|
||||
"${mod}+Shift+d" = "${rofi} -modi drun -show drun";
|
||||
# Start Applications
|
||||
"${mod}+p" = "exec ${pkgs.xfce.thunar}/bin/thunar";
|
||||
# workspace back and forth (with/without active container)
|
||||
"${mod}+b" = "workspace back_and_forth";
|
||||
"${mod}+Shift+b" = "move container to workspace back_and_forth; workspace back_and_forth";
|
||||
# Split horizontally (rebound from ${mod}+b because used above)
|
||||
"${mod}+g" = "splith";
|
||||
# Change container layout
|
||||
"${mod}+q" = "focus child";
|
||||
# i3 control
|
||||
"${mod}+Shift+r" = "restart";
|
||||
# Warp around (ex-keynav)
|
||||
"Mod4+Mod1+x" = "exec ${lib.getExe pkgs.warpd} --hint";
|
||||
"Mod4+Mod1+c" = "exec ${lib.getExe pkgs.warpd} --normal";
|
||||
"Mod4+Mod1+g" = "exec ${lib.getExe pkgs.warpd} --grid";
|
||||
}
|
||||
// lib.mapAttrs' (k: v: lib.nameValuePair v.enter ''mode "${v.name}"'') (
|
||||
lib.filterAttrs (k: v: v.enter != null) modes
|
||||
)
|
||||
// lib.attrsets.mergeAttrsList (
|
||||
forEachCardinal (c: {
|
||||
#navigate workspaces next / previous
|
||||
"${mod}+Ctrl+${c.vi}" = "workspace ${c.workspace}";
|
||||
# Move to workspace next / previous with focused container
|
||||
"${mod}+Ctrl+Shift+${c.vi}" =
|
||||
"move container to workspace ${c.workspace}; workspace ${c.workspace}";
|
||||
# move workspaces to screen (arrow keys)
|
||||
"${mod}+Ctrl+Shift+${c.arrow}" = "move workspace to output ${c.output}";
|
||||
})
|
||||
)
|
||||
// lib.attrsets.mergeAttrsList (
|
||||
forEachWorkspace (w: {
|
||||
# move container to workspace, do not follow (normally bound to ${mod}+Shift+${w.key}
|
||||
"${mod}+Ctrl+${w.key}" = "move container to workspace number ${w.name}";
|
||||
# move container to workspace, follow it
|
||||
"${mod}+Shift+${w.key}" =
|
||||
"move container to workspace number ${w.name}; workspace number ${w.name}";
|
||||
})
|
||||
)
|
||||
);
|
||||
modes = lib.mkOptionDefault (
|
||||
lib.mapAttrs' (
|
||||
k: v:
|
||||
lib.nameValuePair v.name (
|
||||
v.bindings
|
||||
// lib.optionalAttrs v.return_bindings {
|
||||
"Return" = "mode default";
|
||||
"Escape" = "mode default";
|
||||
}
|
||||
)
|
||||
) modes
|
||||
);
|
||||
window = {
|
||||
hideEdgeBorders = "both";
|
||||
titlebar = false; # So that single-container screens are basically almost fullscreen
|
||||
commands = [
|
||||
# switch to workspace with urgent window automatically
|
||||
{
|
||||
criteria = {
|
||||
urgent = "latest";
|
||||
};
|
||||
command = "focus";
|
||||
}
|
||||
];
|
||||
};
|
||||
floating = {
|
||||
criteria = [
|
||||
{ window_role = "pop-up"; }
|
||||
{ window_role = "task_dialog"; }
|
||||
];
|
||||
};
|
||||
seat."*" = {
|
||||
hide_cursor = "10";
|
||||
};
|
||||
startup = [
|
||||
{
|
||||
command = "${
|
||||
pkgs.writeShellApplication {
|
||||
name = "batteryNotify";
|
||||
runtimeInputs = with pkgs; [
|
||||
coreutils
|
||||
libnotify
|
||||
];
|
||||
text = builtins.readFile ./batteryNotify.sh;
|
||||
# TODO Use batsignal instead?
|
||||
# TODO Only on computers with battery
|
||||
}
|
||||
}/bin/batteryNotify";
|
||||
}
|
||||
];
|
||||
workspaceLayout = "tabbed";
|
||||
workspaceOutputAssign = lib.mkIf (builtins.length screenCombinations > 0) (
|
||||
forEachWorkspace (w: {
|
||||
output = builtins.map (
|
||||
combination: builtins.elemAt combination (lib.mod w.id (builtins.length combination))
|
||||
) screenCombinations;
|
||||
workspace = w.name;
|
||||
})
|
||||
);
|
||||
};
|
||||
frogeye.desktop.i3.bindmodes = {
|
||||
"[L] Vérouillage [E] Déconnexion [S] Veille [H] Hibernation [R] Redémarrage [P] Extinction" = {
|
||||
bindings = {
|
||||
"l" = "exec --no-startup-id ${pkgs.procps}/bin/pkill -USR1 swayidle, mode default";
|
||||
"e" = "exit, mode default";
|
||||
# TODO Sometimes, exit gets stuck on terminal. Restarting greetd helps.
|
||||
"s" =
|
||||
"exec --no-startup-id ${pkgs.systemd}/bin/systemctl suspend --check-inhibitors=no, mode default";
|
||||
"h" = "exec --no-startup-id ${pkgs.systemd}/bin/systemctl hibernate, mode default";
|
||||
"r" = "exec --no-startup-id ${pkgs.systemd}/bin/systemctl reboot, mode default";
|
||||
"p" = "exec --no-startup-id ${pkgs.systemd}/bin/systemctl poweroff -i, mode default";
|
||||
};
|
||||
mod_enter = "Escape";
|
||||
};
|
||||
};
|
||||
};
|
||||
options = {
|
||||
frogeye.desktop.i3.bindmodes = lib.mkOption {
|
||||
default = { };
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ config, name, ... }:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = name;
|
||||
};
|
||||
bindings = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.str;
|
||||
default = { };
|
||||
};
|
||||
enter = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "${mod}+${config.mod_enter}";
|
||||
};
|
||||
mod_enter = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
return_bindings = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue