patch 9.1.1784: Wayland code can be improved

Problem:  Wayland code can be improved
Solution: Refactor Wayland Clipboard code (Foxe Chen).

This the second attempt to refactor the Wayland code base:
- Move clipboard code from wayland.c to clipboard.c
- Use C99 bool type
- Properly poll the Wayland display file descriptor
- Instead of checking if the data source is not NULL in order to
  determine if a selection event comes from us, use a special mime type
  to identify selection events coming from ourselves. The problem with
  the previous approach is that race conditions may occur.
- Put the focus stealing code under a new feature "wayland_focus_steal"
- Use ELAPSED_* macros instead of gettimeofday()
- Pass tests
- Reimplement commented out code
- Update docs
- Make Wayland clipboard behaviour more in line with X11 when connection
  is lost
- add missing malloc checks and possible memory leaks + refactored some
  tests.

closes: #18324

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Foxe Chen
2025-09-22 19:06:58 +00:00
committed by Christian Brabandt
parent 70d745a61b
commit 368710abcf
34 changed files with 2685 additions and 2709 deletions

View File

@ -1,4 +1,4 @@
*builtin.txt* For Vim version 9.1. Last change: 2025 Sep 21
*builtin.txt* For Vim version 9.1. Last change: 2025 Sep 22
VIM REFERENCE MANUAL by Bram Moolenaar
@ -13194,7 +13194,9 @@ 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
wayland_clipboard Compiled with support for Wayland clipboard.
wayland_focus_steal Compiled with support for Wayland clipboard focus
stealing.
wildignore Compiled with 'wildignore' option.
wildmenu Compiled with 'wildmenu' option.
win16 old version for MS-Windows 3.1 (always false)

View File

@ -1,4 +1,4 @@
*gui_x11.txt* For Vim version 9.1. Last change: 2025 Sep 02
*gui_x11.txt* For Vim version 9.1. Last change: 2025 Sep 22
VIM REFERENCE MANUAL by Bram Moolenaar
@ -714,6 +714,8 @@ output a warning:
Warning: Clipboard register not available, using register 0 ~
Note: This also applies to the Wayland clipboard feature as well.
*W24*
Vim comes in different flavors, from a tiny build, that just tries to be
compatible to original Vi, to enhanced builds which include many improvements

View File

@ -1,4 +1,4 @@
*options.txt* For Vim version 9.1. Last change: 2025 Sep 20
*options.txt* For Vim version 9.1. Last change: 2025 Sep 22
VIM REFERENCE MANUAL by Bram Moolenaar
@ -10204,7 +10204,8 @@ A jump table for the options with a short description can be found at |Q_op|.
*'wlsteal'* *'wst'* *'nowlsteal'* *'nowst'*
'wlsteal' 'wst' boolean (default off)
global
{only when the |+wayland_clipboard| feature is included}
{only when the |+wayland_focus_steal| 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|.

View File

@ -1541,6 +1541,7 @@ $quote eval.txt /*$quote*
+vtp various.txt /*+vtp*
+wayland various.txt /*+wayland*
+wayland_clipboard various.txt /*+wayland_clipboard*
+wayland_focus_steal various.txt /*+wayland_focus_steal*
+wildignore various.txt /*+wildignore*
+wildmenu various.txt /*+wildmenu*
+windows various.txt /*+windows*

View File

@ -1,4 +1,4 @@
*various.txt* For Vim version 9.1. Last change: 2025 Sep 02
*various.txt* For Vim version 9.1. Last change: 2025 Sep 22
VIM REFERENCE MANUAL by Bram Moolenaar
@ -528,6 +528,9 @@ 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.
N *+wayland_focus_steal*
Unix only: support for Wayland clipboard on
compositors without a data control protocol
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.

View File

@ -1,4 +1,4 @@
*wayland.txt* For Vim version 9.1. Last change: 2025 Sep 15
*wayland.txt* For Vim version 9.1. Last change: 2025 Sep 22
VIM REFERENCE MANUAL by Bram Moolenaar
@ -105,7 +105,8 @@ 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.
xdg-shell protocol must be available. Additionally, Vim must be compiled with
the |+wayland_focus_steal| feature.
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