diff --git a/blueman/gui/Notification.py b/blueman/gui/Notification.py index c4edc9516..8fc7c04a1 100644 --- a/blueman/gui/Notification.py +++ b/blueman/gui/Notification.py @@ -24,7 +24,7 @@ def state_changed(self, state: float) -> None: class _NotificationDialog(Gtk.MessageDialog): - def __init__(self, summary: str, message: str, _timeout: int = -1, + def __init__(self, summary: str, message: str, _timeout: int = -1, _transient: bool = False, actions: Iterable[tuple[str, str]] | None = None, actions_cb: Callable[[str], None] | None = None, icon_name: str | None = None, image_data: GdkPixbuf.Pixbuf | None = None) -> None: @@ -119,7 +119,7 @@ def set_icon_from_icon_name(self, icon_name: str, size: int) -> None: class _NotificationBubble(Gio.DBusProxy): - def __init__(self, summary: str, message: str, timeout: int = -1, + def __init__(self, summary: str, message: str, timeout: int = -1, transient: bool = False, actions: Iterable[tuple[str, str]] | None = None, actions_cb: Callable[[str], None] | None = None, icon_name: str | None = None, image_data: GdkPixbuf.Pixbuf | None = None) -> None: @@ -162,6 +162,12 @@ def __init__(self, summary: str, message: str, timeout: int = -1, self._timeout = timeout self._return_id = None + if transient: + try: + self.set_hint('transient', True) + except ValueError: + pass + if icon_name: self._app_icon = icon_name elif image_data: @@ -267,9 +273,16 @@ def close(self) -> None: self._return_id = None -def Notification(summary: str, message: str, timeout: int = -1, actions: Iterable[tuple[str, str]] | None = None, - actions_cb: Callable[[str], None] | None = None, icon_name: str | None = None, - image_data: GdkPixbuf.Pixbuf | None = None) -> _NotificationBubble | _NotificationDialog: +def Notification( + summary: str, + message: str, + timeout: int = -1, + transient: bool = False, + actions: Iterable[tuple[str, str]] | None = None, + actions_cb: Callable[[str], None] | None = None, + icon_name: str | None = None, + image_data: GdkPixbuf.Pixbuf | None = None +) -> _NotificationBubble | _NotificationDialog: forced_fallback = not Gio.Settings(schema_id='org.blueman.general')['notification-daemon'] try: @@ -289,4 +302,4 @@ def Notification(summary: str, message: str, timeout: int = -1, actions: Iterabl else: klass = _NotificationBubble - return klass(summary, message, timeout, actions, actions_cb, icon_name, image_data) + return klass(summary, message, timeout, transient, actions, actions_cb, icon_name, image_data) diff --git a/blueman/main/applet/BluezAgent.py b/blueman/main/applet/BluezAgent.py index 9c782f8e9..121b59a50 100644 --- a/blueman/main/applet/BluezAgent.py +++ b/blueman/main/applet/BluezAgent.py @@ -229,8 +229,8 @@ def on_confirm_action(action: str) -> None: notify_message += "\n" + _("Confirm value for authentication:") + f" {passkey:06}" actions = [("confirm", _("Confirm")), ("deny", _("Deny"))] - self._notification = Notification("Bluetooth", notify_message, 0, actions, on_confirm_action, - icon_name="blueman") + self._notification = Notification("Bluetooth", notify_message, 0, + actions=actions, actions_cb=on_confirm_action, icon_name="blueman") self._notification.show() def _on_request_authorization(self, object_path: ObjectPath, ok: Callable[[], None], @@ -260,6 +260,7 @@ def on_auth_action(action: str) -> None: ("accept", _("Accept")), ("deny", _("Deny"))] - n = Notification(_("Bluetooth Authentication"), notify_message, 0, actions, on_auth_action, icon_name="blueman") + n = Notification(_("Bluetooth Authentication"), notify_message, 0, + actions=actions, actions_cb=on_auth_action, icon_name="blueman") n.show() self._service_notifications.append(n) diff --git a/blueman/plugins/applet/ConnectionNotifier.py b/blueman/plugins/applet/ConnectionNotifier.py index a18ff8187..2e0004e53 100644 --- a/blueman/plugins/applet/ConnectionNotifier.py +++ b/blueman/plugins/applet/ConnectionNotifier.py @@ -30,11 +30,17 @@ def on_device_property_changed(self, path: ObjectPath, key: str, value: Any) -> self._notifications[path] = notification = Notification( device.display_name, _('Connected'), - icon_name=device["Icon"] + icon_name=device["Icon"], + transient=True, ) notification.show() else: - Notification(device.display_name, _('Disconnected'), icon_name=device["Icon"]).show() + Notification( + device.display_name, + _('Disconnected'), + icon_name=device["Icon"], + transient=True, + ).show() def _on_battery_update(self, path: ObjectPath, value: int) -> None: notification = self._notifications.pop(path, None) diff --git a/blueman/plugins/applet/TransferService.py b/blueman/plugins/applet/TransferService.py index 96c6b9b7d..c055e2b39 100644 --- a/blueman/plugins/applet/TransferService.py +++ b/blueman/plugins/applet/TransferService.py @@ -128,8 +128,8 @@ def _remove() -> bool: _("Incoming file over Bluetooth"), _("Incoming file %(0)s from %(1)s") % {"0": "" + escape(filename) + "", "1": "" + escape(name) + ""}, - 30000, [("accept", _("Accept")), ("reject", _("Reject"))], on_action, - icon_name="blueman" + 30000, + actions=[("accept", _("Accept")), ("reject", _("Reject"))], actions_cb=on_action, icon_name="blueman" ) notification.show() # Device is trusted or was already allowed, larger file -> display a notification, but auto-accept