From d90cb025706011ecb66ef9074518b93167a65eeb Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 15 Apr 2023 14:58:57 +0200 Subject: [PATCH 1/3] window: Don't mark widget prematurely as has-focus has-focus is defined is-focus && toplevel::is-active. We were forgetting to look at is_active when handling focus widget changes. --- gtk/gtkwindow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 7990458095..01b205b87d 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -2023,7 +2023,7 @@ gtk_window_root_set_focus (GtkRoot *root, synthesize_focus_change_events (self, old_focus, focus, GTK_CROSSING_FOCUS); if (focus) - gtk_widget_set_has_focus (focus, TRUE); + gtk_widget_set_has_focus (focus, priv->is_active); g_set_object (&priv->focus_widget, focus); From 189aced844e2309c01f23d720a0f53e0c08b0914 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 15 Apr 2023 15:00:53 +0200 Subject: [PATCH 2/3] wayland: Improve logging for primary selection --- gdk/wayland/gdkprimary-wayland.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gdk/wayland/gdkprimary-wayland.c b/gdk/wayland/gdkprimary-wayland.c index b501deb66b..9a9640d852 100644 --- a/gdk/wayland/gdkprimary-wayland.c +++ b/gdk/wayland/gdkprimary-wayland.c @@ -99,7 +99,7 @@ gdk_wayland_primary_claim_remote (GdkWaylandPrimary *cb, if (cb->source) { - GDK_DISPLAY_DEBUG (gdk_clipboard_get_display (GDK_CLIPBOARD (cb)), CLIPBOARD, "%p: Ignoring clipboard offer for self", cb); + GDK_DISPLAY_DEBUG (gdk_clipboard_get_display (GDK_CLIPBOARD (cb)), CLIPBOARD, "%p: Ignoring primary offer for self", cb); gdk_content_formats_unref (formats); g_clear_pointer (&offer, zwp_primary_selection_offer_v1_destroy); return; @@ -111,7 +111,7 @@ gdk_wayland_primary_claim_remote (GdkWaylandPrimary *cb, if (GDK_DISPLAY_DEBUG_CHECK (gdk_clipboard_get_display (GDK_CLIPBOARD (cb)), CLIPBOARD)) { char *s = gdk_content_formats_to_string (formats); - gdk_debug_message ("%p: remote clipboard claim for %s", cb, s); + gdk_debug_message ("%p: remote primary claim for %s", cb, s); g_free (s); } #endif @@ -119,8 +119,7 @@ gdk_wayland_primary_claim_remote (GdkWaylandPrimary *cb, cb->offer_formats = formats; cb->offer = offer; - gdk_clipboard_claim_remote (GDK_CLIPBOARD (cb), - cb->offer_formats); + gdk_clipboard_claim_remote (GDK_CLIPBOARD (cb), cb->offer_formats); } static void @@ -271,6 +270,14 @@ gdk_wayland_primary_claim (GdkClipboard *clipboard, { GdkWaylandPrimary *cb = GDK_WAYLAND_PRIMARY (clipboard); +#ifdef G_ENABLE_DEBUG + if (GDK_DISPLAY_DEBUG_CHECK (gdk_clipboard_get_display (clipboard), CLIPBOARD)) + { + char *s = gdk_content_formats_to_string (formats); + gdk_debug_message ("%p: claim primary (%s) for %s", cb, local ? "local" : "remote", s); + g_free (s); + } +#endif if (local) { GdkWaylandDisplay *wdisplay = GDK_WAYLAND_DISPLAY (gdk_clipboard_get_display (clipboard)); From 4a22e681b3ae0db90fa2c38ab2c122a23807bcfb Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 15 Apr 2023 15:02:09 +0200 Subject: [PATCH 3/3] text: Only claim primary when focused It does not make sense otherwise, and has unfortunate side-effects on Wayland. --- gtk/gtktext.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gtk/gtktext.c b/gtk/gtktext.c index cc483b3e00..6470b64e7d 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -3260,6 +3260,7 @@ gtk_text_focus_changed (GtkEventControllerFocus *controller, gtk_text_im_set_focus_in (self); gtk_text_reset_blink_time (self); gtk_text_check_cursor_blink (self); + gtk_text_update_primary_selection (self); } else /* Focus out */ { @@ -5364,6 +5365,9 @@ gtk_text_update_primary_selection (GtkText *self) if (!gtk_widget_get_realized (GTK_WIDGET (self))) return; + if (!gtk_widget_has_focus (GTK_WIDGET (self))) + return; + clipboard = gtk_widget_get_primary_clipboard (GTK_WIDGET (self)); if (priv->selection_bound != priv->current_pos)