Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate button controllers - Gtk4 prep #787

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions src/Widgets/TerminalWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ namespace Terminal {
private Gtk.EventControllerMotion motion_controller;
private Gtk.EventControllerScroll scroll_controller;
private Gtk.EventControllerKey key_controller;
private Gtk.GestureMultiPress press_gesture;
private Gtk.GestureMultiPress primary_gesture;
private Gtk.GestureMultiPress secondary_gesture;

private bool modifier_pressed = false;
private double scroll_delta = 0.0;
Expand Down Expand Up @@ -208,12 +209,17 @@ namespace Terminal {
return true;
});

press_gesture = new Gtk.GestureMultiPress (this) {
primary_gesture = new Gtk.GestureMultiPress (this) {
propagation_phase = TARGET,
button = 0
button = 1
};
press_gesture.pressed.connect (button_pressed);
press_gesture.released.connect (button_released);
primary_gesture.pressed.connect (primary_pressed);

secondary_gesture = new Gtk.GestureMultiPress (this) {
propagation_phase = TARGET,
button = 3
};
secondary_gesture.released.connect (secondary_released);

// send events to key controller manually, since key_released isn't emitted in any propagation phase
event.connect (key_controller.handle_event);
Expand Down Expand Up @@ -298,33 +304,28 @@ namespace Terminal {
allow_hyperlink = has_focus;
}

private void button_pressed (Gtk.GestureMultiPress gesture, int n_press, double x, double y) {
link_uri = null;
private void secondary_released (Gtk.GestureMultiPress gesture, int n_press, double x, double y) {
link_uri = get_link (gesture.get_last_event (null));

if (gesture.get_current_button () == Gdk.BUTTON_SECONDARY) {
link_uri = get_link (gesture.get_last_event (null));

if (link_uri != null) {
copy_action.set_enabled (true);
}
if (link_uri != null) {
copy_action.set_enabled (true);
}

popup_context_menu ({ (int) x, (int) y });
popup_context_menu ({ (int) x, (int) y });

gesture.set_state (CLAIMED);
}
gesture.set_state (CLAIMED);
}

private void button_released (Gtk.GestureMultiPress gesture, int n_press, double x, double y) {
if (gesture.get_current_button () == Gdk.BUTTON_PRIMARY) {
if (allow_hyperlink) {
link_uri = get_link (gesture.get_last_event (null));
private void primary_pressed (Gtk.GestureMultiPress gesture, int n_press, double x, double y) {
link_uri = null;
if (allow_hyperlink) {
link_uri = get_link (gesture.get_last_event (null));

if (link_uri != null && !get_has_selection ()) {
main_window.get_simple_action (MainWindow.ACTION_OPEN_IN_BROWSER).activate (null);
}
} else {
allow_hyperlink = true;
if (link_uri != null && !get_has_selection ()) {
main_window.get_simple_action (MainWindow.ACTION_OPEN_IN_BROWSER).activate (null);
}
} else {
allow_hyperlink = true;
}
}

Expand Down