[Xfce4-commits] [apps/parole] 01/02: Inhibit power management during video playback (Bug #15747)
noreply at xfce.org
noreply at xfce.org
Sat Aug 3 12:43:23 CEST 2019
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/parole.
commit f32c7080733a3e1b43ab2196039f1a7dee80fc42
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Wed Jul 31 22:52:02 2019 +0200
Inhibit power management during video playback (Bug #15747)
Signed-off-by: Sean Davis <smd.seandavis at gmail.com>
---
src/common/Makefile.am | 4 +-
src/common/parole-powermanager.c | 114 +++++++++++++++++++++++++++++++++++++++
src/common/parole-powermanager.h | 38 +++++++++++++
src/parole-player.c | 18 ++++++-
4 files changed, 172 insertions(+), 2 deletions(-)
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index af39af2..508166d 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -6,7 +6,9 @@ libparolecommon_la_SOURCES = \
parole-common.c \
parole-common.h \
parole-rc-utils.c \
- parole-rc-utils.h
+ parole-rc-utils.h \
+ parole-powermanager.c \
+ parole-powermanager.h
libparolecommon_la_CFLAGS = \
$(GTK_CFLAGS) \
diff --git a/src/common/parole-powermanager.c b/src/common/parole-powermanager.c
new file mode 100644
index 0000000..c4d7852
--- /dev/null
+++ b/src/common/parole-powermanager.c
@@ -0,0 +1,114 @@
+/*
+ * * Copyright (C) 2019 Simon Steinbeiß <ochosi at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "parole-powermanager.h"
+
+#define DBUS_SERVICE "org.freedesktop.PowerManagement"
+#define DBUS_PATH "/org/freedesktop/PowerManagement/Inhibit"
+#define DBUS_INTERFACE "org.freedesktop.PowerManagement.Inhibit"
+
+
+
+guint32
+parole_power_manager_inhibit (GDBusConnection *connection) {
+ GVariant *reply;
+ GError *error = NULL;
+ guint32 cookie;
+
+ reply = g_dbus_connection_call_sync (connection,
+ DBUS_SERVICE,
+ DBUS_PATH,
+ DBUS_INTERFACE,
+ "Inhibit",
+ g_variant_new ("(ss)",
+ "Parole",
+ "Video Playback"),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error) {
+ g_warning ("Inhibiting power management failed %s", error->message);
+ g_error_free (error);
+ }
+ if (reply != NULL) {
+ g_variant_get (reply, "(u)", &cookie, NULL);
+ g_variant_unref (reply);
+ return cookie;
+ }
+}
+
+void
+parole_power_manager_uninhibit (GDBusConnection *connection,
+ guint32 cookie)
+{
+ GVariant *reply;
+ GError *error = NULL;
+
+ reply = g_dbus_connection_call_sync (connection,
+ DBUS_SERVICE,
+ DBUS_PATH,
+ DBUS_INTERFACE,
+ "UnInhibit",
+ g_variant_new ("(u)",
+ cookie),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error) {
+ g_warning ("Uninhibiting power management failed: %s", error->message);
+ g_error_free (error);
+ }
+ g_variant_unref (reply);
+}
+
+GDBusConnection *
+parole_power_manager_dbus_init ()
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (error) {
+ g_warning ("Failed to get session bus: %s", error->message);
+ g_error_free (error);
+ }
+ return connection;
+}
diff --git a/src/common/parole-powermanager.h b/src/common/parole-powermanager.h
new file mode 100644
index 0000000..2779094
--- /dev/null
+++ b/src/common/parole-powermanager.h
@@ -0,0 +1,38 @@
+/*
+ * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2012-2017 Sean Davis <smd.seandavis at gmail.com>
+ * * Copyright (C) 2012-2017 Simon Steinbeiß <ochosi at xfce.org
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SRC_COMMON_PAROLE_POWERMANAGER_H_
+#define SRC_COMMON_PAROLE_POWERMANAGER_H_
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+guint32 parole_power_manager_inhibit (GDBusConnection *connection);
+void parole_power_manager_uninhibit (GDBusConnection *connection,
+ guint32 cookie);
+GDBusConnection *parole_power_manager_dbus_init ();
+
+G_END_DECLS
+
+#endif /* SRC_COMMON_PAROLE_POWERMANAGER_H_ */
diff --git a/src/parole-player.c b/src/parole-player.c
index 1c1781b..53ac841 100644
--- a/src/parole-player.c
+++ b/src/parole-player.c
@@ -49,6 +49,7 @@
#include "src/common/parole-common.h"
#include "src/common/parole-rc-utils.h"
#include "src/common/parole-screensaver.h"
+#include "src/common/parole-powermanager.h"
#include "src/dbus/parole-dbus.h"
@@ -338,6 +339,8 @@ struct ParolePlayerPrivate {
ParoleMediaList *list;
ParoleDisc *disc;
ParoleScreenSaver *screen_saver;
+ GDBusConnection *connection;
+ guint32 inhibit_cookie;
ParoleConf *conf;
ParoleConfDialog *settings_dialog;
@@ -1546,6 +1549,9 @@ parole_player_reset_saver_changed(ParolePlayer *player, const ParoleStream *stre
if ( !reset_saver ) {
parole_screen_saver_uninhibit(player->priv->screen_saver, GTK_WINDOW(player->priv->window));
+ if (player->priv->inhibit_cookie > 0)
+ parole_power_manager_uninhibit (player->priv->connection, player->priv->inhibit_cookie);
+ player->priv->inhibit_cookie = 0;
} else if ( player->priv->state == PAROLE_STATE_PLAYING ) {
gboolean has_video;
@@ -1554,10 +1560,15 @@ parole_player_reset_saver_changed(ParolePlayer *player, const ParoleStream *stre
NULL);
if ( has_video ) {
- parole_screen_saver_inhibit(player->priv->screen_saver, GTK_WINDOW(player->priv->window));
+ parole_screen_saver_inhibit (player->priv->screen_saver, GTK_WINDOW(player->priv->window));
+ if (player->priv->inhibit_cookie == 0)
+ player->priv->inhibit_cookie = parole_power_manager_inhibit (player->priv->connection);
}
} else {
parole_screen_saver_uninhibit(player->priv->screen_saver, GTK_WINDOW(player->priv->window));
+ if (player->priv->inhibit_cookie > 0)
+ parole_power_manager_uninhibit (player->priv->connection, player->priv->inhibit_cookie);
+ player->priv->inhibit_cookie = 0;
}
}
@@ -2407,6 +2418,7 @@ parole_player_finalize(GObject *object) {
g_object_unref(player->priv->video_filter);
g_object_unref(player->priv->disc);
g_object_unref(player->priv->screen_saver);
+ g_object_unref(player->priv->connection);
if ( player->priv->client_id )
g_free(player->priv->client_id);
@@ -3144,6 +3156,10 @@ parole_player_init(ParolePlayer *player) {
/* ParoleScreenSaver */
player->priv->screen_saver = parole_screen_saver_new();
+ /* PowerManagement Inhibit cookie */
+ player->priv->connection = parole_power_manager_dbus_init ();
+ player->priv->inhibit_cookie = 0;
+
/* ParoleMediaList */
player->priv->list = PAROLE_MEDIA_LIST(parole_media_list_get());
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list