From 21c912af651940b7b8269ffc13d3db847e4b591e Mon Sep 17 00:00:00 2001 From: Jeff Walsh Date: Mon, 27 Sep 2021 00:20:57 +1000 Subject: [PATCH 1/3] pgtk: Handle (child) frame focusing better child frames on pgtk are gtk widgets inside the parent surface, rather than subsurfaces (in wayland ters), and the edit widget is handled separately from the parent window, so we need to handle signals more correctly, rather than squinting and assuming an event for the window is just an event for the edit widget. * src/gtkutil.c (xg_set_no_accept_focus): set focus on widget rather than request it on window * src/pgtkterm.c (pgtk_focus_frame): focus frame on edit_widget instead (button_event): Implement focus calls to replace dead X calls --- src/gtkutil.c | 8 +++++--- src/pgtkterm.c | 13 +++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/gtkutil.c b/src/gtkutil.c index 7f8a33c01d..27431b3be1 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1996,16 +1996,18 @@ xg_set_no_focus_on_map (struct frame *f, Lisp_Object no_focus_on_map) void xg_set_no_accept_focus (struct frame *f, Lisp_Object no_accept_focus) { + gboolean g_no_accept_focus = NILP (no_accept_focus) ? TRUE : FALSE; #ifdef HAVE_PGTK - if (!FRAME_GTK_OUTER_WIDGET (f)) + if (!FRAME_GTK_OUTER_WIDGET (f)) { + if (FRAME_WIDGET(f)) + gtk_widget_set_can_focus(FRAME_WIDGET(f), g_no_accept_focus); return; + } #endif block_input (); if (FRAME_GTK_WIDGET (f)) { GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)); - gboolean g_no_accept_focus = NILP (no_accept_focus) ? TRUE : FALSE; - gtk_window_set_accept_focus (gwin, g_no_accept_focus); } unblock_input (); diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 40489c0c6b..aae4e1011b 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -4702,12 +4702,12 @@ pgtk_focus_frame (struct frame *f, bool noactivate) { struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); - GtkWidget *wid = FRAME_GTK_OUTER_WIDGET (f); + GtkWidget *wid = FRAME_WIDGET (f); if (dpyinfo->x_focus_frame != f && wid != NULL) { block_input (); - gtk_window_present (GTK_WINDOW (wid)); + gtk_widget_grab_focus(wid); unblock_input (); } } @@ -6460,12 +6460,9 @@ button_event (GtkWidget * widget, GdkEvent * event, gpointer * user_data) if (FRAME_PARENT_FRAME (f) || (hf && frame_ancestor_p (f, hf))) { block_input (); -#if 0 - XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), - RevertToParent, CurrentTime); - if (FRAME_PARENT_FRAME (f)) - XRaiseWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f)); -#endif + gtk_widget_grab_focus(FRAME_GTK_WIDGET(f)); + if (FRAME_GTK_OUTER_WIDGET(f)) + gtk_window_present(GTK_WINDOW(FRAME_GTK_OUTER_WIDGET(f))); unblock_input (); } } -- 2.33.1