Index: xpra/client/gtk3/gtk3_notifier.py =================================================================== --- xpra/client/gtk3/gtk3_notifier.py (revision 18038) +++ xpra/client/gtk3/gtk3_notifier.py (working copy) @@ -14,7 +14,7 @@ class GTK3_Notifier(NotifierBase): - def show_notify(self, dbus_id, tray, nid, app_id, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, tray, nid, app_id, app_name, replaces_nid, app_icon, summary, body, action, hints, expire_timeout, icon): if not self.dbus_check(dbus_id): return icon_string = self.get_icon_string(nid, app_icon, icon) Index: xpra/client/gtk_base/gtk_notifier.py =================================================================== --- xpra/client/gtk_base/gtk_notifier.py (revision 18038) +++ xpra/client/gtk_base/gtk_notifier.py (working copy) @@ -104,7 +104,7 @@ def get_origin_y(self): return self.y - def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): self.new_popup(summary, body, icon) def new_popup(self, summary, body, icon): Index: xpra/client/notifications/dbus_notifier.py =================================================================== --- xpra/client/notifications/dbus_notifier.py (revision 18038) +++ xpra/client/notifications/dbus_notifier.py (working copy) @@ -5,7 +5,7 @@ import os -from xpra.util import repr_ellipsized +from xpra.util import repr_ellipsized, csv from xpra.client.notifications.notifier_base import NotifierBase, log try: #new recommended way of using the glib main loop: @@ -46,8 +46,9 @@ self.org_fd_notifications = self.dbus_session.get_object(FD_NOTIFICATIONS, '/org/freedesktop/Notifications') self.dbusnotify = dbus.Interface(self.org_fd_notifications, FD_NOTIFICATIONS) log("using dbusnotify: %s(%s)", type(self.dbusnotify), FD_NOTIFICATIONS) + log("capabilities=%s", csv(str(x) for x in self.dbusnotify.GetCapabilities())) - def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): if not self.dbus_check(dbus_id): return self.may_retry = True @@ -64,7 +65,7 @@ except: app_str = app_name or "Xpra" self.last_notification = (dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon) - self.dbusnotify.Notify(app_str, 0, icon_string, summary, body, [], [], expire_timeout, + self.dbusnotify.Notify(app_str, 0, icon_string, summary, body, actions, hints, expire_timeout, reply_handler = self.cbReply, error_handler = self.cbError) except: Index: xpra/client/notifications/notifier_base.py =================================================================== --- xpra/client/notifications/notifier_base.py (revision 18038) +++ xpra/client/notifications/notifier_base.py (working copy) @@ -25,7 +25,7 @@ for nid in self.temp_files.keys(): self.clean_notification(nid) - def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): pass def get_icon_string(self, nid, app_icon, icon): Index: xpra/client/notifications/pynotify_notifier.py =================================================================== --- xpra/client/notifications/pynotify_notifier.py (revision 18038) +++ xpra/client/notifications/pynotify_notifier.py (working copy) @@ -10,7 +10,7 @@ class PyNotify_Notifier(NotifierBase): - def show_notify(self, dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): if not self.dbus_check(dbus_id): return icon_string = self.get_icon_string(nid, app_icon, icon) @@ -23,8 +23,17 @@ n = pynotify.Notification(summary, body, icon_string) n.set_urgency(pynotify.URGENCY_LOW) n.set_timeout(expire_timeout) + if actions and False: + while len(actions)>=2: + n.show() + def add_action(self, n, action_id, action_label): + #n.add_action("foo", "Foo!", foo_action) + def callback(*args): + pass + n.add_action(action_id, action_label, callback) + def close_notify(self, nid): pass @@ -34,7 +43,7 @@ import gtk def show(): n = PyNotify_Notifier() - n.show_notify("", 0, "Test", 0, "", "Summary", "Body...", 0) + n.show_notify("", 0, "Test", 0, "", "Summary", "Body...", [], {}, 0, "") return False glib.idle_add(show) glib.timeout_add(20000, gtk.main_quit) Index: xpra/client/ui_client_base.py =================================================================== --- xpra/client/ui_client_base.py (revision 18038) +++ xpra/client/ui_client_base.py (working copy) @@ -3430,15 +3430,16 @@ return self._ui_event() dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout = packet[1:9] + icon, actions, hints = None, [], {} if len(packet)>=10: icon = packet[9] - else: - icon = None + if len(packet)>=12: + actions, hints = packet[10], packet[11] #note: if the server doesn't support notification forwarding, #it can still send us the messages (via xpra control or the dbus interface) notifylog("_process_notify_show(%s) notifier=%s, server_notifications=%s", repr_ellipsized(str(packet)), self.notifier, self.server_notifications) + notifylog.info("actions=%s, hints=%s", actions, hints) assert self.notifier - #TODO: choose more appropriate tray if we have more than one shown? #this one of the few places where we actually do care about character encoding: try: summary = summary.decode("utf8") @@ -3449,9 +3450,9 @@ except: body = bytestostr(body) app_name = bytestostr(app_name) - tray = self.get_tray_window(app_name) + tray = self.get_tray_window(app_name, hints) traylog("get_tray_window(%s)=%s", app_name, tray) - self.notifier.show_notify(dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon) + self.notifier.show_notify(dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon) def _process_notify_close(self, packet): if not self.notifications_enabled: @@ -3461,10 +3462,18 @@ log("_process_notify_close(%s)", nid) self.notifier.close_notify(nid) - def get_tray_window(self, app_name): + def get_tray_window(self, app_name, hints): #try to identify the application tray that generated this notification, #so we can show it as coming from the correct systray icon #on platforms that support it (ie: win32) + try: + pid = int(hints.get("pid") or 0) + except (TypeError, ValueError): + pass + else: + #TODO: try to find a tray with this pid? + if pid: + notifylog("tray window: match pid=%i", pid) if app_name and app_name.lower()!="xpra": #exact match: for window in self._id_to_window.values(): Index: xpra/dbus/notifications_forwarder.py =================================================================== --- xpra/dbus/notifications_forwarder.py (revision 18038) +++ xpra/dbus/notifications_forwarder.py (working copy) @@ -4,9 +4,9 @@ # later version. See the file COPYING for details. import os -import gtk import dbus.service +from xpra.dbus.helper import dbus_to_native from xpra.log import Logger log = Logger("dbus", "notify") @@ -44,7 +44,17 @@ nid = replaces_nid log("Notify%s counter=%i, callback=%s", (app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout), self.counter, self.notify_callback) if self.notify_callback: - self.notify_callback(self.dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout) + try: + actions = tuple(str(x) for x in actions) + hints = dbus_to_native(hints) + args = self.dbus_id, int(nid), str(app_name), int(replaces_nid), str(app_icon), str(summary), str(body), actions, hints, int(expire_timeout) + except Exception as e: + log.error("Error: failed to parse Notify arguments:") + log.error(" %s", e) + try: + self.notify_callback(*args) + except Exception as e: + log.error("Error calling notification handler", exc_info=True) log("Notify returning %s", nid) return nid @@ -88,6 +98,7 @@ def main(): register() + import gtk gtk.main() if __name__ == "__main__": Index: xpra/platform/darwin/gui.py =================================================================== --- xpra/platform/darwin/gui.py (revision 18038) +++ xpra/platform/darwin/gui.py (working copy) @@ -110,7 +110,7 @@ self.notification_center = NSUserNotificationCenter.defaultUserNotificationCenter() assert self.notification_center - def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): notification = NSUserNotification.alloc().init() notification.setTitle_(summary) notification.setInformativeText_(body) @@ -133,7 +133,7 @@ class OSX_Subprocess_Notifier(NotifierBase): - def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): from xpra.platform.darwin import osx_notifier osx_notifier_file = osx_notifier.__file__ if osx_notifier_file.endswith("pyc"): Index: xpra/platform/win32/win32_notifier.py =================================================================== --- xpra/platform/win32/win32_notifier.py (revision 18038) +++ xpra/platform/win32/win32_notifier.py (working copy) @@ -8,7 +8,7 @@ class Win32_Notifier(NotifierBase): - def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): + def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): if tray is None: log.warn("Warning: no system tray - cannot show notification!") return Index: xpra/server/server_base.py =================================================================== --- xpra/server/server_base.py (revision 18038) +++ xpra/server/server_base.py (working copy) @@ -1115,7 +1115,7 @@ def idle_grace_timeout_cb(self, source): log("idle_grace_timeout_cb(%s)", source) timeout_nid = 2**16 + 2**8 + 1 - source.notify(0, timeout_nid, "xpra", 0, "", "This Xpra session will timeout soon", "Activate one of the windows to avoid this timeout", 10) + source.notify(0, timeout_nid, "xpra", 0, "", "This Xpra session will timeout soon", "Activate one of the windows to avoid this timeout", [], {}, 10, "") source.go_idle() def _log_disconnect(self, proto, *args): @@ -1784,7 +1784,7 @@ notifylog("control_command_send_notification(%i, %s, %s, %s) will send to sources %s (matching %s)", nid, title, message, client_uuids, sources, client_uuids) count = 0 for source in sources: - if source.notify(0, nid, "control channel", 0, "", title, message, 10, ()): + if source.notify(0, nid, "control channel", 0, "", title, message, [], {}, 10, ""): count += 1 msg = "notification id %i: message sent to %i clients" % (nid, count) notifylog(msg) @@ -2615,15 +2615,15 @@ if self._clipboard_client: self._clipboard_client.send_clipboard(parts) - def notify_callback(self, dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout): + def notify_callback(self, dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout): try: assert self.notifications_forwarder and self.notifications icon = self.get_notification_icon(str(app_icon)) if os.path.isabs(str(app_icon)): app_icon = "" - notifylog("notify_callback%s icon=%s", (dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout), repr_ellipsized(str(icon))) + notifylog("notify_callback%s icon=%s", (dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout), repr_ellipsized(str(icon))) for ss in self._server_sources.values(): - ss.notify(dbus_id, int(nid), str(app_name), int(replaces_nid), str(app_icon), str(summary), str(body), int(expire_timeout), icon) + ss.notify(dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon) except Exception as e: notifylog("notify_callback failed", exc_info=True) notifylog.error("Error processing notification:") Index: xpra/server/source.py =================================================================== --- xpra/server/source.py (revision 18038) +++ xpra/server/source.py (working copy) @@ -1962,8 +1962,8 @@ return self.send_async("bell", wid, device, percent, pitch, duration, bell_class, bell_id, bell_name) - def notify(self, dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon): - args = (dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon) + def notify(self, dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon): + args = (dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon) notifylog("notify%s types=%s", args, tuple(type(x) for x in args)) if not self.send_notifications: notifylog("client %s does not support notifications", self) @@ -1981,7 +1981,8 @@ except: body = str(body) if self.hello_sent: - self.send_async("notify_show", dbus_id, int(nid), str(app_name), int(replaces_nid), str(app_icon), summary, body, int(expire_timeout), icon) + #Warning: actions and hints are send last because they were added later (in version 2.3) + self.send_async("notify_show", dbus_id, nid, app_name, replaces_nid, app_icon, summary, body, expire_timeout, icon, actions, hints) return True def notify_close(self, nid):