From be63f4d7e0292237864aa6316f3c1057aaea3fa3 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Mon, 5 May 2014 12:50:30 +0200 Subject: [PATCH] Add an option to set notification width. --- glade/preferences-trayicon.ui | 57 ++++++++++++++++++++++++++++++++++++++++--- src/tray-icon2.c | 25 +++++++++++++------ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/glade/preferences-trayicon.ui b/glade/preferences-trayicon.ui index bb4ec1aa..84a9f447 100644 --- a/glade/preferences-trayicon.ui +++ b/glade/preferences-trayicon.ui @@ -9,6 +9,14 @@ 0 5 + + 9999 + 100 + 10 + 1 + 0 + 300 + @@ -123,10 +131,38 @@ - + + True + 0 + 0 + + + True + True + adjustment2 + 1 + True + True + True + GTK_UPDATE_IF_VALID + + + + + + 1 + 2 + 2 + 3 + GTK_SHRINK | GTK_FILL + GTK_FILL + + + + True 1 - Position: + Width: 2 @@ -136,6 +172,19 @@ + + True + 1 + Position: + + + 3 + 4 + GTK_FILL + + + + True @@ -150,8 +199,8 @@ 1 2 - 2 - 3 + 3 + 4 GTK_FILL GTK_FILL diff --git a/src/tray-icon2.c b/src/tray-icon2.c index 5db32e26..9eeb9a7e 100644 --- a/src/tray-icon2.c +++ b/src/tray-icon2.c @@ -72,6 +72,7 @@ enum */ static GtkBuilder *tray_icon2_preferences_xml = NULL; void popup_timeout_changed(void); +void popup_width_changed(void); void popup_position_changed(GtkComboBox * om); void popup_enable_toggled(GtkToggleButton * but); void tray_enable_toggled(GtkToggleButton * but); @@ -532,6 +533,7 @@ static void tray_icon2_create_tooltip_real(int position) int state = 0; int x_offset = cfg_get_single_value_as_int_with_default(config, TRAY_ICON2_ID, "x-offset", 0); int y_offset = cfg_get_single_value_as_int_with_default(config, TRAY_ICON2_ID, "y-offset", 0); + int tooltip_width = cfg_get_single_value_as_int_with_default(config, TRAY_ICON2_ID, "tooltip-width", 300); song = mpd_playlist_get_current_song(connection); /** @@ -585,7 +587,7 @@ static void tray_icon2_create_tooltip_real(int position) gtk_style_context_add_class(sc, GTK_STYLE_CLASS_TOOLTIP); /* causes the border */ gtk_container_set_border_width(GTK_CONTAINER(tray_icon2_tooltip), 1); - gtk_window_set_default_size(GTK_WINDOW(tray_icon2_tooltip), 300, -1); + gtk_window_set_default_size(GTK_WINDOW(tray_icon2_tooltip), tooltip_width, -1); gtk_window_set_transient_for(GTK_WINDOW(tray_icon2_tooltip), GTK_WINDOW(pl3_win)); /* @@ -761,7 +763,7 @@ static void tray_icon2_create_tooltip_real(int position) /** Set Y = window height - size; */ y = rect2.y + rect2.height - 50 - 95; /** X =window width - width */ - x = rect2.x + rect2.width - 5 - 300; + x = rect2.x + rect2.width - 5 - tooltip_width; gtk_window_move(GTK_WINDOW(tray_icon2_tooltip), x + x_offset, y + y_offset); } else @@ -782,15 +784,15 @@ static void tray_icon2_create_tooltip_real(int position) y = 0; /* Get X */ - x = rect.x - 300 / 2 - rect2.x + x_offset; - if ((x + 300) > rect2.width) + x = rect.x - tooltip_width / 2 - rect2.x + x_offset; + if ((x + tooltip_width) > rect2.width) { if (orientation == GTK_ORIENTATION_VERTICAL) { - x = rect2.width + -300 - rect.width - 5; + x = rect2.width + -tooltip_width - rect.width - 5; } else { - x = rect2.width - 300; + x = rect2.width - tooltip_width; } } if (x < 0) @@ -824,7 +826,7 @@ static void tray_icon2_create_tooltip_real(int position) /** Set Y = 0; */ y = rect2.y + 5; /** X is upper right - width */ - x = rect2.x + rect2.width - 5 - 300; + x = rect2.x + rect2.width - 5 - tooltip_width; gtk_window_move(GTK_WINDOW(tray_icon2_tooltip), x + x_offset, y + y_offset); } else if (position == TI2_AT_LOWER_LEFT) { @@ -848,7 +850,7 @@ static void tray_icon2_create_tooltip_real(int position) /** Set Y = window height - size; */ y = rect2.y + rect2.height - 5 - 95; /** X =window width - width */ - x = rect2.x + rect2.width - 5 - 300; + x = rect2.x + rect2.width - 5 - tooltip_width; gtk_window_move(GTK_WINDOW(tray_icon2_tooltip), x + x_offset, y + y_offset); } @@ -1087,6 +1089,13 @@ void popup_timeout_changed(void) (tray_icon2_preferences_xml, "popup_timeout")))); } +void popup_width_changed(void) +{ + cfg_set_single_value_as_int(config, TRAY_ICON2_ID, "tooltip-width", + gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON + (gtk_builder_get_object + (tray_icon2_preferences_xml, "popup_width")))); +} static void update_popup_settings(void) { -- 2.11.4.GIT