[epiphany/wip/exalm/scale: 1/2] Fix HiDPI favicons
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/scale: 1/2] Fix HiDPI favicons
- Date: Mon, 16 Nov 2020 08:10:14 +0000 (UTC)
commit fa875fcafd22a9d53bab55c470f1880672aa5ff9
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Nov 16 12:13:16 2020 +0500
Fix HiDPI favicons
Currently the icon is handled in a weird way involving manually managing
a cairo surface instead of just using GIcon. Getting scale factor from the
window doesn't work when the widget isn't realized yet and doesn't have a
window to begin with, which gtk_widget_get_scale_factor() does handle.
Additionally, the icon isn't reloaded on scale factor changes.
Fixes https://gitlab.gnome.org/GNOME/epiphany/-/issues/1298
embed/ephy-web-view.c | 19 ++++++++++++++-----
src/ephy-page-row.c | 17 ++++-------------
src/ephy-tab-label.c | 17 ++++-------------
3 files changed, 22 insertions(+), 31 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 4ed9fc787..488cc71c1 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -570,15 +570,12 @@ maybe_take_snapshot (EphyWebView *view)
static void
_ephy_web_view_update_icon (EphyWebView *view)
{
- if (view->icon != NULL) {
- g_object_unref (view->icon);
- view->icon = NULL;
- }
+ g_clear_object (&view->icon);
if (view->address) {
cairo_surface_t *icon_surface = webkit_web_view_get_favicon (WEBKIT_WEB_VIEW (view));
if (icon_surface) {
- gint scale = gdk_window_get_scale_factor (gtk_widget_get_window (GTK_WIDGET (view)));
+ gint scale = gtk_widget_get_scale_factor (GTK_WIDGET (view));
view->icon = ephy_pixbuf_get_from_surface_scaled (icon_surface, scale * FAVICON_SIZE, scale *
FAVICON_SIZE);
}
}
@@ -2720,6 +2717,14 @@ user_message_received_cb (WebKitWebView *web_view,
return FALSE;
}
+static void
+scale_factor_changed_cb (EphyWebView *web_view,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ _ephy_web_view_update_icon (web_view);
+}
+
/**
* ephy_web_view_load_request:
* @view: the #EphyWebView in which to load the request
@@ -3844,6 +3849,10 @@ ephy_web_view_init (EphyWebView *web_view)
G_CALLBACK (user_message_received_cb),
NULL);
+ g_signal_connect_object (web_view, "notify::scale-factor",
+ G_CALLBACK (scale_factor_changed_cb),
+ web_view, 0);
+
g_signal_connect_object (shell, "password-form-focused",
G_CALLBACK (password_form_focused_cb),
web_view, 0);
diff --git a/src/ephy-page-row.c b/src/ephy-page-row.c
index adacca81a..b85438a0f 100644
--- a/src/ephy-page-row.c
+++ b/src/ephy-page-row.c
@@ -136,20 +136,11 @@ sync_favicon (EphyWebView *view,
GParamSpec *pspec,
EphyPageRow *self)
{
- g_autoptr (GdkPixbuf) pixbuf = NULL;
+ GdkPixbuf *pixbuf = ephy_web_view_get_icon (view);
- if (ephy_web_view_get_icon (view))
- pixbuf = gdk_pixbuf_copy (ephy_web_view_get_icon (view));
-
- if (pixbuf) {
- cairo_surface_t *surface;
-
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf,
- 0,
- gtk_widget_get_window (GTK_WIDGET (view)));
- gtk_image_set_from_surface (GTK_IMAGE (self->icon), surface);
- cairo_surface_destroy (surface);
- } else {
+ if (pixbuf)
+ gtk_image_set_from_gicon (GTK_IMAGE (self->icon), G_ICON (pixbuf), GTK_ICON_SIZE_MENU);
+ else {
const char *favicon_name = ephy_get_fallback_favicon_name (ephy_web_view_get_display_address (view),
EPHY_FAVICON_TYPE_SHOW_MISSING_PLACEHOLDER);
gtk_image_set_from_icon_name (GTK_IMAGE (self->icon), favicon_name, GTK_ICON_SIZE_MENU);
diff --git a/src/ephy-tab-label.c b/src/ephy-tab-label.c
index 40414de92..9ed372533 100644
--- a/src/ephy-tab-label.c
+++ b/src/ephy-tab-label.c
@@ -121,19 +121,10 @@ ephy_tab_label_set_property (GObject *object,
}
break;
case PROP_ICON_BUF:
- if (g_value_get_object (value)) {
- cairo_surface_t *surface;
-
- surface = gdk_cairo_surface_create_from_pixbuf (g_value_get_object (value),
- 0,
- gtk_widget_get_window (GTK_WIDGET (self)));
- gtk_image_set_from_surface (GTK_IMAGE (self->icon), surface);
- cairo_surface_destroy (surface);
- self->has_icon = TRUE;
- } else {
- gtk_image_set_from_surface (GTK_IMAGE (self->icon), NULL);
- self->has_icon = FALSE;
- }
+ gtk_image_set_from_gicon (GTK_IMAGE (self->icon),
+ g_value_get_object (value),
+ GTK_ICON_SIZE_BUTTON);
+ self->has_icon = g_value_get_object (value) != NULL;
ephy_tab_label_update_icon (self);
break;
case PROP_SPINNING:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]