[gtk+] clipboard: Add surface apis



commit 8f6fbc9c24669a5663afcfdb30ecb35be069b674
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Oct 22 22:17:43 2017 +0200

    clipboard: Add surface apis
    
    Add gtk_clipboard_set_surface and gtk_clipboard_wait_for_surface.

 gtk/gtkclipboard.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkclipboard.h |    5 ++++
 2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c
index 329299e..496e44c 100644
--- a/gtk/gtkclipboard.c
+++ b/gtk/gtkclipboard.c
@@ -930,6 +930,21 @@ gtk_clipboard_set_image (GtkClipboard *clipboard,
   gtk_target_list_unref (list);
 }
 
+void
+gtk_clipboard_set_surface (GtkClipboard    *clipboard,
+                           cairo_surface_t *surface)
+{
+  GdkPixbuf *pixbuf;
+
+  pixbuf = gdk_pixbuf_get_from_surface (surface,
+                                        0, 0,
+                                        cairo_image_surface_get_width (surface),
+                                        cairo_image_surface_get_height (surface));
+  gtk_clipboard_set_image (clipboard, pixbuf);
+  g_object_unref (pixbuf);
+
+}
+
 static void
 set_request_contents_info (GtkWidget           *widget,
                           RequestContentsInfo *info)
@@ -1579,6 +1594,19 @@ clipboard_image_received_func (GtkClipboard *clipboard,
   g_main_loop_quit (results->loop);
 }
 
+static void
+clipboard_surface_received_func (GtkClipboard *clipboard,
+                                 GdkPixbuf    *pixbuf,
+                                gpointer      data)
+{
+  WaitResults *results = data;
+
+  if (pixbuf)
+    results->data = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
+
+  g_main_loop_quit (results->loop);
+}
+
 /**
  * gtk_clipboard_wait_for_image:
  * @clipboard: a #GtkClipboard
@@ -1623,6 +1651,31 @@ gtk_clipboard_wait_for_image (GtkClipboard *clipboard)
   return results.data;
 }
 
+cairo_surface_t *
+gtk_clipboard_wait_for_surface (GtkClipboard *clipboard)
+{
+  WaitResults results;
+
+  g_return_val_if_fail (clipboard != NULL, NULL);
+  
+  results.data = NULL;
+  results.loop = g_main_loop_new (NULL, TRUE);
+
+  gtk_clipboard_request_image (clipboard,
+                              clipboard_surface_received_func,
+                              &results);
+
+  if (g_main_loop_is_running (results.loop))
+    {
+      gdk_threads_leave ();
+      g_main_loop_run (results.loop);
+      gdk_threads_enter ();
+    }
+
+  g_main_loop_unref (results.loop);
+
+  return results.data;
+}
 static void 
 clipboard_uris_received_func (GtkClipboard *clipboard,
                              gchar       **uris,
diff --git a/gtk/gtkclipboard.h b/gtk/gtkclipboard.h
index 655c18f..68a68a6 100644
--- a/gtk/gtkclipboard.h
+++ b/gtk/gtkclipboard.h
@@ -221,6 +221,9 @@ void     gtk_clipboard_set_text       (GtkClipboard          *clipboard,
 GDK_AVAILABLE_IN_ALL
 void     gtk_clipboard_set_image      (GtkClipboard          *clipboard,
                                       GdkPixbuf             *pixbuf);
+GDK_AVAILABLE_IN_3_94
+void     gtk_clipboard_set_surface    (GtkClipboard    *clipboard,
+                                       cairo_surface_t *surface);
 
 GDK_AVAILABLE_IN_ALL
 void gtk_clipboard_request_contents  (GtkClipboard                     *clipboard,
@@ -268,6 +271,8 @@ gboolean          gtk_clipboard_wait_for_targets   (GtkClipboard  *clipboard,
                                                     GdkAtom      **targets,
                                                     gint          *n_targets);
 
+GDK_AVAILABLE_IN_3_94
+cairo_surface_t * gtk_clipboard_wait_for_surface   (GtkClipboard  *clipboard);
 GDK_AVAILABLE_IN_ALL
 gboolean gtk_clipboard_wait_is_text_available      (GtkClipboard  *clipboard);
 GDK_AVAILABLE_IN_ALL


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