Something went wrong. Try again.
A Material 3 inspired desktop shell for Niri and Hyprland created with Ignis.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192import time
from gi.repository import GLibfrom ignis.services.notifications import Notification
from ignis import widgetsfrom modules.m3components import Button
def relative_time(timestamp: float) -> str: diff = int(time.time() - timestamp)
if diff < 60: return "now" elif diff < 3600: return f"{diff // 60}m" elif diff < 86400: return f"{diff // 3600}h" else: return f"{diff // 86400}d"
class ExoNotification(widgets.Box): def __init__(self, notification: Notification, compact_popup: bool = False) -> None: self._timestamp = notification.time self._is_expanded = False
self._age_label = widgets.Label( css_classes=["notification-age"], label="", halign="start", ellipsize="end", visible=(not compact_popup), )
self._body_label = ( widgets.Label( css_classes=["notification-body"], label=notification.body, halign="start", ellipsize="end", wrap_mode="word_char", ) if notification.body else None ) if compact_popup: self._body_label.set_single_line_mode(True)
self._expand_button = ( Button.button( css_classes=["notification-expand"], icon="arrow_drop_down", valign="start", vexpand=False, size="xs", on_click=self._toggle_expand, ) if self._body_label and not compact_popup else None )
super().__init__( vertical=True, hexpand=True, halign="fill", css_classes=["notification", "compact-popup" if compact_popup else None], child=[ widgets.Box( spacing=10, child=[ widgets.Icon( image=notification.icon or "dialog-information-symbolic", pixel_size=24 if not compact_popup else 16, halign="start", valign="start", css_classes=["notification-icon"], ), widgets.Box( css_classes=["notification-info"], vertical=not compact_popup, valign="center", hexpand=True, halign="fill", spacing=2 if not compact_popup else 8, child=[ widgets.Box( spacing=5, child=[ widgets.Label( css_classes=["notification-summary"], label=notification.summary, halign="start", ellipsize="end", ), widgets.Label( css_classes=["notification-separator"], label="•", halign="start", visible=(not compact_popup), ), self._age_label, ], ), self._body_label, widgets.Box( css_classes=["notification-actions-container"], child=[ Button.button( label=action.label, on_click=lambda x, action=action: action.invoke(), css_classes=["notification-action"], size="xs", type="text", ) for action in notification.actions ], ) if notification.actions and not compact_popup else None, ], ), widgets.Box( vertical=True, spacing=5, child=[ Button.button( css_classes=["notification-close"], icon="close", valign="start" if not compact_popup else "center", vexpand=compact_popup, size="xs", on_click=lambda x: notification.close(), ), self._expand_button if not compact_popup else None, ], ), ], ), ], )
self._age_source_id = 0 self.connect("destroy", self._cancel_age_timer) self._update_age_label() self._schedule_age_update()
def _cancel_age_timer(self, *_args): if self._age_source_id: GLib.source_remove(self._age_source_id) self._age_source_id = 0
def _seconds_until_next_age_change(self) -> int | None: diff = int(time.time() - self._timestamp) if diff < 60: return max(1, 60 - diff) if diff < 3600: return max(1, 60 - (diff % 60)) if diff < 86400: return max(1, 3600 - (diff % 3600)) return None
def _schedule_age_update(self): self._cancel_age_timer() delay = self._seconds_until_next_age_change() if delay is None: return self._age_source_id = GLib.timeout_add_seconds(delay, self._on_age_timeout)
def _on_age_timeout(self): self._age_source_id = 0 self._update_age_label() if time.time() - self._timestamp >= 86400: return GLib.SOURCE_REMOVE self._schedule_age_update() return GLib.SOURCE_REMOVE
def _toggle_expand(self, _): self._is_expanded = not self._is_expanded if self._body_label: self._body_label.set_ellipsize("none" if self._is_expanded else "end") self._body_label.set_wrap(self._is_expanded)
if self._expand_button: self._expand_button.set_icon( "arrow_drop_up" if self._is_expanded else "arrow_drop_down" )
def _update_age_label(self): self._age_label.set_label(relative_time(self._timestamp))