summaryrefslogtreecommitdiff
path: root/shell/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/clock.c')
-rw-r--r--shell/clock.c224
1 files changed, 1 insertions, 223 deletions
diff --git a/shell/clock.c b/shell/clock.c
index 180f121..1a22089 100644
--- a/shell/clock.c
+++ b/shell/clock.c
@@ -35,19 +35,10 @@ static guint signals[N_SIGNALS] = { 0 };
struct MaynardClockPrivate {
GtkWidget *revealer_clock;
- GtkWidget *revealer_system;
- GtkWidget *revealer_volume;
GtkWidget *label;
- GtkWidget *volume_scale;
- GtkWidget *volume_image;
-
GnomeWallClock *wall_clock;
-
- snd_mixer_t *mixer_handle;
- snd_mixer_elem_t *mixer;
- glong min_volume, max_volume;
};
G_DEFINE_TYPE(MaynardClock, maynard_clock, GTK_TYPE_WINDOW)
@@ -60,123 +51,6 @@ maynard_clock_init (MaynardClock *self)
MaynardClockPrivate);
}
-static gdouble
-alsa_volume_to_percentage (MaynardClock *self,
- glong value)
-{
- glong range;
-
- /* min volume isn't always zero unfortunately */
- range = self->priv->max_volume - self->priv->min_volume;
-
- value -= self->priv->min_volume;
-
- return (value / (gdouble) range) * 100;
-}
-
-static glong
-percentage_to_alsa_volume (MaynardClock *self,
- gdouble value)
-{
- glong range;
-
- /* min volume isn't always zero unfortunately */
- range = self->priv->max_volume - self->priv->min_volume;
-
- return (range * value / 100) + self->priv->min_volume;
-}
-
-static void
-volume_changed_cb (GtkRange *range,
- MaynardClock *self)
-{
- gdouble value;
- const gchar *icon_name;
- GtkWidget *box;
-
- value = gtk_range_get_value (range);
-
- if (self->priv->mixer != NULL)
- {
- snd_mixer_selem_set_playback_volume_all (self->priv->mixer,
- percentage_to_alsa_volume (self, value));
- }
-
- /* update the icon */
- if (value > 75)
- icon_name = "audio-volume-high-symbolic";
- else if (value > 30)
- icon_name = "audio-volume-medium-symbolic";
- else if (value > 0)
- icon_name = "audio-volume-low-symbolic";
- else
- icon_name = "audio-volume-muted-symbolic";
-
- box = gtk_widget_get_parent (self->priv->volume_image);
- gtk_widget_destroy (self->priv->volume_image);
- self->priv->volume_image = gtk_image_new_from_icon_name (
- icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR);
- gtk_box_pack_start (GTK_BOX (box), self->priv->volume_image,
- FALSE, FALSE, 0);
- gtk_widget_show (self->priv->volume_image);
-
- g_signal_emit (self, signals[VOLUME_CHANGED], 0, value, icon_name);
-}
-
-static gboolean
-volume_idle_cb (gpointer data)
-{
- MaynardClock *self = MAYNARD_CLOCK (data);
- glong volume;
-
- if (self->priv->mixer != NULL)
- {
- snd_mixer_selem_get_playback_volume (self->priv->mixer,
- SND_MIXER_SCHN_MONO, &volume);
-
- gtk_range_set_value (GTK_RANGE (self->priv->volume_scale),
- alsa_volume_to_percentage (self, volume));
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static GtkWidget *
-create_system_box (MaynardClock *self)
-{
- return gtk_label_new ("Not implemented");
-}
-
-static GtkWidget *
-create_volume_box (MaynardClock *self)
-{
- GtkWidget *box;
-
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-
- self->priv->volume_image = gtk_image_new_from_icon_name (
- "audio-volume-muted-symbolic",
- GTK_ICON_SIZE_LARGE_TOOLBAR);
- gtk_box_pack_start (GTK_BOX (box), self->priv->volume_image,
- FALSE, FALSE, 0);
-
- self->priv->volume_scale = gtk_scale_new_with_range (
- GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
- gtk_scale_set_draw_value (GTK_SCALE (self->priv->volume_scale), FALSE);
- gtk_widget_set_size_request (self->priv->volume_scale, 100, -1);
- gtk_box_pack_end (GTK_BOX (box), self->priv->volume_scale, TRUE, TRUE, 0);
-
- g_signal_connect (self->priv->volume_scale, "value-changed",
- G_CALLBACK (volume_changed_cb), self);
-
- /* set the initial value in an idle so ::volume-changed is emitted
- * when other widgets are connected to the signal and can react
- * accordingly. */
- g_idle_add (volume_idle_cb, self);
-
- return box;
-}
-
static void
wall_clock_notify_cb (GnomeWallClock *wall_clock,
GParamSpec *pspec,
@@ -197,59 +71,10 @@ wall_clock_notify_cb (GnomeWallClock *wall_clock,
}
static void
-setup_mixer (MaynardClock *self)
-{
- snd_mixer_selem_id_t *sid;
- gint ret;
-
- /* this is all pretty specific to the rpi */
-
- if ((ret = snd_mixer_open (&self->priv->mixer_handle, 0)) < 0)
- goto error;
-
- if ((ret = snd_mixer_attach (self->priv->mixer_handle, "default")) < 0)
- goto error;
-
- if ((ret = snd_mixer_selem_register (self->priv->mixer_handle, NULL, NULL)) < 0)
- goto error;
-
- if ((ret = snd_mixer_load (self->priv->mixer_handle)) < 0)
- goto error;
-
- snd_mixer_selem_id_alloca (&sid);
- snd_mixer_selem_id_set_index (sid, 0);
- snd_mixer_selem_id_set_name (sid, "PCM");
- self->priv->mixer = snd_mixer_find_selem (self->priv->mixer_handle, sid);
-
- /* fallback to mixer "Master" */
- if (self->priv->mixer == NULL)
- {
- snd_mixer_selem_id_set_name (sid, "Master");
- self->priv->mixer = snd_mixer_find_selem (self->priv->mixer_handle, sid);
- if (self->priv->mixer == NULL)
- goto error;
- }
-
- if ((ret = snd_mixer_selem_get_playback_volume_range (self->priv->mixer,
- &self->priv->min_volume, &self->priv->max_volume)) < 0)
- goto error;
-
- return;
-
-error:
- g_debug ("failed to setup mixer: %s", snd_strerror (ret));
-
- if (self->priv->mixer_handle != NULL)
- snd_mixer_close (self->priv->mixer_handle);
- self->priv->mixer_handle = NULL;
- self->priv->mixer = NULL;
-}
-
-static void
maynard_clock_constructed (GObject *object)
{
MaynardClock *self = MAYNARD_CLOCK (object);
- GtkWidget *box, *system_box, *volume_box;
+ GtkWidget *box;
G_OBJECT_CLASS (maynard_clock_parent_class)->constructed (object);
@@ -269,34 +94,6 @@ maynard_clock_constructed (GObject *object)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (self), box);
- /* volume */
- self->priv->revealer_volume = gtk_revealer_new ();
- gtk_revealer_set_transition_type (
- GTK_REVEALER (self->priv->revealer_volume),
- GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
- gtk_revealer_set_reveal_child (
- GTK_REVEALER (self->priv->revealer_volume), FALSE);
- gtk_box_pack_start (GTK_BOX (box), self->priv->revealer_volume,
- TRUE, TRUE, 0);
-
- volume_box = create_volume_box (self);
- gtk_container_add (GTK_CONTAINER (self->priv->revealer_volume),
- volume_box);
-
- /* system */
- self->priv->revealer_system = gtk_revealer_new ();
- gtk_revealer_set_transition_type (
- GTK_REVEALER (self->priv->revealer_system),
- GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
- gtk_revealer_set_reveal_child (
- GTK_REVEALER (self->priv->revealer_system), FALSE);
- gtk_box_pack_start (GTK_BOX (box), self->priv->revealer_system,
- TRUE, TRUE, 0);
-
- system_box = create_system_box (self);
- gtk_container_add (GTK_CONTAINER (self->priv->revealer_system),
- system_box);
-
/* clock */
self->priv->revealer_clock = gtk_revealer_new ();
gtk_revealer_set_transition_type (
@@ -316,8 +113,6 @@ maynard_clock_constructed (GObject *object)
* fix the broken alignment where the clock appears to the right. */
gtk_box_pack_start (GTK_BOX (box), gtk_revealer_new (), TRUE, TRUE, 0);
- setup_mixer (self);
-
wall_clock_notify_cb (self->priv->wall_clock, NULL, self);
}
@@ -328,11 +123,6 @@ maynard_clock_dispose (GObject *object)
g_clear_object (&self->priv->wall_clock);
- if (self->priv->mixer_handle != NULL)
- snd_mixer_close (self->priv->mixer_handle);
- self->priv->mixer_handle = NULL;
- self->priv->mixer = NULL;
-
G_OBJECT_CLASS (maynard_clock_parent_class)->dispose (object);
}
@@ -344,10 +134,6 @@ maynard_clock_class_init (MaynardClockClass *klass)
object_class->constructed = maynard_clock_constructed;
object_class->dispose = maynard_clock_dispose;
- signals[VOLUME_CHANGED] = g_signal_new ("volume-changed",
- G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- NULL, G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_STRING);
-
g_type_class_add_private (object_class, sizeof (MaynardClockPrivate));
}
@@ -365,12 +151,4 @@ maynard_clock_show_section (MaynardClock *self,
gtk_revealer_set_reveal_child (
GTK_REVEALER (self->priv->revealer_clock),
section == MAYNARD_CLOCK_SECTION_CLOCK);
-
- gtk_revealer_set_reveal_child (
- GTK_REVEALER (self->priv->revealer_system),
- section == MAYNARD_CLOCK_SECTION_SYSTEM);
-
- gtk_revealer_set_reveal_child (
- GTK_REVEALER (self->priv->revealer_volume),
- section == MAYNARD_CLOCK_SECTION_VOLUME);
}