aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-08-04 10:40:53 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-08-04 10:40:53 -0300
commit2a7d2f4443dc81e518bb25750574af2de296b6b2 (patch)
treee60e9100c3157a80dcebaa01efe41a52208f74ef
parent43c24a15212f4971ff57d69d62d5ab383ff6d17c (diff)
downloadkvmx-2a7d2f4443dc81e518bb25750574af2de296b6b2.tar.gz
kvmx-2a7d2f4443dc81e518bb25750574af2de296b6b2.tar.bz2
Fix: improved spice window handling
-rw-r--r--ChangeLog.md2
-rw-r--r--TODO.md4
-rwxr-xr-xkvmx54
3 files changed, 54 insertions, 6 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index cc04608..6347bad 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -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 d010c8e..083d764 100644
--- 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 b234f5c..5b386ab 100755
--- 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