]> 91.132.146.200 Git - klimbim.git/commitdiff
new script to detect on which monotor the current active window is
authorBanana <banana@starscream.de>
Tue, 23 Jan 2018 11:34:58 +0000 (12:34 +0100)
committerBanana <banana@starscream.de>
Tue, 23 Jan 2018 11:34:58 +0000 (12:34 +0100)
bash/detect-monitor.sh [new file with mode: 0644]
bash/move-window.sh [changed mode: 0755->0644]
bash/watcher-script-ohne-watch.sh [changed mode: 0755->0644]

diff --git a/bash/detect-monitor.sh b/bash/detect-monitor.sh
new file mode 100644 (file)
index 0000000..5e120af
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+
+# detect on which monitor the current active window is
+# limitation are with negative position coordinates.
+
+# needs the following applications
+# xdotool
+# xwininfo
+# xrandr
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+#
+# You should have received a copy of the
+# COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+# along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+
+# 2018 http://www.bananas-playground.net
+
+OFFSET_RE="[\+\-]([-0-9]+)[\+\-]([-0-9]+)"
+
+# Get the window position
+window_id=$(xdotool getactivewindow)
+posx=$(xwininfo -id $window_id | awk '/Absolute upper-left X:/ { print $4 }')
+posy=$(xwininfo -id $window_id | awk '/Absolute upper-left Y:/ { print $4 }')
+
+# Subtract any offsets caused by window decorations and panels
+x_offset=$(xwininfo -id $window_id | awk '/Relative upper-left X:/ { print $4 }')
+y_offset=$(xwininfo -id $window_id | awk '/Relative upper-left Y:/ { print $4 }')
+posx=$((posx - x_offset))
+posy=$((posy - y_offset))
+
+# Loop through each screen and compare the offset with the window
+# coordinates.
+while read name width height xoff yoff
+do
+  if [ "$posx" -ge "$xoff" \
+    -a "$posy" -ge "$yoff" \
+    -a "$posx" -lt "$(($xoff+$width))" \
+    -a "$posy" -lt "$(($yoff+$height))" ]
+  then
+    monitor=$name   
+  fi
+done < <(xrandr | grep -w connected |
+  sed -r "s/^([^ ]*).*\b([-0-9]+)x([-0-9]+)$OFFSET_RE.*$/\1 \2 \3 \4 \5/" |
+  sort -nk4,5)
+
+# If we found a monitor, echo it out, otherwise print an error.
+if [ ! -z "$monitor" ]
+then
+  echo $monitor
+  exit 0
+else
+  echo "Couldn't find any monitor for the current window." >&2
+  echo "Or the top left pos is moved out of the screen and thus a negative pos." >&2
+  exit 1
+fi
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)