Added CloseButtons
This commit is contained in:
1 parent
0f811def01
commit
dcad41e9f8
3 files changed
+124
-42
No files matched your search
@@ -35,11 +35,13 @@ NOTIFICATION_ICON_CACHE_DIR = os.path.join(data.CACHE_DIR, "notification_icons")
|
|||||||
# Notification image cache directory (for large notification images)
|
# Notification image cache directory (for large notification images)
|
||||||
NOTIFICATION_IMAGE_CACHE_DIR = os.path.join(data.CACHE_DIR, "notification_images")
|
NOTIFICATION_IMAGE_CACHE_DIR = os.path.join(data.CACHE_DIR, "notification_images")
|
||||||
|
|
||||||
|
|
||||||
def ensure_notification_cache_dirs():
|
def ensure_notification_cache_dirs():
|
||||||
"""Ensure notification cache directories exist"""
|
"""Ensure notification cache directories exist"""
|
||||||
os.makedirs(NOTIFICATION_ICON_CACHE_DIR, exist_ok=True)
|
os.makedirs(NOTIFICATION_ICON_CACHE_DIR, exist_ok=True)
|
||||||
os.makedirs(NOTIFICATION_IMAGE_CACHE_DIR, exist_ok=True)
|
os.makedirs(NOTIFICATION_IMAGE_CACHE_DIR, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
def cleanup_old_cache_files():
|
def cleanup_old_cache_files():
|
||||||
"""Clean up old notification cache files (older than 7 days) from icon cache only"""
|
"""Clean up old notification cache files (older than 7 days) from icon cache only"""
|
||||||
try:
|
try:
|
||||||
@@ -56,12 +58,15 @@ def cleanup_old_cache_files():
|
|||||||
file_mtime = os.path.getmtime(filepath)
|
file_mtime = os.path.getmtime(filepath)
|
||||||
if file_mtime < week_ago:
|
if file_mtime < week_ago:
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
logger.debug(f"Cleaned up old notification icon cache: {filename}")
|
logger.debug(
|
||||||
|
f"Cleaned up old notification icon cache: {filename}"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to cleanup cache file {filename}: {e}")
|
logger.warning(f"Failed to cleanup cache file {filename}: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to cleanup notification cache: {e}")
|
logger.warning(f"Failed to cleanup notification cache: {e}")
|
||||||
|
|
||||||
|
|
||||||
def get_cache_key(source_data, size=None):
|
def get_cache_key(source_data, size=None):
|
||||||
"""Generate a cache key from source data and optional size"""
|
"""Generate a cache key from source data and optional size"""
|
||||||
if isinstance(source_data, str):
|
if isinstance(source_data, str):
|
||||||
@@ -82,6 +87,7 @@ def get_cache_key(source_data, size=None):
|
|||||||
|
|
||||||
return hashlib.md5(cache_input.encode()).hexdigest()
|
return hashlib.md5(cache_input.encode()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def save_pixbuf_to_cache(pixbuf, cache_key, cache_dir):
|
def save_pixbuf_to_cache(pixbuf, cache_key, cache_dir):
|
||||||
"""Save a pixbuf to the specified cache directory"""
|
"""Save a pixbuf to the specified cache directory"""
|
||||||
try:
|
try:
|
||||||
@@ -99,6 +105,7 @@ def save_pixbuf_to_cache(pixbuf, cache_key, cache_dir):
|
|||||||
logger.warning(f"Failed to cache notification icon: {e}")
|
logger.warning(f"Failed to cache notification icon: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_cached_pixbuf(cache_key, fallback_size=(48, 48), cache_dir=None):
|
def get_cached_pixbuf(cache_key, fallback_size=(48, 48), cache_dir=None):
|
||||||
"""Get a cached pixbuf or return None if not found"""
|
"""Get a cached pixbuf or return None if not found"""
|
||||||
if cache_dir is None:
|
if cache_dir is None:
|
||||||
@@ -115,6 +122,7 @@ def get_cached_pixbuf(cache_key, fallback_size=(48, 48), cache_dir=None):
|
|||||||
logger.warning(f"Failed to load cached notification icon: {e}")
|
logger.warning(f"Failed to load cached notification icon: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def cache_notification_icon(source, size=(48, 48)):
|
def cache_notification_icon(source, size=(48, 48)):
|
||||||
"""Cache a notification icon from local sources (file, pixbuf) - PERMANENT cache"""
|
"""Cache a notification icon from local sources (file, pixbuf) - PERMANENT cache"""
|
||||||
try:
|
try:
|
||||||
@@ -125,12 +133,14 @@ def cache_notification_icon(source, size=(48, 48)):
|
|||||||
cache_key = get_cache_key(source, size)
|
cache_key = get_cache_key(source, size)
|
||||||
|
|
||||||
# Check if already cached
|
# Check if already cached
|
||||||
cached_pixbuf = get_cached_pixbuf(cache_key, size, NOTIFICATION_ICON_CACHE_DIR)
|
cached_pixbuf = get_cached_pixbuf(
|
||||||
|
cache_key, size, NOTIFICATION_ICON_CACHE_DIR
|
||||||
|
)
|
||||||
if cached_pixbuf:
|
if cached_pixbuf:
|
||||||
return cached_pixbuf
|
return cached_pixbuf
|
||||||
|
|
||||||
# Load and cache the icon (local only)
|
# Load and cache the icon (local only)
|
||||||
if source.startswith('file://'):
|
if source.startswith("file://"):
|
||||||
# Local file URL
|
# Local file URL
|
||||||
file_path = source[7:]
|
file_path = source[7:]
|
||||||
pixbuf = load_and_cache_local_icon(file_path, cache_key, size)
|
pixbuf = load_and_cache_local_icon(file_path, cache_key, size)
|
||||||
@@ -143,17 +153,21 @@ def cache_notification_icon(source, size=(48, 48)):
|
|||||||
|
|
||||||
return pixbuf
|
return pixbuf
|
||||||
|
|
||||||
elif hasattr(source, 'scale_simple'):
|
elif hasattr(source, "scale_simple"):
|
||||||
# Already a pixbuf
|
# Already a pixbuf
|
||||||
cache_key = get_cache_key(source, size)
|
cache_key = get_cache_key(source, size)
|
||||||
|
|
||||||
# Check if already cached
|
# Check if already cached
|
||||||
cached_pixbuf = get_cached_pixbuf(cache_key, size, NOTIFICATION_ICON_CACHE_DIR)
|
cached_pixbuf = get_cached_pixbuf(
|
||||||
|
cache_key, size, NOTIFICATION_ICON_CACHE_DIR
|
||||||
|
)
|
||||||
if cached_pixbuf:
|
if cached_pixbuf:
|
||||||
return cached_pixbuf
|
return cached_pixbuf
|
||||||
|
|
||||||
# Scale and cache
|
# Scale and cache
|
||||||
scaled_pixbuf = source.scale_simple(size[0], size[1], GdkPixbuf.InterpType.BILINEAR)
|
scaled_pixbuf = source.scale_simple(
|
||||||
|
size[0], size[1], GdkPixbuf.InterpType.BILINEAR
|
||||||
|
)
|
||||||
save_pixbuf_to_cache(scaled_pixbuf, cache_key, NOTIFICATION_ICON_CACHE_DIR)
|
save_pixbuf_to_cache(scaled_pixbuf, cache_key, NOTIFICATION_ICON_CACHE_DIR)
|
||||||
return scaled_pixbuf
|
return scaled_pixbuf
|
||||||
|
|
||||||
@@ -163,6 +177,7 @@ def cache_notification_icon(source, size=(48, 48)):
|
|||||||
# Return fallback
|
# Return fallback
|
||||||
return get_fallback_notification_icon(size)
|
return get_fallback_notification_icon(size)
|
||||||
|
|
||||||
|
|
||||||
def load_and_cache_local_icon(file_path, cache_key, size):
|
def load_and_cache_local_icon(file_path, cache_key, size):
|
||||||
"""Load a local icon file and cache it"""
|
"""Load a local icon file and cache it"""
|
||||||
try:
|
try:
|
||||||
@@ -177,6 +192,7 @@ def load_and_cache_local_icon(file_path, cache_key, size):
|
|||||||
|
|
||||||
return get_fallback_notification_icon(size)
|
return get_fallback_notification_icon(size)
|
||||||
|
|
||||||
|
|
||||||
def load_and_cache_theme_icon(icon_name, cache_key, size):
|
def load_and_cache_theme_icon(icon_name, cache_key, size):
|
||||||
"""Load an icon from the current theme and cache it"""
|
"""Load an icon from the current theme and cache it"""
|
||||||
try:
|
try:
|
||||||
@@ -186,14 +202,19 @@ def load_and_cache_theme_icon(icon_name, cache_key, size):
|
|||||||
if icon_info:
|
if icon_info:
|
||||||
pixbuf = icon_info.load_icon()
|
pixbuf = icon_info.load_icon()
|
||||||
if pixbuf:
|
if pixbuf:
|
||||||
scaled_pixbuf = pixbuf.scale_simple(size[0], size[1], GdkPixbuf.InterpType.BILINEAR)
|
scaled_pixbuf = pixbuf.scale_simple(
|
||||||
save_pixbuf_to_cache(scaled_pixbuf, cache_key, NOTIFICATION_ICON_CACHE_DIR)
|
size[0], size[1], GdkPixbuf.InterpType.BILINEAR
|
||||||
|
)
|
||||||
|
save_pixbuf_to_cache(
|
||||||
|
scaled_pixbuf, cache_key, NOTIFICATION_ICON_CACHE_DIR
|
||||||
|
)
|
||||||
return scaled_pixbuf
|
return scaled_pixbuf
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to load theme notification icon {icon_name}: {e}")
|
logger.warning(f"Failed to load theme notification icon {icon_name}: {e}")
|
||||||
|
|
||||||
return get_fallback_notification_icon(size)
|
return get_fallback_notification_icon(size)
|
||||||
|
|
||||||
|
|
||||||
def get_fallback_notification_icon(size=(48, 48)):
|
def get_fallback_notification_icon(size=(48, 48)):
|
||||||
"""Get the fallback notification icon"""
|
"""Get the fallback notification icon"""
|
||||||
try:
|
try:
|
||||||
@@ -205,15 +226,18 @@ def get_fallback_notification_icon(size=(48, 48)):
|
|||||||
logger.warning(f"Failed to load fallback notification icon: {e}")
|
logger.warning(f"Failed to load fallback notification icon: {e}")
|
||||||
# Create a simple colored rectangle as ultimate fallback
|
# Create a simple colored rectangle as ultimate fallback
|
||||||
try:
|
try:
|
||||||
return GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, size[0], size[1])
|
return GdkPixbuf.Pixbuf.new(
|
||||||
|
GdkPixbuf.Colorspace.RGB, True, 8, size[0], size[1]
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_notification_image_cache_key(notification_id, image_pixbuf):
|
def get_notification_image_cache_key(notification_id, image_pixbuf):
|
||||||
"""Generate a cache key for notification images"""
|
"""Generate a cache key for notification images"""
|
||||||
try:
|
try:
|
||||||
# Use notification ID and image hash for unique key
|
# Use notification ID and image hash for unique key
|
||||||
if hasattr(image_pixbuf, 'get_pixels'):
|
if hasattr(image_pixbuf, "get_pixels"):
|
||||||
pixel_data = image_pixbuf.get_pixels()
|
pixel_data = image_pixbuf.get_pixels()
|
||||||
image_hash = hashlib.md5(pixel_data).hexdigest()[:8]
|
image_hash = hashlib.md5(pixel_data).hexdigest()[:8]
|
||||||
else:
|
else:
|
||||||
@@ -222,6 +246,7 @@ def get_notification_image_cache_key(notification_id, image_pixbuf):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return f"notif_{notification_id}_{int(time.time())}"
|
return f"notif_{notification_id}_{int(time.time())}"
|
||||||
|
|
||||||
|
|
||||||
def cache_notification_image(notification_id, image_pixbuf, size=(64, 64)):
|
def cache_notification_image(notification_id, image_pixbuf, size=(64, 64)):
|
||||||
"""Cache a notification image pixbuf - PERMANENT cache until manual clear"""
|
"""Cache a notification image pixbuf - PERMANENT cache until manual clear"""
|
||||||
try:
|
try:
|
||||||
@@ -235,7 +260,9 @@ def cache_notification_image(notification_id, image_pixbuf, size=(64, 64)):
|
|||||||
return cache_path, cache_key
|
return cache_path, cache_key
|
||||||
|
|
||||||
# Scale and save the image
|
# Scale and save the image
|
||||||
scaled_pixbuf = image_pixbuf.scale_simple(size[0], size[1], GdkPixbuf.InterpType.BILINEAR)
|
scaled_pixbuf = image_pixbuf.scale_simple(
|
||||||
|
size[0], size[1], GdkPixbuf.InterpType.BILINEAR
|
||||||
|
)
|
||||||
scaled_pixbuf.savev(cache_path, "png", [], [])
|
scaled_pixbuf.savev(cache_path, "png", [], [])
|
||||||
logger.debug(f"Cached notification image: {cache_key}")
|
logger.debug(f"Cached notification image: {cache_key}")
|
||||||
return cache_path, cache_key
|
return cache_path, cache_key
|
||||||
@@ -243,6 +270,7 @@ def cache_notification_image(notification_id, image_pixbuf, size=(64, 64)):
|
|||||||
logger.warning(f"Failed to cache notification image: {e}")
|
logger.warning(f"Failed to cache notification image: {e}")
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def get_cached_notification_image(cache_key):
|
def get_cached_notification_image(cache_key):
|
||||||
"""Get a cached notification image or return None if not found"""
|
"""Get a cached notification image or return None if not found"""
|
||||||
try:
|
try:
|
||||||
@@ -254,6 +282,7 @@ def get_cached_notification_image(cache_key):
|
|||||||
logger.warning(f"Failed to load cached notification image: {e}")
|
logger.warning(f"Failed to load cached notification image: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def cleanup_notification_image_cache(cache_key=None):
|
def cleanup_notification_image_cache(cache_key=None):
|
||||||
"""Clean up notification image cache - specific key or all"""
|
"""Clean up notification image cache - specific key or all"""
|
||||||
try:
|
try:
|
||||||
@@ -268,17 +297,22 @@ def cleanup_notification_image_cache(cache_key=None):
|
|||||||
else:
|
else:
|
||||||
# Remove all cached images
|
# Remove all cached images
|
||||||
for filename in os.listdir(NOTIFICATION_IMAGE_CACHE_DIR):
|
for filename in os.listdir(NOTIFICATION_IMAGE_CACHE_DIR):
|
||||||
if filename.endswith('.png'):
|
if filename.endswith(".png"):
|
||||||
filepath = os.path.join(NOTIFICATION_IMAGE_CACHE_DIR, filename)
|
filepath = os.path.join(NOTIFICATION_IMAGE_CACHE_DIR, filename)
|
||||||
try:
|
try:
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
logger.debug(f"Cleaned up cached notification image: {filename}")
|
logger.debug(
|
||||||
|
f"Cleaned up cached notification image: {filename}"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to cleanup cache file {filename}: {e}")
|
logger.warning(f"Failed to cleanup cache file {filename}: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to cleanup notification image cache: {e}")
|
logger.warning(f"Failed to cleanup notification image cache: {e}")
|
||||||
|
|
||||||
def cleanup_notification_specific_caches(app_icon_source=None, notification_image_cache_key=None):
|
|
||||||
|
def cleanup_notification_specific_caches(
|
||||||
|
app_icon_source=None, notification_image_cache_key=None
|
||||||
|
):
|
||||||
"""Clean up caches specific to a notification (both app icon and notification image)"""
|
"""Clean up caches specific to a notification (both app icon and notification image)"""
|
||||||
try:
|
try:
|
||||||
# Clean up notification image cache
|
# Clean up notification image cache
|
||||||
@@ -287,7 +321,9 @@ def cleanup_notification_specific_caches(app_icon_source=None, notification_imag
|
|||||||
|
|
||||||
# Clean up app icon cache for this specific source
|
# Clean up app icon cache for this specific source
|
||||||
if app_icon_source:
|
if app_icon_source:
|
||||||
cache_key = get_cache_key(app_icon_source, (24, 24)) # Standard app icon size
|
cache_key = get_cache_key(
|
||||||
|
app_icon_source, (24, 24)
|
||||||
|
) # Standard app icon size
|
||||||
cache_path = os.path.join(NOTIFICATION_ICON_CACHE_DIR, f"{cache_key}.png")
|
cache_path = os.path.join(NOTIFICATION_ICON_CACHE_DIR, f"{cache_key}.png")
|
||||||
if os.path.exists(cache_path):
|
if os.path.exists(cache_path):
|
||||||
os.unlink(cache_path)
|
os.unlink(cache_path)
|
||||||
@@ -295,7 +331,9 @@ def cleanup_notification_specific_caches(app_icon_source=None, notification_imag
|
|||||||
|
|
||||||
# Also clean 35x35 version used in notifications
|
# Also clean 35x35 version used in notifications
|
||||||
cache_key_35 = get_cache_key(app_icon_source, (35, 35))
|
cache_key_35 = get_cache_key(app_icon_source, (35, 35))
|
||||||
cache_path_35 = os.path.join(NOTIFICATION_ICON_CACHE_DIR, f"{cache_key_35}.png")
|
cache_path_35 = os.path.join(
|
||||||
|
NOTIFICATION_ICON_CACHE_DIR, f"{cache_key_35}.png"
|
||||||
|
)
|
||||||
if os.path.exists(cache_path_35):
|
if os.path.exists(cache_path_35):
|
||||||
os.unlink(cache_path_35)
|
os.unlink(cache_path_35)
|
||||||
logger.debug(f"Cleaned up cached app icon (35x35): {cache_key_35}")
|
logger.debug(f"Cleaned up cached app icon (35x35): {cache_key_35}")
|
||||||
@@ -303,19 +341,22 @@ def cleanup_notification_specific_caches(app_icon_source=None, notification_imag
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to cleanup notification specific caches: {e}")
|
logger.warning(f"Failed to cleanup notification specific caches: {e}")
|
||||||
|
|
||||||
|
|
||||||
def cleanup_all_notification_caches():
|
def cleanup_all_notification_caches():
|
||||||
"""Clean up ALL notification caches (icons and images)"""
|
"""Clean up ALL notification caches (icons and images)"""
|
||||||
try:
|
try:
|
||||||
# Clean icon cache
|
# Clean icon cache
|
||||||
if os.path.exists(NOTIFICATION_ICON_CACHE_DIR):
|
if os.path.exists(NOTIFICATION_ICON_CACHE_DIR):
|
||||||
for filename in os.listdir(NOTIFICATION_ICON_CACHE_DIR):
|
for filename in os.listdir(NOTIFICATION_ICON_CACHE_DIR):
|
||||||
if filename.endswith('.png'):
|
if filename.endswith(".png"):
|
||||||
filepath = os.path.join(NOTIFICATION_ICON_CACHE_DIR, filename)
|
filepath = os.path.join(NOTIFICATION_ICON_CACHE_DIR, filename)
|
||||||
try:
|
try:
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
logger.debug(f"Cleaned up cached notification icon: {filename}")
|
logger.debug(f"Cleaned up cached notification icon: {filename}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to cleanup icon cache file {filename}: {e}")
|
logger.warning(
|
||||||
|
f"Failed to cleanup icon cache file {filename}: {e}"
|
||||||
|
)
|
||||||
|
|
||||||
# Clean image cache
|
# Clean image cache
|
||||||
cleanup_notification_image_cache()
|
cleanup_notification_image_cache()
|
||||||
@@ -323,6 +364,7 @@ def cleanup_all_notification_caches():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to cleanup all notification caches: {e}")
|
logger.warning(f"Failed to cleanup all notification caches: {e}")
|
||||||
|
|
||||||
|
|
||||||
# Initialize cache on module load
|
# Initialize cache on module load
|
||||||
ensure_notification_cache_dirs()
|
ensure_notification_cache_dirs()
|
||||||
cleanup_old_cache_files()
|
cleanup_old_cache_files()
|
||||||
@@ -371,18 +413,21 @@ class NotificationWidget(Box):
|
|||||||
notification: Notification,
|
notification: Notification,
|
||||||
timeout_ms=data.NOTIFICATION_TIMEOUT,
|
timeout_ms=data.NOTIFICATION_TIMEOUT,
|
||||||
show_close_button=True,
|
show_close_button=True,
|
||||||
|
name="notification",
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
self.show_close_button = show_close_button
|
self.show_close_button = show_close_button
|
||||||
self.close_button = None
|
self.close_button = None
|
||||||
self._is_hovered = False
|
self._is_hovered = False
|
||||||
self.notification_image_cache_key = None # Track cached image for cleanup
|
self.notification_image_cache_key = None # Track cached image for cleanup
|
||||||
self.app_icon_source = notification.app_icon # Track app icon source for cleanup
|
self.app_icon_source = (
|
||||||
|
notification.app_icon
|
||||||
|
) # Track app icon source for cleanup
|
||||||
self._should_cleanup_cache = False # Only cleanup cache on manual dismissal
|
self._should_cleanup_cache = False # Only cleanup cache on manual dismissal
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
size=(NOTIFICATION_WIDTH, -1),
|
size=(NOTIFICATION_WIDTH, -1),
|
||||||
name="notification",
|
name=name,
|
||||||
orientation="v",
|
orientation="v",
|
||||||
h_align="fill",
|
h_align="fill",
|
||||||
h_expand=True,
|
h_expand=True,
|
||||||
@@ -544,9 +589,9 @@ class NotificationWidget(Box):
|
|||||||
def _get_notification_pixbuf(self, notification):
|
def _get_notification_pixbuf(self, notification):
|
||||||
"""Safely get notification pixbuf with caching for image notifications"""
|
"""Safely get notification pixbuf with caching for image notifications"""
|
||||||
try:
|
try:
|
||||||
if hasattr(notification, 'image_pixbuf') and notification.image_pixbuf:
|
if hasattr(notification, "image_pixbuf") and notification.image_pixbuf:
|
||||||
# Try to get/cache the notification image
|
# Try to get/cache the notification image
|
||||||
notification_id = getattr(notification, 'id', int(time.time()))
|
notification_id = getattr(notification, "id", int(time.time()))
|
||||||
cache_path, cache_key = cache_notification_image(
|
cache_path, cache_key = cache_notification_image(
|
||||||
notification_id, notification.image_pixbuf, (64, 64)
|
notification_id, notification.image_pixbuf, (64, 64)
|
||||||
)
|
)
|
||||||
@@ -557,7 +602,9 @@ class NotificationWidget(Box):
|
|||||||
# Load the cached image
|
# Load the cached image
|
||||||
cached_pixbuf = get_cached_notification_image(cache_key)
|
cached_pixbuf = get_cached_notification_image(cache_key)
|
||||||
if cached_pixbuf:
|
if cached_pixbuf:
|
||||||
return cached_pixbuf.scale_simple(35, 35, GdkPixbuf.InterpType.BILINEAR)
|
return cached_pixbuf.scale_simple(
|
||||||
|
35, 35, GdkPixbuf.InterpType.BILINEAR
|
||||||
|
)
|
||||||
|
|
||||||
# Fallback to direct scaling if caching fails
|
# Fallback to direct scaling if caching fails
|
||||||
return notification.image_pixbuf.scale_simple(
|
return notification.image_pixbuf.scale_simple(
|
||||||
@@ -619,8 +666,10 @@ class NotificationWidget(Box):
|
|||||||
# Only clean up caches if this was a manual dismissal
|
# Only clean up caches if this was a manual dismissal
|
||||||
if self._should_cleanup_cache:
|
if self._should_cleanup_cache:
|
||||||
cleanup_notification_specific_caches(
|
cleanup_notification_specific_caches(
|
||||||
app_icon_source=getattr(self, 'app_icon_source', None),
|
app_icon_source=getattr(self, "app_icon_source", None),
|
||||||
notification_image_cache_key=getattr(self, 'notification_image_cache_key', None)
|
notification_image_cache_key=getattr(
|
||||||
|
self, "notification_image_cache_key", None
|
||||||
|
),
|
||||||
)
|
)
|
||||||
logger.debug(f"Cleaned up caches for manually dismissed notification")
|
logger.debug(f"Cleaned up caches for manually dismissed notification")
|
||||||
else:
|
else:
|
||||||
@@ -720,16 +769,16 @@ class NotificationRevealer(SlideRevealer):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Apply to the notification box
|
# Apply to the notification box
|
||||||
if hasattr(self.notif_box, 'get_style_context'):
|
if hasattr(self.notif_box, "get_style_context"):
|
||||||
style_context = self.notif_box.get_style_context()
|
style_context = self.notif_box.get_style_context()
|
||||||
if style_context:
|
if style_context:
|
||||||
# Use CSS provider for smooth transforms
|
# Use CSS provider for smooth transforms
|
||||||
if not hasattr(self, '_css_provider') or not self._css_provider:
|
if not hasattr(self, "_css_provider") or not self._css_provider:
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
self._css_provider = Gtk.CssProvider()
|
self._css_provider = Gtk.CssProvider()
|
||||||
style_context.add_provider(
|
style_context.add_provider(
|
||||||
self._css_provider,
|
self._css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
||||||
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
|
||||||
)
|
)
|
||||||
|
|
||||||
css_data = f"* {{ {transform_css} }}"
|
css_data = f"* {{ {transform_css} }}"
|
||||||
@@ -760,7 +809,7 @@ class NotificationRevealer(SlideRevealer):
|
|||||||
|
|
||||||
# Smoother fade and scale transitions
|
# Smoother fade and scale transitions
|
||||||
opacity = max(0.0, 1.0 - (progress * 0.9)) # Gentler fade
|
opacity = max(0.0, 1.0 - (progress * 0.9)) # Gentler fade
|
||||||
scale = max(0.9, 1.0 - (progress * 0.1)) # Subtle scale
|
scale = max(0.9, 1.0 - (progress * 0.1)) # Subtle scale
|
||||||
|
|
||||||
self._apply_transform(current_offset, opacity, scale)
|
self._apply_transform(current_offset, opacity, scale)
|
||||||
|
|
||||||
@@ -777,9 +826,7 @@ class NotificationRevealer(SlideRevealer):
|
|||||||
|
|
||||||
# Use consistent 60fps timing
|
# Use consistent 60fps timing
|
||||||
self._animation_in_progress = True
|
self._animation_in_progress = True
|
||||||
self._spring_timer_id = GLib.timeout_add(
|
self._spring_timer_id = GLib.timeout_add(16, animate_step) # ~60 FPS
|
||||||
16, animate_step # ~60 FPS
|
|
||||||
)
|
|
||||||
|
|
||||||
def _calculate_drag_velocity(self, current_x):
|
def _calculate_drag_velocity(self, current_x):
|
||||||
"""Calculate the velocity of the drag gesture"""
|
"""Calculate the velocity of the drag gesture"""
|
||||||
@@ -921,7 +968,7 @@ class ModusNoti(Window):
|
|||||||
|
|
||||||
self._debounce_timer_id = GLib.timeout_add(
|
self._debounce_timer_id = GLib.timeout_add(
|
||||||
self.DEBOUNCE_DELAY,
|
self.DEBOUNCE_DELAY,
|
||||||
lambda: self._process_notification_queue_debounced() or False
|
lambda: self._process_notification_queue_debounced() or False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _process_notification_queue_debounced(self):
|
def _process_notification_queue_debounced(self):
|
||||||
@@ -950,10 +997,7 @@ class ModusNoti(Window):
|
|||||||
|
|
||||||
def _start_smooth_transition(self):
|
def _start_smooth_transition(self):
|
||||||
"""Start smooth transition between notifications"""
|
"""Start smooth transition between notifications"""
|
||||||
if (
|
if self.current_notification and not self.current_notification._is_closing:
|
||||||
self.current_notification
|
|
||||||
and not self.current_notification._is_closing
|
|
||||||
):
|
|
||||||
# Don't mark for cache cleanup during smooth transitions
|
# Don't mark for cache cleanup during smooth transitions
|
||||||
# to maintain performance
|
# to maintain performance
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from services.modus import notification_service
|
|||||||
from widgets.wayland import WaylandWindow as Window
|
from widgets.wayland import WaylandWindow as Window
|
||||||
from fabric.widgets.image import Image
|
from fabric.widgets.image import Image
|
||||||
from fabric.widgets.eventbox import EventBox
|
from fabric.widgets.eventbox import EventBox
|
||||||
|
from widgets.custom_image import CustomImage
|
||||||
from fabric.widgets.revealer import Revealer
|
from fabric.widgets.revealer import Revealer
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +89,19 @@ class ExpandableNotificationGroup(Box):
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Box(
|
||||||
|
orientation="v",
|
||||||
|
children=[
|
||||||
|
Button(
|
||||||
|
name="notification-close",
|
||||||
|
image=CustomImage(
|
||||||
|
icon_name="close-symbolic", icon_size=18
|
||||||
|
),
|
||||||
|
visible=True, # Initially hidden
|
||||||
|
),
|
||||||
|
Box(v_expand=True),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.collapsed_eventbox.add(single_notification)
|
self.collapsed_eventbox.add(single_notification)
|
||||||
@@ -205,10 +219,17 @@ class ExpandableNotificationGroup(Box):
|
|||||||
h_align="end",
|
h_align="end",
|
||||||
),
|
),
|
||||||
Button(
|
Button(
|
||||||
name="notification-close-all",
|
name="notification-close-summery",
|
||||||
label="×",
|
h_expand=False,
|
||||||
|
v_expand=False,
|
||||||
on_clicked=self.close_all,
|
on_clicked=self.close_all,
|
||||||
h_align="end",
|
image=CustomImage(
|
||||||
|
icon_name="close-symbolic",
|
||||||
|
name="notification-close-header",
|
||||||
|
icon_size=18,
|
||||||
|
h_align="end",
|
||||||
|
),
|
||||||
|
visible=True, # Initially hidden
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -297,7 +318,9 @@ class NotificationCenterWidget(NotificationWidget):
|
|||||||
|
|
||||||
self.close_button = Button(
|
self.close_button = Button(
|
||||||
name="notif-close-button",
|
name="notif-close-button",
|
||||||
image=CustomImage(icon_name="close-symbolic", icon_size=18),
|
image=CustomImage(
|
||||||
|
icon_name="close-symbolic", name="notification-close", icon_size=18
|
||||||
|
),
|
||||||
visible=True, # Always visible in notification center
|
visible=True, # Always visible in notification center
|
||||||
on_clicked=self._on_close_clicked,
|
on_clicked=self._on_close_clicked,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -276,3 +276,18 @@
|
|||||||
#notification-centre-notifs:last-child {
|
#notification-centre-notifs:last-child {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#notification-close,
|
||||||
|
#notification-close-header {
|
||||||
|
background-color: alpha(#444, 0.8);
|
||||||
|
min-width: 23px;
|
||||||
|
min-height: 23px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
#notification-close:hover,
|
||||||
|
#notification-close-summery:hover #notification-close-header {
|
||||||
|
background-color: alpha(#666, 0.8);
|
||||||
|
min-width: 23px;
|
||||||
|
min-height: 23px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user