aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/get-focussed-monitor
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/get-focussed-monitor')
-rwxr-xr-x.local/bin/get-focussed-monitor43
1 files changed, 43 insertions, 0 deletions
diff --git a/.local/bin/get-focussed-monitor b/.local/bin/get-focussed-monitor
new file mode 100755
index 0000000..4d7bbd4
--- /dev/null
+++ b/.local/bin/get-focussed-monitor
@@ -0,0 +1,43 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub MAIN (
+ #Bool:D :$shell = False,
+ Bool:D :$coords = False,
+) {
+ my @xrandr = shell('xrandr | grep -w connected', :out).out.slurp.lines;
+ my %monitors;
+
+ my $mouse = shell('xdotool getmouselocation', :out).out.slurp.trim ~~ m/
+ 'x:' $<x> = [ \d+ ]
+ \s*
+ 'y:' $<y> = [ \d+ ]
+ /;
+
+ for @xrandr -> $monitor {
+ my $match = $monitor ~~ m/
+ $<width> = [ \d+ ]
+ 'x'
+ $<height> = [ \d+ ]
+ '+'
+ $<x> = [ \d+ ]
+ '+'
+ $<y> = [ \d+ ]
+ /;
+
+ next unless $match<x> ≤ $mouse<x> ≤ ($match<x> + $match<width>);
+ next unless $match<y> ≤ $mouse<y> ≤ ($match<y> + $match<height>);
+
+ say qq[MONITOR="{$monitor.words.first}"];
+
+ if ($coords) {
+ say qq[W="{$match<width>}"];
+ say qq[H="{$match<height>}"];
+ say qq[X="{$match<x>}"];
+ say qq[Y="{$match<y>}"];
+ }
+
+ last;
+ }
+}