From 658502213896d05190b1eb26860edac07cc8dcbb Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.dev>
Date: Thu, 6 Mar 2025 01:12:32 +0000
Subject: [PATCH] Add displayselect from Luke Smith's dotfiles

---
 nix/home/opdavies/hosts/t490.nix          |  1 +
 nix/pkgs/default.nix                      |  1 +
 nix/pkgs/displayselect/default.nix        | 31 +++++++++++++++++++++++
 nix/pkgs/displayselect/remove-setbg.patch | 12 +++++++++
 4 files changed, 45 insertions(+)
 create mode 100644 nix/pkgs/displayselect/default.nix
 create mode 100644 nix/pkgs/displayselect/remove-setbg.patch

diff --git a/nix/home/opdavies/hosts/t490.nix b/nix/home/opdavies/hosts/t490.nix
index 66ab7932..b18ad5a2 100644
--- a/nix/home/opdavies/hosts/t490.nix
+++ b/nix/home/opdavies/hosts/t490.nix
@@ -30,6 +30,7 @@
   };
 
   home.packages = with pkgs; [
+    displayselect
     isync
     upload-to-files
   ];
diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix
index 6821efdc..5723b5b1 100644
--- a/nix/pkgs/default.nix
+++ b/nix/pkgs/default.nix
@@ -7,6 +7,7 @@ let
 in
 {
   build-glove80 = callPackage ./build-glove80.nix { };
+  displayselect = callPackage ./displayselect { };
   notes = callPackage ./notes { };
   tmux-sessionizer = callPackage ./tmux-sessionizer { };
   upload-to-files = callPackage ./upload-to-files.nix { };
diff --git a/nix/pkgs/displayselect/default.nix b/nix/pkgs/displayselect/default.nix
new file mode 100644
index 00000000..ac72a829
--- /dev/null
+++ b/nix/pkgs/displayselect/default.nix
@@ -0,0 +1,31 @@
+{ pkgs, ... }:
+
+with pkgs;
+
+stdenv.mkDerivation {
+  pname = "displayselect";
+  version = "0.1.0";
+
+  src = fetchFromGitHub {
+    owner = "lukesmithxyz";
+    repo = "voidrice";
+    rev = "master";
+    sha256 = "BybEijy1zH+UNyCgWnenmcazwE8B3PXGc+Cl0FO/n3o=";
+  };
+
+  buildInputs = [
+    bash
+    bc
+    xorg.xrandr
+  ];
+
+  patches = [
+    ./remove-setbg.patch
+  ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp .local/bin/displayselect $out/bin
+    chmod +x $out/bin/displayselect
+  '';
+}
diff --git a/nix/pkgs/displayselect/remove-setbg.patch b/nix/pkgs/displayselect/remove-setbg.patch
new file mode 100644
index 00000000..585f1fc5
--- /dev/null
+++ b/nix/pkgs/displayselect/remove-setbg.patch
@@ -0,0 +1,12 @@
+diff --git a/.local/bin/displayselect b/.local/bin/displayselect
+index 51dd468..f69f154 100755
+--- a/.local/bin/displayselect
++++ b/.local/bin/displayselect
+@@ -57,7 +57,6 @@ onescreen() { # If only one output available or chosen.
+ 	}
+ 
+ postrun() { # Stuff to run to clean up.
+-	setbg		# Fix background if screen size/arangement has changed.
+ 	{ killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen
+ 	}
+