OSDN Git Service

rework getmonitor
authorpaperbenni <paperbenni@gmail.com>
Thu, 26 Dec 2019 10:45:05 +0000 (11:45 +0100)
committerpaperbenni <paperbenni@gmail.com>
Thu, 26 Dec 2019 10:45:05 +0000 (11:45 +0100)
programs/dswitch

index 7742221..93e3b67 100755 (executable)
@@ -43,7 +43,8 @@ if ! [ -e ~/paperbenni/ismultimonitor ]; then
 fi
 
 getmonitor() {
-    XPOS=$(xdotool getwindowfocus getwindowgeometry | grep -Eoi 'position.*,' | grep -o '[0-9]*')
+    xdotool key 'super+W'
+    XPOS=$(xdotool getmouselocation --shell | head -1 | grep -o '[0-9]*')
     if [ "$XPOS" -gt "1919" ]; then
         echo "1"
     else
@@ -70,19 +71,25 @@ OLDM="$(getmonitor)"
 focuswin "$WID"
 
 if ! wincomp "$(pfw)" "$WID"; then
-    if ! [ "$OLD" = "0x000001e1" ]; then
-        if ! [ "$OLDM" = "$(getmonitor)" ]; then
+    if ! [ "$OLDM" = "$(getmonitor)" ]; then
+        if ! [ "$OLD" = "0x000001e1" ]; then
+            xdotool key 'super+comma'
+            focuswin "$OLD"
             xdotool key 'super+comma'
         fi
+        focuswin "$WID"
+    else
         focuswin "$OLD"
+        xdotool key 'super+comma'
+        focuswin "$WID"
     fi
-    xdotool key 'super+comma'
-    focuswin "$WID"
 else
-    if ! [ "$OLDM" = "$(getmonitor)" ]; then
-        xdotool key 'super+comma'
-        [ "$OLD" = "0x000001e1" ] || focuswin "$OLD"
-        xdotool key 'super+comma'
+    if ! [ "$OLD" = "0x000001e1" ]; then
+        if ! [ "$OLDM" = "$(getmonitor)" ]; then
+            xdotool key 'super+comma'
+            focuswin "$OLD"
+            xdotool key 'super+comma'
+        fi
     fi
 fi