border-radius for image on notification
This commit is contained in:
1 parent
16c444c41f
commit
f0423b4969
4 files changed
+64
-9
No files matched your search
@@ -2,6 +2,8 @@ import gi
|
||||
|
||||
gi.require_version("GdkPixbuf", "2.0")
|
||||
|
||||
from gi.repository import GdkPixbuf, GLib
|
||||
|
||||
from fabric.notifications import (
|
||||
Notification,
|
||||
NotificationAction,
|
||||
@@ -15,7 +17,7 @@ from fabric.widgets.image import Image
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.revealer import Revealer
|
||||
from fabric.widgets.wayland import WaylandWindow as Window
|
||||
from gi.repository import GdkPixbuf, GLib
|
||||
from snippets import CustomImage
|
||||
|
||||
|
||||
class ActionButton(Button):
|
||||
@@ -95,11 +97,16 @@ class NotificationWidget(Box):
|
||||
# Use provided image if available, otherwise use "notification-symbolic" icon
|
||||
if image_pixbuf := self._notification.image_pixbuf:
|
||||
body_container.add(
|
||||
Image(
|
||||
pixbuf=image_pixbuf.scale_simple(
|
||||
64, 64, GdkPixbuf.InterpType.BILINEAR
|
||||
)
|
||||
),
|
||||
Box(
|
||||
v_expand=True,
|
||||
v_align="center",
|
||||
children=CustomImage(
|
||||
pixbuf=image_pixbuf.scale_simple(
|
||||
64, 64, GdkPixbuf.InterpType.BILINEAR
|
||||
),
|
||||
style_classes="image",
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
body_container.add(
|
||||
@@ -143,7 +150,12 @@ class NotificationWidget(Box):
|
||||
)
|
||||
|
||||
def get_icon(self, app_icon, app_name, size) -> Image:
|
||||
|
||||
# Normalize app_name
|
||||
app_name = (
|
||||
app_name.lower().replace(" ", "-")
|
||||
if isinstance(app_name, str)
|
||||
else app_name
|
||||
)
|
||||
# Attempt to load file-based icons
|
||||
if isinstance(app_icon, str) and app_icon.strip():
|
||||
if app_icon.startswith("file://") or app_icon.startswith("/"):
|
||||
@@ -164,8 +176,6 @@ class NotificationWidget(Box):
|
||||
else:
|
||||
icon_name = "dialog-information-symbolic"
|
||||
|
||||
print(f"DEBUG: icon_name={icon_name}")
|
||||
|
||||
# Return a symbolic icon as fallback
|
||||
return Image(name="notification-icon", icon_name=icon_name, icon_size=size)
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .animator import Animator
|
||||
from .custom_image import CustomImage
|
||||
from .functions import (
|
||||
get_current_uptime,
|
||||
get_profile_picture_path,
|
||||
@@ -16,4 +17,5 @@ __all__ = [
|
||||
"username",
|
||||
"IconResolver",
|
||||
"get_current_uptime",
|
||||
"CustomImage",
|
||||
]
|
||||
@@ -0,0 +1,39 @@
|
||||
import math
|
||||
from typing import cast
|
||||
|
||||
import cairo
|
||||
from gi.repository import Gtk
|
||||
|
||||
from fabric.widgets.image import Image
|
||||
|
||||
|
||||
class CustomImage(Image):
|
||||
def do_render_rectangle(
|
||||
self, cr: cairo.Context, width: int, height: int, radius: int = 0
|
||||
):
|
||||
cr.move_to(radius, 0)
|
||||
cr.line_to(width - radius, 0)
|
||||
cr.arc(width - radius, radius, radius, -(math.pi / 2), 0)
|
||||
cr.line_to(width, height - radius)
|
||||
cr.arc(width - radius, height - radius, radius, 0, (math.pi / 2))
|
||||
cr.line_to(radius, height)
|
||||
cr.arc(radius, height - radius, radius, (math.pi / 2), math.pi)
|
||||
cr.line_to(0, radius)
|
||||
cr.arc(radius, radius, radius, math.pi, (3 * (math.pi / 2)))
|
||||
cr.close_path()
|
||||
|
||||
def do_draw(self, cr: cairo.Context):
|
||||
context = self.get_style_context()
|
||||
width, height = self.get_allocated_width(), self.get_allocated_height()
|
||||
cr.save()
|
||||
|
||||
self.do_render_rectangle(
|
||||
cr,
|
||||
width,
|
||||
height,
|
||||
cast(int, context.get_property("border-radius", Gtk.StateFlags.NORMAL)),
|
||||
)
|
||||
cr.clip()
|
||||
Image.do_draw(self, cr)
|
||||
|
||||
cr.restore()
|
||||
@@ -45,3 +45,7 @@
|
||||
#notification-icon {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.image {
|
||||
border-radius: 30px;
|
||||
}
|
||||
Reference in new issue
Block a user