2005-07-13 05:44:22 +00:00
|
|
|
/* simple.c
|
2017-11-08 14:49:52 +00:00
|
|
|
* Copyright (C) 2017 Red Hat, Inc
|
|
|
|
* Author: Benjamin Otte
|
2005-07-13 05:44:22 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
|
2019-12-16 10:03:24 +00:00
|
|
|
#ifdef G_OS_UNIX
|
1997-11-24 22:37:52 +00:00
|
|
|
void
|
2018-09-03 22:36:56 +00:00
|
|
|
copy (void)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2018-09-03 22:36:56 +00:00
|
|
|
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));
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 10:03:24 +00:00
|
|
|
#else /* G_OS_UNIX */
|
|
|
|
|
|
|
|
void
|
|
|
|
hello (void)
|
|
|
|
{
|
|
|
|
g_print ("hello world\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !G_OS_UNIX */
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2019-12-17 19:46:36 +00:00
|
|
|
GtkWidget *window;
|
2019-12-16 10:03:24 +00:00
|
|
|
GtkWidget *button = NULL;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2011-02-12 04:59:42 +00:00
|
|
|
|
2017-11-08 14:49:52 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2019-12-07 14:49:10 +00:00
|
|
|
|
|
|
|
if (g_getenv ("CUSTOM_DISPLAY"))
|
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_display_open (NULL);
|
|
|
|
gtk_window_set_display (GTK_WINDOW (window), display);
|
|
|
|
}
|
|
|
|
|
2017-11-08 14:49:52 +00:00
|
|
|
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 ();
|
2019-12-16 10:03:24 +00:00
|
|
|
|
|
|
|
#ifdef G_OS_UNIX /* portal usage is supported on *nix only */
|
2019-12-17 19:46:36 +00:00
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GdkClipboard *clipboard;
|
2018-09-03 22:36:56 +00:00
|
|
|
|
2019-12-17 19:46:36 +00:00
|
|
|
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);
|
2018-09-03 22:36:56 +00:00
|
|
|
|
2019-12-17 19:46:36 +00:00
|
|
|
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);
|
2017-11-08 14:49:52 +00:00
|
|
|
|
2019-12-17 19:46:36 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), box);
|
2017-11-08 14:49:52 +00:00
|
|
|
|
2019-12-17 19:46:36 +00:00
|
|
|
clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
|
|
|
|
g_signal_connect (clipboard, "changed", G_CALLBACK (clipboard_changed), NULL);
|
|
|
|
}
|
2019-12-16 10:03:24 +00:00
|
|
|
#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 */
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
gtk_widget_show (window);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|