From 1649f18a8f134de817396d5bfe835644de51f4e9 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 20 Nov 2024 17:15:50 -0500 Subject: [PATCH] Applied same fix for export to X to import as well. --- .../commands/commands/import_clipboard_from_x.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/fenrirscreenreader/commands/commands/import_clipboard_from_x.py b/src/fenrirscreenreader/commands/commands/import_clipboard_from_x.py index c7fea60b..6c43f7a8 100644 --- a/src/fenrirscreenreader/commands/commands/import_clipboard_from_x.py +++ b/src/fenrirscreenreader/commands/commands/import_clipboard_from_x.py @@ -8,7 +8,6 @@ from fenrirscreenreader.core import debug import subprocess, os from subprocess import Popen, PIPE import _thread - class command(): def __init__(self): pass @@ -21,19 +20,27 @@ class command(): return _("imports the graphical clipboard to Fenrir's clipboard") def run(self): _thread.start_new_thread(self._threadRun , ()) - def _threadRun(self): try: + # Find xclip path + xclip_paths = ['/usr/bin/xclip', '/bin/xclip', '/usr/local/bin/xclip'] + xclip_path = None + for path in xclip_paths: + if os.path.isfile(path) and os.access(path, os.X_OK): + xclip_path = path + break + if not xclip_path: + self.env['runtime']['outputManager'].presentText('xclip not found in common locations', interrupt=True) + return xClipboard = '' for display in range(10): - p = Popen('su ' + self.env['general']['currUser'] + ' -c "xclip -d :0 -o"' , stdout=PIPE, stderr=PIPE, shell=True) + p = Popen('su ' + self.env['general']['currUser'] + ' -p -c "' + xclip_path + ' -d :' + str(display) + ' -o"', stdout=PIPE, stderr=PIPE, shell=True) stdout, stderr = p.communicate() self.env['runtime']['outputManager'].interruptOutput() stderr = stderr.decode('utf-8') xClipboard = stdout.decode('utf-8') if (stderr == ''): break - if stderr != '': self.env['runtime']['outputManager'].presentText(stderr , soundIcon='', interrupt=False) else: