From 0508cac335f775805613a1956ef391f2a03bfc34 Mon Sep 17 00:00:00 2001 From: Michael Murphy Date: Thu, 21 Jun 2018 16:37:07 -0600 Subject: [PATCH 1/3] Improved keyboard navigation support --- src/Views/DiskView.vala | 17 +++++++++++++++++ src/Views/EncryptView.vala | 9 +++++++++ src/Views/KeyboardLayoutView.vala | 9 +++++++++ src/Views/LanguageView.vala | 9 +++++++++ src/Views/SuccessView.vala | 1 - src/Views/TryInstallView.vala | 15 ++++++++++++++- 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Views/DiskView.vala b/src/Views/DiskView.vala index 0597060c9..0f52f89cc 100644 --- a/src/Views/DiskView.vala +++ b/src/Views/DiskView.vala @@ -165,6 +165,19 @@ public class Installer.DiskView : AbstractInstallerView { } }); + disk_button.key_press_event.connect ((event) => { + if (event.keyval == Gdk.Key.Return) { + disk_button.clicked (); + if (next_button.sensitive) { + next_button.clicked (); + } + + return true; + } + + return false; + }); + enabled_buttons += disk_button; } } @@ -179,5 +192,9 @@ public class Installer.DiskView : AbstractInstallerView { disk_grid.show_all (); load_stack.set_visible_child_name ("disk"); + + if (enabled_buttons.length != 0) { + enabled_buttons[0].grab_focus (); + } } } diff --git a/src/Views/EncryptView.vala b/src/Views/EncryptView.vala index 4fb3ef32e..6fd944998 100644 --- a/src/Views/EncryptView.vala +++ b/src/Views/EncryptView.vala @@ -185,6 +185,15 @@ public class EncryptView : AbstractInstallerView { update_next_button (); }); + confirm_entry.key_press_event.connect ((event) => { + if (event.keyval == Gdk.Key.Return && next_button.sensitive) { + next_button.clicked (); + return true; + } + + return false; + }); + show_all (); back_button.hide (); } diff --git a/src/Views/KeyboardLayoutView.vala b/src/Views/KeyboardLayoutView.vala index b70eb7c86..2a6b2e1c8 100644 --- a/src/Views/KeyboardLayoutView.vala +++ b/src/Views/KeyboardLayoutView.vala @@ -76,6 +76,15 @@ public class KeyboardLayoutView : AbstractInstallerView { return ((VariantRow) row1).description.collate (((VariantRow) row2).description); }); + input_variant_widget.key_press_event.connect ((event) => { + if (event.keyval == Gdk.Key.Return && next_button.sensitive) { + next_button.clicked (); + return true; + } + + return false; + }); + back_button.clicked.connect (() => ((Gtk.Stack) get_parent ()).visible_child = previous_view); next_button.clicked.connect (() => { diff --git a/src/Views/LanguageView.vala b/src/Views/LanguageView.vala index 1f68d21e5..7e7daf14d 100644 --- a/src/Views/LanguageView.vala +++ b/src/Views/LanguageView.vala @@ -116,6 +116,15 @@ public class Installer.LanguageView : AbstractInstallerView { lang_variant_widget.main_listbox.select_row (lang_variant_widget.main_listbox.get_row_at_index (0)); lang_variant_widget.main_listbox.row_activated.connect (row_activated); + lang_variant_widget.key_press_event.connect ((event) => { + if (event.keyval == Gdk.Key.Return && next_button.sensitive) { + next_button.clicked (); + return true; + } + + return false; + }); + next_button.clicked.connect (() => { unowned Gtk.ListBoxRow row = lang_variant_widget.main_listbox.get_selected_row (); if (row != null) { diff --git a/src/Views/SuccessView.vala b/src/Views/SuccessView.vala index 39a4292e1..6b28e5b92 100644 --- a/src/Views/SuccessView.vala +++ b/src/Views/SuccessView.vala @@ -70,4 +70,3 @@ public class SuccessView : AbstractInstallerView { show_all (); } } - diff --git a/src/Views/TryInstallView.vala b/src/Views/TryInstallView.vala index ce68e202e..09778260e 100644 --- a/src/Views/TryInstallView.vala +++ b/src/Views/TryInstallView.vala @@ -104,6 +104,7 @@ public class Installer.TryInstallView : AbstractInstallerView { type_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); type_grid.add (custom_button); + demo_button.key_press_event.connect ((event) => handle_key_press (demo_button, event)); demo_button.clicked.connect (() => { if (demo_button.active) { type_grid.get_children ().foreach ((child) => { @@ -121,6 +122,7 @@ public class Installer.TryInstallView : AbstractInstallerView { } }); + clean_install_button.key_press_event.connect ((event) => handle_key_press (clean_install_button, event)); clean_install_button.clicked.connect (() => { if (clean_install_button.active) { type_grid.get_children ().foreach ((child) => { @@ -138,6 +140,7 @@ public class Installer.TryInstallView : AbstractInstallerView { } }); + custom_button.key_press_event.connect ((event) => handle_key_press (custom_button, event)); custom_button.clicked.connect (() => { if (custom_button.active) { type_grid.get_children ().foreach ((child) => { @@ -156,6 +159,16 @@ public class Installer.TryInstallView : AbstractInstallerView { }); show_all (); + demo_button.grab_focus (); } -} + private bool handle_key_press (Gtk.Button button, Gdk.EventKey event) { + if (event.keyval == Gdk.Key.Return) { + button.clicked (); + next_button.clicked (); + return true; + } + + return false; + } +} From fde93fe2a14e4748e7990a5926939cd3f429dff4 Mon Sep 17 00:00:00 2001 From: Michael Murphy Date: Fri, 22 Jun 2018 11:31:52 -0600 Subject: [PATCH 2/3] Ability to go back with backspace / escape --- src/MainWindow.vala | 4 ++++ src/Views/AbstractInstallerView.vala | 13 +++++++++++++ src/Views/KeyboardLayoutView.vala | 17 ++++++++++++++--- src/Views/LanguageView.vala | 13 ++++++++++--- src/Views/PartitioningView.vala | 6 +----- src/Views/TryInstallView.vala | 11 +++++++++++ src/Widgets/VariantWidget.vala | 6 +++++- 7 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index fde8f2c3e..3773c14f5 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -178,6 +178,10 @@ public class Installer.MainWindow : Gtk.Dialog { stack.add (partitioning_view); stack.visible_child = partitioning_view; + partitioning_view.cancel.connect (() => { + stack.visible_child = try_install_view; + }); + partitioning_view.next_step.connect (() => { unowned Configuration config = Configuration.get_default (); config.luks = (owned) partitioning_view.luks; diff --git a/src/Views/AbstractInstallerView.vala b/src/Views/AbstractInstallerView.vala index 551292029..31b11b1d0 100644 --- a/src/Views/AbstractInstallerView.vala +++ b/src/Views/AbstractInstallerView.vala @@ -66,5 +66,18 @@ public abstract class AbstractInstallerView : Gtk.Grid { orientation = Gtk.Orientation.VERTICAL; add (content_area); add (action_area); + + if (cancellable) { + key_press_event.connect ((event) => { + switch (event.keyval) { + case Gdk.Key.BackSpace: + case Gdk.Key.Escape: + cancel (); + return true; + } + + return false; + }); + } } } diff --git a/src/Views/KeyboardLayoutView.vala b/src/Views/KeyboardLayoutView.vala index 2a6b2e1c8..450d81930 100644 --- a/src/Views/KeyboardLayoutView.vala +++ b/src/Views/KeyboardLayoutView.vala @@ -77,9 +77,20 @@ public class KeyboardLayoutView : AbstractInstallerView { }); input_variant_widget.key_press_event.connect ((event) => { - if (event.keyval == Gdk.Key.Return && next_button.sensitive) { - next_button.clicked (); - return true; + switch (event.keyval) { + case Gdk.Key.Return: + if (next_button.sensitive) { + next_button.clicked (); + } + return true; + case Gdk.Key.BackSpace: + case Gdk.Key.Escape: + if (input_variant_widget.variants_visible ()) { + input_variant_widget.back_button.clicked (); + } else { + back_button.clicked (); + }; + return true; } return false; diff --git a/src/Views/LanguageView.vala b/src/Views/LanguageView.vala index 7e7daf14d..c4a3ddb18 100644 --- a/src/Views/LanguageView.vala +++ b/src/Views/LanguageView.vala @@ -117,9 +117,16 @@ public class Installer.LanguageView : AbstractInstallerView { lang_variant_widget.main_listbox.row_activated.connect (row_activated); lang_variant_widget.key_press_event.connect ((event) => { - if (event.keyval == Gdk.Key.Return && next_button.sensitive) { - next_button.clicked (); - return true; + switch (event.keyval) { + case Gdk.Key.Return: + if (next_button.sensitive) { + next_button.clicked (); + } + return true; + case Gdk.Key.BackSpace: + case Gdk.Key.Escape: + lang_variant_widget.back_button.clicked (); + return true; } return false; diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 48d7a58e5..3e2b10793 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -35,7 +35,7 @@ public class Installer.PartitioningView : AbstractInstallerView { public PartitioningView (uint64 size) { minimum_disk_size = size; - Object (cancellable: false); + Object (cancellable: true); } [Flags] @@ -100,16 +100,12 @@ public class Installer.PartitioningView : AbstractInstallerView { action_area.set_child_secondary (modify_partitions_button, true); action_area.set_child_non_homogeneous (modify_partitions_button, true); - var back_button = new Gtk.Button.with_label (_("Back")); - next_button = new Gtk.Button.with_label (_("Erase and Install")); next_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION); next_button.sensitive = false; - action_area.add (back_button); action_area.add (next_button); - back_button.clicked.connect (() => ((Gtk.Stack) get_parent ()).visible_child = previous_view); next_button.clicked.connect (() => next_step ()); show_all (); diff --git a/src/Views/TryInstallView.vala b/src/Views/TryInstallView.vala index 09778260e..b02a9a203 100644 --- a/src/Views/TryInstallView.vala +++ b/src/Views/TryInstallView.vala @@ -67,6 +67,17 @@ public class Installer.TryInstallView : AbstractInstallerView { var back_button = new Gtk.Button.with_label (_("Back")); back_button.clicked.connect (() => ((Gtk.Stack) get_parent ()).visible_child = previous_view); + key_press_event.connect ((event) => { + switch (event.keyval) { + case Gdk.Key.BackSpace: + case Gdk.Key.Escape: + back_button.clicked (); + return true; + } + + return false; + }); + next_button = new Gtk.Button.with_label (_("Next")); next_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); next_button.sensitive = false; diff --git a/src/Widgets/VariantWidget.vala b/src/Widgets/VariantWidget.vala index 4122b6ee1..6a1f5e73a 100644 --- a/src/Widgets/VariantWidget.vala +++ b/src/Widgets/VariantWidget.vala @@ -22,7 +22,7 @@ public class VariantWidget : Gtk.Frame { public signal void going_to_main (); - private Gtk.Button back_button; + public Gtk.Button back_button; private Gtk.Label variant_title; private Gtk.Stack stack; @@ -79,6 +79,10 @@ public class VariantWidget : Gtk.Frame { stack.visible_child_name = "variant"; } + public bool variants_visible () { + return stack.visible_child_name == "variant"; + } + public void clear_variants () { variant_listbox.get_children ().foreach ((child) => { child.destroy (); From a59622f13ac2263286e23b57ff289dec7ac22c71 Mon Sep 17 00:00:00 2001 From: Michael Murphy Date: Fri, 29 Jun 2018 13:33:59 -0600 Subject: [PATCH 3/3] Use MOD1+Left & EncryptView next button has default --- src/Views/AbstractInstallerView.vala | 5 ++++- src/Views/EncryptView.vala | 15 ++++++--------- src/Views/KeyboardLayoutView.vala | 5 ++++- src/Views/LanguageView.vala | 5 ++++- src/Views/TryInstallView.vala | 5 ++++- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Views/AbstractInstallerView.vala b/src/Views/AbstractInstallerView.vala index 31b11b1d0..e58d50e23 100644 --- a/src/Views/AbstractInstallerView.vala +++ b/src/Views/AbstractInstallerView.vala @@ -70,7 +70,10 @@ public abstract class AbstractInstallerView : Gtk.Grid { if (cancellable) { key_press_event.connect ((event) => { switch (event.keyval) { - case Gdk.Key.BackSpace: + case Gdk.Key.Left: + if (event.state != Gdk.ModifierType.MOD1_MASK) { + break; + } case Gdk.Key.Escape: cancel (); return true; diff --git a/src/Views/EncryptView.vala b/src/Views/EncryptView.vala index 6fd944998..cea9e9938 100644 --- a/src/Views/EncryptView.vala +++ b/src/Views/EncryptView.vala @@ -143,6 +143,7 @@ public class EncryptView : AbstractInstallerView { next_button = new Gtk.Button.with_label (_("Choose Password")); next_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); + next_button.can_default = true; action_area.add (no_encrypt_button); action_area.add (back_button); @@ -185,15 +186,6 @@ public class EncryptView : AbstractInstallerView { update_next_button (); }); - confirm_entry.key_press_event.connect ((event) => { - if (event.keyval == Gdk.Key.Return && next_button.sensitive) { - next_button.clicked (); - return true; - } - - return false; - }); - show_all (); back_button.hide (); } @@ -255,6 +247,7 @@ public class EncryptView : AbstractInstallerView { private void update_next_button () { if (pw_entry.is_valid && confirm_entry.is_valid) { next_button.sensitive = true; + next_button.has_default = true; } else { next_button.sensitive = false; } @@ -262,6 +255,10 @@ public class EncryptView : AbstractInstallerView { private class ValidatedEntry : Gtk.Entry { public bool is_valid { get; set; default = false; } + + construct { + activates_default = true; + } } private class ErrorRevealer : Gtk.Revealer { diff --git a/src/Views/KeyboardLayoutView.vala b/src/Views/KeyboardLayoutView.vala index 450d81930..d1b94b1bc 100644 --- a/src/Views/KeyboardLayoutView.vala +++ b/src/Views/KeyboardLayoutView.vala @@ -83,7 +83,10 @@ public class KeyboardLayoutView : AbstractInstallerView { next_button.clicked (); } return true; - case Gdk.Key.BackSpace: + case Gdk.Key.Left: + if (event.state != Gdk.ModifierType.MOD1_MASK) { + break; + } case Gdk.Key.Escape: if (input_variant_widget.variants_visible ()) { input_variant_widget.back_button.clicked (); diff --git a/src/Views/LanguageView.vala b/src/Views/LanguageView.vala index c4a3ddb18..b50ad4548 100644 --- a/src/Views/LanguageView.vala +++ b/src/Views/LanguageView.vala @@ -123,7 +123,10 @@ public class Installer.LanguageView : AbstractInstallerView { next_button.clicked (); } return true; - case Gdk.Key.BackSpace: + case Gdk.Key.Left: + if (event.state != Gdk.ModifierType.MOD1_MASK) { + break; + } case Gdk.Key.Escape: lang_variant_widget.back_button.clicked (); return true; diff --git a/src/Views/TryInstallView.vala b/src/Views/TryInstallView.vala index b02a9a203..e14f7a900 100644 --- a/src/Views/TryInstallView.vala +++ b/src/Views/TryInstallView.vala @@ -69,7 +69,10 @@ public class Installer.TryInstallView : AbstractInstallerView { key_press_event.connect ((event) => { switch (event.keyval) { - case Gdk.Key.BackSpace: + case Gdk.Key.Left: + if (event.state != Gdk.ModifierType.MOD1_MASK) { + break; + } case Gdk.Key.Escape: back_button.clicked (); return true;