summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2021-06-14 08:40:35 -0400
committerVictor Kareh <[email protected]>2023-03-07 13:35:05 -0500
commitdf299574f6db9bcdccc9413f173c2dd4ceff6467 (patch)
tree73e9feadbeded2be39e8797563f4d35833bd7a99
parent319ee4ffaae7bec3289a1a65ce9774982564cd61 (diff)
downloadmarco-df299574f6db9bcdccc9413f173c2dd4ceff6467.tar.bz2
marco-df299574f6db9bcdccc9413f173c2dd4ceff6467.tar.xz
iconcache: replace width and height with size in read_icons
meta_read_icons is used in MetaWindow. In it ideal_width and ideal_height have same value - default icon size. Same with ideal_mini_width and ideal_mini_height. Simplify function by replacing width and height parameters with size parameter. Adapted from https://gitlab.gnome.org/GNOME/libwnck/-/commit/c1460f79
-rw-r--r--src/core/iconcache.c154
-rw-r--r--src/core/iconcache.h6
-rw-r--r--src/core/window.c6
-rw-r--r--src/include/common.h3
-rw-r--r--src/ui/preview-widget.c4
-rw-r--r--src/ui/ui.c4
6 files changed, 45 insertions, 132 deletions
diff --git a/src/core/iconcache.c b/src/core/iconcache.c
index a45d3d99..45452544 100644
--- a/src/core/iconcache.c
+++ b/src/core/iconcache.c
@@ -32,13 +32,9 @@
/* The icon-reading code is also in libwnck, please sync bugfixes */
static void
-get_fallback_icons (MetaScreen *screen,
- GdkPixbuf **iconp,
- int ideal_width,
- int ideal_height,
- GdkPixbuf **mini_iconp,
- int ideal_mini_width,
- int ideal_mini_height)
+get_fallback_icons (MetaScreen *screen,
+ GdkPixbuf **iconp,
+ GdkPixbuf **mini_iconp)
{
/* we don't scale, should be fixed if we ever un-hardcode the icon
* size
@@ -48,42 +44,9 @@ get_fallback_icons (MetaScreen *screen,
}
static gboolean
-find_largest_sizes (gulong *data,
- gulong nitems,
- int *width,
- int *height)
-{
- *width = 0;
- *height = 0;
-
- while (nitems > 0)
- {
- int w, h;
-
- if (nitems < 3)
- return FALSE; /* no space for w, h */
-
- w = data[0];
- h = data[1];
-
- if (nitems < ((gulong)(w * h) + 2))
- return FALSE; /* not enough data */
-
- *width = MAX (w, *width);
- *height = MAX (h, *height);
-
- data += (w * h) + 2;
- nitems -= (w * h) + 2;
- }
-
- return TRUE;
-}
-
-static gboolean
find_best_size (gulong *data,
gulong nitems,
- int ideal_width,
- int ideal_height,
+ int ideal_size,
int *width,
int *height,
gulong **start)
@@ -91,20 +54,11 @@ find_best_size (gulong *data,
int best_w;
int best_h;
gulong *best_start;
- int max_width, max_height;
*width = 0;
*height = 0;
*start = NULL;
- if (!find_largest_sizes (data, nitems, &max_width, &max_height))
- return FALSE;
-
- if (ideal_width < 0)
- ideal_width = max_width;
- if (ideal_height < 0)
- ideal_height = max_height;
-
best_w = 0;
best_h = 0;
best_start = NULL;
@@ -132,7 +86,6 @@ find_best_size (gulong *data,
else
{
/* work with averages */
- const int ideal_size = (ideal_width + ideal_height) / 2;
int best_size = (best_w + best_h) / 2;
int this_size = (w + h) / 2;
@@ -208,18 +161,16 @@ argbdata_to_pixdata (gulong *argb_data, int len, guchar **pixdata)
}
static gboolean
-read_rgb_icon (MetaDisplay *display,
- Window xwindow,
- int ideal_width,
- int ideal_height,
- int ideal_mini_width,
- int ideal_mini_height,
- int *width,
- int *height,
- guchar **pixdata,
- int *mini_width,
- int *mini_height,
- guchar **mini_pixdata)
+read_rgb_icon (MetaDisplay *display,
+ Window xwindow,
+ int ideal_size,
+ int ideal_mini_size,
+ int *width,
+ int *height,
+ guchar **pixdata,
+ int *mini_width,
+ int *mini_height,
+ guchar **mini_pixdata)
{
Atom type;
int format;
@@ -256,16 +207,14 @@ read_rgb_icon (MetaDisplay *display,
data_as_long = (gulong *)data;
- if (!find_best_size (data_as_long, nitems,
- ideal_width, ideal_height,
- &w, &h, &best))
+ if (!find_best_size (data_as_long, nitems, ideal_size, &w, &h, &best))
{
XFree (data);
return FALSE;
}
if (!find_best_size (data_as_long, nitems,
- ideal_mini_width, ideal_mini_height,
+ ideal_mini_size,
&mini_w, &mini_h, &best_mini))
{
XFree (data);
@@ -378,11 +327,9 @@ try_pixmap_and_mask (MetaDisplay *display,
Pixmap src_pixmap,
Pixmap src_mask,
GdkPixbuf **iconp,
- int ideal_width,
- int ideal_height,
+ int ideal_size,
GdkPixbuf **mini_iconp,
- int ideal_mini_width,
- int ideal_mini_height)
+ int ideal_mini_size)
{
GdkPixbuf *unscaled = NULL;
GdkPixbuf *mask = NULL;
@@ -427,17 +374,13 @@ try_pixmap_and_mask (MetaDisplay *display,
{
*iconp =
gdk_pixbuf_scale_simple (unscaled,
- ideal_width > 0 ? ideal_width :
- gdk_pixbuf_get_width (unscaled),
- ideal_height > 0 ? ideal_height :
- gdk_pixbuf_get_height (unscaled),
+ ideal_size,
+ ideal_size,
GDK_INTERP_BILINEAR);
*mini_iconp =
gdk_pixbuf_scale_simple (unscaled,
- ideal_mini_width > 0 ? ideal_mini_width :
- gdk_pixbuf_get_width (unscaled),
- ideal_mini_height > 0 ? ideal_mini_height :
- gdk_pixbuf_get_height (unscaled),
+ ideal_mini_size,
+ ideal_mini_size,
GDK_INTERP_BILINEAR);
g_object_unref (G_OBJECT (unscaled));
@@ -515,10 +458,8 @@ meta_icon_cache_init (MetaIconCache *icon_cache)
#if 0
icon_cache->icon = NULL;
icon_cache->mini_icon = NULL;
- icon_cache->ideal_width = -1; /* won't be a legit width */
- icon_cache->ideal_height = -1;
- icon_cache->ideal_mini_width = -1;
- icon_cache->ideal_mini_height = -1;
+ icon_cache->ideal_size = -1; /* won't be a legit size */
+ icon_cache->ideal_mini_size = -1;
#endif
icon_cache->want_fallback = TRUE;
icon_cache->wm_hints_dirty = TRUE;
@@ -696,11 +637,9 @@ meta_read_icons (MetaScreen *screen,
Pixmap wm_hints_pixmap,
Pixmap wm_hints_mask,
GdkPixbuf **iconp,
- int ideal_width,
- int ideal_height,
+ int ideal_size,
GdkPixbuf **mini_iconp,
- int ideal_mini_width,
- int ideal_mini_height)
+ int ideal_mini_size)
{
guchar *pixdata;
int w, h;
@@ -716,19 +655,6 @@ meta_read_icons (MetaScreen *screen,
*iconp = NULL;
*mini_iconp = NULL;
-#if 0
- if (ideal_width != icon_cache->ideal_width ||
- ideal_height != icon_cache->ideal_height ||
- ideal_mini_width != icon_cache->ideal_mini_width ||
- ideal_mini_height != icon_cache->ideal_mini_height)
- clear_icon_cache (icon_cache, TRUE);
-
- icon_cache->ideal_width = ideal_width;
- icon_cache->ideal_height = ideal_height;
- icon_cache->ideal_mini_width = ideal_mini_width;
- icon_cache->ideal_mini_height = ideal_mini_height;
-#endif
-
if (!meta_icon_cache_get_icon_invalidated (icon_cache))
return FALSE; /* we have no new info to use */
@@ -750,16 +676,15 @@ meta_read_icons (MetaScreen *screen,
icon_cache->net_wm_icon_dirty = FALSE;
if (read_rgb_icon (screen->display, xwindow,
- ideal_width, ideal_height,
- ideal_mini_width, ideal_mini_height,
+ ideal_size,
+ ideal_mini_size,
&w, &h, &pixdata,
&mini_w, &mini_h, &mini_pixdata))
{
- *iconp = scaled_from_pixdata (pixdata, w, h,
- ideal_width, ideal_height);
+ *iconp = scaled_from_pixdata (pixdata, w, h, ideal_size, ideal_size);
*mini_iconp = scaled_from_pixdata (mini_pixdata, mini_w, mini_h,
- ideal_mini_width, ideal_mini_height);
+ ideal_mini_size, ideal_mini_size);
if (*iconp && *mini_iconp)
{
@@ -797,10 +722,9 @@ meta_read_icons (MetaScreen *screen,
{
icon_cache->wm_hints_dirty_forced = FALSE;
- if (try_pixmap_and_mask (screen->display,
- pixmap, mask,
- iconp, ideal_width, ideal_height,
- mini_iconp, ideal_mini_width, ideal_mini_height))
+ if (try_pixmap_and_mask (screen->display, pixmap, mask,
+ iconp, ideal_size,
+ mini_iconp, ideal_mini_size))
{
icon_cache->prev_pixmap = pixmap;
icon_cache->prev_mask = mask;
@@ -828,8 +752,8 @@ meta_read_icons (MetaScreen *screen,
icon_cache->kwm_win_icon_dirty_forced = FALSE;
if (try_pixmap_and_mask (screen->display, pixmap, mask,
- iconp, ideal_width, ideal_height,
- mini_iconp, ideal_mini_width, ideal_mini_height))
+ iconp, ideal_size,
+ mini_iconp, ideal_mini_size))
{
icon_cache->prev_pixmap = pixmap;
icon_cache->prev_mask = mask;
@@ -856,13 +780,7 @@ meta_read_icons (MetaScreen *screen,
}
if (*iconp == NULL || *mini_iconp == NULL)
- get_fallback_icons (screen,
- iconp,
- ideal_width,
- ideal_height,
- mini_iconp,
- ideal_mini_width,
- ideal_mini_height);
+ get_fallback_icons (screen, iconp, mini_iconp);
replace_cache (icon_cache, USING_FALLBACK_ICON,
*iconp, *mini_iconp);
diff --git a/src/core/iconcache.h b/src/core/iconcache.h
index 7e9a1f6d..a558a945 100644
--- a/src/core/iconcache.h
+++ b/src/core/iconcache.h
@@ -72,11 +72,9 @@ gboolean meta_read_icons (MetaScreen *screen,
Pixmap wm_hints_pixmap,
Pixmap wm_hints_mask,
GdkPixbuf **iconp,
- int ideal_width,
- int ideal_height,
+ int ideal_size,
GdkPixbuf **mini_iconp,
- int ideal_mini_width,
- int ideal_mini_height);
+ int ideal_mini_size);
#endif
diff --git a/src/core/window.c b/src/core/window.c
index de3f9c99..4c90fee4 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -6126,11 +6126,9 @@ meta_window_update_icon_now (MetaWindow *window)
window->wm_hints_pixmap,
window->wm_hints_mask,
&icon,
- icon_size, /* width */
- icon_size, /* height */
+ icon_size,
&mini_icon,
- META_MINI_ICON_WIDTH,
- META_MINI_ICON_HEIGHT))
+ META_MINI_ICON_SIZE))
{
if (window->icon)
g_object_unref (G_OBJECT (window->icon));
diff --git a/src/include/common.h b/src/include/common.h
index 9febd63c..05692f7b 100644
--- a/src/include/common.h
+++ b/src/include/common.h
@@ -323,8 +323,7 @@ void meta_frame_borders_clear (MetaFrameBorders *self);
#define META_MIN_ICON_SIZE 8
#define META_MAX_ICON_SIZE 256
-#define META_MINI_ICON_WIDTH 16
-#define META_MINI_ICON_HEIGHT 16
+#define META_MINI_ICON_SIZE 16
#define META_DEFAULT_ICON_NAME "preferences-desktop-theme"
diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c
index e6e08073..9c7fd3ec 100644
--- a/src/ui/preview-widget.c
+++ b/src/ui/preview-widget.c
@@ -471,13 +471,13 @@ meta_preview_get_mini_icon (void)
if (icon_exists)
default_icon = gtk_icon_theme_load_icon (theme,
META_DEFAULT_ICON_NAME,
- META_MINI_ICON_WIDTH,
+ META_MINI_ICON_SIZE,
0,
NULL);
else
default_icon = gtk_icon_theme_load_icon (theme,
"image-missing",
- META_MINI_ICON_WIDTH,
+ META_MINI_ICON_SIZE,
0,
NULL);
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 9976c701..6fc8403a 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -639,7 +639,7 @@ meta_ui_get_default_mini_icon (MetaUI *ui)
if (default_icon == NULL)
{
scale = gtk_widget_get_scale_factor (GTK_WIDGET (ui->frames));
- default_icon = load_default_window_icon (META_MINI_ICON_WIDTH, scale);
+ default_icon = load_default_window_icon (META_MINI_ICON_SIZE, scale);
g_assert (default_icon);
}
@@ -718,7 +718,7 @@ meta_ui_get_mini_icon_from_name (MetaUI *ui, char *name)
int size;
scale = gtk_widget_get_scale_factor (GTK_WIDGET (ui->frames));
- size = META_MINI_ICON_WIDTH / scale;
+ size = META_MINI_ICON_SIZE / scale;
return load_window_icon_from_name (name, size, scale);
}