summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2018-02-27 13:56:14 -0700
committerJohn Stebbins <[email protected]>2018-02-27 13:56:14 -0700
commit369b4f6b65b1fe376fa3ec3b62285c38181829ba (patch)
treef137bf9162c7554ee2da02010ce40987321b4f59
parent236de1df7f803873df720b3103b07f13e5a0ffd1 (diff)
LinGui: add support for GtkApplication suspend inhibit/uninhibit
This is a new API since GTK 3.4. Use it instead of DBUS when available.
-rw-r--r--gtk/src/callbacks.c1062
-rw-r--r--gtk/src/callbacks.h2
2 files changed, 546 insertions, 518 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c
index 79b6f518a..0bdb9c08b 100644
--- a/gtk/src/callbacks.c
+++ b/gtk/src/callbacks.c
@@ -103,6 +103,548 @@ static gboolean ghb_can_suspend_gpm();
static void ghb_suspend_gpm();
static gboolean appcast_busy = FALSE;
+#if !defined(_WIN32)
+#define GPM_DBUS_PM_SERVICE "org.freedesktop.PowerManagement"
+#define GPM_DBUS_PM_PATH "/org/freedesktop/PowerManagement"
+#define GPM_DBUS_PM_INTERFACE "org.freedesktop.PowerManagement"
+#define GPM_DBUS_INHIBIT_PATH "/org/freedesktop/PowerManagement/Inhibit"
+#define GPM_DBUS_INHIBIT_INTERFACE "org.freedesktop.PowerManagement.Inhibit"
+#endif
+
+static gboolean
+ghb_can_suspend_gpm()
+{
+ gboolean can_suspend = FALSE;
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_can_suspend_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return FALSE;
+ }
+ res = dbus_g_proxy_call(proxy, "CanSuspend", &error,
+ G_TYPE_INVALID,
+ G_TYPE_BOOLEAN, &can_suspend,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("CanSuspend failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("CanSuspend failed");
+ // Try to shutdown anyway
+ can_suspend = TRUE;
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+#endif
+ return can_suspend;
+}
+
+static void
+ghb_suspend_gpm()
+{
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_suspend_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return;
+ }
+ res = dbus_g_proxy_call(proxy, "Suspend", &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("Suspend failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("Suspend failed");
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+#endif
+}
+
+#if !defined(_WIN32)
+static gboolean
+ghb_can_shutdown_gpm()
+{
+ gboolean can_shutdown = FALSE;
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_can_shutdown_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return FALSE;
+ }
+ res = dbus_g_proxy_call(proxy, "CanShutdown", &error,
+ G_TYPE_INVALID,
+ G_TYPE_BOOLEAN, &can_shutdown,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("CanShutdown failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("CanShutdown failed");
+ // Try to shutdown anyway
+ can_shutdown = TRUE;
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+ return can_shutdown;
+}
+#endif
+
+#if !defined(_WIN32)
+static void
+ghb_shutdown_gpm()
+{
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_shutdown_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return;
+ }
+ res = dbus_g_proxy_call(proxy, "Shutdown", &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_warning("Shutdown failed: %s", error->message);
+ g_error_free(error);
+ }
+ else
+ g_warning("Shutdown failed");
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+}
+#endif
+
+guint
+ghb_inhibit_gpm()
+{
+ guint cookie = -1;
+
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+ g_debug("ghb_inhibit_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return 0;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return 0;
+ }
+ res = dbus_g_proxy_call(proxy, "Inhibit", &error,
+ G_TYPE_STRING, "ghb",
+ G_TYPE_STRING, "Encoding",
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &cookie,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_error_free(error);
+ }
+ cookie = -1;
+ }
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+#endif
+
+ return cookie;
+}
+
+void
+ghb_uninhibit_gpm(guint cookie)
+{
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+ g_debug("ghb_uninhibit_gpm() cookie %u", cookie);
+
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
+ GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return;
+ }
+ res = dbus_g_proxy_call(proxy, "UnInhibit", &error,
+ G_TYPE_UINT, cookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_error_free(error);
+ }
+ }
+ dbus_g_connection_unref(conn);
+ g_object_unref(G_OBJECT(proxy));
+#endif
+}
+
+#if !defined(_WIN32)
+// For inhibit and shutdown
+#define GPM_DBUS_SM_SERVICE "org.gnome.SessionManager"
+#define GPM_DBUS_SM_PATH "/org/gnome/SessionManager"
+#define GPM_DBUS_SM_INTERFACE "org.gnome.SessionManager"
+#endif
+
+static gboolean
+ghb_can_shutdown_gsm()
+{
+ gboolean can_shutdown = FALSE;
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
+ GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return FALSE;
+ }
+ res = dbus_g_proxy_call(proxy, "CanShutdown", &error,
+ G_TYPE_INVALID,
+ G_TYPE_BOOLEAN, &can_shutdown,
+ G_TYPE_INVALID);
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_error_free(error);
+ }
+ // Try to shutdown anyway
+ can_shutdown = TRUE;
+ // Try the gpm version
+ return ghb_can_shutdown_gpm();
+ }
+#endif
+ return can_shutdown;
+}
+
+static void
+ghb_shutdown_gsm()
+{
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+
+ g_debug("ghb_shutdown_gpm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
+ GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return;
+ }
+ res = dbus_g_proxy_call(proxy, "Shutdown", &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_error_free(error);
+ }
+ // Try the gpm version
+ ghb_shutdown_gpm();
+ }
+#endif
+}
+
+guint
+ghb_inhibit_gsm(signal_user_data_t *ud)
+{
+ guint cookie = -1;
+
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+ guint xid;
+ GtkWidget *widget;
+
+ g_debug("ghb_inhibit_gsm()");
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return -1;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
+ GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return -1;
+ }
+ widget = GHB_WIDGET(ud->builder, "hb_window");
+ xid = GDK_WINDOW_XID(gtk_widget_get_window(widget));
+ res = dbus_g_proxy_call(proxy, "Inhibit", &error,
+ G_TYPE_STRING, "ghb",
+ G_TYPE_UINT, xid,
+ G_TYPE_STRING, "Encoding",
+ G_TYPE_UINT, 1 | 4,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &cookie,
+ G_TYPE_INVALID);
+ g_object_unref(G_OBJECT(proxy));
+ dbus_g_connection_unref(conn);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_error_free(error);
+ }
+ cookie = -1;
+ }
+#endif
+
+ return cookie;
+}
+
+void
+ghb_uninhibit_gsm(guint cookie)
+{
+#if !defined(_WIN32)
+ DBusGConnection *conn;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+ gboolean res;
+
+ g_debug("ghb_uninhibit_gsm() cookie %u", cookie);
+
+ conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL)
+ {
+ g_warning("DBUS cannot connect: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
+ GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
+ if (proxy == NULL)
+ {
+ g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
+ dbus_g_connection_unref(conn);
+ return;
+ }
+ res = dbus_g_proxy_call(proxy, "Uninhibit", &error,
+ G_TYPE_UINT, cookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!res)
+ {
+ if (error != NULL)
+ {
+ g_error_free(error);
+ }
+ }
+ dbus_g_connection_unref(conn);
+ g_object_unref(G_OBJECT(proxy));
+#endif
+}
+
+enum {
+ GHB_SUSPEND_UNINHIBITED = 0,
+ GHB_SUSPEND_INHIBITED_GPM,
+ GHB_SUSPEND_INHIBITED_GSM,
+ GHB_SUSPEND_INHIBITED_GTK
+};
+static int suspend_inhibited = GHB_SUSPEND_UNINHIBITED;
+static guint suspend_cookie;
+
+void
+ghb_inhibit_suspend(signal_user_data_t *ud)
+{
+ if (suspend_inhibited != GHB_SUSPEND_UNINHIBITED)
+ {
+ // Already inhibited
+ return;
+ }
+#if GTK_CHECK_VERSION(3, 4, 0)
+ suspend_cookie = gtk_application_inhibit(ud->app, NULL,
+ GTK_APPLICATION_INHIBIT_SUSPEND, "Encoding");
+ if (suspend_cookie != 0)
+ {
+ suspend_inhibited = GHB_SUSPEND_INHIBITED_GTK;
+ return;
+ }
+#else
+ suspend_cookie = ghb_inhibit_gsm(ud);
+ if (suspend_cookie != -1)
+ {
+ suspend_inhibited = GHB_SUSPEND_INHIBITED_GSM;
+ return;
+ }
+ suspend_cookie = ghb_inhibit_gpm(ud);
+ if (suspend_cookie != -1)
+ {
+ suspend_inhibited = GHB_SUSPEND_INHIBITED_GPM;
+ return;
+ }
+#endif
+}
+
+void
+ghb_uninhibit_suspend(signal_user_data_t *ud)
+{
+ switch (suspend_inhibited)
+ {
+#if GTK_CHECK_VERSION(3, 4, 0)
+ case GHB_SUSPEND_INHIBITED_GTK:
+ gtk_application_uninhibit(ud->app, suspend_cookie);
+ break;
+#endif
+
+ case GHB_SUSPEND_INHIBITED_GPM:
+ ghb_uninhibit_gpm(suspend_cookie);
+ break;
+
+ case GHB_SUSPEND_INHIBITED_GSM:
+ ghb_uninhibit_gsm(suspend_cookie);
+ break;
+
+ default:
+ break;
+ }
+ suspend_inhibited = GHB_SUSPEND_UNINHIBITED;
+}
+
// This is a dependency map used for greying widgets
// that are dependent on the state of another widget.
// The enable_value comes from the values that are
@@ -3442,7 +3984,8 @@ ghb_start_next_job(signal_user_data_t *ud)
status = ghb_dict_get_int(uiDict, "job_status");
if (status == GHB_QUEUE_PENDING)
{
- ghb_inhibit_gsm(ud);
+ ghb_inhibit_suspend(ud);
+printf("inhibited %d\n", suspend_inhibited);
submit_job(ud, queueDict);
ghb_update_pending(ud);
@@ -3464,7 +4007,7 @@ ghb_start_next_job(signal_user_data_t *ud)
}
}
// Nothing pending
- ghb_uninhibit_gsm();
+ ghb_uninhibit_suspend(ud);
ghb_notify_done(ud);
ghb_update_pending(ud);
gtk_widget_hide(progress);
@@ -3836,7 +4379,7 @@ ghb_backend_events(signal_user_data_t *ud)
}
else
{
- ghb_uninhibit_gsm();
+ ghb_uninhibit_suspend(ud);
gtk_widget_hide(GTK_WIDGET(progress));
ghb_dict_set_bool(ud->globals, "SkipDiskFreeCheck", FALSE);
}
@@ -4921,519 +5464,6 @@ drive_changed_cb(GVolumeMonitor *gvm, GDrive *gd, signal_user_data_t *ud)
}
#endif
-#if !defined(_WIN32)
-#define GPM_DBUS_PM_SERVICE "org.freedesktop.PowerManagement"
-#define GPM_DBUS_PM_PATH "/org/freedesktop/PowerManagement"
-#define GPM_DBUS_PM_INTERFACE "org.freedesktop.PowerManagement"
-#define GPM_DBUS_INHIBIT_PATH "/org/freedesktop/PowerManagement/Inhibit"
-#define GPM_DBUS_INHIBIT_INTERFACE "org.freedesktop.PowerManagement.Inhibit"
-static gboolean gpm_inhibited = FALSE;
-static guint gpm_cookie = -1;
-#endif
-
-static gboolean
-ghb_can_suspend_gpm()
-{
- gboolean can_suspend = FALSE;
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
-
- g_debug("ghb_can_suspend_gpm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return FALSE;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
- GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
- dbus_g_connection_unref(conn);
- return FALSE;
- }
- res = dbus_g_proxy_call(proxy, "CanSuspend", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &can_suspend,
- G_TYPE_INVALID);
- if (!res)
- {
- if (error != NULL)
- {
- g_warning("CanSuspend failed: %s", error->message);
- g_error_free(error);
- }
- else
- g_warning("CanSuspend failed");
- // Try to shutdown anyway
- can_suspend = TRUE;
- }
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
-#endif
- return can_suspend;
-}
-
-static void
-ghb_suspend_gpm()
-{
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
-
- g_debug("ghb_suspend_gpm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
- GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
- dbus_g_connection_unref(conn);
- return;
- }
- res = dbus_g_proxy_call(proxy, "Suspend", &error,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!res)
- {
- if (error != NULL)
- {
- g_warning("Suspend failed: %s", error->message);
- g_error_free(error);
- }
- else
- g_warning("Suspend failed");
- }
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
-#endif
-}
-
-#if !defined(_WIN32)
-static gboolean
-ghb_can_shutdown_gpm()
-{
- gboolean can_shutdown = FALSE;
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
-
- g_debug("ghb_can_shutdown_gpm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return FALSE;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
- GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
- dbus_g_connection_unref(conn);
- return FALSE;
- }
- res = dbus_g_proxy_call(proxy, "CanShutdown", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &can_shutdown,
- G_TYPE_INVALID);
- if (!res)
- {
- if (error != NULL)
- {
- g_warning("CanShutdown failed: %s", error->message);
- g_error_free(error);
- }
- else
- g_warning("CanShutdown failed");
- // Try to shutdown anyway
- can_shutdown = TRUE;
- }
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
- return can_shutdown;
-}
-#endif
-
-#if !defined(_WIN32)
-static void
-ghb_shutdown_gpm()
-{
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
-
- g_debug("ghb_shutdown_gpm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
- GPM_DBUS_PM_PATH, GPM_DBUS_PM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
- dbus_g_connection_unref(conn);
- return;
- }
- res = dbus_g_proxy_call(proxy, "Shutdown", &error,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!res)
- {
- if (error != NULL)
- {
- g_warning("Shutdown failed: %s", error->message);
- g_error_free(error);
- }
- else
- g_warning("Shutdown failed");
- }
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
-}
-#endif
-
-void
-ghb_inhibit_gpm()
-{
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
-
- if (gpm_inhibited)
- {
- // Already inhibited
- return;
- }
- g_debug("ghb_inhibit_gpm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
- GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
- dbus_g_connection_unref(conn);
- return;
- }
- res = dbus_g_proxy_call(proxy, "Inhibit", &error,
- G_TYPE_STRING, "ghb",
- G_TYPE_STRING, "Encoding",
- G_TYPE_INVALID,
- G_TYPE_UINT, &gpm_cookie,
- G_TYPE_INVALID);
- gpm_inhibited = TRUE;
- if (!res)
- {
- if (error != NULL)
- {
- g_warning("Inhibit failed: %s", error->message);
- g_error_free(error);
- gpm_cookie = -1;
- }
- else
- g_warning("Inhibit failed");
- gpm_cookie = -1;
- gpm_inhibited = FALSE;
- }
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
-#endif
-}
-
-void
-ghb_uninhibit_gpm()
-{
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
- g_debug("ghb_uninhibit_gpm() gpm_cookie %u", gpm_cookie);
-
- if (!gpm_inhibited)
- {
- // Not inhibited
- return;
- }
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_PM_SERVICE,
- GPM_DBUS_INHIBIT_PATH, GPM_DBUS_INHIBIT_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_PM_SERVICE);
- dbus_g_connection_unref(conn);
- return;
- }
- res = dbus_g_proxy_call(proxy, "UnInhibit", &error,
- G_TYPE_UINT, gpm_cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!res)
- {
- if (error != NULL)
- {
- g_warning("UnInhibit failed: %s", error->message);
- g_error_free(error);
- }
- else
- g_warning("UnInhibit failed");
- }
- gpm_inhibited = FALSE;
- dbus_g_connection_unref(conn);
- g_object_unref(G_OBJECT(proxy));
-#endif
-}
-
-#if !defined(_WIN32)
-
-// For inhibit and shutdown
-#define GPM_DBUS_SM_SERVICE "org.gnome.SessionManager"
-#define GPM_DBUS_SM_PATH "/org/gnome/SessionManager"
-#define GPM_DBUS_SM_INTERFACE "org.gnome.SessionManager"
-
-#endif
-
-static gboolean
-ghb_can_shutdown_gsm()
-{
- gboolean can_shutdown = FALSE;
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
-
- g_debug("ghb_can_shutdown_gpm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return FALSE;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
- GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
- dbus_g_connection_unref(conn);
- return FALSE;
- }
- res = dbus_g_proxy_call(proxy, "CanShutdown", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &can_shutdown,
- G_TYPE_INVALID);
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
- if (!res)
- {
- if (error != NULL)
- {
- g_error_free(error);
- }
- // Try to shutdown anyway
- can_shutdown = TRUE;
- // Try the gpm version
- return ghb_can_shutdown_gpm();
- }
-#endif
- return can_shutdown;
-}
-
-static void
-ghb_shutdown_gsm()
-{
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
-
- g_debug("ghb_shutdown_gpm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
- GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
- dbus_g_connection_unref(conn);
- return;
- }
- res = dbus_g_proxy_call(proxy, "Shutdown", &error,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
- if (!res)
- {
- if (error != NULL)
- {
- g_error_free(error);
- }
- // Try the gpm version
- ghb_shutdown_gpm();
- }
-#endif
-}
-
-void
-ghb_inhibit_gsm(signal_user_data_t *ud)
-{
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
- guint xid;
- GtkWidget *widget;
-
-
- if (gpm_inhibited)
- {
- // Already inhibited
- return;
- }
- g_debug("ghb_inhibit_gsm()");
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
- GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
- dbus_g_connection_unref(conn);
- return;
- }
- widget = GHB_WIDGET(ud->builder, "hb_window");
- xid = GDK_WINDOW_XID(gtk_widget_get_window(widget));
- res = dbus_g_proxy_call(proxy, "Inhibit", &error,
- G_TYPE_STRING, "ghb",
- G_TYPE_UINT, xid,
- G_TYPE_STRING, "Encoding",
- G_TYPE_UINT, 1 | 4,
- G_TYPE_INVALID,
- G_TYPE_UINT, &gpm_cookie,
- G_TYPE_INVALID);
- gpm_inhibited = TRUE;
- g_object_unref(G_OBJECT(proxy));
- dbus_g_connection_unref(conn);
- if (!res)
- {
- if (error != NULL)
- {
- g_error_free(error);
- gpm_cookie = -1;
- }
- gpm_cookie = -1;
- gpm_inhibited = FALSE;
- // Try the gpm version
- ghb_inhibit_gpm();
- }
-#endif
-}
-
-void
-ghb_uninhibit_gsm()
-{
-#if !defined(_WIN32)
- DBusGConnection *conn;
- DBusGProxy *proxy;
- GError *error = NULL;
- gboolean res;
-
- g_debug("ghb_uninhibit_gsm() gpm_cookie %u", gpm_cookie);
-
- if (!gpm_inhibited)
- {
- // Not inhibited
- return;
- }
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL)
- {
- g_warning("DBUS cannot connect: %s", error->message);
- g_error_free(error);
- return;
- }
- proxy = dbus_g_proxy_new_for_name(conn, GPM_DBUS_SM_SERVICE,
- GPM_DBUS_SM_PATH, GPM_DBUS_SM_INTERFACE);
- if (proxy == NULL)
- {
- g_warning("Could not get DBUS proxy: %s", GPM_DBUS_SM_SERVICE);
- dbus_g_connection_unref(conn);
- return;
- }
- res = dbus_g_proxy_call(proxy, "Uninhibit", &error,
- G_TYPE_UINT, gpm_cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- dbus_g_connection_unref(conn);
- g_object_unref(G_OBJECT(proxy));
- if (!res)
- {
- if (error != NULL)
- {
- g_error_free(error);
- }
- ghb_uninhibit_gpm();
- }
- gpm_inhibited = FALSE;
-#endif
-}
-
G_MODULE_EXPORT gboolean
easter_egg_cb(
GtkWidget *widget,
diff --git a/gtk/src/callbacks.h b/gtk/src/callbacks.h
index 472ceea13..80530762e 100644
--- a/gtk/src/callbacks.h
+++ b/gtk/src/callbacks.h
@@ -68,8 +68,6 @@ void ghb_do_scan( signal_user_data_t *ud, const gchar *filename,
gint titlenum, gboolean force);
void ghb_log(gchar *log, ...);
gpointer ghb_check_update(signal_user_data_t *ud);
-void ghb_uninhibit_gsm(void);
-void ghb_inhibit_gsm(signal_user_data_t *ud);
#if defined(_WIN32)
void wm_drive_changed(MSG *msg, signal_user_data_t *ud);
#endif