summaryrefslogtreecommitdiffstats
path: root/pkgs/simple/xoutinfo/xoutinfo.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/simple/xoutinfo/xoutinfo.sh')
-rwxr-xr-xpkgs/simple/xoutinfo/xoutinfo.sh90
1 files changed, 90 insertions, 0 deletions
diff --git a/pkgs/simple/xoutinfo/xoutinfo.sh b/pkgs/simple/xoutinfo/xoutinfo.sh
new file mode 100755
index 0000000..3353cbe
--- /dev/null
+++ b/pkgs/simple/xoutinfo/xoutinfo.sh
@@ -0,0 +1,90 @@
+#! /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)
+ }
+'