From 38e0b14b3896a6bc62ea509fd94d078325596fae Mon Sep 17 00:00:00 2001 From: Eric Wertz Date: Thu, 16 Feb 2017 10:50:50 -0500 Subject: [PATCH] Updated icon rendering and grouping behavior --- clock.c | 3 +- dock_icon.c | 110 +++++++++++++++++++++++++++++++++++++++++++++-- dock_icon.h | 6 ++- eric_window.c | 2 + main.c | 6 ++- pager_item.c | 5 ++- tooltip_window.c | 17 +++----- 7 files changed, 128 insertions(+), 21 deletions(-) diff --git a/clock.c b/clock.c index 33e61e9..94fae5f 100644 --- a/clock.c +++ b/clock.c @@ -48,7 +48,7 @@ gboolean clock_refresh(gpointer data) struct tm * timeinfo; timeinfo = localtime ( &rawtime ); - if( timeinfo->tm_sec != oldsec ); + if( timeinfo->tm_sec != oldsec ) { gtk_widget_queue_draw( GTK_WIDGET( data ) ); } @@ -71,7 +71,6 @@ void clock_draw_timestring(cairo_t* cr, double x, double y, int blurpass) //tm_sec tm_min tm_hour int hour=timeinfo->tm_hour; int minute=timeinfo->tm_min; - int second=timeinfo->tm_sec; //hour+=minute/60; char ampm[3]="am"; if(hour>=12) diff --git a/dock_icon.c b/dock_icon.c index 7099e84..07076e2 100644 --- a/dock_icon.c +++ b/dock_icon.c @@ -7,15 +7,23 @@ #include "ericdock.h" #include "dock_icon.h" #include "tooltip_window.h" +#include "xutils.h" -dock_icon* dock_icon_create( WnckClassGroup* class_group ) +#include +#include +#include + +dock_icon* dock_icon_create( WnckWindow* window ) { dock_icon* icon = malloc( sizeof( dock_icon ) ); - icon->class_group = class_group; - icon->icon_pixbuf = wnck_class_group_get_icon( class_group ); + icon->class_group = wnck_window_get_class_group( window ); + icon->instance_name = wnck_window_get_class_instance_name( window ); + icon->icon_pixbuf = get_icon( window, (int)SCALE_VALUE( 32.0 ) ); icon->pager_items = NULL; icon->icon_state = ICON_STATE_NORMAL; + printf( "Attempted dock icon get%s \n", wnck_class_group_get_id( icon->class_group ) ); + icon->width = SCALE_VALUE( BAR_HEIGHT - 6.0 ); icon->height = SCALE_VALUE( BAR_HEIGHT ); @@ -109,3 +117,99 @@ void dock_icon_mouse_down( dock_icon* icon, double mx, double my, Time time ) dock_icon_activate( icon, time, TRUE ); } } + +gchar* get_icon_from_desktop( const char* name ) +{ + GKeyFile* key_file = g_key_file_new(); + gchar file[256]; + + sprintf( file, "/usr/share/applications/%s.desktop", name ); + if( !g_key_file_load_from_file( key_file, file, G_KEY_FILE_NONE, NULL ) ) + return NULL; + + return g_key_file_get_string( key_file, G_KEY_FILE_DESKTOP_GROUP, "Icon", NULL ); +} + +/* Gets the pixbuf from a desktop file's icon name. Based on the same function * from matchbox-desktop + */ +GdkPixbuf* get_icon( WnckWindow* window, guint size ) +{ + static GtkIconTheme* theme = NULL; + GdkPixbuf* pixbuf = 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; + + + if (theme == NULL) { + theme = gtk_icon_theme_get_default(); + } + + printf( "class: %s\ninstance%s\n", + class_name, + instance_name ); + int i; + for( i = 0; class_name[i] && i < 256; i++ ) + class_lower[i] = tolower( class_name[i] ); + for( i = 0; instance_name[i] && i < 256; i++ ) + instance_lower[i] = tolower( instance_name[i] ); + + //Use the window's icon + if( strcmp( class_lower, instance_lower ) != 0 ) + { + pixbuf = wnck_window_get_icon( window ); + } + + //Check for desktop file entry + if( pixbuf == NULL ) + { + 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 ); + } + + /* Always try and send back something */ + if (pixbuf == NULL) + pixbuf = wnck_window_get_icon( window ); + if (pixbuf == NULL) + pixbuf = gtk_icon_theme_load_icon(theme, "application-x-executable", + size, 0, NULL); + + width = gdk_pixbuf_get_width(pixbuf); + height = gdk_pixbuf_get_height(pixbuf); + + if (width != size || height != size) { + GdkPixbuf* temp = pixbuf; + pixbuf = gdk_pixbuf_scale_simple(temp, + size, + size, + GDK_INTERP_HYPER); + g_object_unref(temp); + } + + g_free(stripped); + + return pixbuf; +} + +/* From matchbox-desktop */ +char* strip_extension (const char *file) +{ + char *stripped, *p; + + stripped = g_strdup (file); + + p = strrchr (stripped, '.'); + if (p && + (!strcmp (p, ".png") || + !strcmp (p, ".svg") || + !strcmp (p, ".xpm"))) + *p = 0; + + return stripped; +} + diff --git a/dock_icon.h b/dock_icon.h index d0a9fc9..59a92f6 100644 --- a/dock_icon.h +++ b/dock_icon.h @@ -6,6 +6,7 @@ * renders/handles events based on how many pager_items it contains */ #include +#include #include #include @@ -24,10 +25,13 @@ typedef struct int icon_state; int is_active; int selected_index; + gchar* instance_name; } dock_icon; -dock_icon* dock_icon_create( WnckClassGroup* class_group ); +dock_icon* dock_icon_create( WnckWindow* window ); pager_item* dock_icon_get_next_pager_item( dock_icon* icon ); void dock_icon_clear_pager_item_state( dock_icon* icon ); void dock_icon_activate( dock_icon* icon, Time time, int from_click ); void dock_icon_mouse_down( dock_icon* icon, double mx, double my, Time time ); +GdkPixbuf* get_icon( WnckWindow* window, guint size ); +char * strip_extension (const char *file); diff --git a/eric_window.c b/eric_window.c index 246307d..1e76486 100644 --- a/eric_window.c +++ b/eric_window.c @@ -79,7 +79,9 @@ eric_window* eric_window_create( int width, int height, char* title ) w->draw_callback = NULL; if( title == NULL ) + { title = "eric window"; + } w->window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); gtk_window_set_title( GTK_WINDOW( w->window ), title ); diff --git a/main.c b/main.c index 2af30f0..29ad61c 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,7 @@ eric_window* dock_window = NULL; #include "dock_icon.h" #include "tooltip_window.h" +#include "xutils.h" int screen_width; int screen_height; @@ -36,10 +37,11 @@ void add_window_to_pager( WnckWindow* window ) dock_icon *icon, *new_dock_icon; WnckClassGroup* class = wnck_window_get_class_group( window ); + gchar* instance_name = wnck_window_get_class_instance_name( window ); for( icon_list = dock_icons; icon_list != NULL; icon_list = icon_list->next ) { icon = (dock_icon*)icon_list->data; - if( icon->class_group == class ) + if( strcmp( icon->instance_name, instance_name ) == 0 ) { icon->pager_items = g_list_append( icon->pager_items, pager_item_create( window ) ); found_class_group = 1; @@ -50,7 +52,7 @@ void add_window_to_pager( WnckWindow* window ) if( !found_class_group ) { //Add a new dock item - new_dock_icon = dock_icon_create( class ); + new_dock_icon = dock_icon_create( window ); new_dock_icon->pager_items = g_list_append( new_dock_icon->pager_items, pager_item_create( window ) diff --git a/pager_item.c b/pager_item.c index 5cd5866..4c9886f 100644 --- a/pager_item.c +++ b/pager_item.c @@ -10,6 +10,7 @@ #include "ericdock.h" #include "drawing.h" +#include "dock_icon.h" void pager_item_name_changed( WnckWindow* window, pager_item* item ) { @@ -18,7 +19,7 @@ void pager_item_name_changed( WnckWindow* window, pager_item* item ) void pager_item_icon_changed( WnckWindow* window, pager_item* item ) { - item->icon_pixbuf = wnck_window_get_mini_icon( window ); + item->icon_pixbuf = get_icon( window, (int)SCALE_VALUE( 16.0 ) ); } void pager_item_state_changed( WnckWindow* window, WnckWindowState changed_mask, WnckWindowState new_state, pager_item* item ) @@ -31,7 +32,7 @@ pager_item* pager_item_create( WnckWindow* window ) pager_item* item = malloc( sizeof( pager_item ) ); item->window = window; strcpy( item->name, wnck_window_get_name( item->window ) ); - item->icon_pixbuf = wnck_window_get_mini_icon( item->window ); + item->icon_pixbuf = get_icon( window, (int)SCALE_VALUE( 16.0 ) ); item->icon_state = ICON_STATE_NORMAL; g_signal_connect( G_OBJECT( window ), "name-changed", G_CALLBACK( pager_item_name_changed ), (gpointer)item ); diff --git a/tooltip_window.c b/tooltip_window.c index c89acd7..dbc8f8b 100644 --- a/tooltip_window.c +++ b/tooltip_window.c @@ -27,13 +27,11 @@ void tooltip_window_mouse_down( GtkWidget* widget, GdkEvent* event, gpointer use if( e->button != 1 ) return; - double mx, my; - double it, ib, il, ir; - dock_icon* icon; pager_item* item; GList* pager_list; - mx = e->x; my = e->y; + double my; + my = e->y; for( pager_list = tooltip_window_icon->pager_items; pager_list != NULL; pager_list = pager_list->next ) { item = pager_list->data; @@ -48,11 +46,9 @@ void tooltip_window_mouse_down( GtkWidget* widget, GdkEvent* event, gpointer use gboolean tooltip_window_mouse_move( GtkWidget* widget, GdkEvent* event, gpointer user ) { double mx, my; - double it, ib, il, ir; - int old_state, new_state, state_changed; - dock_icon* icon; + int state_changed; pager_item* item; - GList *icon_list, *item_list; + GList *item_list; GdkEventMotion* e = (GdkEventMotion*)event; mx = e->x; @@ -102,6 +98,8 @@ gboolean tooltip_window_draw( GtkWidget* widget, cairo_t* cr, eric_window* w ) } cairo_pattern_destroy( pattern ); + + return FALSE; } @@ -140,9 +138,6 @@ void tooltip_window_update_geometry() void tooltip_window_show() { - int wx, wy; - int w, h; - tooltip_window_update_geometry(); gtk_widget_show_all( tooltip_window->window ); gtk_widget_queue_draw( tooltip_window->window ); -- 2.47.0