Commit dd3ed803 authored by Emilio Pozuelo Monfort's avatar Emilio Pozuelo Monfort
Browse files

Add a volume control widget to the panel

parent 2b7e3672
......@@ -21,6 +21,8 @@ weston_gtk_shell_SOURCES = \
launcher-grid.h \
shell-app-system.c \
shell-app-system.h \
sound-applet.c \
sound-applet.h \
desktop-shell-client-protocol.h \
desktop-shell-protocol.c \
$(external_sources)
......
......@@ -8,6 +8,7 @@
#include "clock.h"
#include "favorites.h"
#include "launcher-grid.h"
#include "sound-applet.h"
extern char **environ; /* defined by libc */
......@@ -115,6 +116,7 @@ panel_create(struct desktop *desktop)
GdkWindow *gdk_window;
struct element *panel;
GtkWidget *box1, *box2, *button;
GtkWidget *sound_applet, *popup;
panel = malloc(sizeof *panel);
memset(panel, 0, sizeof *panel);
......@@ -143,6 +145,9 @@ panel_create(struct desktop *desktop)
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_end (GTK_BOX (box2), weston_gtk_clock_new (), FALSE, FALSE, 6);
sound_applet = weston_gtk_sound_applet_new ();
gtk_box_pack_end (GTK_BOX (box2), sound_applet, FALSE, FALSE, 6);
gtk_box_pack_end (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show_all (box1);
......
/*
* Copyright (C) 2013 Collabora Ltd.
*
* Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
*/
#include "config.h"
#include "sound-applet.h"
#include <gio/gio.h>
#include <gtk/gtk.h>
enum {
PROP_0,
};
struct WestonGtkSoundAppletPrivate {
GtkWidget *image;
GtkWidget *scale;
GSettings *settings;
};
G_DEFINE_TYPE(WestonGtkSoundApplet, weston_gtk_sound_applet, GTK_TYPE_BOX)
static void
value_changed_cb (GtkRange *range,
WestonGtkSoundApplet *self)
{
GError *error = NULL;
gdouble value;
gchar *cmd;
value = gtk_range_get_value (range);
cmd = g_strdup_printf ("amixer set PCM %d%%", (int) value);
g_spawn_command_line_async (cmd, &error);
if (error)
{
g_print ("failed to set volume: %s\n", error->message);
g_clear_error (&error);
}
g_free (cmd);
}
static void
weston_gtk_sound_applet_dispose (GObject *object)
{
WestonGtkSoundApplet *self = WESTON_GTK_SOUND_APPLET (object);
g_clear_object (&self->priv->settings);
G_OBJECT_CLASS (weston_gtk_sound_applet_parent_class)->dispose (object);
}
static void
weston_gtk_sound_applet_init (WestonGtkSoundApplet *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
WESTON_GTK_TYPE_SOUND_APPLET,
WestonGtkSoundAppletPrivate);
self->priv->settings = g_settings_new ("org.raspberrypi.weston-gtk-shell");
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
/* FIXME: make this nicer. GtkVolumeButton doesn't work well for us
* because the scale will be placed behind the panel. But we can
* mimic/reimplement it... or fix GtkVolumeButton.
*/
self->priv->image = gtk_image_new_from_icon_name ("audio-volume-high", GTK_ICON_SIZE_MENU);
gtk_box_pack_start (GTK_BOX (self), self->priv->image, FALSE, FALSE, 0);
self->priv->scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
0, 100, 1);
gtk_scale_set_draw_value (GTK_SCALE (self->priv->scale), FALSE);
gtk_widget_set_size_request (self->priv->scale, 100, -1);
g_signal_connect (self->priv->scale, "value-changed",
G_CALLBACK (value_changed_cb), self);
gtk_box_pack_start (GTK_BOX (self), self->priv->scale, FALSE, FALSE, 0);
}
static void
weston_gtk_sound_applet_class_init (WestonGtkSoundAppletClass *klass)
{
GObjectClass *object_class = (GObjectClass *)klass;
object_class->dispose = weston_gtk_sound_applet_dispose;
g_type_class_add_private (object_class, sizeof (WestonGtkSoundAppletPrivate));
}
GtkWidget *
weston_gtk_sound_applet_new (void)
{
return g_object_new (WESTON_GTK_TYPE_SOUND_APPLET, NULL);
}
/*
* Copyright (C) 2013 Collabora Ltd.
*
* Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
*/
#ifndef __WESTON_GTK_SOUND_APPLET_H__
#define __WESTON_GTK_SOUND_APPLET_H__
#include <gtk/gtk.h>
#define WESTON_GTK_TYPE_SOUND_APPLET (weston_gtk_sound_applet_get_type ())
#define WESTON_GTK_SOUND_APPLET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WESTON_GTK_TYPE_SOUND_APPLET, WestonGtkSoundApplet))
#define WESTON_GTK_SOUND_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WESTON_GTK_TYPE_SOUND_APPLET, WestonGtkSoundAppletClass))
#define WESTON_GTK_IS_SOUND_APPLET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WESTON_GTK_TYPE_SOUND_APPLET))
#define WESTON_GTK_IS_SOUND_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WESTON_GTK_TYPE_SOUND_APPLET))
#define WESTON_GTK_SOUND_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WESTON_GTK_TYPE_SOUND_APPLET, WestonGtkSoundAppletClass))
typedef struct WestonGtkSoundApplet WestonGtkSoundApplet;
typedef struct WestonGtkSoundAppletClass WestonGtkSoundAppletClass;
typedef struct WestonGtkSoundAppletPrivate WestonGtkSoundAppletPrivate;
struct WestonGtkSoundApplet
{
GtkBox parent;
WestonGtkSoundAppletPrivate *priv;
};
struct WestonGtkSoundAppletClass
{
GtkBoxClass parent_class;
};
GType weston_gtk_sound_applet_get_type (void) G_GNUC_CONST;
GtkWidget *weston_gtk_sound_applet_new (void);
#endif /* __WESTON_GTK_SOUND_APPLET_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment