Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ to show a notification for volume level 25%. To show a notification for
muted sound, call:

$ volnoti-show -m

To show a notification for muted microphone, call:

$ volnoti-show -c

To show a notification for un-muted microphone, call:

$ volnoti-show -u


The best way to do this is to create simple script and attach it to
the hot-keys on your keyboard. But this depends on your window manager
and system configuration.
Expand Down
3 changes: 2 additions & 1 deletion res/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
datadir = $(datarootdir)/pixmaps/@PACKAGE@/
ICONS = progressbar_empty.png progressbar_full.png \
volume_high.svg volume_medium.svg \
volume_low.svg volume_off.svg volume_muted.svg
volume_low.svg volume_off.svg volume_muted.svg \
mic_muted.svg mic_on.svg

data_DATA = $(ICONS)
EXTRA_DIST = $(ICONS)
125 changes: 125 additions & 0 deletions res/mic_muted.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions res/mic_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ static void print_usage(const char* filename, int failure) {
g_print("Usage: %s [-v] [-m] <volume>\n"
" -h\t--help\t\thelp\n"
" -v\t--verbose\tverbose\n"
" -m\t--mute\t\tmuted\n"
" -m\t--mute\tvolume muted\n"
" -c\t--micmute\tmicrophone muted\n"
" -u\t--micunmute\tmicrophone unmuted\n"
" <volume>\t\tint 0-100\n", filename);
if (failure)
exit(EXIT_FAILURE);
Expand All @@ -43,17 +45,20 @@ int main(int argc, const char* argv[]) {
void *options = gopt_sort(&argc, argv, gopt_start(
gopt_option('h', 0, gopt_shorts('h', '?'), gopt_longs("help", "HELP")),
gopt_option('m', 0, gopt_shorts('m'), gopt_longs("mute")),
gopt_option('c', 0, gopt_shorts('c'), gopt_longs("micmute")),
gopt_option('u', 0, gopt_shorts('u'), gopt_longs("micunmute")),
gopt_option('v', GOPT_REPEAT, gopt_shorts('v'), gopt_longs("verbose"))));
int help = gopt(options, 'h');
int debug = gopt(options, 'v');
int muted = gopt(options, 'm');
int muted = gopt(options, 'm')? 1 : gopt(options, 'c') ? 2 : gopt(options, 'u') ? 3 : 0;

gopt_free(options);

if (help)
print_usage(argv[0], FALSE);

gint volume;
if (muted) {
if (muted ) {
if (argc > 2) {
print_usage(argv[0], TRUE);
} else if (argc == 2) {
Expand Down Expand Up @@ -105,7 +110,7 @@ int main(int argc, const char* argv[]) {
print_debug_ok(debug);

print_debug("Sending volume...", debug);
uk_ac_cam_db538_VolumeNotification_notify(proxy, volume, muted, &error);
uk_ac_cam_db538_VolumeNotification_notify(proxy, volume, muted , &error);
if (error != NULL) {
handle_error("Failed to send notification", error->message, FALSE);
g_clear_error(&error);
Expand Down
3 changes: 3 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
/* And we're interested in using it through this interface.
This must match the entry in the interface definition XML. */
#define VALUE_SERVICE_INTERFACE "uk.ac.cam.db538.VolumeNotification"
#define VOL_MUTED 1
#define MIC_MUTED 2
#define MIC_UNMUTED 3

void handle_error(const char* msg, const char* reason, gboolean fatal);
void print_debug(const gchar *msg, int debug);
Expand Down
47 changes: 37 additions & 10 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef struct {

gint volume;
gboolean muted;
gboolean micmuted;
gboolean micunmuted;

GtkWindow *notification;

Expand All @@ -40,6 +42,8 @@ typedef struct {
GdkPixbuf *icon_low;
GdkPixbuf *icon_off;
GdkPixbuf *icon_muted;
GdkPixbuf *icon_micon;
GdkPixbuf *icon_micmuted;

GdkPixbuf *image_progressbar_empty;
GdkPixbuf *image_progressbar_full;
Expand All @@ -60,7 +64,7 @@ typedef struct {
GType volume_object_get_type(void);
gboolean volume_object_notify(VolumeObject* obj,
gint value_in,
gboolean muted,
int muted,
GError** error);

#define VOLUME_TYPE_OBJECT \
Expand Down Expand Up @@ -117,15 +121,28 @@ time_handler(VolumeObject *obj)

gboolean volume_object_notify(VolumeObject* obj,
gint value,
gboolean muted,
int muted,
GError** error) {
g_assert(obj != NULL);

if (muted) {
obj->muted = TRUE;
if (muted == VOL_MUTED) {
obj->muted = TRUE;
obj->micmuted = FALSE;
obj->micunmuted = FALSE;
} else if ( muted == MIC_MUTED ) {
obj->muted = FALSE;
obj->micunmuted = FALSE;
obj->micmuted = TRUE;
} else if ( muted == MIC_UNMUTED ) {
obj->muted = FALSE;
obj->micunmuted = TRUE;
obj->micmuted = FALSE;
} else {
obj->muted = FALSE;
obj->muted = FALSE;
obj->micmuted = FALSE;
obj->micunmuted = FALSE;
}

obj->volume = (value > 100) ? 100 : value;

if (obj->notification == NULL) {
Expand All @@ -139,14 +156,18 @@ gboolean volume_object_notify(VolumeObject* obj,
// choose icon
if (obj->muted)
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_muted);
else if (obj->micmuted)
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_micmuted);
else if (obj->micunmuted)
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_micon);
else if (obj->volume >= 75)
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_high);
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_high);
else if (obj->volume >= 50)
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_medium);
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_medium);
else if (obj->volume >= 25)
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_low);
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_low);
else
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_off);
set_notification_icon(GTK_WINDOW(obj->notification), obj->icon_off);

// prepare and set progress bar
gint width_full = obj->width_progressbar * obj->volume / 100;
Expand Down Expand Up @@ -304,7 +325,13 @@ int main(int argc, char* argv[]) {
status->icon_muted = gdk_pixbuf_new_from_file(IMAGE_PATH "volume_muted.svg", &error);
if (error != NULL)
handle_error("Couldn't load volume_muted.svg.", error->message, TRUE);

status->icon_micmuted = gdk_pixbuf_new_from_file(IMAGE_PATH "mic_muted.svg", &error);
if (error != NULL)
handle_error("Couldn't load mic_muted.svg.", error->message, TRUE);
status->icon_micon = gdk_pixbuf_new_from_file(IMAGE_PATH "mic_on.svg", &error);
if (error != NULL)
handle_error("Couldn't load mic_on.svg.", error->message, TRUE);

// progress bar
status->image_progressbar_empty = gdk_pixbuf_new_from_file(IMAGE_PATH "progressbar_empty.png", &error);
if (error != NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/specs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<interface name="uk.ac.cam.db538.VolumeNotification">
<method name="notify">
<arg type="i" name="volume" direction="in" />
<arg type="b" name="muted" direction="in" />
<arg type="i" name="muted" direction="in" />
</method>
</interface>
</node>
26 changes: 7 additions & 19 deletions src/value-client-stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ G_BEGIN_DECLS

#ifndef _DBUS_GLIB_ASYNC_DATA_FREE
#define _DBUS_GLIB_ASYNC_DATA_FREE
static
#ifdef G_HAVE_INLINE
inline
#endif
void
static inline void
_dbus_glib_async_data_free (gpointer stuff)
{
g_slice_free (DBusGAsyncData, stuff);
Expand All @@ -21,15 +17,11 @@ _dbus_glib_async_data_free (gpointer stuff)
#ifndef DBUS_GLIB_CLIENT_WRAPPERS_uk_ac_cam_db538_VolumeNotification
#define DBUS_GLIB_CLIENT_WRAPPERS_uk_ac_cam_db538_VolumeNotification

static
#ifdef G_HAVE_INLINE
inline
#endif
gboolean
uk_ac_cam_db538_VolumeNotification_notify (DBusGProxy *proxy, const gint IN_volume, GError **error)
static inline gboolean
uk_ac_cam_db538_VolumeNotification_notify (DBusGProxy *proxy, const gint IN_volume, const gint IN_muted, GError **error)

{
return dbus_g_proxy_call (proxy, "notify", error, G_TYPE_INT, IN_volume, G_TYPE_INVALID, G_TYPE_INVALID);
return dbus_g_proxy_call (proxy, "notify", error, G_TYPE_INT, IN_volume, G_TYPE_INT, IN_muted, G_TYPE_INVALID, G_TYPE_INVALID);
}

typedef void (*uk_ac_cam_db538_VolumeNotification_notify_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
Expand All @@ -44,19 +36,15 @@ uk_ac_cam_db538_VolumeNotification_notify_async_callback (DBusGProxy *proxy, DBu
return;
}

static
#ifdef G_HAVE_INLINE
inline
#endif
DBusGProxyCall*
uk_ac_cam_db538_VolumeNotification_notify_async (DBusGProxy *proxy, const gint IN_volume, uk_ac_cam_db538_VolumeNotification_notify_reply callback, gpointer userdata)
static inline DBusGProxyCall*
uk_ac_cam_db538_VolumeNotification_notify_async (DBusGProxy *proxy, const gint IN_volume, const gint IN_muted, uk_ac_cam_db538_VolumeNotification_notify_reply callback, gpointer userdata)

{
DBusGAsyncData *stuff;
stuff = g_slice_new (DBusGAsyncData);
stuff->cb = G_CALLBACK (callback);
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "notify", uk_ac_cam_db538_VolumeNotification_notify_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_INT, IN_volume, G_TYPE_INVALID);
return dbus_g_proxy_begin_call (proxy, "notify", uk_ac_cam_db538_VolumeNotification_notify_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_INT, IN_volume, G_TYPE_INT, IN_muted, G_TYPE_INVALID);
}
#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_uk_ac_cam_db538_VolumeNotification */

Expand Down
71 changes: 33 additions & 38 deletions src/value-daemon-stub.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/* Generated by dbus-binding-tool; do not edit! */


#ifndef __dbus_glib_marshal_volume_object_MARSHAL_H__
#define __dbus_glib_marshal_volume_object_MARSHAL_H__

#include <glib-object.h>

G_BEGIN_DECLS
/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
#include <glib-object.h>

#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
#define g_marshal_value_peek_char(v) g_value_get_char (v)
#define g_marshal_value_peek_char(v) g_value_get_schar (v)
#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
#define g_marshal_value_peek_int(v) g_value_get_int (v)
#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
Expand Down Expand Up @@ -54,33 +49,36 @@ G_BEGIN_DECLS
#define g_marshal_value_peek_variant(v) (v)->data[0].v_pointer
#endif /* !G_ENABLE_DEBUG */


/* BOOLEAN:INT,POINTER */
extern void dbus_glib_marshal_volume_object_BOOLEAN__INT_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
/* Prototype for -Wmissing-prototypes */
G_BEGIN_DECLS
extern
void dbus_glib_marshal_volume_object_BOOLEAN__INT_INT_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
G_END_DECLS
void
dbus_glib_marshal_volume_object_BOOLEAN__INT_POINTER (GClosure *closure,
GValue *return_value G_GNUC_UNUSED,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint G_GNUC_UNUSED,
gpointer marshal_data)
dbus_glib_marshal_volume_object_BOOLEAN__INT_INT_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint G_GNUC_UNUSED,
gpointer marshal_data)
{
typedef gboolean (*GMarshalFunc_BOOLEAN__INT_POINTER) (gpointer data1,
gint arg_1,
gpointer arg_2,
gpointer data2);
register GMarshalFunc_BOOLEAN__INT_POINTER callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
typedef gboolean (*GMarshalFunc_BOOLEAN__INT_INT_POINTER) (gpointer data1,
gint arg1,
gint arg2,
gpointer arg3,
gpointer data2);
GCClosure *cc = (GCClosure *) closure;
gpointer data1, data2;
GMarshalFunc_BOOLEAN__INT_INT_POINTER callback;
gboolean v_return;

g_return_if_fail (return_value != NULL);
g_return_if_fail (n_param_values == 3);
g_return_if_fail (n_param_values == 4);

if (G_CCLOSURE_SWAP_DATA (closure))
{
Expand All @@ -92,29 +90,26 @@ dbus_glib_marshal_volume_object_BOOLEAN__INT_POINTER (GClosure *closure,
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_BOOLEAN__INT_POINTER) (marshal_data ? marshal_data : cc->callback);
callback = (GMarshalFunc_BOOLEAN__INT_INT_POINTER) (marshal_data ? marshal_data : cc->callback);

v_return = callback (data1,
g_marshal_value_peek_int (param_values + 1),
g_marshal_value_peek_pointer (param_values + 2),
g_marshal_value_peek_int (param_values + 2),
g_marshal_value_peek_pointer (param_values + 3),
data2);

g_value_set_boolean (return_value, v_return);
}

G_END_DECLS

#endif /* __dbus_glib_marshal_volume_object_MARSHAL_H__ */

#include <dbus/dbus-glib.h>
static const DBusGMethodInfo dbus_glib_volume_object_methods[] = {
{ (GCallback) volume_object_notify, dbus_glib_marshal_volume_object_BOOLEAN__INT_POINTER, 0 },
{ (GCallback) volume_object_notify, dbus_glib_marshal_volume_object_BOOLEAN__INT_INT_POINTER, 0 },
};

const DBusGObjectInfo dbus_glib_volume_object_object_info = { 1,
dbus_glib_volume_object_methods,
1,
"uk.ac.cam.db538.VolumeNotification\0notify\0S\0volume\0I\0i\0\0\0",
"uk.ac.cam.db538.VolumeNotification\0notify\0S\0volume\0I\0i\0muted\0I\0i\0\0\0",
"\0",
"\0"
};
Expand Down