Skip to content
Closed
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
LOG_DIR: ${{ github.workspace }}/logs
TERM: xterm
DISPLAY: ':99'
WAYLAND_DISPLAY: 'wayland-1'
DEBIAN_FRONTEND: noninteractive

strategy:
Expand Down Expand Up @@ -125,6 +124,10 @@ jobs:
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
PKGS=( \
gettext \
x11-utils \
labwc \
wl-clipboard \
wayland-utils \
libgtk-3-dev:${{ matrix.architecture }} \
libgtk-3-bin:${{ matrix.architecture }} \
desktop-file-utils \
Expand All @@ -141,7 +144,6 @@ jobs:
libwayland-cursor0:${{ matrix.architecture }} \
locales-all \
software-properties-common \
sway \
)
if ${{ contains(matrix.extra, 'asan') }} && ${{ contains(matrix.architecture, 'native') }}; then
PKGS+=( \
Expand Down Expand Up @@ -270,8 +272,6 @@ jobs:
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0
sudo usermod -a -G audio "${USER}"
sudo bash ci/setup-xvfb.sh
# Sway requires user session
bash ci/setup-sway.sh

- name: Check autoconf
if: contains(matrix.extra, 'unittests')
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ src/auto/osdef.h
src/auto/link.log
src/auto/link.sed
src/auto/pathdef.c
src/auto/wayland/*.c
src/auto/wayland/*.h

# Windows
*.exe
Expand Down
2 changes: 2 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ src/auto/osdef.h
src/auto/link.log
src/auto/link.sed
src/auto/pathdef.c
src/auto/wayland/*.c
src/auto/wayland/*.h

# Windows
*.exe
Expand Down
10 changes: 10 additions & 0 deletions Filelist
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ SRC_ALL = \
src/testdir/ru_RU/LC_MESSAGES/Makefile \
src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.po \
src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.mo \
src/testdir/window_manager.vim \
src/proto.h \
src/protodef.h \
src/proto/alloc.pro \
Expand Down Expand Up @@ -490,6 +491,12 @@ SRC_UNIX = \
src/gui_xmebwp.h \
src/gui_x11.c \
src/gui_x11_pm.h \
src/auto/wayland/README.txt \
src/auto/wayland/Makefile \
src/auto/wayland/protocols/ext-data-control-v1.xml \
src/auto/wayland/protocols/wlr-data-control-unstable-v1.xml \
src/auto/wayland/protocols/xdg-shell.xml \
src/auto/wayland/protocols/primary-selection-unstable-v1.xml \
src/if_xcmdsrv.c \
src/link.sh \
src/installman.sh \
Expand All @@ -508,6 +515,7 @@ SRC_UNIX = \
src/proto/gui_motif.pro \
src/proto/gui_xmdlg.pro \
src/proto/gui_x11.pro \
src/proto/wayland.pro \
src/proto/if_xcmdsrv.pro \
src/proto/os_unix.pro \
src/proto/pty.pro \
Expand All @@ -519,7 +527,9 @@ SRC_UNIX = \
src/vim_mask.xbm \
src/vimtutor \
src/gvimtutor \
src/wayland.c \
src/which.sh \
src/gen-wayland-protocols.sh \
src/xxd/Makefile \

# Source files for both MS Windows and Unix-like.
Expand Down
7 changes: 0 additions & 7 deletions ci/setup-sway.sh

This file was deleted.

2 changes: 2 additions & 0 deletions runtime/doc/Make_all.mak
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ DOCS = \
popup.txt \
print.txt \
quickfix.txt \
wayland.txt \
quickref.txt \
quotes.txt \
recover.txt \
Expand Down Expand Up @@ -236,6 +237,7 @@ HTMLS = \
popup.html \
print.html \
quickfix.html \
wayland.html \
quickref.html \
quotes.html \
recover.html \
Expand Down
2 changes: 2 additions & 0 deletions runtime/doc/builtin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13038,6 +13038,8 @@ vms VMS version of Vim.
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)
Expand Down
15 changes: 15 additions & 0 deletions runtime/doc/eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,15 @@ v:charconvert_to
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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say a bit about why this is necessary? It seems to be 2-way, both set by the code and set by the user. When would each be appropriate? Also, is there a reason this shouldn't have a value relating to winclip.c?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clipmethod is only really relevant to X11 and Wayland. On Windows there is just one implementation of the clipboard so we don't have to worry about that. Could you clarify what you mean by 2-way? Thanks

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally had a chance to test this out and I think I can better explain the disconnect I see between this setting and the rest of the implementation. I am running a wayland session with Xwayland running. Both WAYLAND_DISPLAY and DISPLAY are set to legit values. I run vim --clean -u NONE -N.

echo &clipmethod
wayland,x11
echo v:clipmethod
x11

Why would a user not report this as a bug? It is not a bug per your implementation notes because this is a GNOME session. But it sure seems to be a bug to anyone just reading the documentation. I think the information being expected from the user and the information being provided to them assumes they know how their compositor works. That might be interesting to some users but I feel like it is a undue burden for most users.

On the other hand, if I run this under a sway session, I get the more logical output of

echo v:clipmethod
wayland

Yet, if run with -X -Y then I get:

echo &clipmethod
wayland,x11
echo v:clipmethod
none

This also seems like a bug in a way that I think hints at a simpler approach that would be easier for users to understand. You can technically run x11 embedded in wayland or wayland embedded in x11. In either case both DISPLAY and WAYLAND_DISPLAY could be set simultaneously. However, users can be split into two groups:

  • Those who know what these mean and which they intend to use. They can easily achieve the intended behavior with the -X and -Y options.
  • Those who rely on their distro to deliver sensible defaults, in which case they are going to want the effect of wayland,x11 -- hence the default you chose here.

So I think this would satisfy both sets of users in a way that is simpler for each of them:

  • Get rid of clipemethod as a user setting. Keep v:clipmethod as a feedback mechanism and for scripting/test purposes.
  • Where clipmethod is used in the code now, use the implied order based on whether we are connected or willing to connect to each display.
    • If WAYLAND_DISPLAY is set, include and priortize wayland. Unless -Y is specified.
    • If DISPLAY is set, include x11. Unless -X is specified.
    • In summary, if both display variables are set and neither command flag is set, it is safe to assume wayland,x11.

Copy link
Contributor Author

@64-bitman 64-bitman Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


echo &clipmethod

wayland,x11


echo v:clipmethod

x11

Why would a user not report this as a bug? It is not a bug per your implementation notes because this is a GNOME session. But it sure seems to be a bug to anyone just reading the documentation. I think the information being expected from the user and the information being provided to them assumes they know how their compositor works. That might be interesting to some users but I feel like it is a undue burden for most users.

So what you are saying is to enable wlsteal by default? Problem is that also introduces the fact that wlsteal has issues too. Since autoselect is default for clipboard option, users may be confused why the terminal loses focus seemingly randomly every time they go into visual mode. The "randomness" is actually just when Vim isn't the owner of the selection.

Yet, if run with -X -Y then I get:


echo &clipmethod

wayland,x11


echo v:clipmethod

none

Not sure what you are trying to say, isn't that expected?

This also seems like a bug in a way that I think hints at a simpler approach that would be easier for users to understand. You can technically run x11 embedded in wayland or wayland embedded in x11. In either case both DISPLAY and WAYLAND_DISPLAY could be set simultaneously. However, users can be split into two groups:

  • Those who know what these mean and which they intend to use. They can easily achieve the intended behavior with the -X and -Y options.

  • Those who rely on their distro to deliver sensible defaults, in which case they are going to want the effect of wayland,x11 -- hence the default you chose here.

So I think this would satisfy both sets of users in a way that is simpler for each of them:

  • Get rid of clipemethod as a user setting. Keep v:clipmethod as a feedback mechanism and for scripting/test purposes.

  • Where clipmethod is used in the code now, use the implied order based on whether we are connected or willing to connect to each display.

    • If WAYLAND_DISPLAY is set, include and priortize wayland. Unless -Y is specified.

    • If DISPLAY is set, include x11. Unless -X is specified.

    • In summary, if both display variables are set and neither command flag is set, it is safe to assume wayland,x11.

Correct me if I'm wrong, but I think the problem you are describing only applies to GNOME users, and enabling wlsteal by default would fix things. But that brings it's own problems (see above). Additionally, I don't see any harm in keeping the clip method option, using the -X and -Y options as a replacement I can guess could be annoying to specify it every time.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely not suggesting to enable wlsteal by default, even if just heuristically chosen for GNOME users. I would rather wlsteal be removed and this wayland support being limited to places where wlsteal is not required. Alas, I'm trying to not suggest removing it either because I don't want to kill the momentum here. It is off by default, so live and let live. I'm glad to hear you also think wlsteal is awkward and likely confusing for users :)

What I am suggesting is that the awkwardness of wlsteal stems from a fundamental asymmetry between what "wayland" means as a category versus the various protocols. I think this asymmetry is being papered over by clipmethod in a very confusing way. As a user, I would expect vim to disable functionality I've told it to disable.

vim invocation expected
vim -X -Y clipmethod=none
vim -Y clipmethod=x11
vim -X clipmethod=wayland
vim clipmethod=wayland,x11

In essence, I've told vim I want to stay disconnected from one or both of those servers, so it should know that clipmethod would not need to include them.

My suggestion to rely solely on -X and -Y instead of having a clipmethod at all is because there's very, very few users who would set clipmethod=x11,wayland when running in dual setup with both display servers. On the other hand, there are a lot of users who run GNOME, will know vaguely that it is a "wayland" session (many distros brand it as such), and be very confused why setting clipmethod=wayland,x11 does not yield v:clipmethod=wayland.

I guess one alternative way to say the same thing is that wlsteal should maybe go away in favor of a non-default value of wayland-focus-steal for clipmethod. That would at least put this contradictory asymmetric meaning in front of users when they are inspecting the clipmethod option.

Part of the confusion stems from the symmetric naming between clipmethod and v:clipmethod. If nothing else, I'd suggest renaming clipmethod to cliporder to break this asymmetry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying

My suggestion to rely solely on -X and -Y instead of having a clipmethod at all is because there's very, very few users who would set clipmethod=x11,wayland when running in dual setup with both display servers. On the other hand, there are a lot of users who run GNOME, will know vaguely that it is a "wayland" session (many distros brand it as such), and be very confused why setting clipmethod=wayland,x11 does not yield v:clipmethod=wayland.

I see, I suppose that would make sense. So you are saying to remove clipmethod but still keep v:clipmethod, and instead rely on heuristics and manual user intervention to handle when to use X11 or Wayland?

Overall it seems like clipmethod is the main source of confusion, maybe an alternative would be to update the documentation for it and specify why v:clipmethod may not be the value that clipmethod should imply?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I suppose that would make sense. So you are saying to remove clipmethod but still keep v:clipmethod, and instead rely on heuristics and manual user intervention to handle when to use X11 or Wayland?

Yeah, that is a good synopsis.

Overall it seems like clipmethod is the main source of confusion, maybe an alternative would be to update the documentation for it and specify why v:clipmethod may not be the value that clipmethod should imply?

Updating the documentation would definitely help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I suppose that would make sense. So you are saying to remove clipmethod but still keep v:clipmethod, and instead rely on heuristics and manual user intervention to handle when to use X11 or Wayland?

Yeah, that is a good synopsis.

Overall it seems like clipmethod is the main source of confusion, maybe an alternative would be to update the documentation for it and specify why v:clipmethod may not be the value that clipmethod should imply?

Updating the documentation would definitely help.

Thanks, so which way should we go? I'm not sure

*v:cmdarg* *cmdarg-variable*
v:cmdarg This variable is used for two purposes:
1. The extra arguments given to a file read/write command.
Expand Down Expand Up @@ -2969,6 +2978,12 @@ v:vim_did_enter Zero until most of startup is done. It is set to one just
*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
Expand Down
3 changes: 3 additions & 0 deletions runtime/doc/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ GUI ~
|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
Expand Down
2 changes: 2 additions & 0 deletions runtime/doc/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ tag command action ~
|: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
Expand Down Expand Up @@ -1777,6 +1778,7 @@ tag command action ~
|: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
Expand Down
101 changes: 84 additions & 17 deletions runtime/doc/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ A jump table for the options with a short description can be found at |Q_op|.
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
Expand All @@ -1812,10 +1812,13 @@ A jump table for the options with a short description can be found at |Q_op|.
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,
Expand Down Expand Up @@ -1852,24 +1855,54 @@ A jump table for the options with a short description can be found at |Q_op|.
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
Expand Down Expand Up @@ -4586,9 +4619,9 @@ A jump table for the options with a short description can be found at |Q_op|.
|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
Expand Down Expand Up @@ -10043,6 +10076,40 @@ A jump table for the options with a short description can be found at |Q_op|.
'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
Expand Down
4 changes: 4 additions & 0 deletions runtime/doc/quickref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ Short explanation of each option: *option-list*
'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
Expand Down Expand Up @@ -1018,6 +1019,9 @@ Short explanation of each option: *option-list*
'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
Expand Down
6 changes: 6 additions & 0 deletions runtime/doc/starting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ a slash. Thus "-R" means recovery and "-/R" readonly.
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
Expand Down
Loading
Loading