shell-app: Remove shell_app_get_faded_icon
In previous commit we removed the only use of shell_app_get_faded_icon so we can remove the function on shell-app as well. https://bugzilla.gnome.org/show_bug.cgi?id=744680
This commit is contained in:
parent
e71b0a57fb
commit
ef3285d5e7
184
src/shell-app.c
184
src/shell-app.c
@ -240,190 +240,6 @@ typedef struct {
|
||||
StThemeNode *theme_node;
|
||||
} CreateFadedIconData;
|
||||
|
||||
static CoglHandle
|
||||
shell_app_create_faded_icon_cpu (StTextureCache *cache,
|
||||
const char *key,
|
||||
void *datap,
|
||||
GError **error)
|
||||
{
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
|
||||
CreateFadedIconData *data = datap;
|
||||
ShellApp *app;
|
||||
GdkPixbuf *pixbuf;
|
||||
int size;
|
||||
int scale;
|
||||
CoglHandle texture;
|
||||
gint width, height, rowstride;
|
||||
guint8 n_channels;
|
||||
gboolean have_alpha;
|
||||
gint fade_start;
|
||||
gint fade_end;
|
||||
guint i, j;
|
||||
guint pixbuf_byte_size;
|
||||
guint8 *orig_pixels;
|
||||
guint8 *pixels;
|
||||
GIcon *icon;
|
||||
GtkIconInfo *info;
|
||||
GtkIconLookupFlags lookup_flags;
|
||||
StIconStyle icon_style;
|
||||
|
||||
app = data->app;
|
||||
size = data->size;
|
||||
scale = data->scale;
|
||||
icon_style = st_theme_node_get_icon_style (data->theme_node);
|
||||
|
||||
info = NULL;
|
||||
|
||||
lookup_flags = GTK_ICON_LOOKUP_FORCE_SIZE;
|
||||
if (icon_style == ST_ICON_STYLE_REGULAR)
|
||||
lookup_flags |= GTK_ICON_LOOKUP_FORCE_REGULAR;
|
||||
else if (icon_style == ST_ICON_STYLE_SYMBOLIC)
|
||||
lookup_flags |= GTK_ICON_LOOKUP_FORCE_SYMBOLIC;
|
||||
|
||||
icon = g_app_info_get_icon (G_APP_INFO (app->info));
|
||||
if (icon != NULL)
|
||||
{
|
||||
info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (),
|
||||
icon, size, scale,
|
||||
lookup_flags);
|
||||
}
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
icon = g_themed_icon_new ("application-x-executable");
|
||||
info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (),
|
||||
icon, size, scale,
|
||||
lookup_flags);
|
||||
g_object_unref (icon);
|
||||
}
|
||||
|
||||
if (info == NULL)
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
pixbuf = gtk_icon_info_load_icon (info, NULL);
|
||||
g_object_unref (info);
|
||||
|
||||
if (pixbuf == NULL)
|
||||
return COGL_INVALID_HANDLE;
|
||||
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
||||
orig_pixels = gdk_pixbuf_get_pixels (pixbuf);
|
||||
have_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
|
||||
|
||||
pixbuf_byte_size = (height - 1) * rowstride +
|
||||
+ width * ((n_channels * gdk_pixbuf_get_bits_per_sample (pixbuf) + 7) / 8);
|
||||
|
||||
pixels = g_malloc0 (rowstride * height);
|
||||
memcpy (pixels, orig_pixels, pixbuf_byte_size);
|
||||
|
||||
/* fade on the right side for LTR, left side for RTL */
|
||||
if (data->direction == CLUTTER_TEXT_DIRECTION_LTR)
|
||||
{
|
||||
fade_start = width / 2;
|
||||
fade_end = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
fade_start = 0;
|
||||
fade_end = width / 2;
|
||||
}
|
||||
|
||||
for (i = fade_start; i < fade_end; i++)
|
||||
{
|
||||
for (j = 0; j < height; j++)
|
||||
{
|
||||
guchar *pixel = &pixels[j * rowstride + i * n_channels];
|
||||
float fade = ((float) i - fade_start) / (fade_end - fade_start);
|
||||
if (data->direction == CLUTTER_TEXT_DIRECTION_LTR)
|
||||
fade = 1.0 - fade;
|
||||
pixel[0] = 0.5 + pixel[0] * fade;
|
||||
pixel[1] = 0.5 + pixel[1] * fade;
|
||||
pixel[2] = 0.5 + pixel[2] * fade;
|
||||
if (have_alpha)
|
||||
pixel[3] = 0.5 + pixel[3] * fade;
|
||||
}
|
||||
}
|
||||
|
||||
texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, width, height,
|
||||
have_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
||||
rowstride,
|
||||
pixels,
|
||||
NULL));
|
||||
g_free (pixels);
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_app_get_faded_icon:
|
||||
* @app: A #ShellApp
|
||||
* @size: Size in pixels
|
||||
* @direction: Whether to fade on the left or right
|
||||
*
|
||||
* Return an actor with a horizontally faded look.
|
||||
*
|
||||
* Return value: (transfer none): A floating #ClutterActor, or %NULL if no icon
|
||||
*/
|
||||
ClutterActor *
|
||||
shell_app_get_faded_icon (ShellApp *app, int size, ClutterTextDirection direction)
|
||||
{
|
||||
CoglHandle texture;
|
||||
ClutterActor *result;
|
||||
char *cache_key;
|
||||
CreateFadedIconData data;
|
||||
gint scale;
|
||||
ShellGlobal *global;
|
||||
StThemeContext *context;
|
||||
|
||||
/* Don't fade for window backed apps for now...easier to reuse the
|
||||
* property tracking bits, and this helps us visually distinguish
|
||||
* app-tracked from not.
|
||||
*/
|
||||
if (!app->info)
|
||||
return window_backed_app_get_icon (app, size);
|
||||
|
||||
global = shell_global_get ();
|
||||
context = st_theme_context_get_for_stage (shell_global_get_stage (global));
|
||||
g_object_get (context, "scale-factor", &scale, NULL);
|
||||
|
||||
/* Use icon: prefix so that we get evicted from the cache on
|
||||
* icon theme changes. */
|
||||
cache_key = g_strdup_printf ("icon:%s,size=%d,scale=%d,faded-%s",
|
||||
shell_app_get_id (app),
|
||||
size, scale,
|
||||
direction == CLUTTER_TEXT_DIRECTION_RTL ? "rtl" : "ltr");
|
||||
data.app = app;
|
||||
data.size = size;
|
||||
data.scale = scale;
|
||||
data.direction = direction;
|
||||
data.theme_node = st_theme_context_get_root_node (context);
|
||||
texture = st_texture_cache_load (st_texture_cache_get_default (),
|
||||
cache_key,
|
||||
ST_TEXTURE_CACHE_POLICY_FOREVER,
|
||||
shell_app_create_faded_icon_cpu,
|
||||
&data,
|
||||
NULL);
|
||||
g_free (cache_key);
|
||||
|
||||
if (texture != COGL_INVALID_HANDLE)
|
||||
{
|
||||
result = clutter_texture_new ();
|
||||
clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (result), texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = clutter_texture_new ();
|
||||
g_object_set (result, "opacity", 0, "width", (float) size * scale, "height", (float) size * scale, NULL);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const char *
|
||||
shell_app_get_name (ShellApp *app)
|
||||
{
|
||||
|
@ -40,7 +40,6 @@ const char *shell_app_get_id (ShellApp *app);
|
||||
GDesktopAppInfo *shell_app_get_app_info (ShellApp *app);
|
||||
|
||||
ClutterActor *shell_app_create_icon_texture (ShellApp *app, int size);
|
||||
ClutterActor *shell_app_get_faded_icon (ShellApp *app, int size, ClutterTextDirection direction);
|
||||
const char *shell_app_get_name (ShellApp *app);
|
||||
const char *shell_app_get_description (ShellApp *app);
|
||||
gboolean shell_app_is_window_backed (ShellApp *app);
|
||||
|
Loading…
Reference in New Issue
Block a user