Skip to content

Commit

Permalink
Merge pull request #20 from UbuntuBudgie/panelsize
Browse files Browse the repository at this point in the history
Look to change the iconsize when the panel changes.  This allows to reduce the panel size to around 30px comfortably
  • Loading branch information
fossfreedom authored Jun 4, 2019
2 parents df16457 + 5c392e3 commit 786f2d1
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
75 changes: 67 additions & 8 deletions src/applet-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,52 @@ 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"
#define MENU_DATA_INDICATOR_ENTRY "indicator-entry"

#define IO_DATA_ORDER_NUMBER "indicator-order-number"

void calc_default_icon_size() {
int small_panel_size = 37;
current_icon_size = 22; //appindicator spec size

if (panel_size < small_panel_size ) {
current_icon_size = current_icon_size + (panel_size - current_icon_size - 15);

if (current_icon_size < 16) current_icon_size = 16;
}
}
static gboolean
entry_resized (AppIndicatorApplet *applet, int panel_size, int icon_size, int small_icon_size, gpointer data)
{
IndicatorObject *io = (IndicatorObject *)data;

calc_default_icon_size();

/* Work on the entries */
if (io == NULL) return FALSE;
GList * entries = indicator_object_get_entries(io);
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 */
gtk_image_set_pixel_size (entrydata->image, current_icon_size);
}
}

return FALSE;
}

static void update_accessible_desc(IndicatorObjectEntry *entry, GtkWidget *menuitem);

/*************
Expand Down Expand Up @@ -297,7 +336,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");
Expand Down Expand Up @@ -558,7 +597,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);
Expand Down Expand Up @@ -597,12 +639,18 @@ 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),
G_OBJECT(io));

/* Work on the entries */
GList *entries = indicator_object_get_entries(io);
GList *entry = NULL;

for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
IndicatorObjectEntry *entrydata = (IndicatorObjectEntry *)entry->data;

entry_added(io, entrydata, menubar);
}

Expand All @@ -611,7 +659,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;
Expand Down Expand Up @@ -645,7 +693,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);
Expand All @@ -659,7 +707,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);
Expand All @@ -675,12 +723,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);
Expand All @@ -698,7 +757,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++;
}
}
Expand Down
26 changes: 20 additions & 6 deletions src/applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
#include <libayatana-ido/libayatana-ido.h>
#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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 786f2d1

Please sign in to comment.