diff --git a/programs/autorandr.nix b/programs/autorandr.nix index 2444ec0..737a188 100644 --- a/programs/autorandr.nix +++ b/programs/autorandr.nix @@ -1,25 +1,21 @@ { pkgs, ... }: { - # TODO: this shit ain't working home-manager.users.krizej.programs.autorandr = { enable = true; - hooks.postswitch = { - "notify-i3" = "${pkgs.i3}/bin/i3-msg restart"; - }; profiles = { "main" = { fingerprint = { - "DP-3" = "00ffffffffffff0026cd5961830600001d1f0104b5361e783b4c70a5574ea4260b5054a56b80710081408180a940b3009500950fd1c0023a801871382d40582c4500202f2100001e000000ff0031313737393132393031363637000000fd0030f0ffff3c010a202020202020000000fc00504c3235393048530a20202020019202033bf1529005040302011112131f203f140607151640e200d52309070783010000e305c301e60605016666006d1a0000020130f00000000000005a8780a070384d4030203500202f2100001ad09480a070381e4008203500202f2100001a23e88078703887401c40980c202f2100001a000000000000000000000000000063"; - "HDMI-3" = "00ffffffffffff0026cd326162190000291c010380361e782a9055a75553a028135054a56b80710081408180a940b3009500950fd1c0023a801871382d40582c4500202f2100001e000000ff0031313534333834313036343938000000fd00374c1e5312000a202020202020000000fc00504c32353330480a2020202020016202032bf14f90050403020111121314060715161f230907078301000065030c001000681a00000101284be6023a801871382d40582c4500202f2100001f011d8018711c1620582c2500202f2100009e011d007251d01e206e285500202f2100001e2a4480a07038274030203500202f2100001a000000000000000000000000ab"; + "Left" = "00ffffffffffff0026cd5961830600001d1f0104b5361e783b4c70a5574ea4260b5054a56b80710081408180a940b3009500950fd1c0023a801871382d40582c4500202f2100001e000000ff0031313737393132393031363637000000fd0030f0ffff3c010a202020202020000000fc00504c3235393048530a20202020019202033bf1529005040302011112131f203f140607151640e200d52309070783010000e305c301e60605016666006d1a0000020130f00000000000005a8780a070384d4030203500202f2100001ad09480a070381e4008203500202f2100001a23e88078703887401c40980c202f2100001a000000000000000000000000000063"; + "Right" = "00ffffffffffff0026cd326162190000291c010380361e782a9055a75553a028135054a56b80710081408180a940b3009500950fd1c0023a801871382d40582c4500202f2100001e000000ff0031313534333834313036343938000000fd00374c1e5312000a202020202020000000fc00504c32353330480a2020202020016202032bf14f90050403020111121314060715161f230907078301000065030c001000681a00000101284be6023a801871382d40582c4500202f2100001f011d8018711c1620582c2500202f2100009e011d007251d01e206e285500202f2100001e2a4480a07038274030203500202f2100001a000000000000000000000000ab"; }; config = { - "DP-3" = { + "Left" = { enable = true; mode = "1920x1080"; rate = "239.76"; position = "0x0"; }; - "HDMI-3" = { + "Right" = { enable = true; mode = "1920x1080"; rate = "74.97"; @@ -30,4 +26,18 @@ }; }; }; + # the autorandr service from home-manager sucks, can't customize flags + home-manager.users.krizej.services.autorandr.enable = false; + home-manager.users.krizej.systemd.user.services.autorandr = { + Unit = { + Description = "autorandr"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${pkgs.autorandr}/bin/autorandr --match-edid -l main"; + }; + Install.WantedBy = [ "graphical-session.target" ]; + }; } diff --git a/programs/i3.nix b/programs/i3.nix index 2e773f9..4d0ae99 100644 --- a/programs/i3.nix +++ b/programs/i3.nix @@ -1,6 +1,7 @@ -{ config, pkgs, ... }: +args @ { config, pkgs, lib, ... }: let HOME = config.home-manager.users.krizej.home.homeDirectory; + monitors = import ../utils/monitors.nix args; in { services.xserver.windowManager.i3.enable = true; home-manager.users.krizej = { @@ -50,8 +51,8 @@ in { defaultWorkspace = "workspace number 1"; workspaceOutputAssign = [ - { workspace = "1"; output = "DP-3"; } - { workspace = "2"; output = "HDMI-3"; } + { workspace = "1"; output = "DisplayPort-2"; } # monitors.left; } + { workspace = "2"; output = "HDMI-A-0"; } # monitors.right; } ]; focus = { @@ -68,8 +69,6 @@ in { { command = "i3-msg \"workspace 2; append_layout ~/.config/i3/workspace2.json\""; notification = false; } { command = "discord &"; notification = false; } { command = "element-desktop &"; notification = false; } - - { command = "xrandr --output DP-3 --mode 1920x1080 --rate 239.76 --primary --output HDMI-3 --mode 1920x1080 --rate 74.97 --right-of DP-3 &"; notification = false; } ]; modes = let @@ -242,6 +241,7 @@ in { home.file = { ".config/i3/workspace2.json".source = ../files/workspace2.json; ".config/i3/i3gtk.css".source = ../files/i3gtk.css; + "dupa".text = "[${monitors.left}][${monitors.right}]"; }; }; } diff --git a/utils/monitors.nix b/utils/monitors.nix new file mode 100644 index 0000000..4002557 --- /dev/null +++ b/utils/monitors.nix @@ -0,0 +1,20 @@ +# fixme: when rebuiling the commands are ran as some nixos builder user probably and autorandr does not use my config +{ pkgs, ... }: let + autorandr = "${pkgs.autorandr}/bin/autorandr"; + rg = "${pkgs.ripgrep}/bin/rg"; + rev = "${pkgs.util-linux}/bin/rev"; + cut = "${pkgs.coreutils-full}/bin/cut"; + # epically stolen from https://git.jacekpoz.pl/jacekpoz/nte/src/branch/master/stdlib.nix + # but i changed lib.strings.readFile to lib.fileContents + inherit (pkgs) lib runCommand; + inherit (lib) fileContents; + run = script: builtins.toString (runCommand "run" {} '' + echo $(${script}) > $out + ''); +in { + # this parses "main: renaming display Left to DisplayPort-2" + # and i am interested in "DisplayPort-2" + # and also it's printed to stderr so 2>&1 + left = run "${autorandr} --match-edid 2>&1 | ${rg} Left | ${rev} | ${cut} -d' ' -f1 | ${rev}"; + right = run "${autorandr} --match-edid 2>&1 | ${rg} Right | ${rev} | ${cut} -d' ' -f1 | ${rev}"; +}