diff options
author | Bastien Nocera <hadess@hadess.net> | 2019-12-03 22:32:23 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2019-12-13 00:44:28 +0100 |
commit | 33c10e91806782fe2ab65527cbbb17abd46efdcf (patch) | |
tree | c3221cc168ef48e62f9ad6b1bb4539805d313a20 | |
parent | c7dec4130d817d6588689a76b8bcae0a977c8fce (diff) | |
download | gnome-shell-33c10e91806782fe2ab65527cbbb17abd46efdcf.tar.gz |
shell: Prime the GPUs property cache for switcheroo-control
See: https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/781
-rw-r--r-- | src/shell-global.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/shell-global.c b/src/shell-global.c index d7cbbd61f..f3845277c 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -126,6 +126,29 @@ G_DEFINE_TYPE(ShellGlobal, shell_global, G_TYPE_OBJECT); static guint shell_global_signals [LAST_SIGNAL] = { 0 }; static void +got_switcheroo_control_gpus_property_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + ShellGlobal *global; + GError *error = NULL; + GVariant *gpus; + + gpus = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), + res, &error); + if (!gpus) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_debug ("Could not get GPUs property from switcheroo-control: %s", error->message); + g_clear_error (&error); + return; + } + + global = user_data; + g_dbus_proxy_set_cached_property (global->switcheroo_control, "GPUs", gpus); +} + +static void switcheroo_control_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) @@ -133,6 +156,7 @@ switcheroo_control_ready_cb (GObject *source_object, ShellGlobal *global; GError *error = NULL; ShellNetHadessSwitcherooControl *control; + g_auto(GStrv) cached_props = NULL; control = shell_net_hadess_switcheroo_control_proxy_new_for_bus_finish (res, &error); if (!control) @@ -146,6 +170,25 @@ switcheroo_control_ready_cb (GObject *source_object, global = user_data; global->switcheroo_control = G_DBUS_PROXY (control); g_debug ("Got switcheroo-control proxy successfully"); + + cached_props = g_dbus_proxy_get_cached_property_names (global->switcheroo_control); + if (cached_props != NULL && g_strv_contains ((const gchar * const *) cached_props, "GPUs")) + return; + + g_dbus_connection_call (g_dbus_proxy_get_connection (global->switcheroo_control), + g_dbus_proxy_get_name (global->switcheroo_control), + g_dbus_proxy_get_object_path (global->switcheroo_control), + "org.freedesktop.DBus.Properties", + "Get", + g_variant_new ("(ss)", + g_dbus_proxy_get_interface_name (global->switcheroo_control), + "GPUs"), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + global->switcheroo_cancellable, + got_switcheroo_control_gpus_property_cb, + user_data); } static void |