summaryrefslogtreecommitdiff
path: root/src/module/e_mod_main.c
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-05-08 19:27:57 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-05-08 19:27:57 -0300
commit7f199b977c77d149eb07d818bf5e513bed808505 (patch)
tree126dcddcc499c08b3354768a5264b2715f079c20 /src/module/e_mod_main.c
parentb5f515a035906e9af2e63abdc816af5920b1c4e8 (diff)
[module] Fixing desktop notifications
- Notifications is not per instance anymore - Showing notifications only on volume changes
Diffstat (limited to '')
-rw-r--r--src/module/e_mod_main.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/module/e_mod_main.c b/src/module/e_mod_main.c
index 6f2ad75..22a39a7 100644
--- a/src/module/e_mod_main.c
+++ b/src/module/e_mod_main.c
@@ -60,6 +60,7 @@ struct _Context
60 Eina_List *instances; 60 Eina_List *instances;
61 Eina_List *sinks; 61 Eina_List *sinks;
62 E_Menu *menu; 62 E_Menu *menu;
63 unsigned int notification_id;
63 64
64 struct { 65 struct {
65 E_Action *incr; 66 E_Action *incr;
@@ -81,20 +82,18 @@ struct _Instance
81 Evas_Object *check; 82 Evas_Object *check;
82 83
83 int mute; 84 int mute;
84 unsigned int notification_id;
85}; 85};
86 86
87static Context *mixer_context = NULL; 87static Context *mixer_context = NULL;
88 88
89static void 89static void
90_notify_cb(void *data, unsigned int id) 90_notify_cb(void *data EINA_UNUSED, unsigned int id)
91{ 91{
92 Instance *inst = data; 92 mixer_context->notification_id = id;
93 inst->notification_id = id;
94} 93}
95 94
96static void 95static void
97_notify(const int val, Instance *inst) 96_notify(const int val)
98{ 97{
99 E_Notification_Notify n; 98 E_Notification_Notify n;
100 char *icon, buf[56]; 99 char *icon, buf[56];
@@ -118,12 +117,12 @@ _notify(const int val, Instance *inst)
118 icon = "audio-volume-high"; 117 icon = "audio-volume-high";
119 118
120 n.app_name = _("EPulse"); 119 n.app_name = _("EPulse");
121 n.replaces_id = inst->notification_id; 120 n.replaces_id = mixer_context->notification_id;
122 n.icon.icon = icon; 121 n.icon.icon = icon;
123 n.sumary = _("Volume changed"); 122 n.sumary = _("Volume changed");
124 n.body = buf; 123 n.body = buf;
125 n.timeout = 2000; 124 n.timeout = 2000;
126 e_notification_client_send(&n, _notify_cb, inst); 125 e_notification_client_send(&n, _notify_cb, NULL);
127} 126}
128 127
129static void 128static void
@@ -155,8 +154,6 @@ _mixer_gadget_update(void)
155 if (inst->popup) 154 if (inst->popup)
156 _mixer_popup_update(inst, mixer_context->sink_default->mute, 155 _mixer_popup_update(inst, mixer_context->sink_default->mute,
157 msg->val[1]); 156 msg->val[1]);
158 else
159 _notify(mixer_context->sink_default->mute ? 0 : msg->val[1], inst);
160 } 157 }
161} 158}
162 159
@@ -164,29 +161,30 @@ static void
164_volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 161_volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
165{ 162{
166 Sink *s = mixer_context->sink_default; 163 Sink *s = mixer_context->sink_default;
167 pa_cvolume_inc(&(s->volume), VOLUME_STEP); 164 pa_cvolume v = s->volume;
165 pa_cvolume_inc(&v, VOLUME_STEP);
168 166
169 epulse_sink_volume_set(s->index, s->volume); 167 epulse_sink_volume_set(s->index, v);
170} 168}
171 169
172static void 170static void
173_volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 171_volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
174{ 172{
175 Sink *s = mixer_context->sink_default; 173 Sink *s = mixer_context->sink_default;
176 pa_cvolume_dec(&(s->volume), VOLUME_STEP); 174 pa_cvolume v = s->volume;
175 pa_cvolume_dec(&v, VOLUME_STEP);
177 176
178 epulse_sink_volume_set(s->index, s->volume); 177 epulse_sink_volume_set(s->index, v);
179} 178}
180 179
181static void 180static void
182_volume_mute_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED) 181_volume_mute_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
183{ 182{
184 Sink *s = mixer_context->sink_default; 183 Sink *s = mixer_context->sink_default;
185 s->mute = !s->mute; 184 int mute = !s->mute;
186 if (!epulse_sink_mute_set(s->index, s->mute)) 185 if (!epulse_sink_mute_set(s->index, mute))
187 { 186 {
188 WRN("Could not mute the sink: %d", s->index); 187 WRN("Could not mute the sink: %d", s->index);
189 s->mute = !s->mute;
190 return; 188 return;
191 } 189 }
192} 190}
@@ -593,15 +591,24 @@ _sink_changed_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
593 Epulse_Event *ev = info; 591 Epulse_Event *ev = info;
594 Eina_List *l; 592 Eina_List *l;
595 Sink *s; 593 Sink *s;
594 Eina_Bool volume_changed;
596 595
597 EINA_LIST_FOREACH(mixer_context->sinks, l, s) 596 EINA_LIST_FOREACH(mixer_context->sinks, l, s)
598 { 597 {
599 if (ev->index == s->index) 598 if (ev->index == s->index)
600 { 599 {
600 volume_changed = (s->mute != ev->mute ||
601 !pa_cvolume_equal(&s->volume, &ev->volume))
602 ? EINA_TRUE : EINA_FALSE;
601 s->mute = ev->mute; 603 s->mute = ev->mute;
602 s->volume = ev->volume; 604 s->volume = ev->volume;
603 if (ev->index == mixer_context->sink_default->index) 605 if (ev->index == mixer_context->sink_default->index)
604 _mixer_gadget_update(); 606 {
607 _mixer_gadget_update();
608 if (volume_changed)
609 _notify(s->mute ? 0 : PA_VOLUME_TO_INT(
610 pa_cvolume_avg(&mixer_context->sink_default->volume)));
611 }
605 } 612 }
606 } 613 }
607 614