summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-03-26 12:09:06 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-04-03 22:58:03 -0300
commitd66fa69b19f7c866ab04b6ae9b384b2d2214ae54 (patch)
tree97d387fe265fe8cb024056fc6cbbdaee07a6531d /src
parent4ac33e16ddb3efe95edffab6c67c7bbbd9ffe452 (diff)
[module] Adding support for key bindings
Diffstat (limited to 'src')
-rw-r--r--src/module/e_mod_main.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/module/e_mod_main.c b/src/module/e_mod_main.c
index 232b820..e36d713 100644
--- a/src/module/e_mod_main.c
+++ b/src/module/e_mod_main.c
@@ -5,6 +5,8 @@
5#include <epulse.h> 5#include <epulse.h>
6#include "e_mod_main.h" 6#include "e_mod_main.h"
7 7
8#define VOLUME_STEP (PA_VOLUME_NORM / 10)
9
8/* module requirements */ 10/* module requirements */
9EAPI E_Module_Api e_modapi = 11EAPI E_Module_Api e_modapi =
10 { 12 {
@@ -58,6 +60,12 @@ struct _Context
58 Eina_List *instances; 60 Eina_List *instances;
59 Eina_List *sinks; 61 Eina_List *sinks;
60 E_Menu *menu; 62 E_Menu *menu;
63
64 struct {
65 E_Action *incr;
66 E_Action *decr;
67 E_Action *mute;
68 } actions;
61}; 69};
62 70
63typedef struct _Instance Instance; 71typedef struct _Instance Instance;
@@ -110,6 +118,100 @@ _mixer_gadget_update(void)
110} 118}
111 119
112static void 120static void
121_volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
122{
123 Sink *s = mixer_context->sink_default;
124 pa_cvolume_inc(&(s->volume), VOLUME_STEP);
125
126 epulse_sink_volume_set(s->index, s->volume);
127 _mixer_gadget_update();
128}
129
130static void
131_volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
132{
133 Sink *s = mixer_context->sink_default;
134 pa_cvolume_dec(&(s->volume), VOLUME_STEP);
135
136 epulse_sink_volume_set(s->index, s->volume);
137 _mixer_gadget_update();
138}
139
140static void
141_volume_mute_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
142{
143 Sink *s = mixer_context->sink_default;
144 s->mute = !s->mute;
145 if (!epulse_sink_mute_set(s->index, s->mute))
146 {
147 WRN("Could not mute the sink: %d", s->index);
148 s->mute = !s->mute;
149 return;
150 }
151
152 _mixer_gadget_update();
153}
154
155static void
156_actions_register(void)
157{
158 mixer_context->actions.incr = e_action_add("volume_increase");
159 if (mixer_context->actions.incr)
160 {
161 mixer_context->actions.incr->func.go = _volume_increase_cb;
162 e_action_predef_name_set("Pulse Mixer", "Increase Volume",
163 "volume_increase", NULL, NULL, 0);
164 }
165
166 mixer_context->actions.decr = e_action_add("volume_decrease");
167 if (mixer_context->actions.decr)
168 {
169 mixer_context->actions.decr->func.go = _volume_decrease_cb;
170 e_action_predef_name_set("Pulse Mixer", "Decrease Volume",
171 "volume_decrease", NULL, NULL, 0);
172 }
173
174 mixer_context->actions.mute = e_action_add("volume_mute");
175 if (mixer_context->actions.mute)
176 {
177 mixer_context->actions.mute->func.go = _volume_mute_cb;
178 e_action_predef_name_set("Pulse Mixer", "Mute volume", "volume_mute",
179 NULL, NULL, 0);
180 }
181
182 e_managers_keys_ungrab();
183 e_managers_keys_grab();
184}
185
186static void
187_actions_unregister(void)
188{
189 if (mixer_context->actions.incr)
190 {
191 e_action_predef_name_del("Pulse Mixer", "Volume Increase");
192 e_action_del("volume_increase");
193 mixer_context->actions.incr = NULL;
194 }
195
196 if (mixer_context->actions.decr)
197 {
198 e_action_predef_name_del("Pulse Mixer", "Volume Mute");
199 e_action_del("volume_decrease");
200 mixer_context->actions.decr = NULL;
201 }
202
203 if (mixer_context->actions.mute)
204 {
205 e_action_predef_name_del("Pulse Mixer", "Voume Mute");
206 e_action_del("volume_mute");
207 mixer_context->actions.mute = NULL;
208 }
209
210 e_managers_keys_ungrab();
211 e_managers_keys_grab();
212}
213
214static void
113_popup_del(Instance *inst) 215_popup_del(Instance *inst)
114{ 216{
115 inst->slider = NULL; 217 inst->slider = NULL;
@@ -545,6 +647,7 @@ e_modapi_init(E_Module *m)
545 } 647 }
546 648
547 e_gadcon_provider_register(&_gadcon_class); 649 e_gadcon_provider_register(&_gadcon_class);
650 _actions_register();
548 651
549 return m; 652 return m;
550} 653}
@@ -553,6 +656,8 @@ EAPI int
553e_modapi_shutdown(E_Module *m EINA_UNUSED) 656e_modapi_shutdown(E_Module *m EINA_UNUSED)
554{ 657{
555 Sink *s; 658 Sink *s;
659
660 _actions_unregister();
556 e_gadcon_provider_unregister((const E_Gadcon_Client_Class *)&_gadcon_class); 661 e_gadcon_provider_unregister((const E_Gadcon_Client_Class *)&_gadcon_class);
557 662
558 if (!mixer_context) 663 if (!mixer_context)