diff --git a/src/app.rs b/src/app.rs index 88b05819..348af1d8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -156,6 +156,14 @@ impl App { ), &["u"], ), + ( + format!( + "{}.{}", + browser.action.id, + browser.action.focus.gobject.name() + ), + &["Escape"], + ), // Tab actions ( format!( diff --git a/src/app/browser.rs b/src/app/browser.rs index 0a111da0..90f46bfa 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -69,6 +69,13 @@ impl Browser { } }); + action.focus.connect_activate({ + let widget = widget.clone(); + move || { + widget.application_window.set_focus(gtk::Window::NONE); + } + }); + action.profile.connect_activate({ let profile = profile.clone(); move || { diff --git a/src/app/browser/action.rs b/src/app/browser/action.rs index dce9632c..94b9ac96 100644 --- a/src/app/browser/action.rs +++ b/src/app/browser/action.rs @@ -1,12 +1,14 @@ mod about; mod close; mod debug; +mod focus; mod profile; mod update; use about::About; use close::Close; use debug::Debug; +use focus::Focus; use profile::Profile; use update::Update; @@ -23,6 +25,7 @@ pub struct Action { pub about: Rc, pub close: Rc, pub debug: Rc, + pub focus: Rc, pub profile: Rc, pub update: Rc, // Group @@ -39,6 +42,7 @@ impl Action { let about = Rc::new(About::new()); let close = Rc::new(Close::new()); let debug = Rc::new(Debug::new()); + let focus = Rc::new(Focus::new()); let profile = Rc::new(Profile::new()); let update = Rc::new(Update::new()); @@ -52,6 +56,7 @@ impl Action { gobject.add_action(&about.gobject); gobject.add_action(&close.gobject); gobject.add_action(&debug.gobject); + gobject.add_action(&focus.gobject); gobject.add_action(&profile.gobject); gobject.add_action(&update.gobject); @@ -60,6 +65,7 @@ impl Action { about, close, debug, + focus, profile, update, id, diff --git a/src/app/browser/action/focus.rs b/src/app/browser/action/focus.rs new file mode 100644 index 00000000..0e8be6f6 --- /dev/null +++ b/src/app/browser/action/focus.rs @@ -0,0 +1,25 @@ +use gtk::{gio::SimpleAction, glib::uuid_string_random}; + +/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Focus` action of `Browser` group +pub struct Focus { + pub gobject: SimpleAction, +} + +impl Focus { + // Constructors + + /// Create new `Self` + pub fn new() -> Self { + Self { + gobject: SimpleAction::new(&uuid_string_random(), None), + } + } + + // Events + + /// Define callback function for + /// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal + pub fn connect_activate(&self, callback: impl Fn() + 'static) { + self.gobject.connect_activate(move |_, _| callback()); + } +} diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index d743f34a..dc4cef4d 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -27,7 +27,7 @@ use gtk::{ gdk_pixbuf::Pixbuf, gio::SocketClientEvent, glib::{gformat, GString, Priority, Uri, UriFlags, UriHideFlags}, - prelude::{EditableExt, FileExt, SocketClientExt, WidgetExt}, + prelude::{EditableExt, FileExt, SocketClientExt}, }; use sqlite::Transaction; use std::{rc::Rc, time::Duration}; @@ -149,7 +149,7 @@ impl Page { const DEFAULT_MAX_REDIRECT_COUNT: usize = 10; // Move focus out from navigation entry - self.navigation.reload.widget.gobject.grab_focus(); + // self.navigation.reload.widget.gobject.grab_focus(); // Reset widgets self.input.unset();