Revert unintended changes

I didn't mean to make this a complicated
portal test. Go back to being a simple test.
This commit is contained in:
Matthias Clasen 2019-12-29 12:49:17 -05:00
parent a73947e54f
commit 7078765903

View File

@ -19,115 +19,29 @@
#include <gtk/gtk.h>
#ifdef G_OS_UNIX
void
copy (void)
{
GdkClipboard *clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
GFile *file = g_file_new_for_path ("/home/mclasen/faw-sig");
gdk_clipboard_set (clipboard, G_TYPE_FILE, file);
g_object_unref (file);
}
static void
value_received (GObject *object,
GAsyncResult *result,
gpointer data)
{
const GValue *value;
GError *error = NULL;
GSList *l;
value = gdk_clipboard_read_value_finish (GDK_CLIPBOARD (object), result, &error);
if (value == NULL)
{
g_print ("Failed to read: %s\n", error->message);
g_error_free (error);
return;
}
for (l = g_value_get_boxed (value); l; l = l->next)
g_print ("%s\n", g_file_get_path (l->data));
}
void
paste (void)
{
GdkClipboard *clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
gdk_clipboard_read_value_async (clipboard, GDK_TYPE_FILE_LIST, 0, NULL, value_received, NULL);
}
static void
clipboard_changed (GdkClipboard *clipboard)
{
GdkContentFormats *formats = gdk_clipboard_get_formats (clipboard);
g_autofree char *s = gdk_content_formats_to_string (formats);
g_print ("clipboard contents now: %s, local: %d\n", s, gdk_clipboard_is_local (clipboard));
}
#else /* G_OS_UNIX */
void
hello (void)
{
g_print ("hello world\n");
}
#endif /* !G_OS_UNIX */
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button = NULL;
GtkWidget *window, *button;
gtk_init ();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
if (g_getenv ("CUSTOM_DISPLAY"))
{
GdkDisplay *display = gdk_display_open (NULL);
gtk_window_set_display (GTK_WINDOW (window), display);
}
gtk_window_set_title (GTK_WINDOW (window), "hello world");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
button = gtk_button_new ();
#ifdef G_OS_UNIX /* portal usage is supported on *nix only */
{
GtkWidget *box;
GdkClipboard *clipboard;
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_button_set_label (GTK_BUTTON (button), "copy");
g_signal_connect (button, "clicked", G_CALLBACK (copy), NULL);
gtk_container_add (GTK_CONTAINER (box), button);
button = gtk_button_new ();
gtk_button_set_label (GTK_BUTTON (button), "paste");
g_signal_connect (button, "clicked", G_CALLBACK (paste), NULL);
gtk_container_add (GTK_CONTAINER (box), button);
gtk_container_add (GTK_CONTAINER (window), box);
clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
g_signal_connect (clipboard, "changed", G_CALLBACK (clipboard_changed), NULL);
}
#else /* G_OS_UNIX -- original non-portal-enabled code */
gtk_button_set_label (GTK_BUTTON (button), "hello world");
g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
gtk_container_add (GTK_CONTAINER (window), button);
#endif /* !G_OS_UNIX */
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (window);