dom0/qclipd: use Glib mainloop instead of simple while True

It is actually needed by dbus bindings when using
follow_name_owner_changes=True.
This commit is contained in:
Marek Marczykowski 2013-02-14 19:05:33 +01:00
parent 740ffd2ee7
commit 39a26cdb08

View File

@ -24,6 +24,8 @@ import os
import daemon import daemon
from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent
import dbus import dbus
from dbus.mainloop.glib import DBusGMainLoop
import glib,gobject
from qubes.qubes import QubesDaemonPidfile from qubes.qubes import QubesDaemonPidfile
qubes_clipboard_info_file = "/var/run/qubes/qubes_clipboard.bin.source" qubes_clipboard_info_file = "/var/run/qubes/qubes_clipboard.bin.source"
@ -32,6 +34,7 @@ def watch_qubes_clipboard():
def tray_notify(str, timeout = 3000): def tray_notify(str, timeout = 3000):
notify_object.Notify("Qubes", 0, "dialog-information", "", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") notify_object.Notify("Qubes", 0, "dialog-information", "", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications")
glib_mainloop = DBusGMainLoop(set_as_default=True)
notify_object = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications", follow_name_owner_changes=True) notify_object = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications", follow_name_owner_changes=True)
wm = WatchManager() wm = WatchManager()
mask = EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE') mask = EventsCodes.OP_FLAGS.get('IN_CLOSE_WRITE')
@ -56,10 +59,15 @@ def watch_qubes_clipboard():
notifier = Notifier(wm, ClipboardWatcher()) notifier = Notifier(wm, ClipboardWatcher())
wdd = wm.add_watch(qubes_clipboard_info_file, mask) wdd = wm.add_watch(qubes_clipboard_info_file, mask)
while True: def process_inotify(source, cb_condition):
notifier.process_events()
if notifier.check_events(): if notifier.check_events():
notifier.read_events() notifier.read_events()
notifier.process_events()
return True
glib.io_add_watch(wm.get_fd(), glib.IO_IN, process_inotify)
gobject.MainLoop().run()
def main(): def main():
lock = QubesDaemonPidfile ("qclipd") lock = QubesDaemonPidfile ("qclipd")