From fa61fceddd0952c16b0f0e089403786305044648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 18 Oct 2013 03:33:56 +0200 Subject: [PATCH] Fix watching clipboard change when the file initially doesn't exists (#749) When the file doesn't exists, adding a watch fails. So monitor directory for IN_CREATE event and when file is created - add the modify watch. This watch will miss the first update (rather: create), so fire it in IN_CREATE handler. --- qubesmanager/main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qubesmanager/main.py b/qubesmanager/main.py index e6d57a5..432397d 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -22,6 +22,7 @@ import sys import os +import os.path import signal import fcntl import errno @@ -98,6 +99,11 @@ class QubesManagerFileWatcher(ProcessEvent): "Press Ctrl-Shift-v to copy this clipboard onto dest VM's clipboard.".format(src_vmname), msecs=3000) src_info_file.close() + def process_IN_CREATE(self, event): + if event.name == os.path.basename(qubes_clipboard_info_file): + event.path = qubes_clipboard_info_file + self.process_IN_CLOSE_WRITE(event) + wm.add_watch(qubes_clipboard_info_file, EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE')) class VmIconWidget (QWidget): @@ -2210,13 +2216,15 @@ def main(): global manager_window manager_window = VmManagerWindow() - wm = WatchManager() + global wm + wm = WatchManager() global notifier notifier = ThreadedNotifier(wm, QubesManagerFileWatcher(manager_window.mark_table_for_update)) notifier.start() wm.add_watch(system_path["qubes_store_filename"], EventsCodes.OP_FLAGS.get('IN_MODIFY')) wm.add_watch(qubes_clipboard_info_file, EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE')) + wm.add_watch(os.path.dirname(qubes_clipboard_info_file), EventsCodes.OP_FLAGS.get('IN_CREATE')) global system_bus system_bus = QDBusConnection.systemBus()