[gnome-shell/wip/hadess/always-launch-discrete-gpu: 3/4] shell-app: Respect X-KDE-RunOnDiscreteGpu when launching apps



commit 8c53a1e0897e0d1f2ef62dbc11677d4955bfd127
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Oct 23 11:48:19 2019 +0200

    shell-app: Respect X-KDE-RunOnDiscreteGpu when launching apps
    
    If whether to launch on the discrete GPU or the integrated one isn't
    passed down to us, check whether the application prefers to be launched
    on the discrete GPU.
    
    See: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1804

 src/shell-app.c | 32 +++++++++++++++++++++++++++-----
 src/shell-app.h |  2 +-
 2 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/shell-app.c b/src/shell-app.c
index 63f3edeabc..71525ef44c 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -509,7 +509,7 @@ shell_app_activate_full (ShellApp      *app,
       case SHELL_APP_STATE_STOPPED:
         {
           GError *error = NULL;
-          if (!shell_app_launch (app, timestamp, workspace, FALSE, &error))
+          if (!shell_app_launch (app, timestamp, workspace, -1, &error))
             {
               char *msg;
               msg = g_strdup_printf (_("Failed to launch ā€œ%sā€"), shell_app_get_name (app));
@@ -584,7 +584,7 @@ shell_app_open_new_window (ShellApp      *app,
    * instance (Firefox).  There are a few less-sensical cases such
    * as say Pidgin.
    */
-  shell_app_launch (app, 0, workspace, FALSE, NULL);
+  shell_app_launch (app, 0, workspace, -1, NULL);
 }
 
 /**
@@ -1255,18 +1255,37 @@ wait_pid (GDesktopAppInfo *appinfo,
   g_child_watch_add (pid, (GChildWatchFunc) g_spawn_close_pid, NULL);
 }
 
+static gboolean
+get_with_discrete_gpu (ShellApp *app,
+                       int       discrete_gpu)
+{
+  switch (discrete_gpu)
+    {
+      case 0:
+        return FALSE;
+      case 1:
+        return TRUE;
+      case -1:
+        return g_desktop_app_info_get_boolean (app->info,
+                                               "X-KDE-RunOnDiscreteGpu");
+      default:
+        g_assert_not_reached();
+    }
+}
+
 /**
  * shell_app_launch:
  * @timestamp: Event timestamp, or 0 for current event timestamp
  * @workspace: Start on this workspace, or -1 for default
- * @discrete_gpu: Whether to start on the discrete GPU
+ * @discrete_gpu: 1 to start the application on the discrete GPU, 0 to
+ * start it on the integrated GPU, -1 to respect the [X-KDE-RunOnDiscreteGpu property](FIXME)
  * @error: A #GError
  */
 gboolean
 shell_app_launch (ShellApp     *app,
                   guint         timestamp,
                   int           workspace,
-                  gboolean      discrete_gpu,
+                  int           discrete_gpu,
                   GError      **error)
 {
   ShellGlobal *global;
@@ -1289,7 +1308,10 @@ shell_app_launch (ShellApp     *app,
 
   global = shell_global_get ();
   context = shell_global_create_app_launch_context (global, timestamp, workspace);
-  g_app_launch_context_setenv (context, "DRI_PRIME", discrete_gpu ? "1" : "0");
+  /* FIXME: this should probably check whether we're on a dual-GPU system */
+  g_app_launch_context_setenv (context,
+                               "DRI_PRIME",
+                               get_with_discrete_gpu (app, discrete_gpu) ? "1" : "0");
 
   /* Set LEAVE_DESCRIPTORS_OPEN in order to use an optimized gspawn
    * codepath. The shell's open file descriptors should be marked CLOEXEC
diff --git a/src/shell-app.h b/src/shell-app.h
index 8a09b642dc..d9eb547036 100644
--- a/src/shell-app.h
+++ b/src/shell-app.h
@@ -54,7 +54,7 @@ gboolean shell_app_is_on_workspace (ShellApp *app, MetaWorkspace *workspace);
 gboolean shell_app_launch (ShellApp     *app,
                            guint         timestamp,
                            int           workspace,
-                           gboolean      discrete_gpu,
+                           int           discrete_gpu,
                            GError      **error);
 
 void shell_app_launch_action (ShellApp        *app,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]