main: Move visible focus handling

No need to special-case this anymore; we can use
a regular event controller in GtkWindow for this.
This commit is contained in:
Matthias Clasen 2019-06-21 01:57:51 +00:00
parent a7a0a34da1
commit a7cdcdf92c
2 changed files with 15 additions and 9 deletions

View File

@ -1998,15 +1998,6 @@ gtk_main_do_event (GdkEvent *event)
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
/* make focus visible in a window that receives a key event */
{
GtkRoot *root;
root = gtk_widget_get_root (grab_widget);
if (GTK_IS_WINDOW (root))
gtk_window_set_focus_visible (GTK_WINDOW (root), TRUE);
}
/* Catch alt press to enable auto-mnemonics;
* menus are handled elsewhere
* FIXME: this does not work with mnemonic modifiers other than Alt

View File

@ -406,6 +406,7 @@ static void gtk_window_size_allocate (GtkWidget *widget,
static gboolean gtk_window_close_request (GtkWindow *window);
static void gtk_window_focus_in (GtkWidget *widget);
static void gtk_window_focus_out (GtkWidget *widget);
static gboolean gtk_window_key_press (GtkWidget *widget);
static void surface_state_changed (GtkWidget *widget);
static void surface_size_changed (GtkWidget *widget,
@ -1864,10 +1865,14 @@ gtk_window_init (GtkWindow *window)
gtk_widget_add_controller (widget, motion_controller);
priv->key_controller = gtk_event_controller_key_new ();
gtk_event_controller_set_name (controller, "window focus");
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
g_signal_connect_swapped (priv->key_controller, "focus-in",
G_CALLBACK (gtk_window_focus_in), window);
g_signal_connect_swapped (priv->key_controller, "focus-out",
G_CALLBACK (gtk_window_focus_out), window);
g_signal_connect_swapped (priv->key_controller, "key-pressed",
G_CALLBACK (gtk_window_key_press), window);
gtk_widget_add_controller (widget, priv->key_controller);
}
@ -6207,6 +6212,16 @@ gtk_window_focus_out (GtkWidget *widget)
gtk_window_set_mnemonics_visible (window, FALSE);
}
static gboolean
gtk_window_key_press (GtkWidget *widget)
{
GtkWindow *window = GTK_WINDOW (widget);
gtk_window_set_focus_visible (window, TRUE);
return FALSE;
}
static GtkWindowPopover *
_gtk_window_has_popover (GtkWindow *window,
GtkWidget *widget)