diff options
author | Matthias Clasen <mclasen@redhat.com> | 2004-05-18 20:56:54 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2004-05-18 20:56:54 +0000 |
commit | 7b8616bf76e42e7b71543d4da9a3ca8e02c4d0d5 (patch) | |
tree | 139d727a115ba783ae0655d52f7835d731548700 /gtk/gtkclipboard.c | |
parent | 261d5404386a176a6a209d3deee08dc9b94f2d1a (diff) | |
download | gtk+-7b8616bf76e42e7b71543d4da9a3ca8e02c4d0d5.tar.gz |
Check for XFIXES extension.
2004-05-18 Matthias Clasen <mclasen@redhat.com>
* configure.in: Check for XFIXES extension.
* gdk/x11/gdkdisplay-x11.h (struct _GdkDisplayX11): Add
a gboolean have_xfixes member.
* gdk/x11/gdkdisplay-x11.c (gdk_display_open): Register
XFIXES events and set have_xfixes.
* gdk/gdkevents.h (GdkEventType): Add GDK_OWNER_CHANGE.
(GdkEventOwnerChange): New event struct for owner change events.
(GdkOwnerChange): New enum for the reason field of GdkEventOwnerChange.
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Translate
XFixesSelectionNotify events into GdkEventOwnerChange events.
* gdk/gdkdisplay.h:
* gdk/x11/gdkdisplay-x11.c (gdk_display_supports_selection_notification):
(gdk_display_request_selection_notification): New api
to support selection ownership notification.
* gtk/gtkclipboard.h:
* gtk/gtkclipboard.c (_gtk_clipboard_handle_event): New private
api to handle owner change events.
(clipboard_peek): Refactored out the body of
gtk_clipboard_get_for_display() for use in _gtk_clipboard_handle_event().
* gtk/gtkmain.c (gtk_main_do_event): Handle GDK_OWNER_CHANGE events
by calling _gtk_clipboard_handle_event().
Diffstat (limited to 'gtk/gtkclipboard.c')
-rw-r--r-- | gtk/gtkclipboard.c | 135 |
1 files changed, 97 insertions, 38 deletions
diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c index 107b40d697..fbaafafed1 100644 --- a/gtk/gtkclipboard.c +++ b/gtk/gtkclipboard.c @@ -25,6 +25,7 @@ #include "gtkclipboard.h" #include "gtkinvisible.h" #include "gtkmain.h" +#include "gtkmarshalers.h" #ifdef GDK_WINDOWING_X11 #include "x11/gdkx.h" @@ -34,6 +35,11 @@ #include "win32/gdkwin32.h" #endif +enum { + OWNER_CHANGE, + LAST_SIGNAL +}; + typedef struct _GtkClipboardClass GtkClipboardClass; typedef struct _RequestContentsInfo RequestContentsInfo; @@ -60,6 +66,9 @@ struct _GtkClipboard struct _GtkClipboardClass { GObjectClass parent_class; + + void (*owner_change) (GtkClipboard *clipboard, + GdkEventOwnerChange *event); }; struct _RequestContentsInfo @@ -83,11 +92,13 @@ struct _RequestTargetsInfo static void gtk_clipboard_class_init (GtkClipboardClass *class); static void gtk_clipboard_finalize (GObject *object); -static void clipboard_unset (GtkClipboard *clipboard); -static void selection_received (GtkWidget *widget, - GtkSelectionData *selection_data, - guint time); - +static void clipboard_unset (GtkClipboard *clipboard); +static void selection_received (GtkWidget *widget, + GtkSelectionData *selection_data, + guint time); +static GtkClipboard *clipboard_peek (GdkDisplay *display, + GdkAtom selection, + gboolean only_if_exists); enum { TARGET_STRING, TARGET_TEXT, @@ -102,6 +113,7 @@ static const gchar clipboards_owned_key[] = "gtk-clipboards-owned"; static GQuark clipboards_owned_key_id = 0; static GObjectClass *parent_class; +static guint clipboard_signals[LAST_SIGNAL] = { 0 }; GType gtk_clipboard_get_type (void) @@ -138,10 +150,22 @@ gtk_clipboard_class_init (GtkClipboardClass *class) parent_class = g_type_class_peek_parent (class); gobject_class->finalize = gtk_clipboard_finalize; + + class->owner_change = NULL; + + clipboard_signals[OWNER_CHANGE] = + g_signal_new ("owner_change", + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GtkClipboardClass, owner_change), + NULL, NULL, + _gtk_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); } static void -gtk_clipboard_finalize (GObject *object) +gtk_clipboard_finalize (GObject *object) { clipboard_unset (GTK_CLIPBOARD (object)); @@ -204,44 +228,16 @@ clipboard_display_closed (GdkDisplay *display, * Since: 2.2 **/ GtkClipboard * -gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection) +gtk_clipboard_get_for_display (GdkDisplay *display, + GdkAtom selection) { - GtkClipboard *clipboard = NULL; - GSList *clipboards; - GSList *tmp_list; - g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); g_return_val_if_fail (!display->closed, NULL); - if (selection == GDK_NONE) - selection = GDK_SELECTION_CLIPBOARD; - - clipboards = g_object_get_data (G_OBJECT (display), "gtk-clipboard-list"); - - tmp_list = clipboards; - while (tmp_list) - { - clipboard = tmp_list->data; - if (clipboard->selection == selection) - break; - - tmp_list = tmp_list->next; - } - - if (!tmp_list) - { - clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL); - clipboard->selection = selection; - clipboard->display = display; - clipboards = g_slist_prepend (clipboards, clipboard); - g_object_set_data (G_OBJECT (display), "gtk-clipboard-list", clipboards); - g_signal_connect (display, "closed", - G_CALLBACK (clipboard_display_closed), clipboard); - } - - return clipboard; + return clipboard_peek (display, selection, FALSE); } + /** * gtk_clipboard_get(): * @selection: a #GdkAtom which identifies the clipboard @@ -1108,3 +1104,66 @@ gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, return result; } + +static GtkClipboard * +clipboard_peek (GdkDisplay *display, + GdkAtom selection, + gboolean only_if_exists) +{ + GtkClipboard *clipboard = NULL; + GSList *clipboards; + GSList *tmp_list; + + if (selection == GDK_NONE) + selection = GDK_SELECTION_CLIPBOARD; + + clipboards = g_object_get_data (G_OBJECT (display), "gtk-clipboard-list"); + + tmp_list = clipboards; + while (tmp_list) + { + clipboard = tmp_list->data; + if (clipboard->selection == selection) + break; + + tmp_list = tmp_list->next; + } + + if (!tmp_list && !only_if_exists) + { + clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL); + clipboard->selection = selection; + clipboard->display = display; + clipboards = g_slist_prepend (clipboards, clipboard); + g_object_set_data (G_OBJECT (display), "gtk-clipboard-list", clipboards); + g_signal_connect (display, "closed", + G_CALLBACK (clipboard_display_closed), clipboard); + gdk_display_request_selection_notification (display, selection); + } + + return clipboard; +} + + +/** + * _gtk_clipboard_handle_event: + * @event: a owner change event + * + * Emits the ::owner_change signal on the appropriate @clipboard. + * + * Since: 2.6 + **/ +void +_gtk_clipboard_handle_event (GdkEventOwnerChange *event) +{ + GdkDisplay *display; + GtkClipboard *clipboard; + + display = gdk_drawable_get_display (event->window); + clipboard = clipboard_peek (display, event->selection, TRUE); + + if (clipboard) + g_signal_emit (clipboard, + clipboard_signals[OWNER_CHANGE], 0, event, NULL); +} + |