]> git.eshelyaron.com Git - emacs.git/commit
Make browser windows pop up when browsing URLs on Wayland
authorDaniel Colascione <dancol@dancol.org>
Mon, 23 Dec 2024 18:34:11 +0000 (13:34 -0500)
committerEshel Yaron <me@eshelyaron.com>
Sat, 4 Jan 2025 20:22:39 +0000 (21:22 +0100)
commit68baf7e77cab1e8181a9cfc721889ea68d984fde
tree59f72ac4a42de44b7d834a929a4f643aef00c9d1
parent5a11a91f68c482f2ba72e3fbaa8c1f1f66aa1a2e
Make browser windows pop up when browsing URLs on Wayland

When a user invokes browse-url, the browser window viewing the URL
should be raised in the user's desktop environment.  On X11, running
xdg-open as a subprocess does the job.  However, on Wayland, this
approach doesn't work: xdg-open makes the web browser browse a URL all
right, but doesn't raise the browser window in the GUI.  Therefore, if
the browser window is behind Emacs, browse-url appears to do nothing.
Repeated invocations of browse-url cause the browser to load multiple
tabs in the background, surprising the user when he gives up in
frustration and manually switches to the browser window.

There's no subprocess we can run to make the right thing happen.
Wayland requires that we pass along event activation information to the
browser using the xdg_activation_v1 protocol.

This change adds x-gtk-launch-uri to invoke GTK-native URL-dispatch
machinery.  This machinery DTRT on both X11 and Wayland.  We fall back
to the default browser machinery if we're not on a GTK frame.

The logic is more complicated than it has to be because the GTK URI
launch mechanism requires that we launch with respect to a specific GTK
window, and in some environments (e.g., running emacs -nw in a PGTK
Emacs) we don't have a GTK window.  We also want to preserve the effect
of customizing browse-url-browser-function, so adding an entry to
browse-url-default-handlers that preempts URI open when we happen to be
on a GTK frame is the wrong thing to do.

* lisp/net/browse-url.el (browse-url--browser-defcustom-type):
(browse-url--inhibit-pgtk): avoid infinite recursion
(browse-url-default-browser): use pgtk launch
(x-gtk-launch-uri): new function
(browse-url-default-gtk-browser): ues it

* src/pgtkfns.c (unwind_gerror_ptr): new function
(Fx_gtk_launch_uri): new function
(syms_of_pgtkfns): register it

* etc/NEWS: mention the new feature

(cherry picked from commit 72eb5f8bedbe441f6a3952557b9aa3ef6fd6235d)
etc/NEWS
lisp/net/browse-url.el
src/pgtkfns.c