Fix blurry app icons when UI scale > 1
This commit is contained in:
@@ -47,6 +47,7 @@ static App * apps_lookup_pid (GArray *apps, GPid pid);
|
||||
static App * apps_lookup_app (GArray *apps, WnckApplication *application);
|
||||
static void application_opened (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
||||
static void application_closed (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
||||
static void scale_factor_changed (GdkMonitor *monitor);
|
||||
|
||||
|
||||
|
||||
@@ -63,12 +64,21 @@ xtm_app_manager_init (XtmAppManager *manager)
|
||||
{
|
||||
WnckApplication *application;
|
||||
WnckScreen *screen = wnck_screen_get_default ();
|
||||
GdkMonitor *monitor = gdk_display_get_monitor (gdk_display_get_default (), 0);
|
||||
GList *windows, *l;
|
||||
|
||||
/* Retrieve initial applications */
|
||||
while (gtk_events_pending ())
|
||||
gtk_main_iteration ();
|
||||
|
||||
/* Adapt wnck default icon size when UI scale changes (this is X11 only so
|
||||
* the scale factor is the same for all monitors) */
|
||||
if (monitor != NULL)
|
||||
{
|
||||
scale_factor_changed (monitor);
|
||||
g_signal_connect (monitor, "notify::scale-factor", G_CALLBACK (scale_factor_changed), NULL);
|
||||
}
|
||||
|
||||
manager->apps = g_array_new (FALSE, FALSE, sizeof (App));
|
||||
windows = wnck_screen_get_windows (screen);
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
@@ -123,6 +133,9 @@ static void
|
||||
apps_add_application (GArray *apps, WnckApplication *application, GPid pid)
|
||||
{
|
||||
App app;
|
||||
GdkMonitor *monitor;
|
||||
GdkPixbuf *pixbuf;
|
||||
gint scale_factor = 1;
|
||||
|
||||
if (apps_lookup_pid (apps, pid))
|
||||
return;
|
||||
@@ -130,8 +143,12 @@ apps_add_application (GArray *apps, WnckApplication *application, GPid pid)
|
||||
app.application = application;
|
||||
app.pid = pid;
|
||||
g_snprintf (app.name, sizeof(app.name), "%s", wnck_application_get_name (application));
|
||||
app.icon = wnck_application_get_mini_icon (application);
|
||||
g_object_ref (app.icon);
|
||||
|
||||
monitor = gdk_display_get_monitor (gdk_display_get_default (), 0);
|
||||
if (monitor != NULL)
|
||||
scale_factor = gdk_monitor_get_scale_factor (monitor);
|
||||
pixbuf = wnck_application_get_mini_icon (application);
|
||||
app.surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
|
||||
|
||||
g_array_append_val (apps, app);
|
||||
g_array_sort (apps, app_pid_compare_fn);
|
||||
@@ -146,7 +163,7 @@ apps_remove_application (GArray *apps, WnckApplication *application)
|
||||
app = apps_lookup_app(apps, application);
|
||||
if (app == NULL)
|
||||
return;
|
||||
g_object_unref (app->icon);
|
||||
cairo_surface_destroy (app->surface);
|
||||
g_array_remove_index (apps, (guint)(((size_t)app - (size_t)apps->data) / sizeof(App)));
|
||||
}
|
||||
|
||||
@@ -190,6 +207,12 @@ application_closed (WnckScreen *screen __unused, WnckApplication *application, X
|
||||
apps_remove_application (manager->apps, application);
|
||||
}
|
||||
|
||||
static void
|
||||
scale_factor_changed (GdkMonitor *monitor)
|
||||
{
|
||||
wnck_set_default_mini_icon_size (WNCK_DEFAULT_MINI_ICON_SIZE * gdk_monitor_get_scale_factor (monitor));
|
||||
}
|
||||
|
||||
|
||||
|
||||
XtmAppManager *
|
||||
|
||||
@@ -25,7 +25,7 @@ struct _App
|
||||
WnckApplication * application;
|
||||
GPid pid;
|
||||
gchar name[1024];
|
||||
GdkPixbuf * icon;
|
||||
cairo_surface_t * surface;
|
||||
};
|
||||
|
||||
#define XTM_TYPE_APP_MANAGER (xtm_app_manager_get_type ())
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <glib-object.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gprintf.h>
|
||||
#include <cairo-gobject.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include "process-tree-model.h"
|
||||
@@ -98,7 +99,7 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview)
|
||||
|
||||
/* Create tree view model */
|
||||
#ifdef HAVE_WNCK
|
||||
treeview->model = gtk_list_store_new (XTM_PTV_N_COLUMNS, GDK_TYPE_PIXBUF,
|
||||
treeview->model = gtk_list_store_new (XTM_PTV_N_COLUMNS, CAIRO_GOBJECT_TYPE_SURFACE,
|
||||
#else
|
||||
treeview->model = gtk_list_store_new (XTM_PTV_N_COLUMNS,
|
||||
#endif
|
||||
@@ -277,7 +278,7 @@ column_task_pack_cells (XtmProcessTreeView *treeview, GtkTreeViewColumn *column)
|
||||
#ifdef HAVE_WNCK
|
||||
GtkCellRenderer *cell_icon = gtk_cell_renderer_pixbuf_new ();
|
||||
gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), cell_icon, FALSE);
|
||||
gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), cell_icon, "pixbuf", XTM_PTV_COLUMN_ICON, "cell-background", XTM_PTV_COLUMN_BACKGROUND, NULL);
|
||||
gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), cell_icon, "surface", XTM_PTV_COLUMN_ICON, "cell-background", XTM_PTV_COLUMN_BACKGROUND, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest
|
||||
gchar *background, *foreground;
|
||||
#ifdef HAVE_WNCK
|
||||
App *app = manager->app_manager != NULL ? xtm_app_manager_get_app_from_pid (manager->app_manager, task->pid) : NULL;
|
||||
GdkPixbuf *icon = NULL;
|
||||
cairo_surface_t *surface = NULL;
|
||||
#endif
|
||||
|
||||
vsz = g_format_size_full (task->vsz, G_FORMAT_SIZE_IEC_UNITS);
|
||||
@@ -256,15 +256,15 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest
|
||||
gtk_tree_model_get (model, iter, XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp, XTM_PTV_COLUMN_STATE, &old_state,
|
||||
XTM_PTV_COLUMN_BACKGROUND, &background, XTM_PTV_COLUMN_FOREGROUND, &foreground,
|
||||
#ifdef HAVE_WNCK
|
||||
XTM_PTV_COLUMN_ICON, &icon,
|
||||
XTM_PTV_COLUMN_ICON, &surface,
|
||||
#endif
|
||||
-1);
|
||||
|
||||
#ifdef HAVE_WNCK
|
||||
if (icon != NULL)
|
||||
g_object_unref (icon);
|
||||
if (surface != NULL)
|
||||
cairo_surface_destroy (surface);
|
||||
else if (app != NULL)
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), iter, XTM_PTV_COLUMN_ICON, app->icon, -1);
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), iter, XTM_PTV_COLUMN_ICON, app->surface, -1);
|
||||
|
||||
if (app != NULL && full_cmdline == FALSE)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user