2017-11-20 01:07:31 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
2020-02-06 16:10:13 +00:00
|
|
|
|
static GdkTexture *
|
|
|
|
|
render_paintable_to_texture (GdkPaintable *paintable)
|
|
|
|
|
{
|
|
|
|
|
GtkSnapshot *snapshot;
|
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
int width, height;
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
GdkTexture *texture;
|
|
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
|
|
width = gdk_paintable_get_intrinsic_width (paintable);
|
|
|
|
|
height = gdk_paintable_get_intrinsic_height (paintable);
|
|
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
|
|
|
|
|
|
|
|
|
snapshot = gtk_snapshot_new ();
|
|
|
|
|
gdk_paintable_snapshot (paintable, snapshot, width, height);
|
|
|
|
|
node = gtk_snapshot_free_to_node (snapshot);
|
|
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
gsk_render_node_draw (node, cr);
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
|
|
bytes = g_bytes_new_with_free_func (cairo_image_surface_get_data (surface),
|
|
|
|
|
cairo_image_surface_get_height (surface)
|
|
|
|
|
* cairo_image_surface_get_stride (surface),
|
|
|
|
|
(GDestroyNotify) cairo_surface_destroy,
|
|
|
|
|
cairo_surface_reference (surface));
|
|
|
|
|
texture = gdk_memory_texture_new (cairo_image_surface_get_width (surface),
|
|
|
|
|
cairo_image_surface_get_height (surface),
|
|
|
|
|
GDK_MEMORY_DEFAULT,
|
|
|
|
|
bytes,
|
|
|
|
|
cairo_image_surface_get_stride (surface));
|
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 01:07:31 +00:00
|
|
|
|
static void
|
|
|
|
|
clipboard_changed_cb (GdkClipboard *clipboard,
|
|
|
|
|
GtkWidget *stack)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), "info");
|
|
|
|
|
|
|
|
|
|
child = gtk_stack_get_child_by_name (GTK_STACK (stack), "image");
|
|
|
|
|
gtk_image_clear (GTK_IMAGE (child));
|
2017-11-22 13:19:02 +00:00
|
|
|
|
|
|
|
|
|
child = gtk_stack_get_child_by_name (GTK_STACK (stack), "text");
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (child), "");
|
2017-11-20 01:07:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-12-02 13:38:57 +00:00
|
|
|
|
texture_loaded_cb (GObject *clipboard,
|
2017-11-20 01:07:31 +00:00
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
2017-12-02 13:38:57 +00:00
|
|
|
|
GdkTexture *texture;
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
2017-12-02 13:38:57 +00:00
|
|
|
|
texture = gdk_clipboard_read_texture_finish (GDK_CLIPBOARD (clipboard), res, &error);
|
|
|
|
|
if (texture == NULL)
|
2017-11-20 01:07:31 +00:00
|
|
|
|
{
|
|
|
|
|
g_print ("%s\n", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-16 03:29:42 +00:00
|
|
|
|
gtk_image_set_from_paintable (data, GDK_PAINTABLE (texture));
|
2017-12-02 13:38:57 +00:00
|
|
|
|
g_object_unref (texture);
|
2017-11-22 08:25:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 13:19:02 +00:00
|
|
|
|
static void
|
|
|
|
|
text_loaded_cb (GObject *clipboard,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
|
|
text = gdk_clipboard_read_text_finish (GDK_CLIPBOARD (clipboard), res, &error);
|
|
|
|
|
if (text == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_print ("%s\n", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_label_set_text (data, text);
|
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 01:07:31 +00:00
|
|
|
|
static void
|
|
|
|
|
visible_child_changed_cb (GtkWidget *stack,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GdkClipboard *clipboard)
|
|
|
|
|
{
|
|
|
|
|
const char *visible_child = gtk_stack_get_visible_child_name (GTK_STACK (stack));
|
|
|
|
|
|
|
|
|
|
if (visible_child == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* nothing to do here but avoiding crashes in g_str_equal() */
|
|
|
|
|
}
|
|
|
|
|
else if (g_str_equal (visible_child, "image"))
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *image = gtk_stack_get_child_by_name (GTK_STACK (stack), "image");
|
|
|
|
|
|
2017-12-02 13:38:57 +00:00
|
|
|
|
gdk_clipboard_read_texture_async (clipboard,
|
|
|
|
|
NULL,
|
|
|
|
|
texture_loaded_cb,
|
|
|
|
|
image);
|
2017-11-20 01:07:31 +00:00
|
|
|
|
}
|
2017-11-22 13:19:02 +00:00
|
|
|
|
else if (g_str_equal (visible_child, "text"))
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *label = gtk_stack_get_child_by_name (GTK_STACK (stack), "text");
|
|
|
|
|
|
|
|
|
|
gdk_clipboard_read_text_async (clipboard,
|
|
|
|
|
NULL,
|
|
|
|
|
text_loaded_cb,
|
|
|
|
|
label);
|
|
|
|
|
}
|
2017-11-20 01:07:31 +00:00
|
|
|
|
}
|
2017-11-29 08:37:50 +00:00
|
|
|
|
|
2019-12-16 10:03:24 +00:00
|
|
|
|
#ifdef G_OS_UNIX /* portal usage supported on *nix only */
|
|
|
|
|
|
2018-09-03 22:36:56 +00:00
|
|
|
|
static GSList *
|
2017-11-29 08:37:50 +00:00
|
|
|
|
get_file_list (const char *dir)
|
|
|
|
|
{
|
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
|
GFile *file;
|
2018-09-03 22:36:56 +00:00
|
|
|
|
GFileInfo *info;
|
|
|
|
|
GSList *list = NULL;
|
2017-11-29 08:37:50 +00:00
|
|
|
|
|
|
|
|
|
file = g_file_new_for_path (dir);
|
2018-09-03 22:36:56 +00:00
|
|
|
|
enumerator = g_file_enumerate_children (file, "standard::name,standard::type", 0, NULL, NULL);
|
2017-11-29 08:37:50 +00:00
|
|
|
|
g_object_unref (file);
|
|
|
|
|
if (enumerator == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2018-09-03 22:36:56 +00:00
|
|
|
|
while (g_file_enumerator_iterate (enumerator, &info, &file, NULL, NULL) && file != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* the portal can't handle directories */
|
|
|
|
|
if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
list = g_slist_prepend (list, g_object_ref (file));
|
|
|
|
|
}
|
2017-11-29 08:37:50 +00:00
|
|
|
|
|
2018-09-03 22:36:56 +00:00
|
|
|
|
return g_slist_reverse (list);
|
2017-11-29 08:37:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-16 10:03:24 +00:00
|
|
|
|
#else /* G_OS_UNIX -- original non-portal-enabled code */
|
|
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
|
get_file_list (const char *dir)
|
|
|
|
|
{
|
|
|
|
|
GFileEnumerator *enumerator;
|
|
|
|
|
GFile *file;
|
|
|
|
|
GList *list = NULL;
|
|
|
|
|
|
|
|
|
|
file = g_file_new_for_path (dir);
|
|
|
|
|
enumerator = g_file_enumerate_children (file, "standard::name", 0, NULL, NULL);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
if (enumerator == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
while (g_file_enumerator_iterate (enumerator, NULL, &file, NULL, NULL) && file != NULL)
|
|
|
|
|
list = g_list_prepend (list, g_object_ref (file));
|
|
|
|
|
|
|
|
|
|
return g_list_reverse (list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* !G_OS_UNIX */
|
|
|
|
|
|
2017-11-28 03:00:31 +00:00
|
|
|
|
static void
|
|
|
|
|
format_list_add_row (GtkWidget *list,
|
|
|
|
|
const char *format_name,
|
|
|
|
|
GdkContentFormats *formats)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *box;
|
|
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), gtk_label_new (format_name));
|
|
|
|
|
|
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (list), box);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 01:07:31 +00:00
|
|
|
|
static void
|
|
|
|
|
clipboard_formats_change_cb (GdkClipboard *clipboard,
|
|
|
|
|
GParamSpec *pspec,
|
2017-11-28 03:00:31 +00:00
|
|
|
|
GtkWidget *list)
|
2017-11-20 01:07:31 +00:00
|
|
|
|
{
|
2017-11-28 03:00:31 +00:00
|
|
|
|
GdkContentFormats *formats;
|
|
|
|
|
GtkWidget *row;
|
|
|
|
|
const char * const *mime_types;
|
|
|
|
|
const GType *gtypes;
|
|
|
|
|
gsize i, n;
|
|
|
|
|
|
|
|
|
|
while ((row = GTK_WIDGET (gtk_list_box_get_row_at_index (GTK_LIST_BOX (list), 0))))
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (list), row);
|
|
|
|
|
|
|
|
|
|
formats = gdk_clipboard_get_formats (clipboard);
|
|
|
|
|
|
|
|
|
|
gtypes = gdk_content_formats_get_gtypes (formats, &n);
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
{
|
|
|
|
|
format_list_add_row (list,
|
|
|
|
|
g_type_name (gtypes[i]),
|
|
|
|
|
gdk_content_formats_new_for_gtype (gtypes[i]));
|
|
|
|
|
}
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
2017-11-28 03:00:31 +00:00
|
|
|
|
mime_types = gdk_content_formats_get_mime_types (formats, &n);
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
{
|
|
|
|
|
format_list_add_row (list,
|
|
|
|
|
mime_types[i],
|
|
|
|
|
gdk_content_formats_new ((const char *[2]) { mime_types[i], NULL }, 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
|
get_formats_list (GdkClipboard *clipboard)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *sw, *list;
|
|
|
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
list = gtk_list_box_new ();
|
2017-12-01 05:05:07 +00:00
|
|
|
|
g_signal_connect_object (clipboard, "notify::formats", G_CALLBACK (clipboard_formats_change_cb), list, 0);
|
2017-11-28 03:00:31 +00:00
|
|
|
|
clipboard_formats_change_cb (clipboard, NULL, list);
|
2020-05-02 04:51:20 +00:00
|
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
|
2017-11-28 03:00:31 +00:00
|
|
|
|
|
|
|
|
|
return sw;
|
2017-11-20 01:07:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
|
get_contents_widget (GdkClipboard *clipboard)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *stack, *child;
|
|
|
|
|
|
|
|
|
|
stack = gtk_stack_new ();
|
|
|
|
|
gtk_widget_set_hexpand (stack, TRUE);
|
|
|
|
|
gtk_widget_set_vexpand (stack, TRUE);
|
|
|
|
|
g_signal_connect (stack, "notify::visible-child", G_CALLBACK (visible_child_changed_cb), clipboard);
|
2017-12-01 05:05:07 +00:00
|
|
|
|
g_signal_connect_object (clipboard, "changed", G_CALLBACK (clipboard_changed_cb), stack, 0);
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
2017-11-28 03:00:31 +00:00
|
|
|
|
child = get_formats_list (clipboard);
|
2017-11-20 01:07:31 +00:00
|
|
|
|
gtk_stack_add_titled (GTK_STACK (stack), child, "info", "Info");
|
|
|
|
|
|
|
|
|
|
child = gtk_image_new ();
|
|
|
|
|
gtk_stack_add_titled (GTK_STACK (stack), child, "image", "Image");
|
|
|
|
|
|
2017-11-22 13:19:02 +00:00
|
|
|
|
child = gtk_label_new (NULL);
|
2019-08-22 10:41:39 +00:00
|
|
|
|
gtk_label_set_wrap (GTK_LABEL (child), TRUE);
|
2017-11-22 13:19:02 +00:00
|
|
|
|
gtk_stack_add_titled (GTK_STACK (stack), child, "text", "Text");
|
|
|
|
|
|
2017-11-20 01:07:31 +00:00
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
|
static void
|
|
|
|
|
provider_button_clicked_cb (GtkWidget *button,
|
|
|
|
|
GdkClipboard *clipboard)
|
|
|
|
|
{
|
|
|
|
|
gdk_clipboard_set_content (clipboard,
|
|
|
|
|
g_object_get_data (G_OBJECT (button), "provider"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_provider_button (GtkWidget *box,
|
|
|
|
|
GdkContentProvider *provider,
|
|
|
|
|
GdkClipboard *clipboard,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label (name);
|
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (provider_button_clicked_cb), clipboard);
|
2017-11-25 07:37:03 +00:00
|
|
|
|
if (provider)
|
|
|
|
|
g_object_set_data_full (G_OBJECT (button), "provider", provider, g_object_unref);
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
2017-11-25 21:54:32 +00:00
|
|
|
|
get_button_list (GdkClipboard *clipboard,
|
|
|
|
|
const char *info)
|
2017-11-24 05:17:37 +00:00
|
|
|
|
{
|
2017-11-25 07:37:03 +00:00
|
|
|
|
static const guchar invalid_utf8[] = { 'L', 'i', 'b', 'e', 'r', 't', 0xe9, ',', ' ',
|
|
|
|
|
0xc9, 'g', 'a', 'l', 'i', 't', 0xe9, ',', ' ',
|
|
|
|
|
'F', 'r', 'a', 't', 'e', 'r', 'n', 'i', 't', 0xe9, 0 };
|
2017-11-24 05:17:37 +00:00
|
|
|
|
GtkWidget *box;
|
2020-02-04 16:19:22 +00:00
|
|
|
|
GtkIconPaintable *icon;
|
2020-01-28 09:30:01 +00:00
|
|
|
|
GdkTexture *texture;
|
2017-11-24 05:17:37 +00:00
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
|
|
2017-11-25 21:54:32 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), gtk_label_new (info));
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
2017-11-25 07:37:03 +00:00
|
|
|
|
add_provider_button (box,
|
|
|
|
|
NULL,
|
|
|
|
|
clipboard,
|
|
|
|
|
"Empty");
|
|
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
|
g_value_init (&value, GDK_TYPE_PIXBUF);
|
2020-02-01 22:38:49 +00:00
|
|
|
|
icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gdk_clipboard_get_display (clipboard)),
|
2020-01-28 09:30:01 +00:00
|
|
|
|
"utilities-terminal",
|
2020-02-04 02:53:22 +00:00
|
|
|
|
NULL,
|
2020-02-01 23:27:14 +00:00
|
|
|
|
48, 1,
|
|
|
|
|
gtk_widget_get_direction (box),
|
|
|
|
|
0);
|
2020-02-06 16:10:13 +00:00
|
|
|
|
texture = render_paintable_to_texture (GDK_PAINTABLE (icon));
|
2020-01-28 09:30:01 +00:00
|
|
|
|
g_value_take_object (&value, gdk_pixbuf_get_from_texture (texture));
|
|
|
|
|
g_object_unref (texture);
|
|
|
|
|
g_object_unref (icon);
|
2017-11-24 05:17:37 +00:00
|
|
|
|
add_provider_button (box,
|
|
|
|
|
gdk_content_provider_new_for_value (&value),
|
|
|
|
|
clipboard,
|
2017-11-24 09:13:23 +00:00
|
|
|
|
"GdkPixbuf");
|
2017-11-24 05:17:37 +00:00
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
|
|
add_provider_button (box,
|
2020-02-16 13:24:03 +00:00
|
|
|
|
gdk_content_provider_new_typed (G_TYPE_STRING, "Hello Clipboard ☺"),
|
2017-11-24 05:17:37 +00:00
|
|
|
|
clipboard,
|
2017-11-24 09:13:23 +00:00
|
|
|
|
"gchararry");
|
2017-11-24 05:17:37 +00:00
|
|
|
|
|
2017-11-24 09:13:23 +00:00
|
|
|
|
add_provider_button (box,
|
|
|
|
|
gdk_content_provider_new_for_bytes ("text/plain;charset=utf-8",
|
|
|
|
|
g_bytes_new_static ("𝕳𝖊𝖑𝖑𝖔 𝖀𝖓𝖎𝖈𝖔𝖉𝖊",
|
|
|
|
|
strlen ("𝕳𝖊𝖑𝖑𝖔 𝖀𝖓𝖎𝖈𝖔𝖉𝖊") + 1)),
|
|
|
|
|
clipboard,
|
|
|
|
|
"text/plain");
|
|
|
|
|
|
2017-11-25 07:37:03 +00:00
|
|
|
|
add_provider_button (box,
|
|
|
|
|
gdk_content_provider_new_for_bytes ("text/plain;charset=utf-8",
|
|
|
|
|
g_bytes_new_static (invalid_utf8, sizeof(invalid_utf8))),
|
|
|
|
|
clipboard,
|
|
|
|
|
"Invalid UTF-8");
|
|
|
|
|
|
2017-11-29 07:13:06 +00:00
|
|
|
|
g_value_init (&value, G_TYPE_FILE);
|
|
|
|
|
g_value_take_object (&value, g_file_new_for_path (g_get_home_dir ()));
|
|
|
|
|
add_provider_button (box,
|
|
|
|
|
gdk_content_provider_new_for_value (&value),
|
|
|
|
|
clipboard,
|
|
|
|
|
"home directory");
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
2017-11-29 08:37:50 +00:00
|
|
|
|
g_value_init (&value, GDK_TYPE_FILE_LIST);
|
|
|
|
|
g_value_take_boxed (&value, get_file_list (g_get_home_dir ()));
|
|
|
|
|
add_provider_button (box,
|
|
|
|
|
gdk_content_provider_new_for_value (&value),
|
|
|
|
|
clipboard,
|
|
|
|
|
"files in home");
|
2017-11-24 05:17:37 +00:00
|
|
|
|
return box;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 01:07:31 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
get_clipboard_widget (GdkClipboard *clipboard,
|
2017-11-25 21:54:32 +00:00
|
|
|
|
GdkClipboard *alt_clipboard,
|
2017-11-20 01:07:31 +00:00
|
|
|
|
const char *name)
|
|
|
|
|
{
|
2017-11-24 05:17:37 +00:00
|
|
|
|
GtkWidget *vbox, *hbox, *stack, *switcher;
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), vbox);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), gtk_label_new (name));
|
2017-11-20 01:07:31 +00:00
|
|
|
|
switcher = gtk_stack_switcher_new ();
|
2017-11-24 05:17:37 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), switcher);
|
2017-11-20 01:07:31 +00:00
|
|
|
|
stack = get_contents_widget (clipboard);
|
2017-11-24 05:17:37 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), stack);
|
2017-11-20 01:07:31 +00:00
|
|
|
|
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (stack));
|
2017-11-25 21:54:32 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), get_button_list (clipboard, "Set Locally:"));
|
|
|
|
|
if (clipboard != alt_clipboard)
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), get_button_list (alt_clipboard, "Set Remotely:"));
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
2017-11-24 05:17:37 +00:00
|
|
|
|
return hbox;
|
2017-11-20 01:07:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
2017-11-25 21:54:32 +00:00
|
|
|
|
get_window_contents (GdkDisplay *display,
|
|
|
|
|
GdkDisplay *alt_display)
|
2017-11-20 01:07:31 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *box;
|
|
|
|
|
|
2017-11-25 21:54:32 +00:00
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2017-11-20 01:07:31 +00:00
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box),
|
|
|
|
|
get_clipboard_widget (gdk_display_get_clipboard (display),
|
2017-11-25 21:54:32 +00:00
|
|
|
|
gdk_display_get_clipboard (alt_display),
|
2017-11-20 01:07:31 +00:00
|
|
|
|
"Clipboard"));
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box),
|
|
|
|
|
get_clipboard_widget (gdk_display_get_primary_clipboard (display),
|
2017-11-25 21:54:32 +00:00
|
|
|
|
gdk_display_get_primary_clipboard (alt_display),
|
2017-11-20 01:07:31 +00:00
|
|
|
|
"Primary Clipboard"));
|
|
|
|
|
|
|
|
|
|
return box;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
|
static void
|
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 01:07:31 +00:00
|
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *window;
|
2017-11-25 21:54:32 +00:00
|
|
|
|
GdkDisplay *alt_display;
|
2020-02-10 03:24:47 +00:00
|
|
|
|
gboolean done = FALSE;
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
|
|
|
|
gtk_init ();
|
|
|
|
|
|
2017-11-25 21:54:32 +00:00
|
|
|
|
alt_display = gdk_display_open (NULL);
|
|
|
|
|
if (alt_display == NULL)
|
|
|
|
|
alt_display = gdk_display_get_default ();
|
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
|
window = gtk_window_new ();
|
2020-02-10 03:24:47 +00:00
|
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2020-05-02 21:26:54 +00:00
|
|
|
|
gtk_window_set_child (GTK_WINDOW (window),
|
2017-11-25 21:54:32 +00:00
|
|
|
|
get_window_contents (gtk_widget_get_display (window),
|
|
|
|
|
alt_display));
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
|
while (!done)
|
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2017-11-20 01:07:31 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|