Patch 8.2.4457
Problem: The GPM library can only be linked statically.
Solution: Make it possible to load the GPM library dynamically. (Damien)
Files: runtime/doc/various.txt, src/
config.h.in, src/
configure.ac,
src/Makefile, src/evalfunc.c, src/feature.h, src/os_unix.c,
src/proto/
os_unix.pro, src/version.c
*** ../vim-8.2.4456/runtime/doc/various.txt 2022-01-02 12:05:59.033607215 +0000
--- runtime/doc/various.txt 2022-02-23 16:53:27.436167946 +0000
***************
*** 410,415 ****
--- 410,416 ----
N *+mouseshape* |'mouseshape'|
B *+mouse_dec* Unix only: Dec terminal mouse handling |dec-mouse|
N *+mouse_gpm* Unix only: Linux console mouse handling |gpm-mouse|
+ m *+mouse_gpm/dyn* Same as |+mouse_gpm| with optional library dependency |/dyn|
N *+mouse_jsbterm* JSB mouse handling |jsbterm-mouse|
B *+mouse_netterm* Unix only: netterm mouse handling |netterm-mouse|
N *+mouse_pterm* QNX only: pterm mouse handling |qnx-terminal|
*** ../vim-8.2.4456/src/
config.h.in 2021-11-19 11:27:49.103056914 +0000
--- src/
config.h.in 2022-02-23 16:53:27.436167946 +0000
***************
*** 507,509 ****
--- 507,512 ----
/* Define if _SC_SIGSTKSZ is available via sysconf() */
#undef HAVE_SYSCONF_SIGSTKSZ
+
+ /* Define if you want to load libgpm dynamically */
+ #undef DYNAMIC_GPM
*** ../vim-8.2.4456/src/
configure.ac 2022-01-18 11:11:22.293120455 +0000
--- src/
configure.ac 2022-02-23 16:53:27.436167946 +0000
***************
*** 4096,4108 ****
LIBS="$ac_save_LIBS"
fi
! AC_MSG_CHECKING(--disable-gpm argument)
AC_ARG_ENABLE(gpm,
! [ --disable-gpm Don't use gpm (Linux mouse daemon).], ,
[enable_gpm="yes"])
! if test "$enable_gpm" = "yes"; then
! AC_MSG_RESULT(no)
dnl Checking if gpm support can be compiled
AC_CACHE_CHECK([for gpm], vi_cv_have_gpm,
[olibs="$LIBS" ; LIBS="-lgpm"]
--- 4096,4108 ----
LIBS="$ac_save_LIBS"
fi
! AC_MSG_CHECKING(--enable-gpm argument)
AC_ARG_ENABLE(gpm,
! [ --enable-gpm=OPTS Use gpm (Linux mouse daemon). default=yes OPTS=yes/no/dynamic], ,
[enable_gpm="yes"])
! if test "$enable_gpm" = "yes" -o "$enable_gpm" = "dynamic"; then
! AC_MSG_RESULT($enable_gpm)
dnl Checking if gpm support can be compiled
AC_CACHE_CHECK([for gpm], vi_cv_have_gpm,
[olibs="$LIBS" ; LIBS="-lgpm"]
***************
*** 4117,4127 ****
[LIBS="$olibs"]
)
if test $vi_cv_have_gpm = yes; then
! LIBS="$LIBS -lgpm"
AC_DEFINE(HAVE_GPM)
fi
else
! AC_MSG_RESULT(yes)
fi
AC_MSG_CHECKING(--disable-sysmouse argument)
--- 4117,4131 ----
[LIBS="$olibs"]
)
if test $vi_cv_have_gpm = yes; then
! if test "$enable_gpm" = "yes"; then
! LIBS="$LIBS -lgpm"
! else
! AC_DEFINE(DYNAMIC_GPM)
! fi
AC_DEFINE(HAVE_GPM)
fi
else
! AC_MSG_RESULT(no)
fi
AC_MSG_CHECKING(--disable-sysmouse argument)
*** ../vim-8.2.4456/src/Makefile 2022-02-19 16:00:12.590199398 +0000
--- src/Makefile 2022-02-23 18:03:10.430309839 +0000
***************
*** 526,531 ****
--- 526,533 ----
# though you have gpm libraries and includes.
# For Debian/Ubuntu gpm support requires the libgpm-dev package.
#CONF_OPT_GPM = --disable-gpm
+ # Use this to enable dynamic loading of the GPM library.
+ #CONF_OPT_GPM = --enable-gpm=dynamic
# sysmouse - For mouse support on FreeBSD and DragonFly console via sysmouse
# Uncomment this when you do not want do include sysmouse support, even
*** ../vim-8.2.4456/src/evalfunc.c 2022-02-23 13:16:55.757541153 +0000
--- src/evalfunc.c 2022-02-23 16:53:27.440167949 +0000
***************
*** 5786,5792 ****
#endif
},
{"mouse_gpm",
! #if (defined(UNIX) || defined(VMS)) && defined(FEAT_MOUSE_GPM)
1
#else
0
--- 5786,5792 ----
#endif
},
{"mouse_gpm",
! #if (defined(UNIX) || defined(VMS)) && defined(FEAT_MOUSE_GPM) && !defined(DYNAMIC_GPM)
1
#else
0
***************
*** 6392,6397 ****
--- 6392,6401 ----
else if (STRICMP(name, "terminal") == 0)
n = terminal_enabled();
#endif
+ #ifdef DYNAMIC_GPM
+ else if (STRICMP(name, "mouse_gpm") == 0)
+ n = gpm_available();
+ #endif
}
// features not in has_list[]
*** ../vim-8.2.4456/src/feature.h 2022-02-13 12:24:17.773683851 +0000
--- src/feature.h 2022-02-23 16:53:27.440167949 +0000
***************
*** 952,957 ****
--- 952,963 ----
*/
#if defined(FEAT_NORMAL) && defined(HAVE_GPM)
# define FEAT_MOUSE_GPM
+ /*
+ * +mouse_gpm/dyn Load libgpm dynamically.
+ */
+ # ifndef DYNAMIC_GPM
+ // # define DYNAMIC_GPM
+ # endif
#endif
#if defined(FEAT_NORMAL) && defined(HAVE_SYSMOUSE)
*** ../vim-8.2.4456/src/os_unix.c 2022-02-07 10:45:12.799027338 +0000
--- src/os_unix.c 2022-02-23 16:53:27.440167949 +0000
***************
*** 55,61 ****
--- 55,79 ----
#endif
#ifdef FEAT_MOUSE_GPM
+
# include <gpm.h>
+
+ # ifdef DYNAMIC_GPM
+ # define Gpm_Open (*dll_Gpm_Open)
+ # define Gpm_Close (*dll_Gpm_Close)
+ # define Gpm_GetEvent (*dll_Gpm_GetEvent)
+ # define gpm_flag (dll_gpm_flag != NULL ? *dll_gpm_flag : 0)
+ # define gpm_fd (dll_gpm_fd != NULL ? *dll_gpm_fd : -1)
+
+ static int (*dll_Gpm_Open) (Gpm_Connect *, int);
+ static int (*dll_Gpm_Close) (void);
+ static int (*dll_Gpm_GetEvent) (Gpm_Event *);
+ static int *dll_gpm_flag;
+ static int *dll_gpm_fd;
+
+ static void *libgpm_hinst;
+ # endif
+
// <linux/keyboard.h> contains defines conflicting with "keymap.h",
// I just copied relevant defines here. A cleaner solution would be to put gpm
// code into separate file and include there linux/keyboard.h
***************
*** 6446,6452 ****
}
# endif
# ifdef FEAT_MOUSE_GPM
! if (ret > 0 && gpm_flag && check_for_gpm != NULL && gpm_fd >= 0)
{
if (FD_ISSET(gpm_fd, &efds))
gpm_close();
--- 6464,6470 ----
}
# endif
# ifdef FEAT_MOUSE_GPM
! if (ret > 0 && check_for_gpm != NULL && gpm_flag && gpm_fd >= 0)
{
if (FD_ISSET(gpm_fd, &efds))
gpm_close();
***************
*** 7172,7177 ****
--- 7190,7238 ----
#endif // !HAVE_RENAME
#if defined(FEAT_MOUSE_GPM) || defined(PROTO)
+ # if defined(DYNAMIC_GPM) || defined(PROTO)
+ /*
+ * Initialize Gpm's symbols for dynamic linking.
+ * Must be called only if libgpm_hinst is NULL.
+ */
+ static int
+ load_libgpm(void)
+ {
+ libgpm_hinst = dlopen("libgpm.so", RTLD_LAZY|RTLD_GLOBAL);
+
+ if (libgpm_hinst == NULL)
+ {
+ if (p_verbose > 0)
+ smsg_attr(HL_ATTR(HLF_W),
+ _("Could not load gpm library: %s"), dlerror());
+ return FAIL;
+ }
+
+ if (
+ (dll_Gpm_Open = dlsym(libgpm_hinst, "Gpm_Open")) == NULL
+ || (dll_Gpm_Close = dlsym(libgpm_hinst, "Gpm_Close")) == NULL
+ || (dll_Gpm_GetEvent = dlsym(libgpm_hinst, "Gpm_GetEvent")) == NULL
+ || (dll_gpm_flag = dlsym(libgpm_hinst, "gpm_flag")) == NULL
+ || (dll_gpm_fd = dlsym(libgpm_hinst, "gpm_fd")) == NULL
+ )
+ {
+ semsg(_(e_could_not_load_library_str_str), "gpm", dlerror());
+ dlclose(libgpm_hinst);
+ libgpm_hinst = NULL;
+ dll_gpm_flag = NULL;
+ dll_gpm_fd = NULL;
+ return FAIL;
+ }
+ return OK;
+ }
+
+ int
+ gpm_available(void)
+ {
+ return libgpm_hinst != NULL || load_libgpm() == OK;
+ }
+ # endif // DYNAMIC_GPM
+
/*
* Initializes connection with gpm (if it isn't already opened)
* Return 1 if succeeded (or connection already opened), 0 if failed
***************
*** 7181,7186 ****
--- 7242,7252 ----
{
static Gpm_Connect gpm_connect; // Must it be kept till closing ?
+ #ifdef DYNAMIC_GPM
+ if (!gpm_available())
+ return 0;
+ #endif
+
if (!gpm_flag)
{
gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN);
*** ../vim-8.2.4456/src/proto/
os_unix.pro 2020-08-23 13:28:24.107838497 +0100
--- src/proto/
os_unix.pro 2022-02-23 16:53:27.440167949 +0000
***************
*** 85,88 ****
--- 85,89 ----
int xsmp_handle_requests(void);
void xsmp_init(void);
void xsmp_close(void);
+ int gpm_available(void);
/* vim: set ft=c : */
*** ../vim-8.2.4456/src/version.c 2022-02-23 14:25:08.143591156 +0000
--- src/version.c 2022-02-23 16:57:31.628252488 +0000
***************
*** 375,381 ****
--- 375,385 ----
"-mouse_dec",
# endif
# ifdef FEAT_MOUSE_GPM
+ # ifdef DYNAMIC_GPM
+ "+mouse_gpm/dyn",
+ # else
"+mouse_gpm",
+ # endif
# else
"-mouse_gpm",
# endif
*** ../vim-8.2.4456/src/version.c 2022-02-23 14:25:08.143591156 +0000
--- src/version.c 2022-02-23 16:57:31.628252488 +0000
***************
*** 752,753 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 4457,
/**/
--
I AM THANKFUL...
...for the taxes that I pay because it means that I am employed.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///