Skip to content

Commit 73a7ab1

Browse files
authored
Merge pull request #13 from RandomCoderOrg/clipboard-exp
Clipboard feature for termux-x11
2 parents 4b700e6 + 1a4e2e2 commit 73a7ab1

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

install.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ if [ -f main.py ]; then
3838
}
3939
fi
4040

41+
# Clipboard watcher service
42+
cp utils/clipboard_watcher.service /lib/systemd/system/clipboard_watcher.service || {
43+
die "Failed to install clipboard_watcher.service"
44+
}
45+
4146
if [ -f main.sh ]; then
4247
cp -v main.sh /usr/share/udroid/ || {
4348
die "Failed to copy main.sh"

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def vnc_mode(port=1,mode="start",xstartup=os.getenv('HOME')+"/.vnc/xstartup"):
2020

2121
if __name__ == '__main__':
2222
parser = optparse.OptionParser()
23+
parser.add_option("--clipboard-service", action="store_true", dest="clipboard_service", default=False, help="Start clipboard service")
2324
parser.add_option("--upgrade" ,action="store_true", default=False, help="Installs update if found updates")
2425
parser.add_option("--upgrade-check",action="store_true", default=False, help="check for updates")
2526
parser.add_option("--startvnc" ,action='store_true', default=False, help="Start VNC on port")
@@ -42,4 +43,6 @@ def vnc_mode(port=1,mode="start",xstartup=os.getenv('HOME')+"/.vnc/xstartup"):
4243
from utils.upgrade import *
4344
upgrade_check()
4445
sys.exit(0)
45-
46+
if options.clipboard_service:
47+
from utils.clipboard_watcher import *
48+
start_clipboard_service()

main.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ case $(echo "$0" | cut -d "/" -f 4) in
1414
"udroid-upgrade-check")
1515
python3 /usr/share/udroid/main.py --upgrade-check
1616
;;
17+
"clipboard-service")
18+
python3 /usr/share/udroid/main.py --clipboard-service
1719
esac

utils/clipboard_watcher.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import time
3+
4+
CLIPBOARD_BUFFER_FILE = "/tmp/clipboard"
5+
6+
7+
def start_clipboard_service():
8+
"""
9+
watch if clipboard buffer file has changed
10+
if true, then pipe content buffer to xclip
11+
"""
12+
buffer = os.popen(f"cat {CLIPBOARD_BUFFER_FILE}").read().strip()
13+
14+
# check is xclip installed
15+
_xclip = os.popen("which xclip").read().strip()
16+
if _xclip is None:
17+
print("xclip not found")
18+
os.exit(1)
19+
20+
while os.getenv('DISPLAY') is not None:
21+
time.sleep(0.4)
22+
if os.path.exists(CLIPBOARD_BUFFER_FILE):
23+
if buffer != os.popen(f"cat {CLIPBOARD_BUFFER_FILE}").read().strip():
24+
os.system(
25+
f"cat {CLIPBOARD_BUFFER_FILE} | xclip -selection clipboard")
26+
buffer = os.popen(
27+
f"cat {CLIPBOARD_BUFFER_FILE}").read().strip()
28+
else:
29+
print("clipboard buffer file not found")
30+
os.exit(1)

utils/clipboard_watcher.service

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description="clipboard broaker for termux-x11"
3+
4+
[Service]
5+
WorkingDirectory="/usr/share/udroid"
6+
ExecStart="bash /usr/share/udroid/main.sh --clipboard-service"
7+
Restart=always
8+
9+
[Install]
10+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)