]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Fix: improved spice window handling
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 4 Aug 2024 13:40:53 +0000 (10:40 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 4 Aug 2024 13:40:53 +0000 (10:40 -0300)
ChangeLog.md
TODO.md
kvmx

index cc04608a3982b92e348627b4b7c939034d9025e4..6347bad6e1e4c691c4b97c1167083f8038609970 100644 (file)
@@ -2,6 +2,8 @@
 
 ## 0.3.0 - unreleased
 
+* Improved spice window handling.
+
 * Per-mountpoint mode option (ro, rw).
 
 * Inotify action for watching a folder in the host and issuing commands in the
diff --git a/TODO.md b/TODO.md
index d010c8ef192750ca517dcf8f654c2d7e66d23175..083d764221b8b0b84f61beb233cfd54eb2be19c9 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,9 @@
 # TODO
 
+## Fixes
+
+* [ ] Support for `virt-viewer` is currently broken (as of 2024-08-04).
+
 ## Usability
 
 * [ ] Submit patch for spice-client-gtk for menuless windows (spice usecase) to
diff --git a/kvmx b/kvmx
index b234f5cb15112f651c39508ddb9958f14566a59d..5b386abaff293db8d5a31f7d4816eecb0a38c621 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -265,16 +265,20 @@ function kvmx_spice {
     exit 1
   fi
 
+  local spicestring
+
   if [ "$spice_client" == "spicy" ] && which spicy &> /dev/null; then
+    spicestring="spice display 0:0"
     #spicy -h localhost -p $PORT &
     spicy --uri=spice+unix://$SPICESOCKET &
   elif [ "$spice_client" == "remote-viewer" ] && which remote-viewer &> /dev/null; then
+    spicestring="$VM \(1\)"
     #remote-viewer spice://localhost:$PORT &
     remote-viewer spice+unix://$SPICESOCKET &
   # This is untested due to libvirt requirements
   elif [ "$spice_client" == "virt-viewer" ] && which virt-viewer &> /dev/null; then
     #virt-viewer spice://localhost:$PORT &
-    virt-viewer spice+unix://$SPICESOCKET &
+    virt-viewer -c spice+unix://$SPICESOCKET &
   # Unsupported as spicec was deprecated
   #elif [ "$spice_client" != "spicec" ] && which spicec &> /dev/null; then
   #  # https://lists.freedesktop.org/archives/spice-devel/2013-September/014643.html
@@ -284,6 +288,7 @@ function kvmx_spice {
     exit 1
   else
     if which spicy &> /dev/null; then
+      spicestring="spice display 0:0"
       #spicy -h localhost -p $PORT &
       spicy --uri=spice+unix://$SPICESOCKET &
     fi
@@ -292,22 +297,59 @@ function kvmx_spice {
   SPICEPID="$!"
   echo "$SPICEPID" > $SPICEFILE
 
-  # Give time to connect
-  sleep 2
+  echo $spicestring
 
   # Fix window title and position
-  if which /usr/bin/xdotool &> /dev/null; then
+  if which /usr/bin/xdotool &> /dev/null && [ ! -z "$spicestring" ]; then
+    local spicewait="0"
+    local windowid
+    local windowpid
+
+    # Wait for the spice window to show up. This might take a while and we'll
+    # wait only a few times
+    while (( $spicewait <= 5 )); do
+      # Wait a bit
+      sleep 2
+      let spicewait++
+
+      windowid="`xdotool search --name "$spicestring" 2> /dev/null`"
+
+      if [ ! -z "$windowid" ]; then
+        # Get the SPICE PID
+        windowpid="`xprop -id $windowid | grep '_NET_WM_PID(CARDINAL)' | cut -d = -f 2 | sed -e 's/ //g'`"
+
+        if [ ! -z "$windowpid" ] && [ "$windowpid" == "$SPICEPID" ]; then
+          break
+        else
+          windowid=""
+          windowpid=""
+        fi
+      fi
+    done
+
     # Set window position
     #
     # Configuration xclient_windowmove can be set either at kvmxconfig
     # or as a user setting at ~/.config/kvmxconfig (which will affect all guests).
     if [ ! -z "$xclient_windowmove" ]; then
       #xdotool search --name "SPICEc:0" windowmove $xclient_windowmove
-      xdotool search --name "spice display 0:0" windowmove $xclient_windowmove
+      #xdotool search --name "spice display 0:0" windowmove $xclient_windowmove
+      #xdotool search --name "$spicestring" windowmove $xclient_windowmove
+
+      if [ ! -z "$windowid" ]; then
+        xdotool windowmove $windowid $xclient_windowmove
+      fi
     fi
 
+    # Rename window, search by title version
     #xdotool search --name "SPICEc:0" set_window --name $VM
-    xdotool search --name "spice display 0:0" set_window --name $VM
+    #xdotool search --name "spice display 0:0" set_window --name $VM
+    #xdotool search --name "$spicestring" set_window --name $VM
+
+    # Rename window, window ID version
+    if [ ! -z "$windowid" ]; then
+      xdotool set_window --name $VM $windowid
+    fi
   fi
 
   if [ "$ACTION" == "spice" ]; then