From: Eric Wertz Date: Mon, 20 Feb 2017 20:29:57 +0000 (-0500) Subject: Cleaned up pixbuf handling, still not perfect... made UI_SCALE set from org.gnome... X-Git-Url: https://ericdwertz.com/git/?a=commitdiff_plain;h=2599134c5c9a5167cac5c73928375a360b655c87;p=ericdock.git Cleaned up pixbuf handling, still not perfect... made UI_SCALE set from org.gnome.desktop.interface scaling-factor var --- diff --git a/dock_icon.c b/dock_icon.c index 07076e2..ab5bf70 100644 --- a/dock_icon.c +++ b/dock_icon.c @@ -7,7 +7,6 @@ #include "ericdock.h" #include "dock_icon.h" #include "tooltip_window.h" -#include "xutils.h" #include #include @@ -19,6 +18,7 @@ dock_icon* dock_icon_create( WnckWindow* window ) 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 ) ); + g_object_ref( icon->icon_pixbuf ); icon->pager_items = NULL; icon->icon_state = ICON_STATE_NORMAL; diff --git a/ericdock.h b/ericdock.h index 2ced79a..6aabd9c 100644 --- a/ericdock.h +++ b/ericdock.h @@ -10,7 +10,7 @@ #define ERIC_DOCK_TOOLTIP_SHADOW_RADIUS 16.0 #define ERIC_DOCK_TOOLTIP_WIDTH ERIC_DOCK_TOOLTIP_SHADOW_RADIUS + 320.0 #define ERIC_DOCK_TOOLTIP_ITEM_HEIGHT 24.0 -#define UI_SCALE 2.0 +#define UI_SCALE interface_scale #define SCALE_VALUE(x) (x)*UI_SCALE #define BAR_HEIGHT 48.0 @@ -23,4 +23,5 @@ extern GList* dock_icons; extern eric_window* dock_window; extern eric_window* tooltip_window; extern dock_icon* tooltip_window_icon; +extern double interface_scale; diff --git a/main.c b/main.c index 29ad61c..78a442a 100644 --- a/main.c +++ b/main.c @@ -21,11 +21,11 @@ eric_window* dock_window = NULL; #include "dock_icon.h" #include "tooltip_window.h" -#include "xutils.h" int screen_width; int screen_height; +double interface_scale; //Logic to add a window to the pager items. //If a matching class group already exists it will be added to that, otherwise create @@ -36,8 +36,7 @@ void add_window_to_pager( WnckWindow* window ) int found_class_group = 0; dock_icon *icon, *new_dock_icon; - WnckClassGroup* class = wnck_window_get_class_group( window ); - gchar* instance_name = wnck_window_get_class_instance_name( window ); + const 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; @@ -315,6 +314,9 @@ 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" ); @@ -377,9 +379,18 @@ void init_wnck() g_signal_connect( screen, "active-window-changed", G_CALLBACK( wnck_active_window_changed ), NULL ); } +void load_gsettings() +{ + GSettings* gsettings = g_settings_new ( "org.gnome.desktop.interface" ); + interface_scale = (double)g_settings_get_uint( gsettings, "scaling-factor" ); + if( interface_scale < 1.0 ) + interface_scale = 1.0; +} + int main( int argc, char* argv[] ) { gtk_init( &argc, &argv ); + load_gsettings(); setup_dock_window(); tooltip_window_create( dock_window->window ); diff --git a/pager_item.c b/pager_item.c index 4c9886f..83afcd3 100644 --- a/pager_item.c +++ b/pager_item.c @@ -19,7 +19,11 @@ void pager_item_name_changed( WnckWindow* window, pager_item* item ) void pager_item_icon_changed( WnckWindow* window, pager_item* item ) { + if( GDK_IS_PIXBUF( item->icon_pixbuf ) ) + g_object_unref( item->icon_pixbuf ); + item->icon_pixbuf = get_icon( window, (int)SCALE_VALUE( 16.0 ) ); + g_object_ref( item->icon_pixbuf ); } void pager_item_state_changed( WnckWindow* window, WnckWindowState changed_mask, WnckWindowState new_state, pager_item* item ) @@ -33,6 +37,7 @@ pager_item* pager_item_create( WnckWindow* window ) item->window = window; strcpy( item->name, wnck_window_get_name( item->window ) ); item->icon_pixbuf = get_icon( window, (int)SCALE_VALUE( 16.0 ) ); + g_object_ref( item->icon_pixbuf ); item->icon_state = ICON_STATE_NORMAL; g_signal_connect( G_OBJECT( window ), "name-changed", G_CALLBACK( pager_item_name_changed ), (gpointer)item );