nixos-config/nixos/components/gui/home-manager/i3.nix

300 lines
11 KiB
Nix
Raw Normal View History

2023-02-17 00:41:22 +01:00
{ config, lib, pkgs, ... }:
let
cfg = config.home-manager.users.mainUser.xsession.windowManager.i3;
backgroundCommand = pkgs.writers.writeDash "background" ''
2023-06-23 09:03:24 +02:00
${pkgs.xorg.xrandr}/bin/xrandr | grep " connected" | grep "primary" | \
2023-02-17 00:41:22 +01:00
${pkgs.gnused}/bin/sed -E "s/primary //" | \
${pkgs.coreutils-full}/bin/cut -d' ' -f 3 | \
${pkgs.gnused}/bin/sed -E 's/\+.*$//g' | \
${pkgs.coreutils-full}/bin/sort -r | \
${pkgs.coreutils-full}/bin/head -n 1 | \
${pkgs.gawk}/bin/awk -F 'x' '{print "--width="$1" --height="$2}' | \
${pkgs.findutils}/bin/xargs \
2023-05-27 01:18:11 +02:00
${pkgs.polygon-art.polygon-art}/bin/rings \
/dev/shm/background.png && \
${pkgs.imagemagick}/bin/convert /dev/shm/background.png \
-font ${pkgs.ubuntu_font_family}/share/fonts/ubuntu/UbuntuMono-B.ttf \
-gravity Center -pointsize 30 -annotate 0 '${config.networking.hostName}' \
/dev/shm/background_with_text.png && \
${pkgs.feh}/bin/feh --bg-scale /dev/shm/background_with_text.png
2023-02-17 00:41:22 +01:00
'';
in
{
config = lib.mkIf config.components.gui.enable {
2023-12-08 19:54:55 +01:00
environment.systemPackages = [
# we install this to have a terminal with a dark theme
pkgs.kitty
];
2023-02-17 00:41:22 +01:00
home-manager.users.mainUser = {
programs.i3status-rust = {
enable = true;
bars = {
my = {
2023-07-01 00:20:03 +02:00
icons = "awesome5";
theme = "gruvbox-light";
2023-02-17 00:41:22 +01:00
# https://github.com/greshake/i3status-rust/blob/v0.22.0/doc/blocks.md
blocks = [
{
block = "cpu";
interval = 1;
}
{
block = "memory";
2023-06-29 11:13:24 +02:00
format = "$icon $mem_used_percents ";
2023-02-17 00:41:22 +01:00
}
{
block = "load";
interval = 1;
2023-06-29 11:13:24 +02:00
format = "$icon $1m";
2023-02-17 00:41:22 +01:00
}
2023-06-29 11:13:24 +02:00
{ block = "net"; }
{ block = "sound"; }
2023-02-17 00:41:22 +01:00
{
block = "battery";
interval = 10;
2023-06-29 11:13:24 +02:00
format = "$icon $percentage $time";
}
2023-07-02 22:11:09 +02:00
{ block = "uptime"; }
2023-06-29 11:13:24 +02:00
{
block = "taskwarrior";
interval = 60;
2023-11-03 14:42:18 +01:00
format = " $icon $count.eng(w:3) todo ";
2023-06-29 11:13:24 +02:00
format_singular = " $icon 1 task ";
format_everything_done = "";
warning_threshold = 10;
critical_threshold = 20;
filters = [
{
name = "active";
filter = "+PENDING and ( +ACTIVE or +DUETODAY or +TODAY or +OVERDUE )";
2023-11-03 14:42:18 +01:00
}
];
}
{
block = "taskwarrior";
interval = 60;
format = " $icon $count.eng(w:2) ";
format_singular = " $icon 1 task ";
format_everything_done = "";
warning_threshold = 3;
critical_threshold = 5;
filters = [
{
name = "started";
filter = "+PENDING and +ACTIVE";
2023-06-29 11:13:24 +02:00
}
];
2023-02-17 00:41:22 +01:00
}
{
block = "time";
interval = 60;
2023-06-29 11:13:24 +02:00
format = " $icon $timestamp.datetime(f:'%Y-%m-%d %R', l:de_DE) ";
}
{
block = "tea_timer";
format = " $icon {$minutes:$seconds |}";
2023-06-29 18:14:47 +02:00
done_cmd = "${pkgs.noti}/bin/noti -t 'Timer Finished'";
2023-02-17 00:41:22 +01:00
}
];
};
};
};
programs.alacritty = {
enable = true;
settings = {
2023-07-01 17:34:23 +02:00
font.size = lib.mkForce 6.5;
2023-02-17 00:41:22 +01:00
};
};
2023-07-02 22:11:09 +02:00
services.copyq = {
enable = true;
};
2023-02-17 00:41:22 +01:00
xsession.windowManager.i3 = {
enable = true;
extraConfig = ''
default_border pixel
'';
config = {
modifier = "Mod4";
terminal = "alacritty";
2023-06-21 08:34:43 +02:00
focus = {
followMouse = true;
};
2023-07-11 08:15:27 +02:00
colors.focused =
with config.lib.stylix.colors.withHashtag;
{
# stylix color overrides
border = lib.mkForce base08;
background = lib.mkForce base0A;
text = lib.mkForce base00;
};
2023-02-17 00:41:22 +01:00
startup =
let
height = config.configuration.desktop.height;
width = config.configuration.desktop.width;
in
[
{ command = "${pkgs.albert}/bin/albert"; always = true; }
{ command = toString backgroundCommand; always = true; }
2023-06-23 09:03:24 +02:00
{
command = toString (pkgs.writers.writeDash "xsettings" ''
# to allow sudo commands to access X
${pkgs.xorg.xhost}/bin/xhost +
# no shitty pcspkr crap
${pkgs.xorg.xset}/bin/xset -b
# no sleeping monitor
${pkgs.xorg.xset}/bin/xset -dpms
${pkgs.xorg.xset}/bin/xset s off
'');
always = true;
}
2023-02-17 00:41:22 +01:00
];
2023-06-30 17:28:17 +02:00
bars = [
2023-06-30 22:57:49 +02:00
(config.home-manager.users.mainUser.lib.stylix.i3.bar //
{
#mode = "hide";
hiddenState = "hide";
position = "top";
workspaceButtons = true;
workspaceNumbers = true;
statusCommand = "${pkgs.i3status-rust}/bin/i3status-rs ${config.users.users.mainUser.home}/.config/i3status-rust/config-my.toml";
fonts.size = 10.0;
trayOutput = "primary";
}
)
2023-06-30 17:28:17 +02:00
];
2023-06-21 08:34:43 +02:00
2023-02-17 00:41:22 +01:00
keybindings = {
"Print" = "exec ${pkgs.flameshot}/bin/flameshot gui -c -p /share/";
"${cfg.config.modifier}+Return" = "exec ${cfg.config.terminal}";
"${cfg.config.modifier}+Shift+q" = "exit";
"${cfg.config.modifier}+q" = "kill";
"${cfg.config.modifier}+Left" = "focus left";
"${cfg.config.modifier}+Down" = "focus down";
"${cfg.config.modifier}+Up" = "focus up";
"${cfg.config.modifier}+Right" = "focus right";
"${cfg.config.modifier}+j" = "focus next";
"${cfg.config.modifier}+k" = "focus prev";
"${cfg.config.modifier}+Shift+Left" = "move left";
"${cfg.config.modifier}+Shift+Down" = "move down";
"${cfg.config.modifier}+Shift+Up" = "move up";
"${cfg.config.modifier}+Shift+Right" = "move right";
"${cfg.config.modifier}+h" = "split h";
"${cfg.config.modifier}+v" = "split v";
"${cfg.config.modifier}+f" = "fullscreen toggle";
"${cfg.config.modifier}+s" = "layout stacking";
"${cfg.config.modifier}+w" = "layout tabbed";
"${cfg.config.modifier}+e" = "layout toggle split";
"${cfg.config.modifier}+t" = "floating toggle";
#"${cfg.config.modifier}+space" = "focus mode_toggle";
"${cfg.config.modifier}+b" = "exec ${backgroundCommand}";
"${cfg.config.modifier}+p" = "focus parent";
"${cfg.config.modifier}+Shift+minus" = "move scratchpad";
"${cfg.config.modifier}+minus" = "scratchpad show";
2023-05-28 11:32:42 +02:00
"${cfg.config.modifier}+1" = "workspace 1";
"${cfg.config.modifier}+2" = "workspace 2";
"${cfg.config.modifier}+3" = "workspace 3";
"${cfg.config.modifier}+4" = "workspace 4";
"${cfg.config.modifier}+5" = "workspace 5";
"${cfg.config.modifier}+6" = "workspace 6";
"${cfg.config.modifier}+7" = "workspace 7";
"${cfg.config.modifier}+8" = "workspace 8";
"${cfg.config.modifier}+9" = "workspace 9";
"${cfg.config.modifier}+0" = "workspace 10";
2023-02-17 00:41:22 +01:00
"${cfg.config.modifier}+Shift+1" = "move container to workspace number 1";
"${cfg.config.modifier}+Shift+2" = "move container to workspace number 2";
"${cfg.config.modifier}+Shift+3" = "move container to workspace number 3";
"${cfg.config.modifier}+Shift+4" = "move container to workspace number 4";
"${cfg.config.modifier}+Shift+5" = "move container to workspace number 5";
"${cfg.config.modifier}+Shift+6" = "move container to workspace number 6";
"${cfg.config.modifier}+Shift+7" = "move container to workspace number 7";
"${cfg.config.modifier}+Shift+8" = "move container to workspace number 8";
"${cfg.config.modifier}+Shift+9" = "move container to workspace number 9";
"${cfg.config.modifier}+Shift+0" = "move container to workspace number 10";
"${cfg.config.modifier}+Escape" = "workspace back_and_forth";
# rename workspace
"${cfg.config.modifier}+n" = ''
exec i3-input -F 'rename workspace to "%s"' -P 'New name for this workspace: '
'';
# change to named workspace
2023-02-17 00:41:22 +01:00
"${cfg.config.modifier}+grave" =
let
script = pkgs.writers.writeBash "select-workspace" ''
set -e
set -o pipefail
${pkgs.i3}/bin/i3-msg -t get_workspaces | \
${pkgs.jq}/bin/jq --raw-output '.[] | .name' | \
${pkgs.rofi}/bin/rofi -dmenu -p 'Select Workspace' | \
while read line
do
2023-05-28 11:32:42 +02:00
${pkgs.i3}/bin/i3-msg workspace "$line"
2023-02-17 00:41:22 +01:00
done
'';
in
"exec ${script}";
2023-09-19 12:17:46 +02:00
"${cfg.config.modifier}+Shift+grave" =
let
script = pkgs.writers.writeBash "move-workspace" ''
set -e
set -o pipefail
${pkgs.i3}/bin/i3-msg -t get_workspaces | \
${pkgs.jq}/bin/jq --raw-output '.[] | .name' | \
2023-10-26 09:30:35 +02:00
${pkgs.rofi}/bin/rofi -dmenu -p 'Move to Workspace' | \
2023-09-19 12:17:46 +02:00
while read line
do
${pkgs.i3}/bin/i3-msg move container to workspace "$line"
done
'';
in
"exec ${script}";
2023-02-17 00:41:22 +01:00
"${cfg.config.modifier}+Shift+c" = "reload";
"${cfg.config.modifier}+Shift+r" = "restart";
"${cfg.config.modifier}+Shift+e" = "exec i3-nagbar -t warning -m 'Do you want to exit i3?' -b 'Yes' 'i3-msg exit'";
"${cfg.config.modifier}+r" = "mode resize";
# multiple monitors
# autorandr --save docked # to save setup
# autorandr --save undocked # to save setup
# autorandr --change # automatically detects the setup
"${cfg.config.modifier}+BackSpace" =
let
script = pkgs.writers.writeBash "autorandr" ''
${pkgs.autorandr}/bin/autorandr --change
${backgroundCommand}
'';
in
"exec ${toString script}";
# like vimperator
"${cfg.config.modifier}+a" = "exec ${pkgs.i3-easyfocus}/bin/i3-easyfocus";
};
};
};
};
};
}