Skip to content

Commit

Permalink
panel: Support window changes in IconTasklist
Browse files Browse the repository at this point in the history
We now update either the icon or tooltip should one of those happen
to change for the WnckWindow.
  • Loading branch information
ikeydoherty committed Feb 17, 2014
1 parent 5d66262 commit e9f31ce
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions panel/icon-tasklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ static void active_changed(WnckScreen *screen,
WnckWindow *prev_window,
gpointer userdata);

static void update_window_icon(GtkImage *image,
WnckWindow *window);

static void window_update_icon(WnckWindow *window,
gpointer userdata);
static void window_update_title(WnckWindow *window,
gpointer userdata);

/* Initialisation */
static void icon_tasklist_class_init(IconTasklistClass *klass)
{
Expand Down Expand Up @@ -160,26 +168,16 @@ static void window_opened(WnckScreen *screen,
{
GtkWidget *button = NULL;
GtkWidget *image = NULL;
GdkPixbuf *pixbuf = NULL;
__attribute__ ((unused)) GdkPixbuf *scaled = NULL;
const gchar *title;
const gchar *icon;
IconTasklist *self = ICON_TASKLIST(userdata);

/* Don't add buttons for tasklist skipping apps */
if (wnck_window_is_skip_tasklist(window))
return;

title = wnck_window_get_name(window);
icon = wnck_window_get_icon_name(window);

/* Add the image as a primary component */
if (wnck_window_has_icon_name(window) && !g_str_equal(title, icon)) {
image = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON);
} else {
pixbuf = wnck_window_get_icon(window);
image = gtk_image_new_from_pixbuf(pixbuf);
}
image = gtk_image_new();
update_window_icon(GTK_IMAGE(image), window);

/* Force sizes */
gtk_image_set_pixel_size(GTK_IMAGE(image), -1);
Expand All @@ -199,6 +197,11 @@ static void window_opened(WnckScreen *screen,
/* Store a reference to this window for destroy ops, etc. */
g_object_set_data(G_OBJECT(button), "bwindow", window);

/* When the window changes, update the button
* Icon change is separate so we dont keep reloading images and wasting resources */
g_signal_connect(window, "name-changed", G_CALLBACK(window_update_title), button);
g_signal_connect(window, "icon-changed", G_CALLBACK(window_update_icon), button);

/* Override drawing of this button */
g_signal_connect(button, "draw", G_CALLBACK(button_draw), self);

Expand Down Expand Up @@ -263,3 +266,35 @@ static void active_changed(WnckScreen *screen,
bwindow == active);
}
}

static void update_window_icon(GtkImage *image,
WnckWindow *window)
{
GdkPixbuf *pixbuf;
const gchar *icon, *title;

icon = wnck_window_get_icon_name(window);
title = wnck_window_get_name(window);

if (wnck_window_has_icon_name(window) && !g_str_equal(title, icon)) {
gtk_image_set_from_icon_name(image, icon, GTK_ICON_SIZE_BUTTON);
} else {
pixbuf = wnck_window_get_icon(window);
gtk_image_set_from_pixbuf(image, pixbuf);
}
}

static void window_update_title(WnckWindow *window,
gpointer userdata)
{
gtk_widget_set_tooltip_text(GTK_WIDGET(userdata), wnck_window_get_name(window));
}

static void window_update_icon(WnckWindow *window,
gpointer userdata)
{
GtkImage *image;

image = GTK_IMAGE(gtk_bin_get_child(GTK_BIN(userdata)));
update_window_icon(image, window);
}

0 comments on commit e9f31ce

Please sign in to comment.