2011/8/30 Leif Middelschulte <[email protected]>:
> Dear gals and guys,
>
> find attached a patch that provides optional desktop notifications. I
> didn't have a sound file around with suiting license, so it doesn't
> provide a test sound notification yet.
>
> The notififcations are en-/disabled via the corresponding mixer
> configuration dialog.
Attached is a patch that includes the above changes, but fixes two
issues the old patch had:
1.)copying loaded config data -> runtime data
2.)proper icon for during muted state
> BR,
>
> Leif
>
--
Leif
From 86b346266fb96c481aa47eb22c388ecb5501f13b Mon Sep 17 00:00:00 2001
From: Leif Middelschulte <[email protected]>
Date: Tue, 30 Aug 2011 16:13:24 +0200
Subject: [PATCH] Add optional notification for mixer module.
---
trunk/e/src/modules/mixer/Makefile.am | 8 +++
trunk/e/src/modules/mixer/conf_module.c | 11 ++++-
trunk/e/src/modules/mixer/e_mod_main.c | 79 ++++++++++++++++++++++++++-----
trunk/e/src/modules/mixer/e_mod_main.h | 4 +-
4 files changed, 88 insertions(+), 14 deletions(-)
diff --git a/trunk/e/src/modules/mixer/Makefile.am b/trunk/e/src/modules/mixer/Makefile.am
index 4ea2b91..54a8855 100644
--- a/trunk/e/src/modules/mixer/Makefile.am
+++ b/trunk/e/src/modules/mixer/Makefile.am
@@ -15,6 +15,10 @@ INCLUDES = -I. \
-I$(top_builddir)/src/bin \
-I$(top_srcdir)/src/modules \
@e_cflags@ @SOUND_CFLAGS@
+if HAVE_ENOTIFY
+INCLUDES += @ENOTIFY_CFLAGS@
+endif
+
pkgdir = $(libdir)/enlightenment/modules/$(MODULE)/$(MODULE_ARCH)
pkg_LTLIBRARIES = module.la
@@ -32,6 +36,10 @@ module_la_SOURCES += sys_dummy.c
endif
module_la_LIBADD = @SOUND_LIBS@ @e_libs@ @dlopen_libs@
+if HAVE_ENOTIFY
+module_la_LIBADD += @ENOTIFY_LIBS@
+endif
+
module_la_LDFLAGS = -module -avoid-version
module_la_DEPENDENCIES = $(top_builddir)/config.h
diff --git a/trunk/e/src/modules/mixer/conf_module.c b/trunk/e/src/modules/mixer/conf_module.c
index 88e7613..c667edb 100644
--- a/trunk/e/src/modules/mixer/conf_module.c
+++ b/trunk/e/src/modules/mixer/conf_module.c
@@ -72,6 +72,8 @@ _basic_apply(E_Config_Dialog *dialog, E_Config_Dialog_Data *cfdata)
id = ctxt->default_instance->gcc->cf->id;
conf->default_gc_id = eina_stringshare_add(id);
+
+ conf->desktop_notification = ctxt->desktop_notification;
}
return 1;
@@ -82,7 +84,7 @@ _basic_create_general(E_Config_Dialog *dialog, Evas *evas, E_Config_Dialog_Data
{
struct mixer_config_ui_general *ui = &cfdata->ui.general;
E_Mixer_Module_Context *ctxt = dialog->data;
- Evas_Object *label;
+ Evas_Object *label, *chk;
Eina_List *l;
int i;
@@ -111,7 +113,14 @@ _basic_create_general(E_Config_Dialog *dialog, Evas *evas, E_Config_Dialog_Data
e_widget_framelist_object_append(ui->frame, o);
}
+
e_widget_list_object_append(cfdata->ui.list, ui->frame, 1, 1, 0.5);
+ chk = e_widget_check_add(evas, _("Diplay desktop notifications on volume change"), &ctxt->desktop_notification);
+ e_widget_check_checked_set(chk, ctxt->conf->desktop_notification);
+#ifndef HAVE_ENOTIFY
+ e_widget_disabled_set(chk, EINA_TRUE);
+#endif
+ e_widget_list_object_append(cfdata->ui.list, chk, 1, 1, 0.5);
}
static void
diff --git a/trunk/e/src/modules/mixer/e_mod_main.c b/trunk/e/src/modules/mixer/e_mod_main.c
index 419e0e1..271077e 100644
--- a/trunk/e/src/modules/mixer/e_mod_main.c
+++ b/trunk/e/src/modules/mixer/e_mod_main.c
@@ -1,5 +1,8 @@
#include "e_mod_main.h"
#include "e_mod_system.h"
+#ifdef HAVE_ENOTIFY
+#include <E_Notify.h>
+#endif
static void _mixer_popup_timer_new(E_Mixer_Instance *inst);
static Eina_Bool _mixer_popup_timer_cb(void *data);
@@ -11,6 +14,41 @@ static const char _conf_domain[] = "module.mixer";
static const char _name[] = "mixer";
const char _e_mixer_Name[] = "Mixer";
+static void
+_mixer_notify(const float val, const int mute)
+{
+#ifdef HAVE_ENOTIFY
+ E_Notification *n;
+ E_Mixer_Module_Context *ctxt;
+ char *icon, buf[56];
+ int ret;
+
+ if (val > 100.0 || val < 0.0)
+ return;
+
+ if (!(ctxt = (E_Mixer_Module_Context*)mixer_mod->data) || !ctxt->desktop_notification)
+ return;
+
+ ret = snprintf(buf, (sizeof(buf) - 1), "%s: %d%%", _("New volume"), (int)(val + 0.5));
+ if ((ret < 0) || (ret > sizeof(buf)))
+ return;
+ //Names are taken from FDO icon naming scheme
+ if (val == 0.0 || mute)
+ icon = "audio-volume-muted";
+ else if (val > 66.6)
+ icon = "audio-volume-high";
+ else if ((val > 33.3) && (val < 66.6))
+ icon = "audio-volume-medium";
+ else if (val < 33.3)
+ icon = "audio-volume-low";
+
+ n = e_notification_full_new(_("Mixer"), 0, icon, _("Volume changed"), buf, 2000);
+ e_notification_replaces_id_set(n, EINA_TRUE);
+ e_notification_send(n, NULL, NULL);
+ e_notification_unref(n);
+#endif
+}
+
const char *
e_mixer_theme_path(void)
{
@@ -138,6 +176,7 @@ _mixer_module_configuration_new(void)
return NULL;
conf->version = MOD_CONF_VERSION;
+ conf->desktop_notification = 1;
return conf;
}
@@ -249,7 +288,7 @@ _mixer_balance_right(E_Mixer_Instance *inst)
}
static void
-_mixer_volume_increase(E_Mixer_Instance *inst)
+_mixer_volume_increase(E_Mixer_Instance *inst, Eina_Bool non_ui)
{
E_Mixer_Channel_State *state;
@@ -275,10 +314,12 @@ _mixer_volume_increase(E_Mixer_Instance *inst)
e_mixer_system_set_volume(inst->sys, inst->channel,
state->left, state->right);
_mixer_gadget_update(inst);
+ if (non_ui)
+ _mixer_notify(((float)state->left + (float)state->right) / 2.0, state->mute);
}
static void
-_mixer_volume_decrease(E_Mixer_Instance *inst)
+_mixer_volume_decrease(E_Mixer_Instance *inst, Eina_Bool non_ui)
{
E_Mixer_Channel_State *state;
@@ -303,10 +344,12 @@ _mixer_volume_decrease(E_Mixer_Instance *inst)
e_mixer_system_set_volume(inst->sys, inst->channel,
state->left, state->right);
_mixer_gadget_update(inst);
+ if (non_ui)
+ _mixer_notify(((float)state->left + (float)state->right) / 2.0, state->mute);
}
static void
-_mixer_toggle_mute(E_Mixer_Instance *inst)
+_mixer_toggle_mute(E_Mixer_Instance *inst, Eina_Bool non_ui)
{
E_Mixer_Channel_State *state;
@@ -318,6 +361,8 @@ _mixer_toggle_mute(E_Mixer_Instance *inst)
state->mute = !state->mute;
e_mixer_system_set_mute(inst->sys, inst->channel, state->mute);
_mixer_gadget_update(inst);
+ if (non_ui)
+ _mixer_notify(((float)state->left + (float)state->right) / 2.0, state->mute);
}
static void
@@ -425,12 +470,12 @@ _mixer_popup_input_window_key_down_cb(void *data, int type __UNUSED__, void *eve
if (strcmp(keysym, "Escape") == 0)
_mixer_popup_del(inst);
else if (strcmp(keysym, "Up") == 0)
- _mixer_volume_increase(inst);
+ _mixer_volume_increase(inst, EINA_FALSE);
else if (strcmp(keysym, "Down") == 0)
- _mixer_volume_decrease(inst);
+ _mixer_volume_decrease(inst, EINA_FALSE);
else if ((strcmp(keysym, "Return") == 0) ||
(strcmp(keysym, "KP_Enter") == 0))
- _mixer_toggle_mute(inst);
+ _mixer_toggle_mute(inst, EINA_FALSE);
else
{
E_Action *act;
@@ -744,7 +789,7 @@ _mixer_cb_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSE
_mixer_popup_del(inst);
}
else if (ev->button == 2)
- _mixer_toggle_mute(inst);
+ _mixer_toggle_mute(inst, EINA_FALSE);
else if ((ev->button == 3) && (!inst->menu))
_mixer_menu_new(inst, ev);
}
@@ -758,9 +803,9 @@ _mixer_cb_mouse_wheel(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUS
if (ev->direction == 0)
{
if (ev->z > 0)
- _mixer_volume_decrease(inst);
+ _mixer_volume_decrease(inst, EINA_FALSE);
else if (ev->z < 0)
- _mixer_volume_increase(inst);
+ _mixer_volume_increase(inst, EINA_FALSE);
}
else if (ev->direction == 1)
{
@@ -1062,7 +1107,7 @@ _mixer_cb_volume_increase(E_Object *obj __UNUSED__, const char *params __UNUSED_
if (ctxt->default_instance->conf->keybindings_popup)
_mixer_popup_timer_new(ctxt->default_instance);
- _mixer_volume_increase(ctxt->default_instance);
+ _mixer_volume_increase(ctxt->default_instance, EINA_TRUE);
}
static void
@@ -1082,7 +1127,7 @@ _mixer_cb_volume_decrease(E_Object *obj __UNUSED__, const char *params __UNUSED_
if (ctxt->default_instance->conf->keybindings_popup)
_mixer_popup_timer_new(ctxt->default_instance);
- _mixer_volume_decrease(ctxt->default_instance);
+ _mixer_volume_decrease(ctxt->default_instance, EINA_TRUE);
}
static void
@@ -1102,7 +1147,7 @@ _mixer_cb_volume_mute(E_Object *obj __UNUSED__, const char *params __UNUSED__)
if (ctxt->default_instance->conf->keybindings_popup)
_mixer_popup_timer_new(ctxt->default_instance);
- _mixer_toggle_mute(ctxt->default_instance);
+ _mixer_toggle_mute(ctxt->default_instance, EINA_TRUE);
}
static E_Config_Dialog *
@@ -1162,6 +1207,7 @@ _mixer_module_configuration_descriptor_new(E_Config_DD *gadget_conf_edd)
E_CONFIG_VAL(conf_edd, E_Mixer_Module_Config, version, INT);
E_CONFIG_VAL(conf_edd, E_Mixer_Module_Config, default_gc_id, STR);
E_CONFIG_HASH(conf_edd, E_Mixer_Module_Config, gadgets, gadget_conf_edd);
+ E_CONFIG_VAL(conf_edd, E_Mixer_Module_Config, desktop_notification, INT);
return conf_edd;
}
@@ -1235,6 +1281,7 @@ _mixer_module_configuration_setup(E_Mixer_Module_Context *ctxt)
ctxt->gadget_conf_edd = gadget_edd;
ctxt->module_conf_edd = module_edd;
ctxt->conf = _mixer_module_configuration_load(module_edd);
+ ctxt->desktop_notification = ctxt->conf->desktop_notification;
}
static const char _act_increase[] = "volume_increase";
@@ -1303,6 +1350,10 @@ e_modapi_init(E_Module *m)
if (!ctxt)
return NULL;
+#ifdef HAVE_ENOTIFY
+ e_notification_init();
+#endif
+
_mixer_configure_registry_register();
_mixer_actions_register(ctxt);
e_gadcon_provider_register(&_gc_class);
@@ -1348,6 +1399,10 @@ e_modapi_shutdown(E_Module *m)
_mixer_module_configuration_descriptor_free(ctxt->module_conf_edd);
}
+#ifdef HAVE_ENOTIFY
+ e_notification_shutdown();
+#endif
+
E_FREE(ctxt);
mixer_mod = NULL;
return 1;
diff --git a/trunk/e/src/modules/mixer/e_mod_main.h b/trunk/e/src/modules/mixer/e_mod_main.h
index f390985..5ed5e27 100644
--- a/trunk/e/src/modules/mixer/e_mod_main.h
+++ b/trunk/e/src/modules/mixer/e_mod_main.h
@@ -5,7 +5,7 @@
#include "e_mod_system.h"
#include <e.h>
-#define MOD_CONF_VERSION 3
+#define MOD_CONF_VERSION 4
typedef struct E_Mixer_Gadget_Config
{
@@ -24,6 +24,7 @@ typedef struct E_Mixer_Module_Config
int version;
const char *default_gc_id;
Eina_Hash *gadgets;
+ int desktop_notification;
} E_Mixer_Module_Config;
typedef struct E_Mixer_Instance
@@ -71,6 +72,7 @@ typedef struct E_Mixer_Module_Context
E_Action *decr;
E_Action *mute;
} actions;
+ int desktop_notification;
} E_Mixer_Module_Context;
EAPI extern E_Module_Api e_modapi;
--
1.7.6
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel