mirror of
https://github.com/vim/vim.git
synced 2025-11-14 23:04:02 -05:00
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:
committed by
Christian Brabandt
parent
6a2d0496a1
commit
f50504a87b
@@ -5731,7 +5731,7 @@ mch_call_shell_fork(
|
||||
#ifdef FEAT_WAYLAND
|
||||
// Handle Wayland events such as sending data as the source
|
||||
// client.
|
||||
wayland_client_update();
|
||||
wayland_update();
|
||||
#endif
|
||||
}
|
||||
finished:
|
||||
@@ -5805,7 +5805,7 @@ finished:
|
||||
#ifdef FEAT_WAYLAND
|
||||
// Handle Wayland events such as sending data as the source
|
||||
// client.
|
||||
wayland_client_update();
|
||||
wayland_update();
|
||||
#endif
|
||||
|
||||
// Wait for 1 to 10 msec. 1 is faster but gives the child
|
||||
@@ -6657,6 +6657,9 @@ RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *interrupted)
|
||||
int mzquantum_used = FALSE;
|
||||
# endif
|
||||
#endif
|
||||
#ifdef FEAT_WAYLAND
|
||||
int wayland_fd = -1;
|
||||
#endif
|
||||
#ifndef HAVE_SELECT
|
||||
// each channel may use in, out and err
|
||||
struct pollfd fds[7 + 3 * MAX_OPEN_CHANNELS];
|
||||
@@ -6700,11 +6703,11 @@ RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *interrupted)
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef FEAT_WAYLAND_CLIPBOARD
|
||||
if (wayland_may_restore_connection())
|
||||
# ifdef FEAT_WAYLAND
|
||||
if ((wayland_fd = wayland_prepare_read()) >= 0)
|
||||
{
|
||||
wayland_idx = nfd;
|
||||
fds[nfd].fd = wayland_display_fd;
|
||||
fds[nfd].fd = wayland_fd;
|
||||
fds[nfd].events = POLLIN;
|
||||
nfd++;
|
||||
}
|
||||
@@ -6768,13 +6771,9 @@ RealWaitForChar(int fd, long msec, int *check_for_gpm UNUSED, int *interrupted)
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef FEAT_WAYLAND_CLIPBOARD
|
||||
// Technically we should first call wl_display_prepare_read() before
|
||||
// polling the fd, then read and dispatch after we poll. However that is
|
||||
// only needed for multi threaded environments to prevent deadlocks so
|
||||
// we are fine.
|
||||
if (fds[wayland_idx].revents & POLLIN)
|
||||
wayland_client_update();
|
||||
# ifdef FEAT_WAYLAND
|
||||
if (wayland_idx >= 0)
|
||||
wayland_poll_check(fds[wayland_idx].revents);
|
||||
# endif
|
||||
|
||||
# ifdef FEAT_XCLIPBOARD
|
||||
@@ -6867,14 +6866,13 @@ select_eintr:
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef FEAT_WAYLAND_CLIPBOARD
|
||||
|
||||
if (wayland_may_restore_connection())
|
||||
# ifdef FEAT_WAYLAND
|
||||
if ((wayland_fd = wayland_prepare_read()) >= 0)
|
||||
{
|
||||
FD_SET(wayland_display_fd, &rfds);
|
||||
FD_SET(wayland_fd, &rfds);
|
||||
|
||||
if (maxfd < wayland_display_fd)
|
||||
maxfd = wayland_display_fd;
|
||||
if (maxfd < wayland_fd)
|
||||
maxfd = wayland_fd;
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -6974,13 +6972,9 @@ select_eintr:
|
||||
socket_server_uninit();
|
||||
# endif
|
||||
|
||||
# ifdef FEAT_WAYLAND_CLIPBOARD
|
||||
// Technically we should first call wl_display_prepare_read() before
|
||||
// polling the fd, then read and dispatch after we poll. However that is
|
||||
// only needed for multi threaded environments to prevent deadlocks so
|
||||
// we are fine.
|
||||
if (ret > 0 && FD_ISSET(wayland_display_fd, &rfds))
|
||||
wayland_client_update();
|
||||
# ifdef FEAT_WAYLAND
|
||||
if (wayland_fd != -1)
|
||||
wayland_select_check(ret > 0 && FD_ISSET(wayland_fd, &rfds));
|
||||
# endif
|
||||
|
||||
# ifdef FEAT_XCLIPBOARD
|
||||
|
||||
Reference in New Issue
Block a user