From 50a54689236cf4c26ad4b9abf3c002fafaedb86f Mon Sep 17 00:00:00 2001 From: Eric Wertz Date: Thu, 6 Jul 2017 10:02:26 -0400 Subject: [PATCH] Still trying to fix crashes, added shadows to dock icon squares --- dock_icon.c | 38 +++++++++++++++++++++++++++----------- main.c | 17 +++++++++++++---- pager_item.c | 6 +++--- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/dock_icon.c b/dock_icon.c index 5edc248..c56a71b 100644 --- a/dock_icon.c +++ b/dock_icon.c @@ -135,12 +135,14 @@ GdkPixbuf* get_icon( WnckWindow* window, guint size ) { static GtkIconTheme* theme = NULL; GdkPixbuf* pixbuf = NULL; + GdkPixbuf* copy = NULL; gchar* stripped = NULL; const gchar* class_name = wnck_window_get_class_group_name( window ); const gchar* instance_name = wnck_window_get_class_instance_name( window ); gchar instance_lower[256] = {0}; gchar class_lower[256] = {0}; gint width, height; + int unref = 0; if (theme == NULL) { @@ -162,6 +164,7 @@ GdkPixbuf* get_icon( WnckWindow* window, guint size ) if( strcmp( class_lower, instance_lower ) != 0 ) { pixbuf = wnck_window_get_icon( window ); + unref = 0; } } @@ -170,16 +173,25 @@ GdkPixbuf* get_icon( WnckWindow* window, guint size ) { gchar* icon_name = get_icon_from_desktop( instance_name ); if( icon_name != NULL ) + { pixbuf = gtk_icon_theme_load_icon( theme, icon_name, size, GTK_ICON_LOOKUP_FORCE_SIZE, NULL ); + unref = 1; + } } /* Always try and send back something */ if (pixbuf == NULL) + { pixbuf = wnck_window_get_icon( window ); + unref = 0; + } if (pixbuf == NULL) + { pixbuf = gtk_icon_theme_load_icon(theme, "application-x-executable", size, 0, NULL); + unref = 1; + } width = gdk_pixbuf_get_width(pixbuf); height = gdk_pixbuf_get_height(pixbuf); @@ -190,28 +202,32 @@ GdkPixbuf* get_icon( WnckWindow* window, guint size ) size, size, GDK_INTERP_HYPER); - g_object_unref(temp); + if( unref ) + g_object_unref(temp); } g_free(stripped); - return gdk_pixbuf_copy( pixbuf ); + copy = gdk_pixbuf_copy( pixbuf ); + if( unref ) + g_object_unref( pixbuf ); + return copy; } /* From matchbox-desktop */ char* strip_extension (const char *file) { - char *stripped, *p; + char *stripped, *p; - stripped = g_strdup (file); + stripped = g_strdup (file); - p = strrchr (stripped, '.'); - if (p && - (!strcmp (p, ".png") || - !strcmp (p, ".svg") || - !strcmp (p, ".xpm"))) - *p = 0; + p = strrchr (stripped, '.'); + if (p && + (!strcmp (p, ".png") || + !strcmp (p, ".svg") || + !strcmp (p, ".xpm"))) + *p = 0; - return stripped; + return stripped; } diff --git a/main.c b/main.c index f8b08f8..8c4009e 100644 --- a/main.c +++ b/main.c @@ -166,6 +166,7 @@ static gboolean draw_dock_window( GtkWidget* widget, cairo_t* cr, eric_window* w } if( !GDK_IS_PIXBUF( icon->icon_pixbuf ) ) { + printf( "Trying to draw without an icon\n" ); icon->icon_pixbuf = gdk_pixbuf_copy( wnck_class_group_get_icon( icon->class_group ) ); } gdk_cairo_set_source_pixbuf( cr, icon->icon_pixbuf, x+SCALE_VALUE( 4.0 ), y ); @@ -176,10 +177,21 @@ static gboolean draw_dock_window( GtkWidget* widget, cairo_t* cr, eric_window* w { //Draw rectangles width = (SCALE_VALUE(32.0) / pager_count ); - rx = x + SCALE_VALUE(4.0); ry = y + SCALE_VALUE(34.0); w->text_color.alpha = 0.5; + + //Shadow pass + cairo_set_source_rgba( cr, 1.0 - w->text_color.red, 1.0 - w->text_color.green, 1.0 - w->text_color.blue, w->text_color.alpha*0.5 ); + rx = x + SCALE_VALUE(4.0); + for( i = 0; i < pager_count; i++ ) + { + cairo_rectangle( cr, rx+SCALE_VALUE( 2.0 ), ry+SCALE_VALUE( 1.0 ), width-SCALE_VALUE( 2.0 ), SCALE_VALUE( 4.0 ) ); + rx += width; + } + cairo_fill( cr ); + gdk_cairo_set_source_rgba( cr, &w->text_color ); + rx = x + SCALE_VALUE(4.0); for( i = 0; i < pager_count; i++ ) { cairo_rectangle( cr, rx+SCALE_VALUE( 1.0 ), ry, width-SCALE_VALUE( 2.0 ), SCALE_VALUE( 4.0 ) ); @@ -330,9 +342,6 @@ static void wnck_window_closed( WnckScreen* screen, WnckWindow* window, gpointer item = (pager_item*)pager_list->data; if( item->window == window ) { - if( GDK_IS_PIXBUF( item->icon_pixbuf ) ) - g_object_unref( item->icon_pixbuf ); - icon->pager_items = g_list_remove( icon->pager_items, item ); free( item ); printf( "Removed pager item\n" ); diff --git a/pager_item.c b/pager_item.c index ac30af9..d213daa 100644 --- a/pager_item.c +++ b/pager_item.c @@ -19,9 +19,8 @@ void pager_item_name_changed( WnckWindow* window, pager_item* item ) void pager_item_icon_changed( WnckWindow* window, pager_item* item ) { - if( item->icon_pixbuf && GDK_IS_PIXBUF( item->icon_pixbuf ) ) + if( item->icon_pixbuf != NULL && !GDK_IS_PIXBUF( item->icon_pixbuf ) ) { - g_object_unref( item->icon_pixbuf ); item->icon_pixbuf = NULL; } @@ -32,6 +31,7 @@ void pager_item_icon_changed( WnckWindow* window, pager_item* item ) void pager_item_state_changed( WnckWindow* window, WnckWindowState changed_mask, WnckWindowState new_state, pager_item* item ) { + printf( "Item state changed %s\n", item->name ); //item->icon_pixbuf = wnck_window_get_mini_icon( window ); } @@ -81,7 +81,7 @@ int pager_item_mouse_move( pager_item* item, double mx, double my ) void pager_item_draw( pager_item* item, cairo_t* cr, eric_window* w, cairo_pattern_t* pattern ) { - if( item->icon_pixbuf && !GDK_IS_PIXBUF( item->icon_pixbuf ) ) + if( item->icon_pixbuf != NULL && !GDK_IS_PIXBUF( item->icon_pixbuf ) ) { item->icon_pixbuf = get_icon( item->window, (int)SCALE_VALUE( 16.0 ) ); if( !GDK_IS_PIXBUF( item->icon_pixbuf ) ) -- 2.47.0