printers: Close new printer dialog when pressing Escape key

The GtkSearchEntry dialog was eating up the Escape key press events,
causing the dialog not to close as expected.

This adds a controller to explicitly handle key-press events on a
dialog level, which will close the dialog for the Escape key and
just propagate the event down the chain otherwise.

Fixes #3086
This commit is contained in:
Felipe Borges 2024-06-11 10:39:18 +02:00 committed by Marek Kašík
parent 7da19bfeec
commit 3f612ab812
2 changed files with 25 additions and 0 deletions

View file

@ -1338,6 +1338,24 @@ search_entry_activated_cb (PpNewPrinterDialog *self)
FALSE);
}
static gboolean
on_key_press_event (GtkEventControllerKey *controller,
guint keyval,
guint keycode,
GdkModifierType state,
PpNewPrinterDialog *self)
{
/* Capture Escape key press before it propagates down to the Search Entry,
* so the dialog can close on Escape. */
if (keyval == GDK_KEY_Escape) {
gtk_window_close (GTK_WINDOW (self));
return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
}
static void
search_entry_changed_cb (PpNewPrinterDialog *self)
{
@ -1883,6 +1901,7 @@ pp_new_printer_dialog_class_init (PpNewPrinterDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, add_cb);
gtk_widget_class_bind_template_callback (widget_class, cancel_cb);
gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
object_class->dispose = pp_new_printer_dialog_dispose;
window_class->close_request = pp_new_printer_dialog_close_request;

View file

@ -32,6 +32,12 @@
<style>
<class name="view"/>
</style>
<child>
<object class="GtkEventControllerKey">
<property name="propagation-phase">capture</property>
<signal name="key-pressed" handler="on_key_press_event"/>
</object>
</child>
<property name="content">
<object class="AdwToolbarView">
<child type="top">