From b4072486caaee681b9f742c814b60fc3169fd852 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Fri, 31 May 2019 16:49:05 +0100 Subject: [PATCH 1/2] Initial implementation to vary icon size depending on panel size changes --- README.md | 4 +-- src/applet-main.c | 88 ++++++++++++++++++++++++++++++++++++++++++----- src/applet.c | 26 ++++++++++---- 3 files changed, 102 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a5cf546..e0b8b36 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,6 @@ Enhancements GTK_DEBUG=interactive budgie-panel --replace - Use the following to print out g_debug messages i.e. use "zzz" in the g_debug to show in the grep filter + Use the following to print out g_debug messages - G_MESSAGES_DEBUG=all budgie-panel --replace | grep "zzz" + G_MESSAGES_DEBUG=Indicator-Applet-DEBUG budgie-panel --replace diff --git a/src/applet-main.c b/src/applet-main.c index 7b2a7b7..3732e09 100644 --- a/src/applet-main.c +++ b/src/applet-main.c @@ -75,6 +75,11 @@ static gchar *indicator_order[] = { "libayatana-application.so", "libayatana-mes static gchar *blacklist_applets[] = { "nm-applet", 0 }; BudgiePanelPosition orient = BUDGIE_PANEL_POSITION_NONE; +static guint current_icon_size; +static guint panel_size; +static guint icon_size; +static guint small_icon_size; + GtkPackDirection packdirection = GTK_ORIENTATION_HORIZONTAL; #define MENU_DATA_INDICATOR_OBJECT "indicator-object" @@ -82,6 +87,52 @@ GtkPackDirection packdirection = GTK_ORIENTATION_HORIZONTAL; #define IO_DATA_ORDER_NUMBER "indicator-order-number" +#define PANEL_PADDING 6 + +void calc_default_icon_size() { + current_icon_size = icon_size - 10; + + if ((panel_size - PANEL_PADDING) <= icon_size) { + current_icon_size = small_icon_size - 10; + } + + if (current_icon_size <= 0) { + current_icon_size = 22; //appindicator spec size + return; + } +} +static gboolean +entry_resized (AppIndicatorApplet *applet, gpointer data) +{ + //IndicatorObject *io = + // INDICATOR_OBJECT(g_object_get_data(G_OBJECT(data), MENU_DATA_INDICATOR_OBJECT)); + //g_assert(io != NULL); + IndicatorObject *io = (IndicatorObject *)data; + + calc_default_icon_size(); + + g_debug("icon size %d", current_icon_size); + /* Work on the entries */ + g_debug("get entries before"); + if (io == NULL) return FALSE; + GList * entries = indicator_object_get_entries(io); + g_debug("get entries after"); + if (entries == NULL) return FALSE; + GList * entry = NULL; + + for (entry = entries; entry != NULL; entry = g_list_next(entry)) { + IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data; + if (entrydata->image != NULL) { + /* Resize to fit panel */ + g_debug("before set"); + gtk_image_set_pixel_size (entrydata->image, current_icon_size); + g_debug("after set"); + } + } + + return FALSE; +} + static void update_accessible_desc(IndicatorObjectEntry *entry, GtkWidget *menuitem); /************* @@ -297,7 +348,7 @@ static void entry_added(IndicatorObject *io, IndicatorObjectEntry *entry, GtkWid if (entry->image != NULL) { g_debug("zzz have an image"); - gtk_image_set_pixel_size(entry->image, 22); + gtk_image_set_pixel_size(entry->image, current_icon_size); gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(entry->image), FALSE, FALSE, 1); if (gtk_widget_get_visible(GTK_WIDGET(entry->image))) { g_debug("zzz and is visible"); @@ -558,7 +609,10 @@ static void update_accessible_desc(IndicatorObjectEntry *entry, GtkWidget *menui return; } -static void load_indicator(GtkWidget *menubar, IndicatorObject *io, const gchar *name) +static void load_indicator(AppIndicatorApplet *applet, + GtkWidget *menubar, + IndicatorObject *io, + const gchar *name) { /* Set the environment it's in */ indicator_object_set_environment(io, (const GStrv)indicator_env); @@ -597,6 +651,13 @@ static void load_indicator(GtkWidget *menubar, IndicatorObject *io, const gchar G_CALLBACK(accessible_desc_update), menubar); + //g_signal_connect(G_OBJECT(applet), + // "panel-size-changed", + // G_CALLBACK(entry_resized), + // io); + + g_signal_connect_object(G_OBJECT(applet), "panel-size-changed", G_CALLBACK(entry_resized), G_OBJECT(io), 0); + /* Work on the entries */ GList *entries = indicator_object_get_entries(io); GList *entry = NULL; @@ -611,7 +672,7 @@ static void load_indicator(GtkWidget *menubar, IndicatorObject *io, const gchar #if HAVE_AYATANA_INDICATOR_NG || HAVE_UBUNTU_INDICATOR_NG void -load_indicators_from_indicator_files (GtkWidget *menubar, gint *indicators_loaded) +load_indicators_from_indicator_files (AppIndicatorApplet *applet, GtkWidget *menubar, gint *indicators_loaded) { GDir *dir; const gchar *name; @@ -645,7 +706,7 @@ load_indicators_from_indicator_files (GtkWidget *menubar, gint *indicators_loade continue; } if (indicator) { - load_indicator(menubar, INDICATOR_OBJECT (indicator), name); + load_indicator(applet, menubar, INDICATOR_OBJECT (indicator), name); count++; }else{ g_warning ("unable to load '%s': %s", name, error->message); @@ -659,7 +720,7 @@ load_indicators_from_indicator_files (GtkWidget *menubar, gint *indicators_loade } #endif /* HAVE_AYATANA_INDICATOR_NG || HAVE_UBUNTU_INDICATOR_NG */ -static gboolean load_module(const gchar *name, GtkWidget *menubar) +static gboolean load_module(const gchar *name, AppIndicatorApplet *applet, GtkWidget *menubar) { g_debug("Looking at Module: %s", name); g_return_val_if_fail(name != NULL, FALSE); @@ -675,12 +736,23 @@ static gboolean load_module(const gchar *name, GtkWidget *menubar) IndicatorObject *io = indicator_object_new_from_file(fullpath); g_free(fullpath); - load_indicator(menubar, io, name); + load_indicator(applet, menubar, io, name); return TRUE; } -void load_modules(GtkWidget *menubar, gint *indicators_loaded) +void update_panel_size(AppIndicatorApplet *applet, int u_panel_size, int u_icon_size, int u_small_icon_size){ + g_debug("Panel size %d", u_panel_size); + g_debug("icon size %d", u_icon_size); + g_debug("small size %d", u_small_icon_size); + panel_size = u_panel_size; + icon_size = u_icon_size; + small_icon_size = u_small_icon_size; + + calc_default_icon_size(); +} + +void load_modules(AppIndicatorApplet *applet, GtkWidget *menubar, gint *indicators_loaded) { if (g_file_test(INDICATOR_DIR, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) { GDir *dir = g_dir_open(INDICATOR_DIR, 0, NULL); @@ -698,7 +770,7 @@ void load_modules(GtkWidget *menubar, gint *indicators_loaded) continue; } g_debug("zzz a: %s", name); - if (load_module(name, menubar)) { + if (load_module(name, applet, menubar)) { count++; } } diff --git a/src/applet.c b/src/applet.c index 74d3810..5e7a7e3 100644 --- a/src/applet.c +++ b/src/applet.c @@ -31,8 +31,9 @@ #include #endif -void load_modules(GtkWidget *menubar, gint *indicators_loaded); -void load_indicators_from_indicator_files(GtkWidget *menubar, gint *indicators_loaded); +void load_modules(AppIndicatorApplet *applet, GtkWidget *menubar, gint *indicators_loaded); +void load_indicators_from_indicator_files(AppIndicatorApplet *applet, GtkWidget *menubar, gint *indicators_loaded); +void update_panel_size(AppIndicatorApplet *applet, int panel_size, int icon_size, int small_icon_size); #define MENU_DATA_INDICATOR_OBJECT "indicator-object" #define MENU_DATA_INDICATOR_ENTRY "indicator-entry" @@ -113,6 +114,16 @@ static void native_applet_real_panel_position_changed(BudgieApplet *base, } } +static void native_applet_real_panel_size_changed(BudgieApplet *base, + int panel_size, + int icon_size, + int small_icon_size) +{ + AppIndicatorApplet *self; + self = (AppIndicatorApplet *)base; + update_panel_size(self, panel_size, icon_size, small_icon_size); +} + G_DEFINE_DYNAMIC_TYPE_EXTENDED(AppIndicatorApplet, appindicator_applet, BUDGIE_TYPE_APPLET, 0, ) extern GtkCssProvider *css_provider; @@ -142,6 +153,9 @@ static void appindicator_applet_class_init(AppIndicatorAppletClass *klazz) ((BudgieAppletClass *)klazz)->panel_position_changed = (void (*)(BudgieApplet *, BudgiePanelPosition))native_applet_real_panel_position_changed; + ((BudgieAppletClass *)klazz)->panel_size_changed = + (void (*)(BudgieApplet *, + int, int, int))native_applet_real_panel_size_changed; } /** @@ -154,12 +168,12 @@ static void appindicator_applet_class_finalize(__budgie_unused__ AppIndicatorApp static GtkWidget *eventbox = NULL; static GtkWidget *menubar = NULL; -static gboolean delay_load_indicators(gpointer data) +static gboolean delay_load_indicators(AppIndicatorApplet *applet) { gint indicators_loaded = 0; gtk_menu_bar_set_pack_direction(GTK_MENU_BAR(menubar), packdirection); - load_modules(menubar, &indicators_loaded); + load_modules(applet, menubar, &indicators_loaded); if (indicators_loaded == 0) { /* A label to allow for click through */ @@ -243,13 +257,13 @@ static void appindicator_applet_init(AppIndicatorApplet *self) gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), INDICATOR_ICONS_DIR); #if HAVE_AYATANA_INDICATOR_NG || HAVE_UBUNTU_INDICATOR_NG - load_indicators_from_indicator_files (menubar, &indicators_loaded); + load_indicators_from_indicator_files (self, menubar, &indicators_loaded); #endif /* Show all of our things. */ gtk_widget_show_all(GTK_WIDGET(self)); - g_timeout_add_seconds(1, delay_load_indicators, NULL); + g_timeout_add_seconds(1, delay_load_indicators, self); } void appindicator_applet_init_gtype(GTypeModule *module) From 5c392e36fa1c6e42635aa35f9737dfb2ed94759d Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Mon, 3 Jun 2019 16:39:54 +0100 Subject: [PATCH 2/2] Reduce icon size gradually with panel size changes --- src/applet-main.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/applet-main.c b/src/applet-main.c index 3732e09..5b72637 100644 --- a/src/applet-main.c +++ b/src/applet-main.c @@ -87,36 +87,26 @@ GtkPackDirection packdirection = GTK_ORIENTATION_HORIZONTAL; #define IO_DATA_ORDER_NUMBER "indicator-order-number" -#define PANEL_PADDING 6 - void calc_default_icon_size() { - current_icon_size = icon_size - 10; + int small_panel_size = 37; + current_icon_size = 22; //appindicator spec size - if ((panel_size - PANEL_PADDING) <= icon_size) { - current_icon_size = small_icon_size - 10; - } + if (panel_size < small_panel_size ) { + current_icon_size = current_icon_size + (panel_size - current_icon_size - 15); - if (current_icon_size <= 0) { - current_icon_size = 22; //appindicator spec size - return; + if (current_icon_size < 16) current_icon_size = 16; } } static gboolean -entry_resized (AppIndicatorApplet *applet, gpointer data) +entry_resized (AppIndicatorApplet *applet, int panel_size, int icon_size, int small_icon_size, gpointer data) { - //IndicatorObject *io = - // INDICATOR_OBJECT(g_object_get_data(G_OBJECT(data), MENU_DATA_INDICATOR_OBJECT)); - //g_assert(io != NULL); IndicatorObject *io = (IndicatorObject *)data; calc_default_icon_size(); - g_debug("icon size %d", current_icon_size); /* Work on the entries */ - g_debug("get entries before"); if (io == NULL) return FALSE; GList * entries = indicator_object_get_entries(io); - g_debug("get entries after"); if (entries == NULL) return FALSE; GList * entry = NULL; @@ -124,9 +114,7 @@ entry_resized (AppIndicatorApplet *applet, gpointer data) IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data; if (entrydata->image != NULL) { /* Resize to fit panel */ - g_debug("before set"); gtk_image_set_pixel_size (entrydata->image, current_icon_size); - g_debug("after set"); } } @@ -651,12 +639,10 @@ static void load_indicator(AppIndicatorApplet *applet, G_CALLBACK(accessible_desc_update), menubar); - //g_signal_connect(G_OBJECT(applet), - // "panel-size-changed", - // G_CALLBACK(entry_resized), - // io); - - g_signal_connect_object(G_OBJECT(applet), "panel-size-changed", G_CALLBACK(entry_resized), G_OBJECT(io), 0); + g_signal_connect(G_OBJECT(applet), + "panel-size-changed", + G_CALLBACK(entry_resized), + G_OBJECT(io)); /* Work on the entries */ GList *entries = indicator_object_get_entries(io); @@ -664,6 +650,7 @@ static void load_indicator(AppIndicatorApplet *applet, for (entry = entries; entry != NULL; entry = g_list_next(entry)) { IndicatorObjectEntry *entrydata = (IndicatorObjectEntry *)entry->data; + entry_added(io, entrydata, menubar); }