]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Adds kvmx-clipboard
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 24 Oct 2018 21:36:38 +0000 (18:36 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 24 Oct 2018 21:36:38 +0000 (18:36 -0300)
kvmx
kvmx-clipboard [new file with mode: 0755]
share/provision/desktop-basic

diff --git a/kvmx b/kvmx
index 102391d2d4212535f799a6b70dc4e7dfe312ba8f..06fd28819aac438b664cb1b8351839d5c84c9dff 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -277,6 +277,7 @@ function kvmx_spice {
     fi
 
     xdotool search --name "SPICEc:0" set_window --name $VM
+    xdotool search --name "spice display 0:0" set_window --name $VM
   fi
 
   if [ "$ACTION" == "spice" ]; then
diff --git a/kvmx-clipboard b/kvmx-clipboard
new file mode 100755 (executable)
index 0000000..3005c51
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/env bash
+#
+# kvmx-clipboard manage clipboard sharing between host and guests
+#
+# Copyright (C) 2018 Silvio Rhatto - rhatto at riseup.net
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation, either version 3 of the License,
+# or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# Parameters
+CONTENT=""
+
+function __kvmx_clipboard_receive {
+  local VM="$1"
+
+  if [ "$VM" == "host" ]; then
+    #CONTENT="`xclip -o`"
+    CONTENT="`xsel -o`"
+  else
+    #CONTENT="`kvmx ssh $VM -X 'DISPLAY=:0 xclip -o'`"
+    CONTENT="`kvmx ssh $VM -X 'xsel -o --display :0'`"
+  fi
+}
+
+function __kvmx_clipboard_send {
+  local VM="$1"
+
+  if [ "$VM" == "host" ]; then
+    #echo $CONTENT | xclip -i
+    echo $CONTENT | xsel -i
+  else
+    #echo $CONTENT | kvmx ssh $VM -X 'DISPLAY=:0 xclip -i -l 1'
+    echo $CONTENT | kvmx ssh $VM -X 'xsel -i --display :0'
+  fi
+}
+
+function __kvmx_clipboard_copy {
+  local ORIG="$1"
+  local DEST="$2"
+
+  __kvmx_clipboard_receive $ORIG
+  __kvmx_clipboard_send    $DEST
+}
+
+function __kvmx_clipboard_list {
+  # That's crude, but fast
+  instances="`ps aux | grep qemu-system | grep -- '-name ' | sed -e 's/^.*-name //' -e 's/ .*//'`"
+  instances="host $instances"
+
+  echo "KVMX Clipboard"
+  echo ""
+
+  n="0"
+
+  # Buld menu entries
+  for orig_instance in $instances; do
+    for dest_instance in $instances; do
+      if [ "$orig_instance" == "$dest_instance" ]; then
+        continue
+      fi
+
+      echo "$n: $orig_instance -> $dest_instance"
+
+      let n++
+    done
+  done
+}
+
+function __kvmx_clipboard_menu {
+  __kvmx_clipboard_list
+
+  echo ""
+  read -rep "Your choice: " n
+
+  choice="$(__kvmx_clipboard_list | grep ^$n: | sed -e "s/^$n://" -e "s/->//")"
+
+  if [ ! -z "$choice" ]; then
+    __kvmx_clipboard_copy $choice
+  fi
+}
+
+# Main
+if [ -z "$2" ]; then
+  __kvmx_clipboard_menu
+else
+  __kvmx_clipboard_copy $1 $2
+fi
index b90c83e799b2f28f788b296355b13a80250b0a09..7571a89abb8228abf222de0ec5dcb9b5012ad608 100755 (executable)
@@ -46,7 +46,7 @@ apps/metadot/metadot deps-bundle desktop-basic
 
 # Additional packages
 echo "Installing additional desktop-basic packages..."
-$APT_INSTALL xpra lightdm firejail
+$APT_INSTALL xpra lightdm firejail xsel
 
 # See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=861744
 $APT_INSTALL torbrowser-launcher alsa-utils pulseaudio