aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/service.c73
-rw-r--r--src/unity-menu-item.c74
-rw-r--r--src/unity-menu-item.h35
4 files changed, 44 insertions, 140 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index eb87ea7..92117fc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,8 +65,6 @@ libindciatorpower_upower_a_LDFLAGS = $(COVERAGE_LDFLAGS)
libindicatorpower_service_a_SOURCES = \
ib-brightness-control.c \
ib-brightness-control.h \
- unity-menu-item.c \
- unity-menu-item.h \
device-provider.c \
device-provider.h \
device.c \
diff --git a/src/service.c b/src/service.c
index 1c61cb2..f69d429 100644
--- a/src/service.c
+++ b/src/service.c
@@ -27,7 +27,6 @@
#include "device-provider.h"
#include "ib-brightness-control.h"
#include "service.h"
-#include "unity-menu-item.h"
#define BUS_NAME "com.canonical.indicator.power"
#define BUS_PATH "/com/canonical/indicator/power"
@@ -446,25 +445,42 @@ create_phone_devices_section (IndicatorPowerService * self G_GNUC_UNUSED)
****
***/
+static void
+get_brightness_range (IndicatorPowerService * self, gint * low, gint * high)
+{
+ const int max = ib_brightness_control_get_max_value (self->priv->brightness_control);
+ *low = max * 0.05; /* 5% minimum -- don't let the screen go completely dark */
+ *high = max;
+}
+
+static gdouble
+brightness_to_percentage (IndicatorPowerService * self, int brightness)
+{
+ int lo, hi;
+ get_brightness_range (self, &lo, &hi);
+ return (brightness-lo) / (double)(hi-lo);
+}
+
+static int
+percentage_to_brightness (IndicatorPowerService * self, double percentage)
+{
+ int lo, hi;
+ get_brightness_range (self, &lo, &hi);
+ return (int)(lo + (percentage*(hi-lo)));
+}
+
static GMenuItem *
create_brightness_menuitem (IndicatorPowerService * self)
{
- priv_t * p = self->priv;
- const int max_value = ib_brightness_control_get_max_value (p->brightness_control);
- const int min_value = max_value * 0.05; /* 5% */
- GIcon * icon;
+ int lo, hi;
GMenuItem * item;
- icon = g_themed_icon_new_with_default_fallbacks ("display-brightness-symbolic");
+ get_brightness_range (self, &lo, &hi);
- item = unity_menu_item_slider_new (NULL,
- "indicator.brightness",
- (min_value <= 0 ? 1 : min_value),
- max_value,
- NULL,
- g_icon_serialize (icon));
-
- g_object_unref (icon);
+ item = g_menu_item_new ("Brightness", "indicator.brightness");
+ g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.unity.slider");
+ g_menu_item_set_attribute (item, "min-value", "d", brightness_to_percentage (self, lo));
+ g_menu_item_set_attribute (item, "max-value", "d", brightness_to_percentage (self, hi));
return item;
}
@@ -472,8 +488,8 @@ static GVariant *
action_state_for_brightness (IndicatorPowerService * self)
{
priv_t * p = self->priv;
- double value = ib_brightness_control_get_value (p->brightness_control);
- return g_variant_new_double (value);
+ const gint brightness = ib_brightness_control_get_value (p->brightness_control);
+ return g_variant_new_double (brightness_to_percentage (self, brightness));
}
static void
@@ -483,6 +499,18 @@ update_brightness_action_state (IndicatorPowerService * self)
action_state_for_brightness (self));
}
+static void
+on_brightness_change_requested (GSimpleAction * action G_GNUC_UNUSED,
+ GVariant * parameter,
+ gpointer gself)
+{
+ IndicatorPowerService * self = INDICATOR_POWER_SERVICE (gself);
+ const gdouble percentage = g_variant_get_double (parameter);
+ const int brightness = percentage_to_brightness (self, percentage);
+ ib_brightness_control_set_value (self->priv->brightness_control, brightness);
+ update_brightness_action_state (self);
+}
+
static GMenuModel *
create_desktop_settings_section (IndicatorPowerService * self G_GNUC_UNUSED)
{
@@ -678,19 +706,6 @@ on_statistics_activated (GSimpleAction * a G_GNUC_UNUSED,
execute_command ("gnome-power-statistics");
}
-static void
-on_brightness_change_requested (GSimpleAction * action G_GNUC_UNUSED,
- GVariant * parameter,
- gpointer gself)
-{
- const double value = g_variant_get_double (parameter);
- IndicatorPowerService * self = INDICATOR_POWER_SERVICE (gself);
-
- g_debug ("setting brightness value: %f", value);
- ib_brightness_control_set_value (self->priv->brightness_control, (int)value);
- update_brightness_action_state (self);
-}
-
/* FIXME: use a GBinding to tie the gaction's state and the GSetting together? */
static void
diff --git a/src/unity-menu-item.c b/src/unity-menu-item.c
deleted file mode 100644
index e2b9b8f..0000000
--- a/src/unity-menu-item.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2012 Canonical Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Renato Araujo Oliveira Filho <renato@canonical.com>
- */
-
-#include "unity-menu-item.h"
-
-GMenuItem*
-unity_menu_item_slider_new (const gchar *label,
- const gchar *value_action,
- int min_value,
- int max_value,
- GVariant * left_icon,
- GVariant * right_icon)
-{
- GMenuItem *menu_item = g_menu_item_new (label, value_action);
-
- g_menu_item_set_attribute (menu_item,
- "x-canonical-type",
- "s",
- "com.canonical.unity.slider");
- g_menu_item_set_attribute (menu_item,
- "x-canonical-min",
- "i",
- min_value);
- g_menu_item_set_attribute (menu_item,
- "x-canonical-max",
- "i",
- max_value);
- if (left_icon != NULL) {
- g_menu_item_set_attribute (menu_item,
- "min-icon",
- "*",
- left_icon);
- }
-
- if (right_icon != NULL) {
- g_menu_item_set_attribute (menu_item,
- "max-icon",
- "*",
- right_icon);
- }
-
- return menu_item;
-}
-
-
-GMenuItem*
-unity_menu_item_switch_new (const gchar *label,
- const gchar *state_action)
-{
- GMenuItem *menu_item = g_menu_item_new (label, state_action);
-
- g_menu_item_set_attribute (menu_item,
- "x-canonical-type",
- "s",
- "com.canonical.unity.switch");
-
- return menu_item;
-}
diff --git a/src/unity-menu-item.h b/src/unity-menu-item.h
deleted file mode 100644
index ab1f1d5..0000000
--- a/src/unity-menu-item.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2012 Canonical Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Renato Araujo Oliveira Filho <renato@canonical.com>
- */
-
-#ifndef __UNITY_MENU_ITEM_H_
-#define __UNITY_MENU_ITEM_H_
-
-#include <gio/gio.h>
-
-GMenuItem* unity_menu_item_slider_new (const gchar *label,
- const gchar *value_action,
- int min_value,
- int max_value,
- GVariant * left_icon,
- GVariant * right_icon);
-
-GMenuItem* unity_menu_item_switch_new (const gchar *label,
- const gchar *state_action);
-
-#endif