[gtk/wip/chergert/quartz4u] macos: track clipboard changes when foreground changes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/quartz4u] macos: track clipboard changes when foreground changes
- Date: Thu, 11 Jun 2020 21:29:38 +0000 (UTC)
commit df5b81ddd8e48b1c24f07fbf8f99e35b7dd87575
Author: Christian Hergert <chergert redhat com>
Date: Thu Jun 11 14:27:16 2020 -0700
macos: track clipboard changes when foreground changes
There doesn't seem to be a way to track changes to the clipboard
automatically (correct me if I'm wrong here, as that would be more
ideal for us) so we just update our GdkClipboard:formats when the
toplevel changes.
Usually that is fine since you would expect the focus application
to be the one to update the clipboard. Of course that isn't strictly
true, but it's comprehensive enough for an initial port.
gdk/macos/gdkmacosclipboard-private.h | 3 ++-
gdk/macos/gdkmacosclipboard.c | 15 +++++++++++++++
gdk/macos/gdkmacosdisplay.c | 8 ++++++++
3 files changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/gdk/macos/gdkmacosclipboard-private.h b/gdk/macos/gdkmacosclipboard-private.h
index aae2727120..cf4f61c41e 100644
--- a/gdk/macos/gdkmacosclipboard-private.h
+++ b/gdk/macos/gdkmacosclipboard-private.h
@@ -31,7 +31,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GdkMacosClipboard, _gdk_macos_clipboard, GDK, MACOS_CLIPBOARD, GdkClipboard)
-GdkClipboard *_gdk_macos_clipboard_new (GdkMacosDisplay *display);
+GdkClipboard *_gdk_macos_clipboard_new (GdkMacosDisplay *display);
+void _gdk_macos_clipboard_check_externally_modified (GdkMacosClipboard *self);
@interface GdkMacosClipboardOwner : NSObject
{
diff --git a/gdk/macos/gdkmacosclipboard.c b/gdk/macos/gdkmacosclipboard.c
index eab746c177..707a51d3b4 100644
--- a/gdk/macos/gdkmacosclipboard.c
+++ b/gdk/macos/gdkmacosclipboard.c
@@ -29,6 +29,7 @@ struct _GdkMacosClipboard
GdkClipboard parent_instance;
NSPasteboard *pasteboard;
GdkMacosClipboardOwner *owner;
+ NSInteger last_change_count;
};
G_DEFINE_TYPE (GdkMacosClipboard, _gdk_macos_clipboard, GDK_TYPE_CLIPBOARD)
@@ -79,12 +80,17 @@ static void
_gdk_macos_clipboard_load_contents (GdkMacosClipboard *self)
{
GdkContentFormats *formats;
+ NSInteger change_count;
g_assert (GDK_IS_MACOS_CLIPBOARD (self));
+ change_count = [self->pasteboard changeCount];
+
formats = load_offer_formats (self);
gdk_clipboard_claim_remote (GDK_CLIPBOARD (self), formats);
gdk_content_formats_unref (formats);
+
+ self->last_change_count = change_count;
}
static gboolean
@@ -317,6 +323,15 @@ _gdk_macos_clipboard_new (GdkMacosDisplay *display)
return GDK_CLIPBOARD (self);
}
+void
+_gdk_macos_clipboard_check_externally_modified (GdkMacosClipboard *self)
+{
+ g_return_if_fail (GDK_IS_MACOS_CLIPBOARD (self));
+
+ if ([self->pasteboard changeCount] != self->last_change_count)
+ _gdk_macos_clipboard_load_contents (self);
+}
+
@implementation GdkMacosClipboardOwner
-(void)pasteboard:(NSPasteboard *)pb provideDataForType:(NSString *)type
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 3e44452f45..bd328075f0 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -1032,6 +1032,14 @@ _gdk_macos_display_get_surfaces (GdkMacosDisplay *self)
self->sorted_surfaces = sorted;
+ /* We don't get notification of clipboard changes from the system so we
+ * instead update it every time the foreground changes (and thusly
+ * rebuild the sorted list). Things could change other ways, such as
+ * with scripts, but that is currently out of scope for us.
+ */
+ _gdk_macos_clipboard_check_externally_modified (
+ GDK_MACOS_CLIPBOARD (GDK_DISPLAY (self)->clipboard));
+
GDK_END_MACOS_ALLOC_POOL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]