summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Zesch <[email protected]>2012-11-22 14:18:05 -0500
committerSteve Zesch <[email protected]>2012-11-22 14:18:05 -0500
commitde6402cb66f3eecfbb4aa92155f2cec7bc45225a (patch)
tree1b95148af81aebf1359dab9e55217f1fa1f1eafa
parentf915c8482adab2076b25427517ec6166bb9209a2 (diff)
parent433b548ea199a66afbb5fc874bfdaa31695c1e3c (diff)
downloadmate-power-manager-de6402cb66f3eecfbb4aa92155f2cec7bc45225a.tar.bz2
mate-power-manager-de6402cb66f3eecfbb4aa92155f2cec7bc45225a.tar.xz
Merge branch 'master' of github.com:mate-desktop/mate-power-manager
-rw-r--r--configure.ac20
-rw-r--r--src/gpm-kbd-backlight.c173
-rw-r--r--src/gpm-manager.c88
3 files changed, 253 insertions, 28 deletions
diff --git a/configure.ac b/configure.ac
index 312f220..6e36106 100644
--- a/configure.ac
+++ b/configure.ac
@@ -270,6 +270,25 @@ AC_MSG_RESULT([$have_applets])
AM_CONDITIONAL([HAVE_APPLETS], [test $have_applets = yes])
dnl ---------------------------------------------------------------------------
+dnl systemd inhibit
+dnl ---------------------------------------------------------------------------
+
+AC_ARG_WITH(systemdinhibit,
+ AS_HELP_STRING([--with-systemdinhibit],
+ [Add systemdinhibit support]),,
+ with_systemdinhibit=auto)
+
+use_systemdinhibit=no
+if test "x$with_systemdinhibit" != "xno" ; then
+ use_systemdinhibit=yes
+ AC_DEFINE(WITH_SYSTEMD_INHIBIT, 1, [systemdinhibit support])
+
+ PKG_CHECK_MODULES(SYSTEMD_INHIBIT, libsystemd-login libsystemd-daemon)
+fi
+AM_CONDITIONAL(WITH_SYSTEMD_INHIBIT, test x$use_systemdinhibit = xyes)
+AC_SUBST(WITH_SYSTEMD_INHIBIT)
+
+dnl ---------------------------------------------------------------------------
dnl - DocBook Documentation
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(docbook-docs,
@@ -382,6 +401,7 @@ echo "
Building extra applets: ${enable_applets}
Self test support: ${have_tests}
Use libunique: ${enable_libunique}
+ systemd support: ${use_systemdinhibit}
Docbook support: ${enable_docbook_docs}
documentation dir: $DOCDIR
dbus-1 services dir: $DBUS_SERVICES_DIR
diff --git a/src/gpm-kbd-backlight.c b/src/gpm-kbd-backlight.c
index 4ed3fcf..b7aa4a4 100644
--- a/src/gpm-kbd-backlight.c
+++ b/src/gpm-kbd-backlight.c
@@ -23,11 +23,13 @@
#include <glib.h>
#include <libupower-glib/upower.h>
+#include "egg-debug.h"
#include "gpm-button.h"
#include "gpm-common.h"
#include "gpm-control.h"
#include "gpm-idle.h"
#include "gpm-kbd-backlight.h"
+#include "gsd-media-keys-window.h"
static const gchar *kbd_backlight_introspection = ""
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>""<node name=\"/\">"
@@ -48,23 +50,24 @@ static const gchar *kbd_backlight_introspection = ""
struct GpmKbdBacklightPrivate
{
- UpClient *client;
- GpmButton *button;
- GSettings *settings;
- GSettings *settings_gsd;
- GpmControl *control;
- GpmIdle *idle;
- gboolean can_dim;
- gboolean system_is_idle;
- GTimer *idle_timer;
- guint idle_dim_timeout;
- guint master_percentage;
- guint brightness;
- guint max_brightness;
- guint brightness_percent;
- GDBusProxy *upower_proxy;
- GDBusConnection *bus_connection;
- guint bus_object_id;
+ UpClient *client;
+ GpmButton *button;
+ GSettings *settings;
+ GSettings *settings_gsd;
+ GpmControl *control;
+ GpmIdle *idle;
+ gboolean can_dim;
+ gboolean system_is_idle;
+ GTimer *idle_timer;
+ guint idle_dim_timeout;
+ guint master_percentage;
+ guint brightness;
+ guint max_brightness;
+ guint brightness_percent;
+ GDBusProxy *upower_proxy;
+ GDBusConnection *bus_connection;
+ guint bus_object_id;
+ GtkWidget *popup;
};
enum {
@@ -145,10 +148,94 @@ gpm_kbd_backlight_set (GpmKbdBacklight *backlight,
NULL,
NULL);
}
-
+ egg_debug("Set brightness to %i", backlight->priv->brightness);
return TRUE;
}
+/**
+ * gpm_kbd_backlight_dialog_init
+ **/
+static void
+gpm_kbd_backlight_dialog_init (GpmKbdBacklight *backlight)
+{
+ if (backlight->priv->popup != NULL
+ && !gsd_media_keys_window_is_valid (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup))) {
+ gtk_widget_destroy (backlight->priv->popup);
+ backlight->priv->popup = NULL;
+ }
+
+ if (backlight->priv->popup == NULL) {
+ backlight->priv->popup= gsd_media_keys_window_new ();
+ gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup),
+ "gpm-brightness-kbd",
+ TRUE);
+ gtk_window_set_position (GTK_WINDOW (backlight->priv->popup), GTK_WIN_POS_NONE);
+
+ }
+}
+/**
+ * gpm_kbd_backlight_dialog_show:
+ *
+ * Show the brightness popup, and place it nicely on the screen.
+ **/
+static void
+gpm_kbd_backlight_dialog_show (GpmKbdBacklight *backlight)
+{
+ int orig_w;
+ int orig_h;
+ int screen_w;
+ int screen_h;
+ int x;
+ int y;
+ int pointer_x;
+ int pointer_y;
+ GtkRequisition win_req;
+ GdkScreen *pointer_screen;
+ GdkRectangle geometry;
+ int monitor;
+
+ /*
+ * get the window size
+ * if the window hasn't been mapped, it doesn't necessarily
+ * know its true size, yet, so we need to jump through hoops
+ */
+ gtk_window_get_default_size (GTK_WINDOW (backlight->priv->popup), &orig_w, &orig_h);
+ gtk_widget_size_request (backlight->priv->popup, &win_req);
+
+ if (win_req.width > orig_w) {
+ orig_w = win_req.width;
+ }
+ if (win_req.height > orig_h) {
+ orig_h = win_req.height;
+ }
+
+ pointer_screen = NULL;
+ gdk_display_get_pointer (gtk_widget_get_display (backlight->priv->popup),
+ &pointer_screen,
+ &pointer_x,
+ &pointer_y,
+ NULL);
+ monitor = gdk_screen_get_monitor_at_point (pointer_screen,
+ pointer_x,
+ pointer_y);
+
+ gdk_screen_get_monitor_geometry (pointer_screen,
+ monitor,
+ &geometry);
+
+ screen_w = geometry.width;
+ screen_h = geometry.height;
+
+ x = ((screen_w - orig_w) / 2) + geometry.x;
+ y = geometry.y + (screen_h / 2) + (screen_h / 2 - orig_h) / 2;
+
+ gtk_window_move (GTK_WINDOW (backlight->priv->popup), x, y);
+
+ gtk_widget_show (backlight->priv->popup);
+
+ gdk_display_sync (gtk_widget_get_display (backlight->priv->popup));
+}
+
/**
* gpm_kbd_backlight_brightness_up:
**/
@@ -462,15 +549,30 @@ gpm_kbd_backlight_button_pressed_cb (GpmButton *button,
GpmKbdBacklight *backlight)
{
static guint saved_brightness;
+ gboolean ret;
saved_brightness = backlight->priv->master_percentage;
if (g_strcmp0 (type, GPM_BUTTON_KBD_BRIGHT_UP) == 0) {
- gpm_kbd_backlight_brightness_up (backlight);
+ ret = gpm_kbd_backlight_brightness_up (backlight);
+
+ if (ret) {
+ egg_debug("Going to display OSD");
+ gpm_kbd_backlight_dialog_init (backlight);
+ gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup), backlight->priv->brightness_percent);
+ gpm_kbd_backlight_dialog_show (backlight);
+ }
} else if (g_strcmp0 (type, GPM_BUTTON_KBD_BRIGHT_DOWN) == 0) {
- gpm_kbd_backlight_brightness_down (backlight);
-
+ ret = gpm_kbd_backlight_brightness_down (backlight);
+
+ if (ret) {
+ egg_debug("Going to display OSD");
+ gpm_kbd_backlight_dialog_init (backlight);
+ gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup), backlight->priv->brightness_percent);
+ gpm_kbd_backlight_dialog_show (backlight);
+ }
+
} else if (g_strcmp0 (type, GPM_BUTTON_KBD_BRIGHT_TOGGLE) == 0) {
if (backlight->priv->master_percentage == 0) {
/* backlight is off turn it back on */
@@ -506,6 +608,8 @@ gpm_kbd_backlight_idle_changed_cb (GpmIdle *idle,
gboolean on_battery;
gboolean enable_action;
+ egg_debug("Idle changed");
+
lid_closed = gpm_button_is_lid_closed (backlight->priv->button);
if (lid_closed)
@@ -516,22 +620,26 @@ gpm_kbd_backlight_idle_changed_cb (GpmIdle *idle,
&on_battery,
NULL);
+ //These were all "settings_gsd" originally
+
enable_action = on_battery
- ? g_settings_get_boolean (backlight->priv->settings_gsd, GPM_SETTINGS_IDLE_DIM_BATT)
- : g_settings_get_boolean (backlight->priv->settings_gsd, GPM_SETTINGS_IDLE_DIM_AC);
+ ? g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_IDLE_DIM_BATT)
+ : g_settings_get_boolean (backlight->priv->settings, GPM_SETTINGS_IDLE_DIM_AC);
if (!enable_action)
return;
if (mode == GPM_IDLE_MODE_NORMAL) {
+ egg_debug("GPM_IDLE_MODE_NORMAL");
backlight->priv->master_percentage = 100;
gpm_kbd_backlight_evaluate_power_source_and_set (backlight);
} else if (mode == GPM_IDLE_MODE_DIM) {
+ egg_debug("GPM_IDLE_MODE_DIM");
brightness = backlight->priv->master_percentage;
value = g_settings_get_int (backlight->priv->settings, GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_IDLE);
if (value > 100) {
- g_warning ("Cannot scale brightness down by more than 100%%. Scaling by 50%%");
+ egg_warning ("Cannot scale brightness down by more than 100%%. Scaling by 50%%");
value = 50;
}
@@ -572,7 +680,7 @@ gpm_kbd_backlight_finalize (GObject *object)
g_object_unref (backlight->priv->control);
g_object_unref (backlight->priv->settings);
- g_object_unref (backlight->priv->settings_gsd);
+ //g_object_unref (backlight->priv->settings_gsd);
g_object_unref (backlight->priv->client);
g_object_unref (backlight->priv->button);
g_object_unref (backlight->priv->idle);
@@ -695,8 +803,10 @@ noerr:
g_signal_connect (backlight->priv->client, "changed",
G_CALLBACK (gpm_kbd_backlight_client_changed_cb), backlight);
- backlight->priv->settings = g_settings_new (GPM_SETTINGS_SCHEMA);
- //backlight->priv->settings_gsd = g_settings_new (GSD_SETTINGS_SCHEMA);
+ backlight->priv->settings = g_settings_new (GPM_SETTINGS_SCHEMA);
+ //g_signal_connect (backlight->priv->settings, "changed", G_CALLBACK (gpm_settings_key_changed_cb), backlight);
+
+ //backlight->priv->settings_gsd = g_settings_new (GSD_SETTINGS_SCHEMA);
/* watch for kbd brightness up and down button presses */
backlight->priv->button = gpm_button_new ();
@@ -707,9 +817,16 @@ noerr:
g_signal_connect (backlight->priv->idle, "idle-changed",
G_CALLBACK (gpm_kbd_backlight_idle_changed_cb), backlight);
+ /* use a visual widget */
+ backlight->priv->popup = gsd_media_keys_window_new ();
+ gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup),
+ "gpm-brightness-kbd", TRUE);
+ gtk_window_set_position (GTK_WINDOW (backlight->priv->popup), GTK_WIN_POS_NONE);
+
/* since gpm is just starting we can pretty safely assume that we're not idle */
backlight->priv->system_is_idle = FALSE;
- backlight->priv->idle_dim_timeout = g_settings_get_int (backlight->priv->settings_gsd, GPM_SETTINGS_IDLE_DIM_TIME);
+ //This was settings_gsd originally
+ backlight->priv->idle_dim_timeout = g_settings_get_int (backlight->priv->settings, GPM_SETTINGS_IDLE_DIM_TIME);
gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);
/* make sure we turn the keyboard backlight back on after resuming */
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index 9ee8781..c6f4d79 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -100,6 +100,8 @@ struct GpmManagerPrivate
NotifyNotification *notification_warning_low;
NotifyNotification *notification_discharging;
NotifyNotification *notification_fully_charged;
+ gint32 systemd_inhibit;
+ GDBusProxy *systemd_inhibit_proxy;
};
typedef enum {
@@ -1840,6 +1842,76 @@ gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, Gpm
g_timeout_add_seconds (1, gpm_manager_reset_just_resumed_cb, manager);
}
+#ifdef WITH_SYSTEMD_INHIBIT
+/**
+ * gpm_main_system_inhibit:
+ **/
+static gint32
+gpm_manager_systemd_inhibit (GDBusProxy *proxy) {
+ /* Return a fd to the to the inhibitor, that we can close on exit. */
+ //GDBusProxy *proxy;
+ GError *error = NULL;
+ gint32 r = -1;
+ gint32 fd = -1;
+ GVariant *res;
+ GUnixFDList *fd_list = NULL;
+ //proxy == NULL;
+ /* Should we define these elsewhere? */
+ const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch";
+ const char* arg_who = g_get_user_name ();
+ const char* arg_why = "Mate power manager handles these events";
+ const char* arg_mode = "block";
+
+ egg_debug ("Inhibiting systemd sleep");
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ NULL,
+ &error );
+ //append all our arguments
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return -1;
+ }
+ res = g_dbus_proxy_call_with_unix_fd_list_sync (proxy, "Inhibit",
+ g_variant_new( "(ssss)",
+ arg_what,
+ arg_who,
+ arg_why,
+ arg_mode
+ ),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &fd_list,
+ NULL,
+ &error
+ );
+ if (error == NULL && res != NULL) {
+ g_variant_get(res, "(h)", &r);
+ egg_debug ("Inhibiting systemd sleep res = %i", r);
+ fd = g_unix_fd_list_get (fd_list, r, &error);
+ if (fd == -1) {
+ egg_debug("Failed to get systemd inhibitor");
+ return r;
+ }
+ egg_debug ("System inhibitor fd is %d", fd);
+ g_object_unref (fd_list);
+ g_variant_unref (res);
+ } else if (error != NULL || res == NULL) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ return -EIO;
+ }
+ egg_debug ("Inhibiting systemd sleep - success");
+ return r;
+}
+#endif
+
/**
* gpm_manager_init:
* @manager: This class instance
@@ -1857,6 +1929,11 @@ gpm_manager_init (GpmManager *manager)
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
g_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+#ifdef WITH_SYSTEMD_INHIBIT
+ /* We want to inhibit the systemd suspend options, and take care of them ourselves */
+ manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy);
+#endif
+
/* init to unthrottled */
manager->priv->screensaver_ac_throttle_id = 0;
manager->priv->screensaver_dpms_throttle_id = 0;
@@ -2014,6 +2091,17 @@ gpm_manager_finalize (GObject *object)
g_object_unref (manager->priv->client);
g_object_unref (manager->priv->status_icon);
+#ifdef WITH_SYSTEMD_INHIBIT
+ /* Let systemd take over again ... */
+ if (manager->priv->systemd_inhibit > 0) {
+ close(manager->priv->systemd_inhibit);
+ }
+ if (manager->priv->systemd_inhibit_proxy != NULL) {
+ g_object_unref (manager->priv->systemd_inhibit_proxy);
+ }
+ //g_object_unref (manager->priv->systemd_inhibit);
+#endif
+
G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object);
}