diff options
-rw-r--r-- | pkgs/haskell/xoutinfo.nix | 16 | ||||
-rw-r--r-- | pkgs/simple/xoutinfo/default.nix | 19 | ||||
-rwxr-xr-x | pkgs/simple/xoutinfo/xoutinfo.sh | 90 |
3 files changed, 16 insertions, 109 deletions
diff --git a/pkgs/haskell/xoutinfo.nix b/pkgs/haskell/xoutinfo.nix new file mode 100644 index 0000000..64b6f87 --- /dev/null +++ b/pkgs/haskell/xoutinfo.nix @@ -0,0 +1,16 @@ +{ mkDerivation, aeson, base, bytestring, fetchgit, lib, X11 }: +mkDerivation { + pname = "xoutinfo"; + version = "0.1.0.0"; + src = fetchgit { + url = "https://cgit.ni.krebsco.de/xoutinfo"; + sha256 = "1g3s9vyy7bpsl2zjiq6kk16c8hhf3n2yz4lv3ic0qy0n6wn6qqi8"; + rev = "cf7377886a55e36701bd0d5ce7c723aa6d7bd9bd"; + fetchSubmodules = true; + }; + isLibrary = false; + isExecutable = true; + executableHaskellDepends = [ aeson base bytestring X11 ]; + license = lib.licenses.wtfpl; + mainProgram = "xoutinfo"; +} diff --git a/pkgs/simple/xoutinfo/default.nix b/pkgs/simple/xoutinfo/default.nix deleted file mode 100644 index 92dbb42..0000000 --- a/pkgs/simple/xoutinfo/default.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ lib, pkgs }: - -pkgs.runCommand "xoutinfo-1.0.0" {} /* sh */ '' - mkdir -p $out/bin - - cp ${./xoutinfo.sh} $out/bin/xoutinfo - sed -i ' - s|#! /bin/sh|#! ${pkgs.dash}/bin/dash| - s|^export AWKPATH=.*|export AWKPATH=${lib.makeSearchPath "/lib/awk" [ - pkgs.awklib - ]}| - s|#PATH=|PATH=${lib.makeBinPath [ - pkgs.coreutils - pkgs.gawk - pkgs.xdotool - pkgs.xorg.xrandr - ]}| - ' $out/bin/xoutinfo -'' diff --git a/pkgs/simple/xoutinfo/xoutinfo.sh b/pkgs/simple/xoutinfo/xoutinfo.sh deleted file mode 100755 index 3353cbe..0000000 --- a/pkgs/simple/xoutinfo/xoutinfo.sh +++ /dev/null @@ -1,90 +0,0 @@ -#! /bin/sh -# usage: xoutinfo - -set -efu - -#PATH= -export AWKPATH=$HOME/sync/src/hrm/pkgs/simple/awklib/src/lib/awk - -{ - echo derp - xrandr --query --nograb - echo Screen 7: derp - echo bah -} | -awk \ - $( - # assign X, Y, SCREEN, and WINDOW variables - xdotool getmouselocation --shell --prefix '-v ' | tr '\n' ' ' - ) \ -' - @include "json" - - function dprint(x) { - #print(x) > "/dev/stderr" - } - - BEGIN { - default_dpi = 96 - skip = mkbool(1) - } - $1 == "Screen" { skip=mkbool($2!=SCREEN":") } - - { dprint( (skip?"skip:\033[31m":"read:\033[32m") $0 "\033[m") } - - skip { next } - - $2 == "connected" { - # Example line: - # HDMI-A-0 connected 3840x2160+0+0 (normal left inverted right x axis y axis) 597mm x 336mm - - sub(/ [(][^)]+[)]/, "") - - # Get physical width and height [in mm] - split(gensub(/^.* ([0-9]+)mm x ([0-9]+)mm$/, "\\1 \\2", 1), physical_geometry) - if (/\<left\>/ || /\<right\>/) { - pw=strtonum(physical_geometry[2]) - ph=strtonum(physical_geometry[1]) - } else { - pw=strtonum(physical_geometry[1]) - ph=strtonum(physical_geometry[2]) - } - - name=$1 - split(gensub(/^.* ([0-9]+x[0-9]+\+[0-9]+\+[0-9]+) .*$/, "\\1", 1), geometry, /[x+]/) - w=strtonum(geometry[1]) - h=strtonum(geometry[2]) - x=strtonum(geometry[3]) - y=strtonum(geometry[4]) - - dpi_x = w / pw * 25.4 - dpi_y = h / ph * 25.4 - - # This assumes DPI has not been configured - # (e.g. by passing -dpi to X or calling xrandr --dpi) - device_scale_factor = dpi_x / default_dpi - - is_current_display=(x <= X && X < x + w && y <= Y && Y < y + h) - - if (is_current_display) { - output["name"] = name - output["width"] = w - output["height"] = h - output["x"] = x - output["y"] = y - output["width_mm"] = pw - output["height_mm"] = ph - output["dpi_x"] = dpi_x - output["dpi_y"] = dpi_y - output["device_scale_factor"] = device_scale_factor - print toJSON(output) - delete output - } - - dprint(name " " w "x" h "+" x "+" y " is_current_display:" is_current_display) - dprint("physical_geometry:" pw "mm" "x" ph "mm" ", dpi:" dpi_x "," dpi_y ", 0:" $0 \ - ", device_scale_factor:" device_scale_factor) - dprint("X:" X) - dprint("Y:" Y) - } -' |