Skip to content

Commit

Permalink
feat(RichLabel): middle click open external browser (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Feb 16, 2025
1 parent 5361d67 commit 8cb9757
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Widgets/LabelWithWidgets.vala
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,8 @@ public class Tuba.Widgets.LabelWithWidgets : Gtk.Widget, Gtk.Buildable, Gtk.Acce
get { return label.justify; }
set { label.justify = value; }
}

public string? get_current_uri () {
return this.label.get_current_uri ();
}
}
19 changes: 19 additions & 0 deletions src/Widgets/RichLabel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ public class Tuba.Widgets.RichLabel : Adw.Bin {

this.update_relation (Gtk.AccessibleRelation.LABELLED_BY, widget, null, -1);
this.update_relation (Gtk.AccessibleRelation.DESCRIBED_BY, widget, null, -1);

#if WEBKIT
Gtk.GestureClick middle_click_gesture = new Gtk.GestureClick () {
button = Gdk.BUTTON_MIDDLE
};
middle_click_gesture.pressed.connect (on_middle_clicked);
this.add_controller (middle_click_gesture);
#endif
}

public bool on_activate_link (string url) {
Expand Down Expand Up @@ -197,4 +205,15 @@ public class Tuba.Widgets.RichLabel : Adw.Bin {
|| url.index_of_char ('@') != -1
|| "/user" in url;
}

#if WEBKIT
private void on_middle_clicked (int n_press, double x, double y) {
if (n_press > 1 || !settings.use_in_app_browser_if_available) return;

string? current_uri = widget.get_current_uri ();
if (current_uri == null) return;

Host.open_url.begin (current_uri);
}
#endif
}

0 comments on commit 8cb9757

Please sign in to comment.