refactor(src/window/notification/notification_center): scale notification icons to 35x35 for consistency and adjust widget sizing
This commit is contained in:
1 file changed
+61
-35
@@ -1,6 +1,6 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from fabric.utils import GLib, logger
|
from fabric.utils import GLib, GdkPixbuf, logger
|
||||||
from fabric.widgets.box import Box
|
from fabric.widgets.box import Box
|
||||||
from fabric.widgets.button import Button
|
from fabric.widgets.button import Button
|
||||||
from fabric.widgets.centerbox import CenterBox
|
from fabric.widgets.centerbox import CenterBox
|
||||||
@@ -171,9 +171,10 @@ class ExpandableNotificationGroup(Box):
|
|||||||
self.create_expanded_state()
|
self.create_expanded_state()
|
||||||
|
|
||||||
def _get_notification_pixbuf_for_group(self, cached_notification):
|
def _get_notification_pixbuf_for_group(self, cached_notification):
|
||||||
"""Get notification pixbuf using cached image key - fallback to app icon"""
|
"""Get notification pixbuf at 35x35 - matches app icon size for consistency"""
|
||||||
notification = cached_notification._notification
|
notification = cached_notification._notification
|
||||||
getattr(notification, "id", None)
|
getattr(notification, "id", None)
|
||||||
|
pixbuf = None
|
||||||
|
|
||||||
# First try to get cached notification image using stored cache key
|
# First try to get cached notification image using stored cache key
|
||||||
if (
|
if (
|
||||||
@@ -189,12 +190,12 @@ class ExpandableNotificationGroup(Box):
|
|||||||
notification_image_cache_key
|
notification_image_cache_key
|
||||||
)
|
)
|
||||||
if cached_image:
|
if cached_image:
|
||||||
return cached_image
|
pixbuf = cached_image
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Failed to load cached notification image: {e}")
|
logger.debug(f"Failed to load cached notification image: {e}")
|
||||||
|
|
||||||
# Fallback to app icon using cached key
|
# Fallback to app icon using cached key
|
||||||
if (
|
if not pixbuf and (
|
||||||
hasattr(cached_notification, "cache_metadata")
|
hasattr(cached_notification, "cache_metadata")
|
||||||
and cached_notification.cache_metadata
|
and cached_notification.cache_metadata
|
||||||
):
|
):
|
||||||
@@ -205,22 +206,29 @@ class ExpandableNotificationGroup(Box):
|
|||||||
try:
|
try:
|
||||||
cached_app_icon = get_from_cache(app_icon_cache_key, (35, 35))
|
cached_app_icon = get_from_cache(app_icon_cache_key, (35, 35))
|
||||||
if cached_app_icon:
|
if cached_app_icon:
|
||||||
return cached_app_icon
|
pixbuf = cached_app_icon
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Failed to load cached app icon: {e}")
|
logger.debug(f"Failed to load cached app icon: {e}")
|
||||||
|
|
||||||
# Final fallback - try to cache app icon directly if available
|
# Final fallback - try to cache app icon directly if available
|
||||||
try:
|
if not pixbuf:
|
||||||
app_icon_source = getattr(notification, "app_icon", None)
|
try:
|
||||||
if app_icon_source:
|
app_icon_source = getattr(notification, "app_icon", None)
|
||||||
cached_app_icon = cache_notification_icon(app_icon_source, (35, 35))
|
if app_icon_source:
|
||||||
if cached_app_icon:
|
cached_app_icon = cache_notification_icon(app_icon_source, (35, 35))
|
||||||
return cached_app_icon
|
if cached_app_icon:
|
||||||
except Exception as e:
|
pixbuf = cached_app_icon
|
||||||
logger.debug(f"Failed to get directly cached app icon: {e}")
|
except Exception as e:
|
||||||
|
logger.debug(f"Failed to get directly cached app icon: {e}")
|
||||||
|
|
||||||
# Ultimate fallback
|
if not pixbuf:
|
||||||
return get_fallback_notification_icon((35, 35))
|
pixbuf = get_fallback_notification_icon((35, 35))
|
||||||
|
|
||||||
|
# Always scale to 35x35 so screenshot thumbnails match app icon size
|
||||||
|
try:
|
||||||
|
return pixbuf.scale_simple(35, 35, GdkPixbuf.InterpType.BILINEAR)
|
||||||
|
except Exception:
|
||||||
|
return pixbuf
|
||||||
|
|
||||||
def create_expanded_state(self):
|
def create_expanded_state(self):
|
||||||
# Create main expanded container
|
# Create main expanded container
|
||||||
@@ -437,10 +445,14 @@ class NotificationCenterWidget(NotificationWidget):
|
|||||||
name="notification-centre-notifs",
|
name="notification-centre-notifs",
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
# Clear the hardcoded NOTIFICATION_WIDTH=360 size so the widget
|
||||||
|
# fills the notification center container width instead of overflowing
|
||||||
|
self.set_size_request(-1, -1)
|
||||||
|
|
||||||
def _get_notification_pixbuf(self, notification):
|
def _get_notification_pixbuf(self, notification):
|
||||||
"""Get notification pixbuf using cached image key - fallback to app icon"""
|
"""Get notification pixbuf at 35x35 - matches app icon size for consistency"""
|
||||||
getattr(notification, "id", None)
|
getattr(notification, "id", None)
|
||||||
|
pixbuf = None
|
||||||
|
|
||||||
# First try to get cached notification image using stored cache key
|
# First try to get cached notification image using stored cache key
|
||||||
if self.cache_metadata:
|
if self.cache_metadata:
|
||||||
@@ -453,33 +465,40 @@ class NotificationCenterWidget(NotificationWidget):
|
|||||||
notification_image_cache_key
|
notification_image_cache_key
|
||||||
)
|
)
|
||||||
if cached_image:
|
if cached_image:
|
||||||
return cached_image
|
pixbuf = cached_image
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Failed to load cached notification image: {e}")
|
logger.debug(f"Failed to load cached notification image: {e}")
|
||||||
|
|
||||||
# Fallback to app icon using cached key
|
# Fallback to app icon using cached key
|
||||||
if self.cache_metadata:
|
if not pixbuf and self.cache_metadata:
|
||||||
app_icon_cache_key = self.cache_metadata.get("app_icon_cache_key")
|
app_icon_cache_key = self.cache_metadata.get("app_icon_cache_key")
|
||||||
if app_icon_cache_key:
|
if app_icon_cache_key:
|
||||||
try:
|
try:
|
||||||
cached_app_icon = get_from_cache(app_icon_cache_key, (35, 35))
|
cached_app_icon = get_from_cache(app_icon_cache_key, (35, 35))
|
||||||
if cached_app_icon:
|
if cached_app_icon:
|
||||||
return cached_app_icon
|
pixbuf = cached_app_icon
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Failed to load cached app icon: {e}")
|
logger.debug(f"Failed to load cached app icon: {e}")
|
||||||
|
|
||||||
# Final fallback - try to cache app icon directly if available
|
# Final fallback - try to cache app icon directly if available
|
||||||
try:
|
if not pixbuf:
|
||||||
app_icon_source = getattr(notification, "app_icon", None)
|
try:
|
||||||
if app_icon_source:
|
app_icon_source = getattr(notification, "app_icon", None)
|
||||||
cached_app_icon = cache_notification_icon(app_icon_source, (35, 35))
|
if app_icon_source:
|
||||||
if cached_app_icon:
|
cached_app_icon = cache_notification_icon(app_icon_source, (35, 35))
|
||||||
return cached_app_icon
|
if cached_app_icon:
|
||||||
except Exception as e:
|
pixbuf = cached_app_icon
|
||||||
logger.debug(f"Failed to get directly cached app icon: {e}")
|
except Exception as e:
|
||||||
|
logger.debug(f"Failed to get directly cached app icon: {e}")
|
||||||
|
|
||||||
# Ultimate fallback
|
if not pixbuf:
|
||||||
return get_fallback_notification_icon((35, 35))
|
pixbuf = get_fallback_notification_icon((35, 35))
|
||||||
|
|
||||||
|
# Always scale to 35x35 so screenshot thumbnails match app icon size
|
||||||
|
try:
|
||||||
|
return pixbuf.scale_simple(35, 35, GdkPixbuf.InterpType.BILINEAR)
|
||||||
|
except Exception:
|
||||||
|
return pixbuf
|
||||||
|
|
||||||
def create_content(self, notification):
|
def create_content(self, notification):
|
||||||
# Create our custom close button for notification center
|
# Create our custom close button for notification center
|
||||||
@@ -512,6 +531,7 @@ class NotificationCenterWidget(NotificationWidget):
|
|||||||
name="notification-text",
|
name="notification-text",
|
||||||
orientation="v",
|
orientation="v",
|
||||||
v_align="center",
|
v_align="center",
|
||||||
|
h_expand=True,
|
||||||
children=[
|
children=[
|
||||||
Box(
|
Box(
|
||||||
name="notification-summary-box",
|
name="notification-summary-box",
|
||||||
@@ -523,8 +543,9 @@ class NotificationCenterWidget(NotificationWidget):
|
|||||||
notification.summary.replace("\n", " ")
|
notification.summary.replace("\n", " ")
|
||||||
),
|
),
|
||||||
h_align="start",
|
h_align="start",
|
||||||
max_chars_width=25,
|
wrap=True,
|
||||||
ellipsization="end",
|
wrap_mode="word-char",
|
||||||
|
max_chars_width=30,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -534,14 +555,14 @@ class NotificationCenterWidget(NotificationWidget):
|
|||||||
notification.body.replace("\n", " ")
|
notification.body.replace("\n", " ")
|
||||||
),
|
),
|
||||||
h_align="start",
|
h_align="start",
|
||||||
|
wrap=True,
|
||||||
|
wrap_mode="word-char",
|
||||||
max_chars_width=35,
|
max_chars_width=35,
|
||||||
ellipsization="end",
|
|
||||||
)
|
)
|
||||||
if notification.body
|
if notification.body
|
||||||
else Label(
|
else Label(
|
||||||
markup="",
|
markup="",
|
||||||
h_align="start",
|
h_align="start",
|
||||||
ellipsization="end",
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -550,7 +571,7 @@ class NotificationCenterWidget(NotificationWidget):
|
|||||||
Box(
|
Box(
|
||||||
orientation="v",
|
orientation="v",
|
||||||
children=[
|
children=[
|
||||||
self.close_button, # Use our custom close button
|
self.close_button,
|
||||||
Box(v_expand=True),
|
Box(v_expand=True),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -624,7 +645,12 @@ class NotificationCenter(AppletWindow):
|
|||||||
name="noti-center-box",
|
name="noti-center-box",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.scrolled = ScrolledWindow(h_expand=False, v_expand=False)
|
self.scrolled = ScrolledWindow(
|
||||||
|
h_expand=False,
|
||||||
|
v_expand=False,
|
||||||
|
h_scrollbar_policy="never",
|
||||||
|
propagate_width=False,
|
||||||
|
)
|
||||||
self.notifications_box = Box(
|
self.notifications_box = Box(
|
||||||
v_expand=False,
|
v_expand=False,
|
||||||
h_expand=False,
|
h_expand=False,
|
||||||
|
|||||||
Reference in new issue
Block a user