Skip to content

Commit dc82f88

Browse files
committed
Improve shortcuts: <Ctrl>l, open in tab with <Ctrl>mouse, document hidden shortcuts
1 parent a780926 commit dc82f88

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

data/resources/ui/shortcuts.blp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Gtk.ShortcutsWindow help_overlay {
2929
action-name: "win.close-tab";
3030
}
3131

32+
Gtk.ShortcutsShortcut {
33+
title: C_("shortcut window", "Go to Nth Tab");
34+
accelerator: "<Alt>1...9";
35+
}
36+
3237
Gtk.ShortcutsShortcut {
3338
title: C_("shortcut window", "View Source");
3439
action-name: "win.view-source";
@@ -38,12 +43,12 @@ Gtk.ShortcutsWindow help_overlay {
3843
title: C_("shortcut window", "Navigation");
3944

4045
Gtk.ShortcutsShortcut {
41-
title: C_("shortcut window", "Previous Tab");
46+
title: C_("shortcut window", "Previous Page");
4247
action-name: "win.previous";
4348
}
4449

4550
Gtk.ShortcutsShortcut {
46-
title: C_("shortcut window", "Next Tab");
51+
title: C_("shortcut window", "Next Page");
4752
action-name: "win.next";
4853
}
4954

src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,10 @@ fn main() {
9393
application.set_accels_for_action("win.bookmark-current", &["<Ctrl>d"]);
9494
application.set_accels_for_action("win.new-tab", &["<Ctrl>t"]);
9595
application.set_accels_for_action("win.close-tab", &["<Ctrl>w"]);
96-
application.set_accels_for_action("win.focus-url-bar", &["F6"]);
96+
application.set_accels_for_action("win.focus-url-bar", &["F6", "<Ctrl>L"]);
9797
application.set_accels_for_action("win.zoom-in", &["<Ctrl>plus"]);
9898
application.set_accels_for_action("win.zoom-out", &["<Ctrl>minus"]);
9999
application.set_accels_for_action("win.reset-zoom", &["<Ctrl>0"]);
100-
// Sadly Tab doesn't work as an accelerator in gtk...
101-
application.set_accels_for_action("win.focus-next-tab", &["<Ctrl>Tab"]);
102-
application.set_accels_for_action("win.focus-previous-tab", &["<Ctrl><Shift>Tab"]);
103100
// FIXME: win.view-source
104101
let ret = application.run();
105102
std::process::exit(ret);

src/widgets/tab.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl Tab {
167167
this.bind_signals();
168168
this
169169
}
170-
pub fn handle_click(&self, x: f64, y: f64) -> Result<()> {
170+
pub fn handle_click(&self, ctrl: &gtk::GestureClick, x: f64, y: f64) -> Result<()> {
171171
let imp = self.imp();
172172
let gemini_text_ext = imp.gemini_text_ext.borrow();
173173
let text_view = &gemini_text_ext.as_ref().unwrap().text_view;
@@ -177,7 +177,18 @@ impl Tab {
177177
}
178178
let link = Self::extract_linkhandler(gemini_text_ext.as_ref().unwrap(), x, y)?;
179179
let url = self.parse_link(&link)?;
180-
self.spawn_open_url(url);
180+
if ctrl
181+
.current_event()
182+
.unwrap()
183+
.modifier_state()
184+
.contains(gdk::ModifierType::CONTROL_MASK)
185+
{
186+
self.activate_action("win.open-in-new-tab", Some(&url.as_str().to_variant()))
187+
.unwrap()
188+
} else {
189+
self.spawn_open_url(url);
190+
}
191+
181192
Ok(())
182193
}
183194
fn handle_right_click(&self, x: f64, y: f64) -> Result<()> {
@@ -395,8 +406,8 @@ impl Tab {
395406
let this = self.clone();
396407
let left_click_ctrl = imp.left_click_ctrl.borrow();
397408
let left_click_ctrl = left_click_ctrl.as_ref().unwrap();
398-
left_click_ctrl.connect_released(move |_ctrl, _n_press, x, y| {
399-
if let Err(e) = this.handle_click(x, y) {
409+
left_click_ctrl.connect_released(move |ctrl, _n_press, x, y| {
410+
if let Err(e) = this.handle_click(ctrl, x, y) {
400411
info!("{}", e);
401412
};
402413
});

src/widgets/window.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ impl Window {
215215
self_action!(self, "focus-url-bar", focus_url_bar);
216216
self_action!(self, "shortcuts", present_shortcuts);
217217
self_action!(self, "about", present_about);
218-
self_action!(self, "focus-tab-previous", focus_tab_previous);
219-
self_action!(self, "focus-tab-next", focus_tab_next);
218+
self_action!(self, "focus-previous-tab", focus_previous_tab);
219+
self_action!(self, "focus-next-tab", focus_next_tab);
220220
self_action!(self, "donate", donate);
221221
self_action!(self, "zoom-in", zoom_in);
222222
self_action!(self, "zoom-out", zoom_out);
@@ -313,6 +313,24 @@ impl Window {
313313
ctrl.connect_motion(move |_, _, _| {
314314
url_status_box_clone.set_visible(false);
315315
});
316+
317+
let ctrl = gtk::EventControllerKey::new();
318+
ctrl.set_propagation_limit(gtk::PropagationLimit::None);
319+
ctrl.set_propagation_phase(gtk::PropagationPhase::Capture);
320+
self.add_controller(&ctrl);
321+
ctrl.connect_key_pressed(
322+
clone!(@weak self as this => @default-panic, move |_, key, _, modif| {
323+
let action = match (modif.contains(gdk::ModifierType::CONTROL_MASK), key) {
324+
(true, gdk::Key::ISO_Left_Tab) => Some("win.focus-previous-tab"),
325+
(true, gdk::Key::Tab) => Some("win.focus-next-tab"),
326+
_ => None,
327+
};
328+
action
329+
.map(|a| WidgetExt::activate_action(&this, a, None))
330+
.map(|_| gtk::Inhibit(true))
331+
.unwrap_or(gtk::Inhibit(false))
332+
}),
333+
);
316334
}
317335
fn setup_zoom_popover_item(&self) {
318336
let imp = self.imp();
@@ -597,11 +615,11 @@ impl Window {
597615
0,
598616
);
599617
}
600-
fn focus_tab_next(&self) {
618+
fn focus_next_tab(&self) {
601619
let imp = self.imp();
602620
imp.tab_view.select_next_page();
603621
}
604-
fn focus_tab_previous(&self) {
622+
fn focus_previous_tab(&self) {
605623
let imp = self.imp();
606624
imp.tab_view.select_previous_page();
607625
}

0 commit comments

Comments
 (0)