]> Eric's Git Repo - ericdock.git/commitdiff
Updated icon rendering and grouping behavior
authorEric Wertz <ericdwertz@gmail.com>
Thu, 16 Feb 2017 15:50:50 +0000 (10:50 -0500)
committerEric Wertz <ericdwertz@gmail.com>
Thu, 16 Feb 2017 15:50:50 +0000 (10:50 -0500)
clock.c
dock_icon.c
dock_icon.h
eric_window.c
main.c
pager_item.c
tooltip_window.c

diff --git a/clock.c b/clock.c
index 33e61e98abbf3c76651fdab21337585cc69a63c9..94fae5f662e9ea7c622c9e942b027aaac619f2f8 100644 (file)
--- 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) 
index 7099e8426ef3821c412b7ed9df8e276b54134a81..07076e2955d5a33aeece9a53003a899aaa722531 100644 (file)
@@ -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 <stdio.h>
+#include <ctype.h>
+#include <glib.h>
+
+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;
+}
+
index d0a9fc913109bda6a952dfc17c0fc62004667d5b..59a92f620bc43b9762c4e1bcc8fd6d8c7297b1e4 100644 (file)
@@ -6,6 +6,7 @@
  * renders/handles events based on how many pager_items it contains
  */
 #include <gtk/gtk.h>
+#include <gdk/gdk.h>
 #include <X11/Xlib.h>
 #include <time.h>
 
@@ -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);
index 246307d2947d09daeb57942a8e15e12039c17679..1e76486d648121567fffa85391fa744ab3afbbfe 100644 (file)
@@ -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 2af30f04e69e513d51ad2f174b86c94501205a97..29ad61c4047f6aaad4fa0c6d4ebf6e30e27af115 100644 (file)
--- 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 )
index 5cd586628d6108494f280957e8378ef7a38c7271..4c9886fdbe1f125579620b47add45b585b202362 100644 (file)
@@ -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 );
index c89acd7ba2e141b36a7ed360113da82a5d9fb25d..dbc8f8bb051c8e8a0ed63dcbd98c3f54d977c7bc 100644 (file)
@@ -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 );