shell-app: Fade the app icon on the left in RTL layouts

The point of fading the icon is to make the text displayed over the
icon more legible. In RTL layouts, the text is displayed on the left
of the icon, so fading the right-hand-side of the icon doesn't work
well.

https://bugzilla.gnome.org/show_bug.cgi?id=704583
This commit is contained in:
Jasper St. Pierre 2013-07-19 15:39:48 -04:00 committed by Ray Strode
parent 31f67d9142
commit c1d107a682
3 changed files with 33 additions and 14 deletions

View File

@ -371,13 +371,16 @@ const AppMenuButton = new Lang.Class({
this._updateIconBoxClip(); this._updateIconBoxClip();
}, },
_syncIcon: function() {
let icon = this._targetApp.get_faded_icon(2 * PANEL_ICON_SIZE, this._iconBox.text_direction);
this._iconBox.set_child(icon);
},
_onIconThemeChanged: function() { _onIconThemeChanged: function() {
if (this._iconBox.child == null) if (this._iconBox.child == null)
return; return;
this._iconBox.child.destroy(); this._syncIcon();
let icon = this._targetApp.get_faded_icon(2 * PANEL_ICON_SIZE);
this._iconBox.set_child(icon);
}, },
_updateIconBoxClip: function() { _updateIconBoxClip: function() {
@ -595,12 +598,10 @@ const AppMenuButton = new Lang.Class({
} }
this._targetApp = targetApp; this._targetApp = targetApp;
let icon = targetApp.get_faded_icon(2 * PANEL_ICON_SIZE);
this._label.setText(targetApp.get_name()); this._label.setText(targetApp.get_name());
this.setName(targetApp.get_name()); this.setName(targetApp.get_name());
this._iconBox.set_child(icon); this._syncIcon();
this._iconBox.show(); this._iconBox.show();
if (targetApp.get_state() == Shell.AppState.STARTING) if (targetApp.get_state() == Shell.AppState.STARTING)

View File

@ -210,6 +210,7 @@ shell_app_create_icon_texture (ShellApp *app,
typedef struct { typedef struct {
ShellApp *app; ShellApp *app;
int size; int size;
ClutterTextDirection direction;
} CreateFadedIconData; } CreateFadedIconData;
static CoglHandle static CoglHandle
@ -227,7 +228,7 @@ shell_app_create_faded_icon_cpu (StTextureCache *cache,
guint8 n_channels; guint8 n_channels;
gboolean have_alpha; gboolean have_alpha;
gint fade_start; gint fade_start;
gint fade_range; gint fade_end;
guint i, j; guint i, j;
guint pixbuf_byte_size; guint pixbuf_byte_size;
guint8 *orig_pixels; guint8 *orig_pixels;
@ -279,14 +280,26 @@ shell_app_create_faded_icon_cpu (StTextureCache *cache,
pixels = g_malloc0 (rowstride * height); pixels = g_malloc0 (rowstride * height);
memcpy (pixels, orig_pixels, pixbuf_byte_size); memcpy (pixels, orig_pixels, pixbuf_byte_size);
fade_start = width / 2; /* fade on the right side for LTR, left side for RTL */
fade_range = width - fade_start; if (data->direction == CLUTTER_TEXT_DIRECTION_LTR)
for (i = fade_start; i < width; i++) {
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++) for (j = 0; j < height; j++)
{ {
guchar *pixel = &pixels[j * rowstride + i * n_channels]; guchar *pixel = &pixels[j * rowstride + i * n_channels];
float fade = 1.0 - ((float) i - fade_start) / fade_range; 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[0] = 0.5 + pixel[0] * fade;
pixel[1] = 0.5 + pixel[1] * fade; pixel[1] = 0.5 + pixel[1] * fade;
pixel[2] = 0.5 + pixel[2] * fade; pixel[2] = 0.5 + pixel[2] * fade;
@ -312,13 +325,14 @@ shell_app_create_faded_icon_cpu (StTextureCache *cache,
* shell_app_get_faded_icon: * shell_app_get_faded_icon:
* @app: A #ShellApp * @app: A #ShellApp
* @size: Size in pixels * @size: Size in pixels
* @direction: Whether to fade on the left or right
* *
* Return an actor with a horizontally faded look. * Return an actor with a horizontally faded look.
* *
* Return value: (transfer none): A floating #ClutterActor, or %NULL if no icon * Return value: (transfer none): A floating #ClutterActor, or %NULL if no icon
*/ */
ClutterActor * ClutterActor *
shell_app_get_faded_icon (ShellApp *app, int size) shell_app_get_faded_icon (ShellApp *app, int size, ClutterTextDirection direction)
{ {
CoglHandle texture; CoglHandle texture;
ClutterActor *result; ClutterActor *result;
@ -334,9 +348,13 @@ shell_app_get_faded_icon (ShellApp *app, int size)
/* Use icon: prefix so that we get evicted from the cache on /* Use icon: prefix so that we get evicted from the cache on
* icon theme changes. */ * icon theme changes. */
cache_key = g_strdup_printf ("icon:%s,size=%d,faded", shell_app_get_id (app), size); cache_key = g_strdup_printf ("icon:%s,size=%d,faded-%s",
shell_app_get_id (app),
size,
direction == CLUTTER_TEXT_DIRECTION_RTL ? "rtl" : "ltr");
data.app = app; data.app = app;
data.size = size; data.size = size;
data.direction = direction;
texture = st_texture_cache_load (st_texture_cache_get_default (), texture = st_texture_cache_load (st_texture_cache_get_default (),
cache_key, cache_key,
ST_TEXTURE_CACHE_POLICY_FOREVER, ST_TEXTURE_CACHE_POLICY_FOREVER,

View File

@ -42,7 +42,7 @@ GMenuTreeEntry *shell_app_get_tree_entry (ShellApp *app);
GDesktopAppInfo *shell_app_get_app_info (ShellApp *app); GDesktopAppInfo *shell_app_get_app_info (ShellApp *app);
ClutterActor *shell_app_create_icon_texture (ShellApp *app, int size); ClutterActor *shell_app_create_icon_texture (ShellApp *app, int size);
ClutterActor *shell_app_get_faded_icon (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_name (ShellApp *app);
const char *shell_app_get_description (ShellApp *app); const char *shell_app_get_description (ShellApp *app);
gboolean shell_app_is_window_backed (ShellApp *app); gboolean shell_app_is_window_backed (ShellApp *app);