/* xselproxy -- a program to fool a stupid xterm. * Copyright (C) 2002 Simon Budig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #define WINDOW_EVENTS ( 0 ) void event_selection_get (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { gchar *text = *((gchar **) data); if (*((gchar *) data)) gtk_selection_data_set (selection_data, selection_data->target, 8, text, strlen (text)); } void event_selection_received (GtkWidget *widget, GtkSelectionData *selection_data, guint time, gpointer data) { gchar *text = NULL; if (!selection_data->type && *((gchar *) data)) { gtk_selection_owner_set (widget, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); gtk_selection_add_target (widget, GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, 0); } if (selection_data->type == GDK_SELECTION_TYPE_STRING) { if (selection_data->data) { g_free (*((gchar **) data)); text = g_strndup (selection_data->data, selection_data->length); *((gchar **) data) = text; } } } gint timeout_convert (gpointer data) { gtk_selection_convert ((GtkWidget *) data, GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, GDK_CURRENT_TIME); return TRUE; } int main (int argc, char **argv) { GtkWidget *win; gchar *data = NULL; gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_usize (GTK_WIDGET (win), 1, 1); gtk_widget_set_uposition (GTK_WIDGET (win), 0, 0); gtk_widget_set_events (win, WINDOW_EVENTS); gtk_signal_connect (GTK_OBJECT (win), "delete-event", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); gtk_signal_connect (GTK_OBJECT (win), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); gtk_signal_connect (GTK_OBJECT (win), "selection_get", GTK_SIGNAL_FUNC (event_selection_get), (gpointer) &data); gtk_signal_connect (GTK_OBJECT (win), "selection_received", GTK_SIGNAL_FUNC (event_selection_received), (gpointer) &data); gtk_timeout_add (250, timeout_convert, (gpointer) win); gtk_main (); return 0; } /* vim: set sw=3 ts=8 cindent noai bs=2 cinoptions=(0 : */