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>
This commit is contained in:
Foxe Chen
2025-09-01 20:52:44 +02:00
committed by Christian Brabandt
parent 6a2d0496a1
commit f50504a87b
29 changed files with 2613 additions and 2684 deletions

View File

@ -2464,11 +2464,25 @@ AC_ARG_WITH(wayland,
AC_MSG_RESULT([yes])]))
if test "$with_wayland" = yes; then
cppflags_save=$CPPFLAGS
cflags_save=$CFLAGS
cppflags_save=$CPPFLAGS
cflags_save=$CFLAGS
AC_MSG_CHECKING(for wayland)
if "$PKG_CONFIG" --exists 'wayland-client'; then
AC_MSG_RESULT([yes])
AC_MSG_CHECKING(--enable-wayland-focus-steal argument)
AC_ARG_ENABLE(wayland-focus-steal,
[AS_HELP_STRING([--enable-wayland-focus-steal],
[Include focus stealing support for Wayland clipboard.])],
[enable_wayland_fs=$enableval],
enable_wayland_fs="yes")
AS_IF([test "$enable_wayland_fs" = "yes"],
[AC_MSG_RESULT([yes])
AC_DEFINE(FEAT_WAYLAND_CLIPBOARD_FS)],
[AC_MSG_RESULT([no])])
AC_DEFINE(HAVE_WAYLAND)
WAYLAND_CPPFLAGS=`$PKG_CONFIG --cflags-only-I wayland-client`
WAYLAND_CFLAGS=`$PKG_CONFIG --cflags-only-other wayland-client`
@ -2478,15 +2492,20 @@ cflags_save=$CFLAGS
WAYLAND_SRC=" \
auto/wayland/wlr-data-control-unstable-v1.c \
auto/wayland/ext-data-control-v1.c \
auto/wayland/xdg-shell.c \
auto/wayland/primary-selection-unstable-v1.c \
wayland.c"
WAYLAND_OBJ=" \
objects/wlr-data-control-unstable-v1.o \
objects/ext-data-control-v1.o \
objects/xdg-shell.o \
objects/primary-selection-unstable-v1.o \
objects/wayland.o"
AS_IF([test "$enable_wayland_fs" = "yes"],
[WAYLAND_SRC+=" \
auto/wayland/xdg-shell.c \
auto/wayland/primary-selection-unstable-v1.c"
WAYLAND_OBJ+=" \
objects/xdg-shell.o \
objects/primary-selection-unstable-v1.o"])
AC_SUBST(WAYLAND_CPPFLAGS)
AC_SUBST(WAYLAND_CFLAGS)
AC_SUBST(WAYLAND_LIBS)