Blob Blame History Raw
From c4e07c78940aa873a0258d45da7f417f483b8873 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofourdan@redhat.com>
Date: Fri, 28 Sep 2018 10:48:31 +0200
Subject: [PATCH 08/12] screen-cast-session: Add support for RecordWindow

Add support for the RecordWindow screencast method, casting the
currently focused window.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/306
(cherry picked from commit ec25f3a6b7923627484c6c1c65f8af0bebe56423)
---
 src/backends/meta-screen-cast-session.c | 52 +++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/src/backends/meta-screen-cast-session.c b/src/backends/meta-screen-cast-session.c
index e1b6393..3ee02c5 100644
--- a/src/backends/meta-screen-cast-session.c
+++ b/src/backends/meta-screen-cast-session.c
@@ -26,9 +26,11 @@
 
 #include "backends/meta-backend-private.h"
 #include "backends/meta-dbus-session-watcher.h"
+#include "backends/meta-remote-access-controller-private.h"
 #include "backends/meta-screen-cast-monitor-stream.h"
 #include "backends/meta-screen-cast-stream.h"
-#include "backends/meta-remote-access-controller-private.h"
+#include "backends/meta-screen-cast-window-stream.h"
+#include "core/display-private.h"
 
 #define META_SCREEN_CAST_SESSION_DBUS_PATH "/org/gnome/Mutter/ScreenCast/Session"
 
@@ -333,6 +335,14 @@ handle_record_window (MetaDBusScreenCastSession *skeleton,
                       GVariant                  *properties_variant)
 {
   MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (skeleton);
+  GDBusInterfaceSkeleton *interface_skeleton;
+  GDBusConnection *connection;
+  MetaWindow *window;
+  GError *error = NULL;
+  MetaDisplay *display;
+  MetaScreenCastWindowStream *window_stream;
+  MetaScreenCastStream *stream;
+  char *stream_path;
 
   if (!check_permission (session, invocation))
     {
@@ -342,9 +352,43 @@ handle_record_window (MetaDBusScreenCastSession *skeleton,
       return TRUE;
     }
 
-  g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
-                                         G_DBUS_ERROR_FAILED,
-                                         "Recording a window not yet supported");
+  display = meta_get_display ();
+  window = meta_display_get_focus_window (display);
+  if (!window)
+    {
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+                                             G_DBUS_ERROR_FAILED,
+                                             "Window not found");
+      return TRUE;
+    }
+
+  interface_skeleton = G_DBUS_INTERFACE_SKELETON (skeleton);
+  connection = g_dbus_interface_skeleton_get_connection (interface_skeleton);
+
+  window_stream = meta_screen_cast_window_stream_new (connection,
+                                                      window,
+                                                      &error);
+  if (!window_stream)
+    {
+      g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+                                             G_DBUS_ERROR_FAILED,
+                                             "Failed to record window: %s",
+                                             error->message);
+      g_error_free (error);
+      return TRUE;
+    }
+
+  stream = META_SCREEN_CAST_STREAM (window_stream);
+  stream_path = meta_screen_cast_stream_get_object_path (stream);
+
+  session->streams = g_list_append (session->streams, stream);
+
+  g_signal_connect (stream, "closed", G_CALLBACK (on_stream_closed), session);
+
+  meta_dbus_screen_cast_session_complete_record_window (skeleton,
+                                                        invocation,
+                                                        stream_path);
+
   return TRUE;
 }
 
-- 
2.19.2