Skip to content

Commit bd21ea1

Browse files
authored
Merge pull request #28 from ranfdev/accels
Add prev, forward accelerators on extra mouse buttons (8, 9)
2 parents a5713de + b115564 commit bd21ea1

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ fn main() {
8787
windows.borrow_mut().push(window);
8888
});
8989

90-
application.set_accels_for_action("win.previous", &["<Alt>Left"]);
91-
application.set_accels_for_action("win.next", &["<Alt>Right"]);
90+
application.set_accels_for_action(
91+
"win.previous",
92+
&["<Alt>Left", "<Alt>KP_Left", "Pointer_DfltBtnPrev"],
93+
);
94+
application.set_accels_for_action(
95+
"win.next",
96+
&["<Alt>Right", "<Alt>KP_Right", "Pointer_DfltBtnNext"],
97+
);
9298
application.set_accels_for_action("win.show-bookmarks", &["<Ctrl>b"]);
9399
application.set_accels_for_action("win.bookmark-current", &["<Ctrl>d"]);
94100
application.set_accels_for_action("win.new-tab", &["<Ctrl>t"]);

src/widgets/window.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub mod imp {
6666
#[property(get = Self::progress_animated, set = Self::set_progress_animated)]
6767
pub(crate) progress: PhantomData<f64>,
6868
pub(crate) scroll_ctrl: gtk::EventControllerScroll,
69+
pub(crate) mouse_prev_next_ctrl: gtk::GestureClick,
6970
pub(crate) action_previous: RefCell<Option<gio::SimpleAction>>,
7071
pub(crate) action_next: RefCell<Option<gio::SimpleAction>>,
7172
pub(crate) style_provider: RefCell<gtk::CssProvider>,
@@ -252,6 +253,7 @@ impl Window {
252253
let imp = self.imp();
253254

254255
self.add_controller(&imp.scroll_ctrl);
256+
self.add_controller(&imp.mouse_prev_next_ctrl);
255257
imp.scroll_ctrl
256258
.set_propagation_phase(gtk::PropagationPhase::Capture);
257259
imp.scroll_ctrl
@@ -272,6 +274,21 @@ impl Window {
272274
}
273275
}),
274276
);
277+
imp.mouse_prev_next_ctrl.set_button(0);
278+
imp.mouse_prev_next_ctrl.connect_pressed(
279+
clone!(@weak self as this => @default-panic, move |ctrl, _, _, _| {
280+
match ctrl.current_button() {
281+
8 => {
282+
this.previous();
283+
},
284+
9 => {
285+
this.next();
286+
},
287+
_ => {},
288+
}
289+
}),
290+
);
291+
275292
self.connect_local(
276293
"notify::url",
277294
false,

0 commit comments

Comments
 (0)