-
-
Notifications
You must be signed in to change notification settings - Fork 236
Make the fallback dialog less annoying #3297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
infirit
wants to merge
6
commits into
blueman-project:main
Choose a base branch
from
infirit:fallbackdialogfixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−85
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e1ad54
Notification: Add a close button to fallback if there are no actions
infirit 13749cf
Notification: Remove unused action
infirit be8662f
Notification: Destroy fallback window
infirit 4223a53
Notification: Remove transparency fade from fallback
infirit 7391eb7
Notification: Rework actions
infirit 523d2d0
Notification: Use the virtual method do_response
infirit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,43 @@ | ||
| from collections.abc import Callable, Iterable | ||
| from gettext import gettext as _ | ||
| from typing import NamedTuple | ||
|
|
||
| import gi | ||
| gi.require_version("Gtk", "3.0") | ||
| gi.require_version("Gdk", "3.0") | ||
| from gi.repository import Gtk | ||
| from gi.repository import Gdk | ||
| from gi.repository import GdkPixbuf | ||
| from gi.repository import GLib | ||
| from gi.repository import Gio | ||
| from blueman.gui.GtkAnimation import AnimBase | ||
| import logging | ||
|
|
||
| OPACITY_START = 0.7 | ||
|
|
||
|
|
||
| class Fade(AnimBase): | ||
| def __init__(self, window: Gtk.Window) -> None: | ||
| super().__init__(state=OPACITY_START) | ||
| self.window = window | ||
|
|
||
| def state_changed(self, state: float) -> None: | ||
| self.window.props.opacity = state | ||
| class NotificationAction(NamedTuple): | ||
| id: str | ||
| name: str | ||
| callback: Callable[[str], None] | None = None | ||
|
|
||
|
|
||
| class _NotificationDialog(Gtk.MessageDialog): | ||
| 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, | ||
| actions: Iterable[NotificationAction] | None = None, icon_name: str | None = None, | ||
| image_data: GdkPixbuf.Pixbuf | None = None) -> None: | ||
| super().__init__(parent=None, type=Gtk.MessageType.QUESTION, | ||
| buttons=Gtk.ButtonsType.NONE, text=None) | ||
|
|
||
| self.set_name("NotificationDialog") | ||
| i = 100 | ||
| self.actions_supported = True | ||
| self.actions: dict[int, str] = {} | ||
| self.callback = actions_cb | ||
| if actions: | ||
| for a in actions: | ||
| action_id = a[0] | ||
| action_name = a[1] | ||
| self.actions: dict[int, NotificationAction] = {} | ||
|
|
||
| self.actions[i] = action_id | ||
| self.add_button(action_name, i) | ||
| i += 1 | ||
| if actions is None: | ||
| actions = [NotificationAction("close", _("_Close"), lambda s: self.close())] | ||
|
|
||
| self.actions[Gtk.ResponseType.DELETE_EVENT] = "close" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fired by the window manager, e.g., in reaction to Esc or a request to close the window. I think those controls are broken now. Also, |
||
| for action in actions: | ||
| self.add_action(action) | ||
|
|
||
| self.props.secondary_use_markup = True | ||
| self.resize(350, 50) | ||
|
|
||
| self.fader = Fade(self) | ||
|
|
||
| self.props.skip_taskbar_hint = False | ||
|
|
||
| self.props.title = summary | ||
|
|
@@ -65,47 +51,38 @@ def __init__(self, summary: str, message: str, _timeout: int = -1, _transient: b | |
| elif image_data: | ||
| self.set_icon_from_pixbuf(image_data) | ||
|
|
||
| self.connect("response", self.dialog_response) | ||
| self.props.icon_name = "blueman" | ||
|
|
||
| self.entered = False | ||
|
|
||
| def on_enter(_widget: "_NotificationDialog", _event: Gdk.Event) -> bool: | ||
| if self.get_window() == Gdk.Window.at_pointer()[0] or not self.entered: | ||
| self.fader.animate(start=self.fader.get_state(), end=1.0, duration=500) | ||
| self.entered = True | ||
| return False | ||
|
|
||
| def on_leave(_widget: "_NotificationDialog", _event: Gdk.Event) -> bool: | ||
| if not Gdk.Window.at_pointer(): | ||
| self.entered = False | ||
| self.fader.animate(start=self.fader.get_state(), end=OPACITY_START, duration=500) | ||
| return False | ||
|
|
||
| self.connect("enter-notify-event", on_enter) | ||
| self.connect("leave-notify-event", on_leave) | ||
|
|
||
| def set_message(self, message: str) -> None: | ||
| self.props.secondary_text = message | ||
|
|
||
| def set_notification_icon(self, icon_name: str) -> None: | ||
| self.set_icon_from_icon_name(icon_name, 48) | ||
|
|
||
| def dialog_response(self, _dialog: Gtk.Dialog, response: int) -> None: | ||
| if self.callback: | ||
| self.callback(self.actions[response]) | ||
| self.hide() | ||
| def do_response(self, response: int) -> None: | ||
| action = self.actions.pop(response, None) | ||
| if action is None: | ||
| logging.error(f"Unhandled response {response}") | ||
| return | ||
|
|
||
| if action.callback is not None: | ||
| action.callback(action.id) | ||
| self.destroy() | ||
|
|
||
| def show(self) -> None: | ||
| self.set_opacity(OPACITY_START) | ||
| self.present() | ||
| self.set_opacity(OPACITY_START) | ||
|
|
||
| def close(self) -> None: | ||
| self.hide() | ||
| self.destroy() | ||
|
|
||
| def add_action(self, _action_id: str, _label: str, _callback: Callable[[str], None] | None = None) -> None: | ||
| logging.warning("stub") | ||
| def add_action(self, action: NotificationAction) -> None: | ||
| if not self.actions: | ||
| response_id = 100 | ||
| else: | ||
| response_id = max(self.actions.keys()) + 1 | ||
|
|
||
| self.actions[response_id] = action | ||
| self.add_button(action.name, response_id) | ||
|
|
||
| def set_icon_from_pixbuf(self, pixbuf: GdkPixbuf.Pixbuf) -> None: | ||
| im = Gtk.Image.new_from_pixbuf(pixbuf) | ||
|
|
@@ -120,8 +97,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, transient: bool = False, | ||
| actions: Iterable[tuple[str, str]] | None = None, | ||
| actions_cb: Callable[[str], None] | None = None, icon_name: str | None = None, | ||
| actions: Iterable[NotificationAction] | None = None, icon_name: str | None = None, | ||
| image_data: GdkPixbuf.Pixbuf | None = None) -> None: | ||
| super().__init__( | ||
| g_name='org.freedesktop.Notifications', | ||
|
|
@@ -134,8 +110,8 @@ def __init__(self, summary: str, message: str, timeout: int = -1, transient: boo | |
|
|
||
| self._app_name = 'blueman' | ||
| self._app_icon = '' | ||
| self._actions: list[str] = [] | ||
| self._callbacks: dict[str, Callable[[str], None]] = {} | ||
| self._actions: dict[str, NotificationAction] = {} | ||
| self._notification_actions: list[str] = [] | ||
| self._hints: dict[str, GLib.Variant] = {} | ||
|
|
||
| # hint : (variant format, spec version) | ||
|
|
@@ -190,9 +166,9 @@ def __init__(self, summary: str, message: str, timeout: int = -1, transient: boo | |
|
|
||
| self.set_hint(key, (w, h, stride, alpha, bits, channel, data)) | ||
|
|
||
| if actions: | ||
| if actions is not None: | ||
| for action in actions: | ||
| self.add_action(action[0], action[1], actions_cb) | ||
| self.add_action(action) | ||
|
|
||
| self._capabilities = self.GetCapabilities() | ||
|
|
||
|
|
@@ -231,14 +207,13 @@ def remove_hint(self, key: str) -> None: | |
| def clear_hints(self) -> None: | ||
| self._hints = {} | ||
|
|
||
| def add_action(self, action_id: str, label: str, callback: Callable[[str], None] | None = None) -> None: | ||
| self._actions.extend([action_id, label]) | ||
| if callback: | ||
| self._callbacks[action_id] = callback | ||
| def add_action(self, action: NotificationAction) -> None: | ||
| self._actions[action.id] = action | ||
| self._notification_actions.extend([action.id, action.name]) | ||
|
|
||
| def clear_actions(self) -> None: | ||
| self._actions = [] | ||
| self._callbacks = {} | ||
| self._actions.clear() | ||
| self._notification_actions.clear() | ||
|
|
||
| def do_g_signal(self, _sender_name: str, signal_name: str, params: GLib.Variant) -> None: | ||
| notif_id, signal_val = params.unpack() | ||
|
|
@@ -257,13 +232,18 @@ def do_g_signal(self, _sender_name: str, signal_name: str, params: GLib.Variant) | |
| elif signal_val == 4: | ||
| logging.debug('Undefined/reserved reasons.') | ||
| elif signal_name == 'ActionInvoked': | ||
| if signal_val in self._callbacks: | ||
| self._callbacks[signal_val](signal_val) | ||
| action = self._actions.pop(signal_val, None) | ||
| if action is None: | ||
| logging.error(f"Unhandled action {signal_val}") | ||
| return | ||
|
|
||
| if action.callback is not None: | ||
| action.callback(action.id) | ||
|
|
||
| def show(self) -> None: | ||
| replace_id = self._return_id if self._return_id else 0 | ||
| return_id = self.Notify('(susssasa{sv}i)', self._app_name, replace_id, self._app_icon, | ||
| self._summary, self._body, self._actions, self._hints, | ||
| self._summary, self._body, self._notification_actions, self._hints, | ||
| self._timeout) | ||
| self._return_id = return_id | ||
|
|
||
|
|
@@ -278,8 +258,7 @@ def Notification( | |
| message: str, | ||
| timeout: int = -1, | ||
| transient: bool = False, | ||
| actions: Iterable[tuple[str, str]] | None = None, | ||
| actions_cb: Callable[[str], None] | None = None, | ||
| actions: Iterable[NotificationAction] | None = None, | ||
| icon_name: str | None = None, | ||
| image_data: GdkPixbuf.Pixbuf | None = None | ||
| ) -> _NotificationBubble | _NotificationDialog: | ||
|
|
@@ -302,4 +281,4 @@ def Notification( | |
| else: | ||
| klass = _NotificationBubble | ||
|
|
||
| return klass(summary, message, timeout, transient, actions, actions_cb, icon_name, image_data) | ||
| return klass(summary, message, timeout, transient, actions, icon_name, image_data) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.close()should be redundant here, asdo_responsealready destroys.