blob: 524553dfa813cfea3bc60ab52d4aa79065580046 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#!/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
SPOOL="$TMP/.kvmx-spice-copy"
BASENAME="`basename $0`"
WINDOWID="`xdotool getwindowfocus`"
DEST="`xprop -id $WINDOWID | grep "^WM_NAME" | cut -d '=' -f 2 | cut -d '"' -f 2`"
# Logic
if [ "$BASENAME" == "kvmx-spice-copy" ]; then
mkdir -p "$TMP"
echo "$DEST" > $SPOOL
# UX
if which awesome-client &> /dev/null; then
echo "naughty.notify({title = \"KVMX Clipboard:\", text =\"Set orig to active window's system\", timeout = 2})" | awesome-client
fi
# Optional logging to ~/.xsession-erros
#echo "[kvmx-copy] [`date '+%Y%m%d %H:%M:%S'`] set ORIG to $DEST"
else
if [ -f "$SPOOL" ]; then
ORIG="`cat $SPOOL`"
else
ORIG="host"
fi
if [ "$ORIG" != "host" ] && ! kvmx running $ORIG &> /dev/null; then
ORIG="host"
fi
if [ "$DEST" != "host" ] && ! kvmx running $DEST &> /dev/null; then
DEST="host"
fi
if [ "$ORIG" == "$DEST" ]; then
exit
fi
if [ "$ORIG" == "host" ] && [ "$DEST" == "host" ]; then
exit
fi
# Optional logging to ~/.xsession-erros
#echo "[kvmx-paste] [`date '+%Y%m%d %H:%M:%S'`] from $ORIG to $DEST"
# UX
#if which awesome-client &> /dev/null; then
# echo "naughty.notify({title = \"KVMX Clipboard:\", text =\"Pasting from $ORIG to $DEST\", timeout = 2})" | awesome-client
#fi
# Dispatch
kvmx-clipboard $ORIG $DEST
# UX
if which awesome-client &> /dev/null; then
echo "naughty.notify({title = \"KVMX Clipboard:\", text =\"Done pasting from $ORIG to $DEST\", timeout = 2})" | awesome-client
fi
fi
|