patch 9.1.1485: missing Wayland clipboard support

Problem:  missing Wayland clipboard support
Solution: make it work (Foxe Chen)

fixes: #5157
closes: #17097

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/runtime/doc/Make_all.mak b/runtime/doc/Make_all.mak
index 1715382..938ee69 100644
--- a/runtime/doc/Make_all.mak
+++ b/runtime/doc/Make_all.mak
@@ -153,6 +153,7 @@
 	vim9class.txt \
 	visual.txt \
 	vietnamese.txt \
+	wayland.txt \
 	windows.txt \
 	workshop.txt
 
@@ -309,6 +310,7 @@
 	vim9.html \
 	vim9class.html \
 	visual.html \
+	wayland.html \
 	windows.html \
 	workshop.html
 
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 8bd914b..969b9c7 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -1,4 +1,4 @@
-*builtin.txt*	For Vim version 9.1.  Last change: 2025 Jun 23
+*builtin.txt*	For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
@@ -13038,6 +13038,8 @@
 vreplace		Compiled with |gR| and |gr| commands. (always true)
 vtp			Compiled for vcon support |+vtp| (check vcon to find
 			out if it works in the current console).
+wayland			Compiled with Wayland protocol support.
+wayland_clipboard       Compiled with support for Wayland selections/clipboard
 wildignore		Compiled with 'wildignore' option.
 wildmenu		Compiled with 'wildmenu' option.
 win16			old version for MS-Windows 3.1 (always false)
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 492a444..4ea7a5c 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1,4 +1,4 @@
-*eval.txt*	For Vim version 9.1.  Last change: 2025 Jun 04
+*eval.txt*	For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
@@ -2240,6 +2240,15 @@
 		The name of the character encoding of a file after conversion.
 		Only valid while evaluating the 'charconvert' option.
 
+					*v:clipmethod*
+v:clipmethod	The current method of accessing the clipboard that is being
+		used. Can either have the value of:
+			wayland		The Wayland protocol is being used.
+			x11		X11 selections are being used.
+			none		The above methods are unavailable
+					or cannot be used.
+		See 'clipmethod' for more details.
+
 					*v:cmdarg* *cmdarg-variable*
 v:cmdarg	This variable is used for two purposes:
 		1. The extra arguments given to a file read/write command.
@@ -2969,6 +2978,12 @@
 					*v:warningmsg* *warningmsg-variable*
 v:warningmsg	Last given warning message.  It's allowed to set this variable.
 
+					*v:wayland_display*
+v:wayland_display
+		The name of the Wayland display that Vim is connected to.
+		Equivalent to the $WAYLAND_DISPLAY environment variable.
+		If this is empty, then Vim is not connected to any display.
+
 					*v:windowid* *windowid-variable*
 v:windowid	When any X11/Wayland based GUI is running or when running in a
 		terminal and Vim connects to the X server (|-X|) this will be
diff --git a/runtime/doc/help.txt b/runtime/doc/help.txt
index a798685..e8f15c7 100644
--- a/runtime/doc/help.txt
+++ b/runtime/doc/help.txt
@@ -1,4 +1,4 @@
-*help.txt*	For Vim version 9.1.  Last change: 2024 Dec 06
+*help.txt*	For Vim version 9.1.  Last change: 2025 Jun 27
 
 			VIM - main help file
 									 k
@@ -187,6 +187,9 @@
 |gui_w32.txt|	Win32 GUI
 |gui_x11.txt|	X11 GUI
 
+System Integration ~
+|wayland.txt|	Wayland protocol support
+
 Interfaces ~
 |if_cscop.txt|	using Cscope with Vim
 |if_lua.txt|	Lua interface
diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt
index 11c0efd..8205777 100644
--- a/runtime/doc/index.txt
+++ b/runtime/doc/index.txt
@@ -1,4 +1,4 @@
-*index.txt*     For Vim version 9.1.  Last change: 2025 Jun 23
+*index.txt*     For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1587,6 +1587,7 @@
 |:redrawtabpanel| :redrawtabp[anel] force a redraw of the tabpanel
 |:registers|	:reg[isters]	display the contents of registers
 |:resize|	:res[ize]	change current window height
+|:clipreset|	:clip[reset]	reset 'clipmethod'
 |:retab|	:ret[ab]	change tab size
 |:return|	:retu[rn]	return from a user function
 |:rewind|	:rew[ind]	go to the first file in the argument list
@@ -1777,6 +1778,7 @@
 |:winsize|	:wi[nsize]	get or set window size (obsolete)
 |:wincmd|	:winc[md]	execute a Window (CTRL-W) command
 |:winpos|	:winp[os]	get or set window position
+|:wlrestore|	:wl[restore]	restore the Wayland compositor connection
 |:wnext|	:wn[ext]	write to a file and go to next file in
 				argument list
 |:wprevious|	:wp[revious]	write to a file and go to previous file in
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 1f2f400..d4fb51e 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1,4 +1,4 @@
-*options.txt*	For Vim version 9.1.  Last change: 2025 Jun 18
+*options.txt*	For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
@@ -1785,7 +1785,7 @@
 						  for X-windows, "" otherwise)
 			global
 			{only in GUI versions or when the |+xterm_clipboard|
-			feature is included}
+			or |+wayland_clipboard| features are included}
 	This option is a list of comma-separated names.
 	Note: if one of the items is "exclude:", then you can't add an item
 	after that.  Therefore do not append an item with += but use ^= to
@@ -1812,10 +1812,13 @@
 			register.  When "unnamed" is also included to the
 			option, yank operations (but not delete, change or
 			put) will additionally copy the text into register
-			'*'.
-			Only available with the |+X11| feature.
-			Availability can be checked with: >
-				if has('unnamedplus')
+			'*'. If wayland is being used and the compositor does
+			not support the primary-selection-unstable-v1
+			protocol, then the regular selection is used in its
+			place.  Only available with the |+X11| or
+			|+wayland_clipboard| feature.  Availability can be
+			checked with: >
+			if has('unnamedplus')
 <
 						*clipboard-autoselect*
 	autoselect	Works like the 'a' flag in 'guioptions': If present,
@@ -1852,24 +1855,54 @@
 	exclude:{pattern}
 			Defines a pattern that is matched against the name of
 			the terminal 'term'.  If there is a match, no
-			connection will be made to the X server.  This is
-			useful in this situation:
+			connection will be made to the X server or wayland
+			compositor.  This is useful in this situation:
 			- Running Vim in a console.
-			- $DISPLAY is set to start applications on another
-			  display.
-			- You do not want to connect to the X server in the
-			  console, but do want this in a terminal emulator.
-			To never connect to the X server use: >
+			- $DISPLAY/$WAYLAND_DISPLAY is set to start
+			   applications on another display.
+			- You do not want to connect to the X server/Wayland
+			  compositor in the console, but do want this in a
+			  terminal emulator.
+			To never connect to the X server/Wayland compositor
+			use: >
 				exclude:.*
-<			This has the same effect as using the |-X| argument.
+<			This has the same effect as using the |-X| or |-Y| argument.
 			Note that when there is no connection to the X server
 			the window title won't be restored and the clipboard
-			cannot be accessed.
+			cannot be accessed. This is the same for Wayland,
+			except there is no title restoring.
 			The value of 'magic' is ignored, {pattern} is
 			interpreted as if 'magic' was on.
 			The rest of the option value will be used for
 			{pattern}, this must be the last entry.
 
+						*'clipmethod'* *'cpm'*
+'clipmethod' 'cpm'	string	(default for Unix: "wayland,x11",
+				 for VMS: "x11",
+				 otherwise: "")
+
+			global
+			{only when the |+xterm_clipboard| or |+wayland_clipboard|
+			features are included}
+	Specifies which method of accessing the system clipboard is used,
+	depending on which method works first or is available.  Supported
+	methods are:
+		wayland		Wayland selections
+		x11		X11 selections
+
+	Note: This option is ignored when either the GUI is running or if Vim
+	is run on a system without wayland or X11 support, such as Windows or
+	macOS.  The GUI or system way of accessing the clipboard is always
+	used instead.
+
+	The option value is a list of comma separated items.  The list is parsed
+	left to right in order, and the first method that Vim determines is
+	available or is working is used as the actual method for accessing the
+	clipboard.
+
+	The current method that is being used can be found in the |v:clipmethod|
+	variable.
+
 						*'cmdheight'* *'ch'*
 'cmdheight' 'ch'	number	(default 1)
 			global or local to tab page
@@ -4586,9 +4619,9 @@
 	|hl-Title|	 t  Titles for output from ":set all", ":autocmd" etc.
 	|hl-VertSplit|	 c  column used to separate vertically split windows
 	|hl-Visual|	 v  Visual mode
-	|hl-VisualNOS|	 V  Visual mode when Vim does is "Not Owning the
-			    Selection" Only X11 Gui's |gui-x11| and
-			    |xterm-clipboard|.
+	|hl-VisualNOS|	 V  Visual mode when Vim is "Not Owning the
+			    Selection" Only X11 Gui's |gui-x11|,
+			    |xterm-clipboard| and |wayland-selections|
 	|hl-WarningMsg|	 w  warning messages
 	|hl-WildMenu|	 W  wildcard matches displayed for 'wildmenu'
 	|hl-Folded|	 f  line used for closed folds
@@ -10043,6 +10076,40 @@
 	'winwidth' applies to the current window.  Use 'winminwidth' to set
 	the minimal width for other windows.
 
+						*'wlseat'* *'wse'*
+'wlseat' 'wse'		string	(default "")
+			global
+			{only when the |+wayland| feature is included}
+	Specifies the Wayland seat to use for Wayland functionality,
+	specifically the clipboard. If the seat does not exist, then the
+	option will still be set to the new value, with the Wayland clipboard
+	being unavailable as a result. If an empty value is passed then Vim
+	will attempt to use the value of $XDG_SEAT if it exists, if not then
+	it resorts to using the first seat found available. Updating this
+	option will also update |v:clipmethod|.
+
+					*'wlsteal'* *'wst'* *'nowlsteal'* *'nowst'*
+'wlsteal' 'wst'		boolean  (default off)
+			global
+			{only when the |+wayland_clipboard| feature is included}
+	When enabled, then allow Vim to steal focus by creating a temporary
+	surface, in order to access the clipboard. For more information see
+	|wayland-focus-steal|.
+
+						*'wltimeoutlen'* *'wtm'*
+'wltimeoutlen' 'wtm'	number	(default 500)
+			global
+			{only when the |+wayland| feature is included}
+	The timeout in milliseconds before Vim gives up on waiting for the
+	Wayland compositor.  While Vim waits on the compositor, it is
+	unresponsive to input and does not update the screen.  Therefore
+	setting this to a lower value may make Vim feel more responsive in
+	some cases.  On the other hand, it may also mean you receive errors
+	when the compositor takes more time to respond than usual.
+
+	Additionally, this option is also used as the maximum timeout when
+	waiting for a surface to gain focus, see |wayland-focus-steal|.
+
 						*'wrap'* *'nowrap'*
 'wrap'			boolean	(default on)
 			local to window
diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt
index ecabac5..55e7cc3 100644
--- a/runtime/doc/quickref.txt
+++ b/runtime/doc/quickref.txt
@@ -1,4 +1,4 @@
-*quickref.txt*  For Vim version 9.1.  Last change: 2025 Jun 12
+*quickref.txt*  For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -646,6 +646,7 @@
 'cinscopedecls'	  'cinsd'   words that are recognized by 'cino-g'
 'cinwords'	  'cinw'    words where 'si' and 'cin' add an indent
 'clipboard'	  'cb'	    use the clipboard as the unnamed register
+'clipmethod'      'cpm'     specify order of what clipboard methods to use
 'cmdheight'	  'ch'	    number of lines to use for the command-line
 'cmdwinheight'	  'cwh'     height of the command-line window
 'colorcolumn'	  'cc'	    columns to highlight
@@ -1018,6 +1019,9 @@
 'winminwidth'	  'wmw'     minimal number of columns for any window
 'winptydll'		    name of the winpty dynamic library
 'winwidth'	  'wiw'     minimal number of columns for current window
+'wlseat'	  'wse'     the wayland seat to use
+'wlsteal'	  'wst'     allow focus stealing functionality for wayland
+'wltimeoutlen'    'wtm'     timeout to use when polling in wayland
 'wrap'			    long lines wrap and continue on the next line
 'wrapmargin'	  'wm'	    chars from the right where wrapping starts
 'wrapscan'	  'ws'	    searches wrap around the end of the file
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index ccedc1a..7d3cd2b 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -1,4 +1,4 @@
-*starting.txt*  For Vim version 9.1.  Last change: 2025 Feb 27
+*starting.txt*  For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -559,6 +559,12 @@
 		client-server messages), call the |serverlist()| function.
 		This does not enable the XSMP handler though.
 
+							*-Y*
+-Y		Do not try connecting to the Wayland compositor. Is only
+		relevant for Unix when compiled with the |+wayland| feature,
+		otherwise it's ignored. Note that this will make any feature
+		that uses Wayland unavailable, such as the clipboard.
+
 							*-s*
 -s {scriptin}	The script file "scriptin" is read.  The characters in the
 		file are interpreted as if you had typed them.  The same can
diff --git a/runtime/doc/tags b/runtime/doc/tags
index 2ec4979..c96a8b6 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -149,6 +149,7 @@
 'cinw'	options.txt	/*'cinw'*
 'cinwords'	options.txt	/*'cinwords'*
 'clipboard'	options.txt	/*'clipboard'*
+'clipmethod'	options.txt	/*'clipmethod'*
 'cm'	options.txt	/*'cm'*
 'cmdheight'	options.txt	/*'cmdheight'*
 'cmdwinheight'	options.txt	/*'cmdwinheight'*
@@ -178,6 +179,7 @@
 'copyindent'	options.txt	/*'copyindent'*
 'cot'	options.txt	/*'cot'*
 'cp'	options.txt	/*'cp'*
+'cpm'	options.txt	/*'cpm'*
 'cpo'	options.txt	/*'cpo'*
 'cpoptions'	options.txt	/*'cpoptions'*
 'cpp'	options.txt	/*'cpp'*
@@ -803,6 +805,7 @@
 'nowinfixheight'	options.txt	/*'nowinfixheight'*
 'nowinfixwidth'	options.txt	/*'nowinfixwidth'*
 'nowiv'	options.txt	/*'nowiv'*
+'nowlsteal'	options.txt	/*'nowlsteal'*
 'nowmnu'	options.txt	/*'nowmnu'*
 'nowrap'	options.txt	/*'nowrap'*
 'nowrapscan'	options.txt	/*'nowrapscan'*
@@ -810,6 +813,7 @@
 'nowriteany'	options.txt	/*'nowriteany'*
 'nowritebackup'	options.txt	/*'nowritebackup'*
 'nows'	options.txt	/*'nows'*
+'nowst'	options.txt	/*'nowst'*
 'noxtermcodes'	options.txt	/*'noxtermcodes'*
 'nrformats'	options.txt	/*'nrformats'*
 'nu'	options.txt	/*'nu'*
@@ -1334,6 +1338,9 @@
 'winwidth'	options.txt	/*'winwidth'*
 'wiv'	options.txt	/*'wiv'*
 'wiw'	options.txt	/*'wiw'*
+'wlseat'	options.txt	/*'wlseat'*
+'wlsteal'	options.txt	/*'wlsteal'*
+'wltimeoutlen'	options.txt	/*'wltimeoutlen'*
 'wm'	options.txt	/*'wm'*
 'wmh'	options.txt	/*'wmh'*
 'wmnu'	options.txt	/*'wmnu'*
@@ -1347,6 +1354,9 @@
 'writebackup'	options.txt	/*'writebackup'*
 'writedelay'	options.txt	/*'writedelay'*
 'ws'	options.txt	/*'ws'*
+'wse'	options.txt	/*'wse'*
+'wst'	options.txt	/*'wst'*
+'wtm'	options.txt	/*'wtm'*
 'ww'	options.txt	/*'ww'*
 'xtermcodes'	options.txt	/*'xtermcodes'*
 '{	motion.txt	/*'{*
@@ -1512,6 +1522,8 @@
 +visualextra	various.txt	/*+visualextra*
 +vreplace	various.txt	/*+vreplace*
 +vtp	various.txt	/*+vtp*
++wayland	various.txt	/*+wayland*
++wayland_clipboard	various.txt	/*+wayland_clipboard*
 +wildignore	various.txt	/*+wildignore*
 +wildmenu	various.txt	/*+wildmenu*
 +windows	various.txt	/*+windows*
@@ -1582,6 +1594,7 @@
 -V	starting.txt	/*-V*
 -W	starting.txt	/*-W*
 -X	starting.txt	/*-X*
+-Y	starting.txt	/*-Y*
 -Z	starting.txt	/*-Z*
 -b	starting.txt	/*-b*
 -background	gui_x11.txt	/*-background*
@@ -2404,6 +2417,8 @@
 :clast	quickfix.txt	/*:clast*
 :cle	motion.txt	/*:cle*
 :clearjumps	motion.txt	/*:clearjumps*
+:clip	various.txt	/*:clip*
+:clipreset	various.txt	/*:clipreset*
 :clist	quickfix.txt	/*:clist*
 :clo	windows.txt	/*:clo*
 :close	windows.txt	/*:close*
@@ -3652,6 +3667,8 @@
 :winp	gui.txt	/*:winp*
 :winpos	gui.txt	/*:winpos*
 :winsize	gui.txt	/*:winsize*
+:wl	wayland.txt	/*:wl*
+:wlrestore	wayland.txt	/*:wlrestore*
 :wn	editing.txt	/*:wn*
 :wnext	editing.txt	/*:wnext*
 :wp	editing.txt	/*:wp*
@@ -4646,6 +4663,7 @@
 E1540	eval.txt	/*E1540*
 E1541	vi_diff.txt	/*E1541*
 E1547	various.txt	/*E1547*
+E1548	wayland.txt	/*E1548*
 E155	sign.txt	/*E155*
 E156	sign.txt	/*E156*
 E157	sign.txt	/*E157*
@@ -11094,6 +11112,7 @@
 v:char	eval.txt	/*v:char*
 v:charconvert_from	eval.txt	/*v:charconvert_from*
 v:charconvert_to	eval.txt	/*v:charconvert_to*
+v:clipmethod	eval.txt	/*v:clipmethod*
 v:cmdarg	eval.txt	/*v:cmdarg*
 v:cmdbang	eval.txt	/*v:cmdbang*
 v:collate	eval.txt	/*v:collate*
@@ -11197,6 +11216,7 @@
 v:versionlong	eval.txt	/*v:versionlong*
 v:vim_did_enter	eval.txt	/*v:vim_did_enter*
 v:warningmsg	eval.txt	/*v:warningmsg*
+v:wayland_display	eval.txt	/*v:wayland_display*
 v:windowid	eval.txt	/*v:windowid*
 v_!	change.txt	/*v_!*
 v_$	visual.txt	/*v_$*
@@ -11555,6 +11575,17 @@
 w:var	eval.txt	/*w:var*
 waittime	channel.txt	/*waittime*
 warningmsg-variable	eval.txt	/*warningmsg-variable*
+wayland	wayland.txt	/*wayland*
+wayland-and-x11	wayland.txt	/*wayland-and-x11*
+wayland-focus-steal	wayland.txt	/*wayland-focus-steal*
+wayland-gnome	wayland.txt	/*wayland-gnome*
+wayland-gui	wayland.txt	/*wayland-gui*
+wayland-persist	wayland.txt	/*wayland-persist*
+wayland-primary-selection	wayland.txt	/*wayland-primary-selection*
+wayland-seat	wayland.txt	/*wayland-seat*
+wayland-selections	wayland.txt	/*wayland-selections*
+wayland-useful	wayland.txt	/*wayland-useful*
+wayland.txt	wayland.txt	/*wayland.txt*
 wdl-syntax	syntax.txt	/*wdl-syntax*
 wdl.vim	syntax.txt	/*wdl.vim*
 white-space	pattern.txt	/*white-space*
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
index d6fb641..7a097be 100644
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -1,4 +1,4 @@
-*various.txt*   For Vim version 9.1.  Last change: 2025 Jun 10
+*various.txt*   For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -524,6 +524,8 @@
 T  *+visualextra*	extra Visual mode commands |blockwise-operators|
 T  *+vreplace*		|gR| and |gr|
    *+vtp*		on MS-Windows console: support for 'termguicolors'
+N  *+wayland*		Unix only: support for the Wayland protocol.
+N  *+wayland_clipboard*	Unix only: support for Wayland selections/clipboard.
 T  *+wildignore*	|'wildignore'|  Always enabled since 9.0.0278
 T  *+wildmenu*		|'wildmenu'|  Always enabled since 9.0.0279
 T  *+windows*		more than one window; Always enabled since 8.0.1118.
@@ -791,7 +793,15 @@
 			was used for the previous execution of this command.
 			If the value was never specified, then it uses the
 			value of $DISPLAY environment variable as it was when
-			Vim was started.
+			Vim was started.  This will also update |v:clipmethod|.
+			{only available when compiled with the |+xterm_clipboard|
+			feature}
+
+							*:clipreset* *:clip*
+:clip[reset]		Attempts to choose a new method for accessing the
+			clipboard, using the 'clipmethod' option. This is
+			useful when the current method has become unavailable,
+			and you want to try using another method.
 			{only available when compiled with the |+clipboard|
 			feature}
 
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index 606ec79..f2618e5 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2025 Jun 23
+*version9.txt*  For Vim version 9.1.  Last change: 2025 Jun 27
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41571,7 +41571,7 @@
 The new packages |package-comment|, |package-nohlsearch| and |package-hlyank|
 are included.
 
-Support for Wayland UI.
+Support for Wayland UI and support for the Wayland clipboard
 
 Support for the XDG Desktop Specification |xdg-base-dir|
 
diff --git a/runtime/doc/vim.1 b/runtime/doc/vim.1
index efef7bb..1371cb1 100644
--- a/runtime/doc/vim.1
+++ b/runtime/doc/vim.1
@@ -1,4 +1,4 @@
-.TH VIM 1 "2024 Aug 12"
+.TH VIM 1 "2025 Jun 27"
 .SH NAME
 vim \- Vi IMproved, a programmer's text editor
 .SH SYNOPSIS
@@ -404,6 +404,9 @@
 Don't connect to the X server.  Shortens startup time in a terminal, but the
 window title and clipboard will not be used.
 .TP
+\-Y
+Don't connect to the wayland compositor
+.TP
 \-y
 Start
 .B Vim
@@ -559,7 +562,7 @@
 System wide gvim initializations.
 .TP
 ~/.gvimrc, ~/.vim/gvimrc, $XDG_CONFIG_HOME/vim/gvimrc
-Your personal 
+Your personal
 .B gVim
 initializations (first one found is used).
 .TP
@@ -567,7 +570,7 @@
 Script used for the ":options" command, a nice way to view and set options.
 .TP
 /usr/local/share/vim/vim??/menu.vim
-System wide menu initializations for 
+System wide menu initializations for
 .B gVim.
 .TP
 /usr/local/share/vim/vim??/bugreport.vim
diff --git a/runtime/doc/vim.man b/runtime/doc/vim.man
index ce1cc63..6d9cfe6 100644
--- a/runtime/doc/vim.man
+++ b/runtime/doc/vim.man
@@ -36,11 +36,11 @@
             vim [options] [filelist]
 
        If the filelist is missing, the editor will start with an empty buffer.
-       Otherwise exactly one out of the following four may be used  to  choose
+       Otherwise  exactly  one out of the following four may be used to choose
        one or more files to be edited.
 
-       file ..     A  list  of  filenames.   The first one will be the current
-                   file and read into the buffer.  The cursor  will  be  posi‐
+       file ..     A list of filenames.  The first one  will  be  the  current
+                   file  and  read  into the buffer.  The cursor will be posi‐
                    tioned on the first line of the buffer.  You can get to the
                    other files with the ":next" command.  To edit a file  that
                    starts with a dash, precede the filelist with "--".
@@ -49,18 +49,18 @@
                    from stderr, which should be a tty.
 
        -t {tag}    The file to edit and the initial cursor position depends on
-                   a  "tag",  a sort of goto label.  {tag} is looked up in the
+                   a "tag", a sort of goto label.  {tag} is looked up  in  the
                    tags file, the associated file becomes the current file and
                    the  associated  command  is executed.  Mostly this is used
                    for C programs, in which case {tag}  could  be  a  function
                    name.  The effect is that the file containing that function
-                   becomes the current file and the cursor  is  positioned  on
+                   becomes  the  current  file and the cursor is positioned on
                    the start of the function.  See ":help tag-commands".
 
        -q [errorfile]
-                   Start  in  quickFix mode.  The file [errorfile] is read and
-                   the first error is displayed.  If [errorfile]  is  omitted,
-                   the  filename  is obtained from the 'errorfile' option (de‐
+                   Start in quickFix mode.  The file [errorfile] is  read  and
+                   the  first  error is displayed.  If [errorfile] is omitted,
+                   the filename is obtained from the 'errorfile'  option  (de‐
                    faults to "AztecC.Err" for the Amiga, "errors.err" on other
                    systems).   Further  errors can be jumped to with the ":cn"
                    command.  See ":help quickfix".
@@ -70,10 +70,10 @@
 
        vim       The "normal" way, everything is default.
 
-       ex        Start  in Ex mode.  Go to Normal mode with the ":vi" command.
+       ex        Start in Ex mode.  Go to Normal mode with the ":vi"  command.
                  Can also be done with the "-e" argument.
 
-       view      Start in read-only mode.  You will be protected from  writing
+       view      Start  in read-only mode.  You will be protected from writing
                  the files.  Can also be done with the "-R" argument.
 
        gvim gview
@@ -124,72 +124,72 @@
                    ists.
 
        -d          Start in diff mode.  There should between two to eight file
-                   name  arguments.  Vim will open all the files and show dif‐
+                   name arguments.  Vim will open all the files and show  dif‐
                    ferences between them.  Works like vimdiff(1).
 
        -d {device}, -dev {device}
-                   Open {device} for use as a terminal.  Only  on  the  Amiga.
+                   Open  {device}  for  use as a terminal.  Only on the Amiga.
                    Example: "-d con:20/30/600/150".
 
-       -D          Debugging.   Go  to debugging mode when executing the first
+       -D          Debugging.  Go to debugging mode when executing  the  first
                    command from a script.
 
-       -e          Start Vim in Ex mode, just like the executable  was  called
+       -e          Start  Vim  in Ex mode, just like the executable was called
                    "ex".
 
        -E          Start Vim in improved Ex mode, just like the executable was
                    called "exim".
 
        -f          Foreground.  For the GUI version, Vim will not fork and de‐
-                   tach  from  the shell it was started in.  On the Amiga, Vim
-                   is not restarted to open a new window.  This option  should
-                   be  used  when  Vim is executed by a program that will wait
-                   for the edit session to finish (e.g. mail).  On  the  Amiga
+                   tach from the shell it was started in.  On the  Amiga,  Vim
+                   is  not restarted to open a new window.  This option should
+                   be used when Vim is executed by a program  that  will  wait
+                   for  the  edit session to finish (e.g. mail).  On the Amiga
                    the ":sh" and ":!" commands will not work.
 
-       -F          If  Vim  has  been  compiled with FKMAP support for editing
-                   right-to-left oriented files and  Farsi  keyboard  mapping,
-                   this  option  starts  Vim  in  Farsi mode, i.e. 'fkmap' and
-                   'rightleft' are set.  Otherwise an error message  is  given
+       -F          If Vim has been compiled with  FKMAP  support  for  editing
+                   right-to-left  oriented  files  and Farsi keyboard mapping,
+                   this option starts Vim in  Farsi  mode,  i.e.  'fkmap'  and
+                   'rightleft'  are  set.  Otherwise an error message is given
                    and Vim aborts.
                    Note: Farsi support has been removed in patch 8.1.0932.
 
-       -g          If  Vim has been compiled with GUI support, this option en‐
+       -g          If Vim has been compiled with GUI support, this option  en‐
                    ables the GUI.  If no GUI support was compiled in, an error
                    message is given and Vim aborts.
 
        -H          If Vim has been compiled with RIGHTLEFT support for editing
-                   right-to-left oriented files and Hebrew  keyboard  mapping,
-                   this  option  starts  Vim  in Hebrew mode, i.e. 'hkmap' and
-                   'rightleft' are set.  Otherwise an error message  is  given
+                   right-to-left  oriented  files and Hebrew keyboard mapping,
+                   this option starts Vim in Hebrew  mode,  i.e.  'hkmap'  and
+                   'rightleft'  are  set.  Otherwise an error message is given
                    and Vim aborts.
 
        -i {viminfo}
-                   Specifies  the  filename to use when reading or writing the
-                   viminfo file, instead of the  default  "~/.viminfo".   This
-                   can  also  be used to skip the use of the .viminfo file, by
+                   Specifies the filename to use when reading or  writing  the
+                   viminfo  file,  instead  of the default "~/.viminfo".  This
+                   can also be used to skip the use of the .viminfo  file,  by
                    giving the name "NONE".
 
        -l          Lisp mode.  Sets the 'lisp' and 'showmatch' options on.
 
        -L          Same as -r.
 
-       -m          Modifying files is disabled.  Resets  the  'write'  option.
-                   You  can still modify the buffer, but writing a file is not
+       -m          Modifying  files  is  disabled.  Resets the 'write' option.
+                   You can still modify the buffer, but writing a file is  not
                    possible.
 
-       -M          Modifications not allowed.  The  'modifiable'  and  'write'
-                   options  will be unset, so that changes are not allowed and
-                   files can not be written.  Note that these options  can  be
+       -M          Modifications  not  allowed.   The 'modifiable' and 'write'
+                   options will be unset, so that changes are not allowed  and
+                   files  can  not be written.  Note that these options can be
                    set to enable making modifications.
 
-       -n          No  swap file will be used.  Recovery after a crash will be
-                   impossible.  Handy if you want to edit a  file  on  a  very
-                   slow  medium  (e.g.  floppy).   Can also be done with ":set
+       -n          No swap file will be used.  Recovery after a crash will  be
+                   impossible.   Handy  if  you  want to edit a file on a very
+                   slow medium (e.g. floppy).  Can also  be  done  with  ":set
                    uc=0".  Can be undone with ":set uc=200".
 
-       -N          No-compatible mode.  Resets the 'compatible' option.   This
-                   will  make Vim behave a bit better, but less Vi compatible,
+       -N          No-compatible  mode.  Resets the 'compatible' option.  This
+                   will make Vim behave a bit better, but less Vi  compatible,
                    even though a .vimrc file does not exist.
 
        -nb         Become an editor server for NetBeans.  See the docs for de‐
@@ -198,7 +198,7 @@
        -o[N]       Open N windows stacked.  When N is omitted, open one window
                    for each file.
 
-       -O[N]       Open N windows side by side.  When N is omitted,  open  one
+       -O[N]       Open  N  windows side by side.  When N is omitted, open one
                    window for each file.
 
        -p[N]       Open N tab pages.  When N is omitted, open one tab page for
@@ -209,15 +209,15 @@
                    tion.   When possible, Vim will run in an MDI window inside
                    the application. {parent-title} must appear in  the  window
                    title of the parent application.  Make sure that it is spe‐
-                   cific enough. Note that the implementation is still  primi‐
-                   tive.   It  won't  work  with all applications and the menu
+                   cific  enough. Note that the implementation is still primi‐
+                   tive.  It won't work with all  applications  and  the  menu
                    doesn't work.
 
-       -r          List swap files, with information about using them for  re‐
+       -r          List  swap files, with information about using them for re‐
                    covery.
 
-       -r {file}   Recovery  mode.  The swap file is used to recover a crashed
-                   editing session.  The swap file is a  file  with  the  same
+       -r {file}   Recovery mode.  The swap file is used to recover a  crashed
+                   editing  session.   The  swap  file is a file with the same
                    filename as the text file with ".swp" appended.  See ":help
                    recovery".
 
@@ -272,15 +272,15 @@
 
        -V[N]{filename}
                    Like -V and set 'verbosefile' to {filename}.  The result is
-                   that messages are not displayed but  written  to  the  file
+                   that  messages  are  not  displayed but written to the file
                    {filename}.  {filename} must not start with a digit.
 
        -w{number}  Set the 'window' option to {number}.
 
        -w {scriptout}
-                   All  the  characters that you type are recorded in the file
-                   {scriptout}, until you exit Vim.  This  is  useful  if  you
-                   want  to  create  a script file to be used with "vim -s" or
+                   All the characters that you type are recorded in  the  file
+                   {scriptout},  until  you  exit  Vim.  This is useful if you
+                   want to create a script file to be used with  "vim  -s"  or
                    ":source!".  If the {scriptout} file exists, characters are
                    appended.
 
@@ -294,33 +294,35 @@
                    terminal,  but  the  window title and clipboard will not be
                    used.
 
+       -Y          Don't connect to the wayland compositor
+
        -y          Start Vim in easy mode, just like the executable was called
-                   "evim"  or "eview".  Makes Vim behave like a click-and-type
+                   "evim" or "eview".  Makes Vim behave like a  click-and-type
                    editor.
 
-       -Z          Restricted mode.  Works like  the  executable  starts  with
+       -Z          Restricted  mode.   Works  like  the executable starts with
                    "r".
 
-       --          Denotes  the end of the options.  Arguments after this will
-                   be handled as a file name.  This can  be  used  to  edit  a
+       --          Denotes the end of the options.  Arguments after this  will
+                   be  handled  as  a  file  name.  This can be used to edit a
                    filename that starts with a '-'.
 
-       --clean     Do  not  use  any  personal  configuration (vimrc, plugins,
-                   etc.).  Useful to see if a problem reproduces with a  clean
+       --clean     Do not use  any  personal  configuration  (vimrc,  plugins,
+                   etc.).   Useful to see if a problem reproduces with a clean
                    Vim setup.
 
        --cmd {command}
-                   Like  using  "-c",  but the command is executed just before
-                   processing any vimrc file.  You can use up to 10  of  these
+                   Like using "-c", but the command is  executed  just  before
+                   processing  any  vimrc file.  You can use up to 10 of these
                    commands, independently from "-c" commands.
 
        --echo-wid  GTK GUI only: Echo the Window ID on stdout.
 
        --gui-dialog-file {name}
-                   When  using the GUI, instead of showing a dialog, write the
-                   title and message of the dialog to file {name}.   The  file
-                   is  created  or  appended  to.  Only useful for testing, to
-                   avoid that the test gets stuck on a dialog  that  can't  be
+                   When using the GUI, instead of showing a dialog, write  the
+                   title  and  message of the dialog to file {name}.  The file
+                   is created or appended to.  Only  useful  for  testing,  to
+                   avoid  that  the  test gets stuck on a dialog that can't be
                    seen.  Without the GUI the argument is ignored.
 
        --help, -h, -?
@@ -374,7 +376,7 @@
                    List the names of all Vim servers that can be found.
 
        --servername {name}
-                   Use {name} as the server name.  Used for the  current  Vim,
+                   Use  {name}  as the server name.  Used for the current Vim,
                    unless used with a --remote argument, then it's the name of
                    the server to connect to.
 
@@ -404,12 +406,12 @@
 
 FILES
        /usr/local/share/vim/vim??/doc/*.txt
-                      The Vim documentation files.  Use ":help  doc-file-list"
+                      The  Vim documentation files.  Use ":help doc-file-list"
                       to get the complete list.
                       vim??  is short version number, like vim91 for Vim 9.1
 
        /usr/local/share/vim/vim??/doc/tags
-                      The  tags file used for finding information in the docu‐
+                      The tags file used for finding information in the  docu‐
                       mentation files.
 
        /usr/local/share/vim/vim??/syntax/syntax.vim
@@ -422,18 +424,18 @@
                       System wide Vim initializations.
 
        ~/.vimrc, ~/.vim/vimrc, $XDG_CONFIG_HOME/vim/vimrc
-                      Your personal Vim initializations (first  one  found  is
+                      Your  personal  Vim  initializations (first one found is
                       used).
 
        /usr/local/share/vim/gvimrc
                       System wide gvim initializations.
 
        ~/.gvimrc, ~/.vim/gvimrc, $XDG_CONFIG_HOME/vim/gvimrc
-                      Your  personal  gVim initializations (first one found is
+                      Your personal gVim initializations (first one  found  is
                       used).
 
        /usr/local/share/vim/vim??/optwin.vim
-                      Script used for the ":options" command, a  nice  way  to
+                      Script  used  for  the ":options" command, a nice way to
                       view and set options.
 
        /usr/local/share/vim/vim??/menu.vim
@@ -443,11 +445,11 @@
                       Script to generate a bug report.  See ":help bugs".
 
        /usr/local/share/vim/vim??/filetype.vim
-                      Script  to  detect  the type of a file by its name.  See
+                      Script to detect the type of a file by  its  name.   See
                       ":help 'filetype'".
 
        /usr/local/share/vim/vim??/scripts.vim
-                      Script to detect the type of a  file  by  its  contents.
+                      Script  to  detect  the  type of a file by its contents.
                       See ":help 'filetype'".
 
        /usr/local/share/vim/vim??/print/*.ps
@@ -475,4 +477,4 @@
        vi_diff.txt  when  in  Vim).   Also have a look at the 'compatible' and
        'cpoptions' options.
 
-                                  2024 Aug 12                           VIM(1)
+                                  2025 Jun 27                           VIM(1)
diff --git a/runtime/doc/wayland.txt b/runtime/doc/wayland.txt
new file mode 100644
index 0000000..b228dc1
--- /dev/null
+++ b/runtime/doc/wayland.txt
@@ -0,0 +1,117 @@
+*wayland.txt*   For Vim version 9.1.  Last change: 2025 Jun 27
+
+
+		  VIM REFERENCE MANUAL    by Bram Moolenaar
+
+
+Wayland Protocol Support				*wayland*
+
+1. Useful Wayland information	|wayland-useful|
+2. Wayland selections		|wayland-selections|
+
+==============================================================================
+1. Useful Wayland information				*wayland-useful*
+
+							*wayland-seat*
+Functionality such as the clipboard for Wayland requires a seat to use.  A
+Wayland seat can consist of a keyboard, pointer, and touch device(s).  The
+seat to use can be set with the 'wlseat' option. Only useful if you use
+multiple Wayland seats in the same Wayland session.
+
+							*wayland-gui*
+See |gui-wayland|.  Please note that when using the GUI, Vim uses the toolkit
+such as GTK for accessing the clipboard, and does not access the clipboard
+though Wayland.  You can check this though the |v:clipmethod| variable, which
+should equal to "none" when running the GUI.
+
+Wayland commands:
+							*:wlrestore* *:wl*
+:wl[estore] [display]	Reinitializes the connection to the wayland compositor.
+			Useful when running Vim in a screen/tmux session that
+			continues running after the Wayland compositor
+			restarts.
+
+			[display] should be in the format of the
+			$WAYLAND_DISPLAY environment variable (e.g.
+			"wayland-0"). If [display] is omitted, then it
+			reinitializes the connection using the same value as
+			was used for the previous execution of this command.
+			If the value was never specified, then it uses the
+			value of $WAYLAND_DISPLAY environment variable.  This
+			will also update |v:clipmethod|.
+			{only available when compiled with the |+wayland| feature}
+
+Wayland errors:
+							*E1548*
+Vim failed communicating with the wayland compositor.  This is likely due to
+the Wayland compositor process being killed.  Try the `:wlrestore` command to
+try connecting again.
+
+==============================================================================
+2. Wayland Selections					*wayland-selections*
+
+Vim supports the wlr-data-control-unstable-v1 and ext-data-control-v1
+protocols, for accessing the current Wayland selection.  These are the best
+case scenario protocols, see |wayland-focus-steal|.  Selection in this case
+essentially means the "clipboard."  You can check if your Wayland compositor
+supports either of these protocols by running the wayland-info command, which
+should be bunded with libwayland on your system: >
+	wayland-info | grep -E '(ext_data_control|zwlr_data_control)'
+<If grep finds a match, then you have either or both protocols on your system.
+If you don't get any match, then please see |wayland-focus-steal| for more
+information.
+
+If you come from X11, then the regular wayland selection is equivalent to the
+CLIPBOARD selection in X11, and the primary wayland selection equates to the
+X11 primary selection.  Accessing these selections is the same as X11 in Vim,
+in which the + register is the regular selection, and the * register is the
+primary selection, note that your compositor may not support primary
+selections, see |wayland-primary-selection| for more details.
+
+							*wayland-persist*
+If you use X11 cut buffers, no such things exist on Wayland. Instead to
+emulate such functionality, a separate clipboard manager must be used in order
+to persist selection data when a Wayland client exists.
+
+							*wayland-and-x11*
+If your version of Vim comes compiled with both X11 and Wayland support, then
+Vim determines which one to use when accessing the clipboard using the
+'clipmethod' option.
+
+							*wayland-primary-selection*
+If you find X11 style primary selections useful, Wayland also implements this
+behaviour in its own protocols:
+
+- The primary selection protocol is the most widely supported, but requires
+  focus in order to be used, see |wayland-focus-steal|.
+
+- Data control protocol available on your system, such as the ext or wlr
+  protocols, then primary selection is also supported.  This is unless you are
+  using version 1 (not the same as the 'v1' in the protocol name), of the
+  wlr-data-control protocol. Then the primary selection protocol will be used
+  as a fallback.
+
+						*wayland-focus-steal* *wayland-gnome*
+If you are using the GNOME desktop environment on Wayland, as of this writing,
+there is no method of accessing/modifying the clipboard for external clients
+such as Vim without being focused.  Focused in this case means the client has
+received some sort of input event, such as a window being focused.  This is
+what the wlr-data-control-unstable-v1 and ext-data-control-v1 protocols solve.
+If your Wayland compositor does not support the above protocols, then the
+above explanation applies.
+
+To solve this problem, Vim implements a way of gaining focus in order to
+access the clipboard, by creating a temporary transparent top-level surface.
+This is by default disabled and can be enabled via the 'wlsteal' option.
+Moreover, a seat that has a keyboard is also required, see 'wlseat', and the
+xdg-shell protocol must be available.
+
+Note that this method can have several side effects from the result of focus
+stealing.  For example, if you have a taskbar that shows currently opened apps
+in your desktop environment, then when Vim attempts to steal focus, it may
+"flicker," as if a window was opened then immediately closed after.
+Additionally, if you are in fullscreen mode, this focus stealing won't work,
+because the created surface won't ever gain focus.  If this happens, Vim will
+seem to freeze temporarily, see 'wltimeoutlen' for more information.
+
+ vim:tw=78:sw=4:ts=8:noet:ft=help:norl:js