[gnome-shell/wip/hadess/add-nvidia-other-gpu-support: 3/5] shell: Add API to access switcheroo-control D-Bus proxy
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/hadess/add-nvidia-other-gpu-support: 3/5] shell: Add API to access switcheroo-control D-Bus proxy
- Date: Thu, 12 Dec 2019 23:44:53 +0000 (UTC)
commit c7dec4130d817d6588689a76b8bcae0a977c8fce
Author: Bastien Nocera <hadess hadess net>
Date: Tue Dec 3 12:07:54 2019 +0100
shell: Add API to access switcheroo-control D-Bus proxy
See: https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/781
src/shell-global.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/shell-global.h | 3 +++
2 files changed, 69 insertions(+)
---
diff --git a/src/shell-global.c b/src/shell-global.c
index 05e632e275..d7cbbd61f3 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -48,6 +48,7 @@
#include "shell-wm.h"
#include "shell-util.h"
#include "st.h"
+#include "switcheroo-control.h"
static ShellGlobal *the_object = NULL;
@@ -85,6 +86,9 @@ struct _ShellGlobal {
gboolean has_modal;
gboolean frame_timestamps;
gboolean frame_finish_timestamp;
+
+ GDBusProxy *switcheroo_control;
+ GCancellable *switcheroo_cancellable;
};
enum {
@@ -106,6 +110,7 @@ enum {
PROP_FOCUS_MANAGER,
PROP_FRAME_TIMESTAMPS,
PROP_FRAME_FINISH_TIMESTAMP,
+ PROP_SWITCHEROO_CONTROL,
};
/* Signals */
@@ -120,6 +125,29 @@ G_DEFINE_TYPE(ShellGlobal, shell_global, G_TYPE_OBJECT);
static guint shell_global_signals [LAST_SIGNAL] = { 0 };
+static void
+switcheroo_control_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ShellGlobal *global;
+ GError *error = NULL;
+ ShellNetHadessSwitcherooControl *control;
+
+ control = shell_net_hadess_switcheroo_control_proxy_new_for_bus_finish (res, &error);
+ if (!control)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_debug ("Could not get switcheroo-control GDBusProxy: %s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ global = user_data;
+ global->switcheroo_control = G_DBUS_PROXY (control);
+ g_debug ("Got switcheroo-control proxy successfully");
+}
+
static void
shell_global_set_property(GObject *object,
guint prop_id,
@@ -214,6 +242,9 @@ shell_global_get_property(GObject *object,
case PROP_FRAME_FINISH_TIMESTAMP:
g_value_set_boolean (value, global->frame_finish_timestamp);
break;
+ case PROP_SWITCHEROO_CONTROL:
+ g_value_set_object (value, global->switcheroo_control);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -313,6 +344,15 @@ shell_global_init (ShellGlobal *global)
global->save_ops = g_hash_table_new_full (g_file_hash,
(GEqualFunc) g_file_equal,
g_object_unref, g_object_unref);
+
+ global->switcheroo_cancellable = g_cancellable_new ();
+ shell_net_hadess_switcheroo_control_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "net.hadess.SwitcherooControl",
+ "/net/hadess/SwitcherooControl",
+ global->switcheroo_cancellable,
+ switcheroo_control_ready_cb,
+ global);
}
static void
@@ -325,6 +365,9 @@ shell_global_finalize (GObject *object)
the_object = NULL;
+ g_cancellable_cancel (global->switcheroo_cancellable);
+ g_clear_object (&global->switcheroo_cancellable);
+
g_clear_object (&global->userdatadir_path);
g_clear_object (&global->runtime_state_path);
@@ -481,6 +524,13 @@ shell_global_class_init (ShellGlobalClass *klass)
"Whether at the end of a frame to call glFinish and
log paintCompletedTimestamp",
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class,
+ PROP_SWITCHEROO_CONTROL,
+ g_param_spec_object ("switcheroo-control",
+ "switcheroo-control",
+ "D-Bus Proxy for switcheroo-control daemon",
+ G_TYPE_DBUS_PROXY,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
/*
@@ -1264,6 +1314,22 @@ shell_global_sync_pointer (ShellGlobal *global)
clutter_event_put ((ClutterEvent *)&event);
}
+/**
+ * _shell_global_get_switcheroo_control: (skip)
+ * @global: A #ShellGlobal
+ *
+ * Get the global #GDBusProxy instance for the switcheroo-control
+ * daemon.
+ *
+ * Return value: (transfer none): the #GDBusProxy for the daemon,
+ * or %NULL on error.
+ */
+GDBusProxy *
+_shell_global_get_switcheroo_control (ShellGlobal *global)
+{
+ return global->switcheroo_control;
+}
+
/**
* shell_global_get_settings:
* @global: A #ShellGlobal
diff --git a/src/shell-global.h b/src/shell-global.h
index ad67c72c07..860e60ab6c 100644
--- a/src/shell-global.h
+++ b/src/shell-global.h
@@ -66,6 +66,9 @@ void shell_global_run_at_leisure (ShellGlobal *global,
/* Misc utilities / Shell API */
void shell_global_sync_pointer (ShellGlobal *global);
+GDBusProxy *
+ _shell_global_get_switcheroo_control (ShellGlobal *global);
+
GAppLaunchContext *
shell_global_create_app_launch_context (ShellGlobal *global,
guint32 timestamp,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]