[xdg-desktop-portal-gnome/gbsneto/screencast-session-restore: 2/2] screencast: Pass stream ids




commit e2e4f6f97c7a48da25b2314510faa2aeacd6fef9
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Nov 11 00:05:27 2021 -0300

    screencast: Pass stream ids
    
    The stream id is any string that can uniquely
    identify a stream within a screencast session.
    Add that to the list of stream properties.
    
    For now, only use a simple positional integer
    as id.

 src/gnomescreencast.c  | 21 ++++++++++++++++++---
 src/screencast.c       |  5 ++++-
 src/screencast.h       |  1 +
 src/screencastwidget.c |  4 ++++
 4 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/gnomescreencast.c b/src/gnomescreencast.c
index 7388686..623f577 100644
--- a/src/gnomescreencast.c
+++ b/src/gnomescreencast.c
@@ -59,6 +59,7 @@ typedef struct _GnomeScreenCastStream
 
   ScreenCastSourceType source_type;
 
+  uint32_t id;
   char *path;
   OrgGnomeMutterScreenCastStream *proxy;
 
@@ -219,6 +220,7 @@ void
 gnome_screen_cast_session_add_stream_properties (GnomeScreenCastSession *gnome_screen_cast_session,
                                                  GVariantBuilder *streams_builder)
 {
+  char id[64] = { 0, };
   GList *streams;
   GList *l;
 
@@ -234,6 +236,10 @@ gnome_screen_cast_session_add_stream_properties (GnomeScreenCastSession *gnome_s
 
       g_variant_builder_init (&stream_properties_builder, G_VARIANT_TYPE_VARDICT);
 
+      g_snprintf (id, G_N_ELEMENTS (id), "%u", stream->id);
+      g_variant_builder_add (&stream_properties_builder, "{sv}",
+                             "id",
+                             g_variant_new ("s", id));
       g_variant_builder_add (&stream_properties_builder, "{sv}",
                              "source_type",
                              g_variant_new ("u", stream->source_type));
@@ -275,6 +281,7 @@ cursor_mode_to_gnome_cursor_mode (ScreenCastCursorMode cursor_mode)
 
 static gboolean
 gnome_screen_cast_session_record_window (GnomeScreenCastSession  *gnome_screen_cast_session,
+                                         uint32_t                 id,
                                          Window                  *window,
                                          ScreenCastSelection     *select,
                                          GError                 **error)
@@ -327,6 +334,7 @@ gnome_screen_cast_session_record_window (GnomeScreenCastSession  *gnome_screen_c
   stream->session = gnome_screen_cast_session;
   stream->path = g_strdup (stream_path);
   stream->proxy = stream_proxy;
+  stream->id = id;
 
   parameters = org_gnome_mutter_screen_cast_stream_get_parameters (stream->proxy);
   if (parameters)
@@ -357,6 +365,7 @@ gnome_screen_cast_session_record_window (GnomeScreenCastSession  *gnome_screen_c
 
 static gboolean
 gnome_screen_cast_session_record_monitor (GnomeScreenCastSession  *gnome_screen_cast_session,
+                                          uint32_t                 id,
                                           Monitor                 *monitor,
                                           ScreenCastSelection     *select,
                                           GError                 **error)
@@ -409,6 +418,7 @@ gnome_screen_cast_session_record_monitor (GnomeScreenCastSession  *gnome_screen_
   stream->session = gnome_screen_cast_session;
   stream->path = g_strdup (stream_path);
   stream->proxy = stream_proxy;
+  stream->id = id;
 
   parameters = org_gnome_mutter_screen_cast_stream_get_parameters (stream->proxy);
   if (parameters)
@@ -438,9 +448,10 @@ gnome_screen_cast_session_record_monitor (GnomeScreenCastSession  *gnome_screen_
 }
 
 static gboolean
-gnome_screen_cast_session_record_virtual (GnomeScreenCastSession *gnome_screen_cast_session,
-                                          ScreenCastSelection *select,
-                                          GError **error)
+gnome_screen_cast_session_record_virtual (GnomeScreenCastSession  *gnome_screen_cast_session,
+                                          uint32_t                 id,
+                                          ScreenCastSelection     *select,
+                                          GError                 **error)
 {
   OrgGnomeMutterScreenCastSession *session_proxy =
     gnome_screen_cast_session->proxy;
@@ -487,6 +498,7 @@ gnome_screen_cast_session_record_virtual (GnomeScreenCastSession *gnome_screen_c
   stream->session = gnome_screen_cast_session;
   stream->path = g_strdup (stream_path);
   stream->proxy = stream_proxy;
+  stream->id = id;
 
   parameters = org_gnome_mutter_screen_cast_stream_get_parameters (stream->proxy);
   if (parameters)
@@ -531,6 +543,7 @@ gnome_screen_cast_session_record_selections (GnomeScreenCastSession  *gnome_scre
         {
         case SCREEN_CAST_SOURCE_TYPE_MONITOR:
           if (!gnome_screen_cast_session_record_monitor (gnome_screen_cast_session,
+                                                         info->id,
                                                          info->data.monitor,
                                                          select,
                                                          error))
@@ -538,6 +551,7 @@ gnome_screen_cast_session_record_selections (GnomeScreenCastSession  *gnome_scre
           break;
         case SCREEN_CAST_SOURCE_TYPE_WINDOW:
           if (!gnome_screen_cast_session_record_window (gnome_screen_cast_session,
+                                                        info->id,
                                                         info->data.window,
                                                         select,
                                                         error))
@@ -545,6 +559,7 @@ gnome_screen_cast_session_record_selections (GnomeScreenCastSession  *gnome_scre
           break;
         case SCREEN_CAST_SOURCE_TYPE_VIRTUAL:
           if (!gnome_screen_cast_session_record_virtual (gnome_screen_cast_session,
+                                                         info->id,
                                                          select,
                                                          error))
             return FALSE;
diff --git a/src/screencast.c b/src/screencast.c
index 93522b7..8239056 100644
--- a/src/screencast.c
+++ b/src/screencast.c
@@ -170,7 +170,7 @@ serialize_streams_as_restore_data (ScreenCastSession *screen_cast_session,
 
       g_variant_builder_add (&impl_builder,
                              "(uuv)",
-                             i,
+                             info->id,
                              info->type,
                              stream_variant);
     }
@@ -510,6 +510,7 @@ restore_stream_from_data (ScreenCastSession *screen_cast_session)
             info = g_new0 (ScreenCastStreamInfo, 1);
             info->type = SCREEN_CAST_SOURCE_TYPE_MONITOR;
             info->data.monitor = monitor;
+            info->id = id;
             g_ptr_array_add (streams, info);
           }
           break;
@@ -534,6 +535,7 @@ restore_stream_from_data (ScreenCastSession *screen_cast_session)
             info = g_new0 (ScreenCastStreamInfo, 1);
             info->type = SCREEN_CAST_SOURCE_TYPE_WINDOW;
             info->data.window = window;
+            info->id = id;
             g_ptr_array_add (streams, info);
           }
           break;
@@ -546,6 +548,7 @@ restore_stream_from_data (ScreenCastSession *screen_cast_session)
 
             info = g_new0 (ScreenCastStreamInfo, 1);
             info->type = SCREEN_CAST_SOURCE_TYPE_VIRTUAL;
+            info->id = id;
             g_ptr_array_add (streams, info);
           }
           break;
diff --git a/src/screencast.h b/src/screencast.h
index 04f7616..d50340c 100644
--- a/src/screencast.h
+++ b/src/screencast.h
@@ -56,6 +56,7 @@ typedef struct _ScreenCastSelection
 typedef struct
 {
   ScreenCastSourceType type;
+  uint32_t id;
   union {
     Monitor *monitor;
     Window *window;
diff --git a/src/screencastwidget.c b/src/screencastwidget.c
index 089ee2a..5246bc2 100644
--- a/src/screencastwidget.c
+++ b/src/screencastwidget.c
@@ -623,6 +623,7 @@ screen_cast_widget_get_selected_streams (ScreenCastWidget *self)
   g_autoptr(GList) selected_monitor_rows = NULL;
   g_autoptr(GList) selected_window_rows = NULL;
   gboolean selected_virtual;
+  uint32_t id = 0;
   GList *l;
 
   streams = g_ptr_array_new_with_free_func (g_free);
@@ -647,6 +648,7 @@ screen_cast_widget_get_selected_streams (ScreenCastWidget *self)
       info = g_new0 (ScreenCastStreamInfo, 1);
       info->type = SCREEN_CAST_SOURCE_TYPE_MONITOR;
       info->data.monitor = monitor;
+      info->id = id++;
       g_ptr_array_add (streams, info);
     }
 
@@ -661,6 +663,7 @@ screen_cast_widget_get_selected_streams (ScreenCastWidget *self)
       info = g_new0 (ScreenCastStreamInfo, 1);
       info->type = SCREEN_CAST_SOURCE_TYPE_WINDOW;
       info->data.window = window;
+      info->id = id++;
       g_ptr_array_add (streams, info);
     }
 
@@ -668,6 +671,7 @@ screen_cast_widget_get_selected_streams (ScreenCastWidget *self)
     {
       info = g_new0 (ScreenCastStreamInfo, 1);
       info->type = SCREEN_CAST_SOURCE_TYPE_VIRTUAL;
+      info->id = id++;
       g_ptr_array_add (streams, info);
     }
 


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