Skip to content

Commit f50504a

Browse files
64-bitmanchrisbra
authored andcommitted
patch 9.1.1725: Wayland code can be improved
Problem: Wayland code can be improved Solution: Refactor Wayland Clipboard code (Foxe Chen) This refactor makes the Wayland codebase less convoluted: - Move clipboard code in 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: #18139 Signed-off-by: Foxe Chen <chen.foxe@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 6a2d049 commit f50504a

29 files changed

Lines changed: 2415 additions & 2486 deletions

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ SRC_UNIX = \
537537
src/vimtutor \
538538
src/gvimtutor \
539539
src/wayland.c \
540+
src/wayland.h \
540541
src/which.sh \
541542
src/gen-wayland-protocols.sh \
542543
src/xxd/Makefile \

runtime/doc/builtin.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*builtin.txt* For Vim version 9.1. Last change: 2025 Aug 24
1+
*builtin.txt* For Vim version 9.1. Last change: 2025 Sep 01
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -13161,7 +13161,9 @@ vreplace Compiled with |gR| and |gr| commands. (always true)
1316113161
vtp Compiled for vcon support |+vtp| (check vcon to find
1316213162
out if it works in the current console).
1316313163
wayland Compiled with Wayland protocol support.
13164-
wayland_clipboard Compiled with support for Wayland selections/clipboard
13164+
wayland_clipboard Compiled with support for Wayland clipboard.
13165+
wayland_focus_steal Compiled with support for Wayland clipboard focus
13166+
stealing.
1316513167
wildignore Compiled with 'wildignore' option.
1316613168
wildmenu Compiled with 'wildmenu' option.
1316713169
win16 old version for MS-Windows 3.1 (always false)

runtime/doc/gui_x11.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*gui_x11.txt* For Vim version 9.1. Last change: 2025 Aug 10
1+
*gui_x11.txt* For Vim version 9.1. Last change: 2025 Sep 01
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -709,8 +709,8 @@ overwriting selected text.
709709

710710
*W23*
711711
When you are yanking into the "* or "+ register and Vim cannot establish a
712-
connection to the X11 selection (or clipboard), it will use register 0 and
713-
output a warning:
712+
connection to the X11 selection (or X11/Wayland clipboard), it will use
713+
register 0 and output a warning:
714714

715715
Warning: Clipboard register not available, using register 0 ~
716716

runtime/doc/options.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2025 Aug 27
1+
*options.txt* For Vim version 9.1. Last change: 2025 Sep 01
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -10195,7 +10195,8 @@ A jump table for the options with a short description can be found at |Q_op|.
1019510195
*'wlsteal'* *'wst'* *'nowlsteal'* *'nowst'*
1019610196
'wlsteal' 'wst' boolean (default off)
1019710197
global
10198-
{only when the |+wayland_clipboard| feature is included}
10198+
{only when the |+wayland_focus_steal| feature is
10199+
included}
1019910200
When enabled, then allow Vim to steal focus by creating a temporary
1020010201
surface, in order to access the clipboard. For more information see
1020110202
|wayland-focus-steal|.

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,7 @@ $quote eval.txt /*$quote*
15421542
+vtp various.txt /*+vtp*
15431543
+wayland various.txt /*+wayland*
15441544
+wayland_clipboard various.txt /*+wayland_clipboard*
1545+
+wayland_focus_steal various.txt /*+wayland_focus_steal*
15451546
+wildignore various.txt /*+wildignore*
15461547
+wildmenu various.txt /*+wildmenu*
15471548
+windows various.txt /*+windows*

runtime/doc/various.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*various.txt* For Vim version 9.1. Last change: 2025 Aug 18
1+
*various.txt* For Vim version 9.1. Last change: 2025 Sep 01
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -528,6 +528,8 @@ T *+vreplace* |gR| and |gr|
528528
*+vtp* on MS-Windows console: support for 'termguicolors'
529529
N *+wayland* Unix only: support for the Wayland protocol.
530530
N *+wayland_clipboard* Unix only: support for Wayland selections/clipboard.
531+
N *+wayland_focus_steal* Unix only: support for Wayland clipboard on
532+
compositors without a data control protocol.
531533
T *+wildignore* 'wildignore' Always enabled since 9.0.0278
532534
T *+wildmenu* 'wildmenu' Always enabled since 9.0.0279
533535
T *+windows* more than one window; Always enabled since 8.0.1118.

runtime/doc/wayland.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*wayland.txt* For Vim version 9.1. Last change: 2025 Aug 27
1+
*wayland.txt* For Vim version 9.1. Last change: 2025 Sep 01
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -105,7 +105,8 @@ To solve this problem, Vim implements a way of gaining focus in order to
105105
access the clipboard, by creating a temporary transparent top-level surface.
106106
This is by default disabled and can be enabled via the 'wlsteal' option.
107107
Moreover, a seat that has a keyboard is also required, see 'wlseat', and the
108-
xdg-shell protocol must be available.
108+
xdg-shell protocol must be available. Additionally, Vim must be compiled with
109+
the |+wayland_focus_steal| feature.
109110

110111
Note that this method can have several side effects from the result of focus
111112
stealing. For example, if you have a taskbar that shows currently opened apps

runtime/optwin.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" These commands create the option window.
22
"
33
" Maintainer: The Vim Project <https://github.com/vim/vim>
4-
" Last Change: 2025 Aug 23
4+
" Last Change: 2025 Sep 01
55
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
66

77
" If there already is an option window, jump to that one.
@@ -822,7 +822,7 @@ if has('wayland')
822822
call <SID>AddOption("wlseat", gettext("Wayland seat to use"))
823823
call <SID>OptionG("wse", &wse)
824824
endif
825-
if has("wayland_clipboard")
825+
if has("wayland_focus_steal")
826826
call <SID>AddOption("wlsteal", gettext("Enable wayland focus stealing functionality in order to access the clipboard"))
827827
call <SID>BinOptionG("wst", &wst)
828828
endif

src/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,9 @@ MESSAGE_TEST_TARGET = message_test$(EXEEXT)
16461646

16471647
UNITTEST_SRC = $(JSON_TEST_SRC) $(KWORD_TEST_SRC) $(MEMFILE_TEST_SRC) $(MESSAGE_TEST_SRC)
16481648
UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(KWORD_TEST_TARGET) $(MEMFILE_TEST_TARGET) $(MESSAGE_TEST_TARGET)
1649-
RUN_UNITTESTS = run_json_test run_kword_test run_memfile_test run_message_test
1649+
# We need to put WAYLAND_SRC because the protocol files need to be generated
1650+
# else wayland.h will error
1651+
RUN_UNITTESTS = $(WAYLAND_SRC) run_json_test run_kword_test run_memfile_test run_message_test
16501652

16511653
# All sources, also the ones that are not configured
16521654
ALL_LOCAL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC) \
@@ -3861,9 +3863,9 @@ objects/clientserver.o: clientserver.c vim.h protodef.h auto/config.h feature.h
38613863
ex_cmds.h spell.h proto.h globals.h errors.h
38623864
objects/clipboard.o: clipboard.c vim.h protodef.h auto/config.h feature.h \
38633865
os_unix.h auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h \
3864-
beval.h proto/gui_beval.pro structs.h regexp.h gui.h \
3865-
libvterm/include/vterm.h libvterm/include/vterm_keycodes.h alloc.h \
3866-
ex_cmds.h spell.h proto.h globals.h errors.h
3866+
beval.h structs.h regexp.h gui.h libvterm/include/vterm.h \
3867+
libvterm/include/vterm_keycodes.h xdiff/xdiff.h xdiff/../vim.h alloc.h \
3868+
ex_cmds.h spell.h proto.h globals.h errors.h wayland.h
38673869
objects/cmdexpand.o: cmdexpand.c vim.h protodef.h auto/config.h feature.h \
38683870
os_unix.h auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h \
38693871
beval.h proto/gui_beval.pro structs.h regexp.h gui.h \
@@ -4564,7 +4566,7 @@ objects/wayland.o: wayland.c vim.h protodef.h auto/config.h feature.h os_unix.h
45644566
auto/osdef.h ascii.h keymap.h termdefs.h macros.h option.h beval.h \
45654567
structs.h regexp.h gui.h libvterm/include/vterm.h \
45664568
libvterm/include/vterm_keycodes.h xdiff/xdiff.h xdiff/../vim.h alloc.h \
4567-
ex_cmds.h spell.h proto.h globals.h errors.h \
4569+
ex_cmds.h spell.h proto.h globals.h errors.h wayland.h \
45684570
auto/wayland/wlr-data-control-unstable-v1.h \
45694571
auto/wayland/ext-data-control-v1.h auto/wayland/xdg-shell.h \
45704572
auto/wayland/primary-selection-unstable-v1.h

src/auto/configure

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ enable_farsi
862862
enable_xim
863863
enable_fontset
864864
with_wayland
865+
enable_wayland_focus_steal
865866
with_x
866867
enable_gui
867868
enable_gtk2_check
@@ -1542,6 +1543,9 @@ Optional Features:
15421543
--disable-farsi Deprecated.
15431544
--enable-xim Include XIM input support.
15441545
--enable-fontset Include X fontset output support.
1546+
--enable-wayland-focus-steal
1547+
Include focus stealing support for Wayland
1548+
clipboard.
15451549
--enable-gui=OPTS X11 GUI. default=auto OPTS=auto/no/gtk2/gnome2/gtk3/motif/haiku/photon/carbon
15461550
--enable-gtk2-check If auto-select GUI, check for GTK+ 2 default=yes
15471551
--enable-gnome-check If GTK GUI, check for GNOME default=no
@@ -9271,13 +9275,39 @@ fi
92719275

92729276

92739277
if test "$with_wayland" = yes; then
9274-
cppflags_save=$CPPFLAGS
9275-
cflags_save=$CFLAGS
9278+
cppflags_save=$CPPFLAGS
9279+
cflags_save=$CFLAGS
9280+
92769281
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for wayland" >&5
92779282
printf %s "checking for wayland... " >&6; }
92789283
if "$PKG_CONFIG" --exists 'wayland-client'; then
92799284
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
92809285
printf "%s\n" "yes" >&6; }
9286+
9287+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking --enable-wayland-focus-steal argument" >&5
9288+
printf %s "checking --enable-wayland-focus-steal argument... " >&6; }
9289+
# Check whether --enable-wayland-focus-steal was given.
9290+
if test ${enable_wayland_focus_steal+y}
9291+
then :
9292+
enableval=$enable_wayland_focus_steal; enable_wayland_fs=$enableval
9293+
else case e in #(
9294+
e) enable_wayland_fs="yes" ;;
9295+
esac
9296+
fi
9297+
9298+
9299+
if test "$enable_wayland_fs" = "yes"
9300+
then :
9301+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
9302+
printf "%s\n" "yes" >&6; }
9303+
printf "%s\n" "#define FEAT_WAYLAND_CLIPBOARD_FS 1" >>confdefs.h
9304+
9305+
else case e in #(
9306+
e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
9307+
printf "%s\n" "no" >&6; } ;;
9308+
esac
9309+
fi
9310+
92819311
printf "%s\n" "#define HAVE_WAYLAND 1" >>confdefs.h
92829312

92839313
WAYLAND_CPPFLAGS=`$PKG_CONFIG --cflags-only-I wayland-client`
@@ -9288,16 +9318,23 @@ printf "%s\n" "yes" >&6; }
92889318
WAYLAND_SRC=" \
92899319
auto/wayland/wlr-data-control-unstable-v1.c \
92909320
auto/wayland/ext-data-control-v1.c \
9291-
auto/wayland/xdg-shell.c \
9292-
auto/wayland/primary-selection-unstable-v1.c \
92939321
wayland.c"
92949322
WAYLAND_OBJ=" \
92959323
objects/wlr-data-control-unstable-v1.o \
92969324
objects/ext-data-control-v1.o \
9297-
objects/xdg-shell.o \
9298-
objects/primary-selection-unstable-v1.o \
92999325
objects/wayland.o"
93009326

9327+
if test "$enable_wayland_fs" = "yes"
9328+
then :
9329+
WAYLAND_SRC+=" \
9330+
auto/wayland/xdg-shell.c \
9331+
auto/wayland/primary-selection-unstable-v1.c"
9332+
WAYLAND_OBJ+=" \
9333+
objects/xdg-shell.o \
9334+
objects/primary-selection-unstable-v1.o"
9335+
fi
9336+
9337+
93019338

93029339

93039340

0 commit comments

Comments
 (0)