Merge lp:~bratsche/indicator-sound/scale-size-fu into lp:indicator-sound/0.1
- scale-size-fu
- Merge into trunk
Proposed by
Cody Russell
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~bratsche/indicator-sound/scale-size-fu |
Merge into: | lp:indicator-sound/0.1 |
Diff against target: |
305 lines (+66/-56) 1 file modified
src/indicator-sound.c (+66/-56) |
To merge this branch: | bzr merge lp:~bratsche/indicator-sound/scale-size-fu |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Conor Curran (community) | Approve | ||
Review via email: mp+21195@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/indicator-sound.c' |
2 | --- src/indicator-sound.c 2010-03-11 11:50:40 +0000 |
3 | +++ src/indicator-sound.c 2010-03-11 23:01:22 +0000 |
4 | @@ -8,16 +8,16 @@ |
5 | Conor Curran <conor.curran@canonical.com> |
6 | Ted Gould <ted@canonical.com> |
7 | |
8 | -This program is free software: you can redistribute it and/or modify it |
9 | -under the terms of the GNU General Public License version 3, as published |
10 | +This program is free software: you can redistribute it and/or modify it |
11 | +under the terms of the GNU General Public License version 3, as published |
12 | by the Free Software Foundation. |
13 | |
14 | -This program is distributed in the hope that it will be useful, but |
15 | -WITHOUT ANY WARRANTY; without even the implied warranties of |
16 | -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
17 | +This program is distributed in the hope that it will be useful, but |
18 | +WITHOUT ANY WARRANTY; without even the implied warranties of |
19 | +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
20 | PURPOSE. See the GNU General Public License for more details. |
21 | |
22 | -You should have received a copy of the GNU General Public License along |
23 | +You should have received a copy of the GNU General Public License along |
24 | with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | */ |
26 | #include <math.h> |
27 | @@ -94,7 +94,7 @@ |
28 | static DBusGProxy *sound_dbus_proxy = NULL; |
29 | static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); |
30 | static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean value, gpointer userdata); |
31 | -static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); |
32 | +static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); |
33 | static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata); |
34 | static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata); |
35 | static void fetch_volume_percent_from_dbus(); |
36 | @@ -143,7 +143,7 @@ |
37 | io_class->get_label = get_label; |
38 | io_class->get_image = get_icon; |
39 | io_class->get_menu = get_menu; |
40 | - |
41 | + |
42 | design_team_size = gtk_icon_size_register("design-team-size", 22, 22); |
43 | |
44 | return; |
45 | @@ -205,15 +205,21 @@ |
46 | static GtkMenu * |
47 | get_menu (IndicatorObject * io) |
48 | { |
49 | - DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); |
50 | - DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); |
51 | + DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); |
52 | + DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); |
53 | dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); |
54 | |
55 | // register Key-press listening on the menu widget as the slider does not allow this. |
56 | - g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); |
57 | + g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); |
58 | return GTK_MENU(menu); |
59 | } |
60 | |
61 | +static void |
62 | +slider_parent_changed (GtkWidget *widget, |
63 | + gpointer user_data) |
64 | +{ |
65 | + gtk_widget_set_size_request (widget, 200, -1); |
66 | +} |
67 | |
68 | /** |
69 | new_slider_item: |
70 | @@ -221,39 +227,43 @@ |
71 | **/ |
72 | static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) |
73 | { |
74 | - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); |
75 | - g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); |
76 | - |
77 | + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); |
78 | + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); |
79 | + |
80 | volume_slider = ido_scale_menu_item_new_with_range ("Volume", initial_volume_percent, 0, 100, 0.5); |
81 | - g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL); |
82 | + g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL); |
83 | + |
84 | + g_signal_connect (volume_slider, |
85 | + "notify::parent", G_CALLBACK (slider_parent_changed), |
86 | + NULL); |
87 | |
88 | GtkMenuItem *menu_volume_slider = GTK_MENU_ITEM(volume_slider); |
89 | |
90 | - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent); |
91 | - |
92 | + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent); |
93 | + |
94 | // register slider changes listening on the range |
95 | - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); |
96 | + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); |
97 | |
98 | g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); |
99 | g_signal_connect(volume_slider, "slider-grabbed", G_CALLBACK(slider_grabbed), NULL); |
100 | - g_signal_connect(volume_slider, "slider-released", G_CALLBACK(slider_released), NULL); |
101 | + g_signal_connect(volume_slider, "slider-released", G_CALLBACK(slider_released), NULL); |
102 | /* g_signal_connect(slider, "size-allocate", G_CALLBACK(slider_size_allocate), NULL);*/ |
103 | |
104 | // Set images on the ido |
105 | - GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); |
106 | - GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO))); |
107 | + GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); |
108 | + GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO))); |
109 | gtk_image_set_from_gicon(GTK_IMAGE(primary_image), primary_gicon, GTK_ICON_SIZE_MENU); |
110 | - g_object_unref(primary_gicon); |
111 | + g_object_unref(primary_gicon); |
112 | |
113 | - GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); |
114 | - GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH))); |
115 | + GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); |
116 | + GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH))); |
117 | gtk_image_set_from_gicon(GTK_IMAGE(secondary_image), secondary_gicon, GTK_ICON_SIZE_MENU); |
118 | - g_object_unref(secondary_gicon); |
119 | + g_object_unref(secondary_gicon); |
120 | |
121 | gtk_widget_set_sensitive(volume_slider, !initial_mute); |
122 | gtk_widget_show_all(volume_slider); |
123 | |
124 | - return TRUE; |
125 | + return TRUE; |
126 | } |
127 | |
128 | static void |
129 | @@ -328,8 +338,8 @@ |
130 | |
131 | gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); |
132 | gchar* muted_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED)); |
133 | - GtkIconTheme* theme = gtk_icon_theme_get_default(); |
134 | - GdkPixbuf* mute_buf = gtk_icon_theme_load_icon(theme, |
135 | + GtkIconTheme* theme = gtk_icon_theme_get_default(); |
136 | + GdkPixbuf* mute_buf = gtk_icon_theme_load_icon(theme, |
137 | muted_name, |
138 | 22, |
139 | GTK_ICON_LOOKUP_GENERIC_FALLBACK, |
140 | @@ -338,7 +348,7 @@ |
141 | g_error("indicator-sound : prepare_blocked_animation - %s", error->message); |
142 | g_error_free(error); |
143 | return; |
144 | - } |
145 | + } |
146 | |
147 | GdkPixbuf* blocked_buf = gtk_icon_theme_load_icon(theme, blocked_name, |
148 | 22, |
149 | @@ -348,17 +358,17 @@ |
150 | g_error("indicator-sound : prepare_blocked_animation - %s", error->message); |
151 | g_error_free(error); |
152 | return; |
153 | - } |
154 | + } |
155 | // sample 22 snapshots - range : 0-256 |
156 | for(i = 0; i < 23; i++) |
157 | - { |
158 | + { |
159 | gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0, |
160 | gdk_pixbuf_get_width(mute_buf), |
161 | - gdk_pixbuf_get_height(mute_buf), |
162 | + gdk_pixbuf_get_height(mute_buf), |
163 | 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 11)); |
164 | g_debug("creating blocking animation - alpha value = %i", MIN(255, i * 11)); |
165 | blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); |
166 | - } |
167 | + } |
168 | } |
169 | |
170 | |
171 | @@ -416,15 +426,15 @@ |
172 | } |
173 | else if(volume_percent == 0.0){ |
174 | state = STATE_ZERO; |
175 | - } |
176 | - update_state(state); |
177 | + } |
178 | + update_state(state); |
179 | } |
180 | - |
181 | + |
182 | |
183 | static void fetch_sink_availability_from_dbus() |
184 | { |
185 | GError * error = NULL; |
186 | - gboolean * available_input; |
187 | + gboolean * available_input; |
188 | available_input = g_new0(gboolean, 1); |
189 | org_ayatana_indicator_sound_get_sink_availability(sound_dbus_proxy, available_input, &error); |
190 | if (error != NULL) { |
191 | @@ -444,7 +454,7 @@ |
192 | static void fetch_volume_percent_from_dbus() |
193 | { |
194 | GError * error = NULL; |
195 | - gdouble *volume_percent_input; |
196 | + gdouble *volume_percent_input; |
197 | volume_percent_input = g_new0(gdouble, 1); |
198 | org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error); |
199 | if (error != NULL) { |
200 | @@ -462,7 +472,7 @@ |
201 | static void fetch_mute_value_from_dbus() |
202 | { |
203 | GError * error = NULL; |
204 | - gboolean *mute_input; |
205 | + gboolean *mute_input; |
206 | mute_input = g_new0(gboolean, 1); |
207 | org_ayatana_indicator_sound_get_sink_mute(sound_dbus_proxy, mute_input, &error); |
208 | if (error != NULL) { |
209 | @@ -490,16 +500,16 @@ |
210 | |
211 | blocked_iter = blocked_animation_list; |
212 | animation_id = g_timeout_add_seconds(1, fade_back_to_mute_image, NULL); |
213 | - } |
214 | + } |
215 | } |
216 | - |
217 | + |
218 | static gboolean fade_back_to_mute_image() |
219 | { |
220 | if(blocked_iter != NULL) |
221 | { |
222 | g_debug("in animation 'loop'\n"); |
223 | gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); |
224 | - blocked_iter = blocked_iter->next; |
225 | + blocked_iter = blocked_iter->next; |
226 | return TRUE; |
227 | } |
228 | else{ |
229 | @@ -513,12 +523,12 @@ |
230 | { |
231 | if (slider_in_direct_use != TRUE){ |
232 | GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); |
233 | - GtkRange *range = (GtkRange*)slider; |
234 | - |
235 | + GtkRange *range = (GtkRange*)slider; |
236 | + |
237 | // DEBUG |
238 | gdouble current_value = gtk_range_get_value(range); |
239 | g_debug("SIGNAL- update sink volume - current_value : %f and new value : %f", current_value, volume_percent); |
240 | - gtk_range_set_value(range, volume_percent); |
241 | + gtk_range_set_value(range, volume_percent); |
242 | determine_state_from_volume(volume_percent); |
243 | } |
244 | } |
245 | @@ -558,13 +568,13 @@ |
246 | **/ |
247 | static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data) |
248 | { |
249 | - gdouble current_value = CLAMP(gtk_range_get_value(range), 0, 100); |
250 | + gdouble current_value = CLAMP(gtk_range_get_value(range), 0, 100); |
251 | DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; |
252 | GValue value = {0}; |
253 | g_value_init(&value, G_TYPE_DOUBLE); |
254 | g_value_set_double(&value, current_value); |
255 | g_debug("Value changed callback - = %f", current_value); |
256 | - dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); |
257 | + dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); |
258 | // This is not ideal in that the icon ui will update on ui actions and not on actual service feedback. |
259 | // but necessary for now as the server does not send volume update information if the source of change was this ui. |
260 | determine_state_from_volume(current_value); |
261 | @@ -608,8 +618,8 @@ |
262 | gboolean digested = FALSE; |
263 | |
264 | GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); |
265 | - GtkRange* range = (GtkRange*)slider; |
266 | - gdouble current_value = gtk_range_get_value(range); |
267 | + GtkRange* range = (GtkRange*)slider; |
268 | + gdouble current_value = gtk_range_get_value(range); |
269 | gdouble new_value = current_value; |
270 | const gdouble five_percent = 5; |
271 | GtkWidget *menuitem; |
272 | @@ -638,26 +648,26 @@ |
273 | } |
274 | else |
275 | { |
276 | - new_value = current_value - five_percent; |
277 | + new_value = current_value - five_percent; |
278 | } |
279 | break; |
280 | case GDK_plus: |
281 | digested = TRUE; |
282 | - new_value = current_value + five_percent; |
283 | + new_value = current_value + five_percent; |
284 | break; |
285 | case GDK_minus: |
286 | digested = TRUE; |
287 | - new_value = current_value - five_percent; |
288 | + new_value = current_value - five_percent; |
289 | break; |
290 | default: |
291 | break; |
292 | - } |
293 | - |
294 | + } |
295 | + |
296 | new_value = CLAMP(new_value, 0, 100); |
297 | if(new_value != current_value && current_state != STATE_MUTED) |
298 | { |
299 | - g_debug("Attempting to set the range from the key listener to %f", new_value); |
300 | - gtk_range_set_value(range, new_value); |
301 | + g_debug("Attempting to set the range from the key listener to %f", new_value); |
302 | + gtk_range_set_value(range, new_value); |
303 | } |
304 | } |
305 | return digested; |
looks good thx Cody