[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: export _mouse_fd for select(2)

From: sgerwk
Subject: Re: export _mouse_fd for select(2)
Date: Thu, 27 Jun 2019 13:03:19 +0000 (UTC)

> Currently, one can include STDIN_FILENO in a select(2), and then call getch() if input is available on stdin. This allows for a main loop that also wait on other file descriptors, signals and a timeout. Unfortunataly, the mouse cannot be included  in this select because the _mouse_fd field of the SCREEN structure is private. 

> A workaroud is to have a thread call getch() in blocking mode and then serve the result on a pipe whose other end goes in the select. But this solution seems awkward to me, especially considering that STDIN_FILENO is instead always available to the application, and compared with having a function like getmousefd() that returns _mouse_fd. 

> This function would be similar to ConnectionNumber(Display *) in XWindow: it returns a file descriptor to be used in a select, so that the application may then call XNextEvent() or similar if something can be read there. I believe it is not supposed to be used in any other way. 

Here is a patch for doing this:

--- ncurses-6.1/include/curses.tail 2016-02-13 17:37:45.000000000 +0100
+++ ncurses-6.1-withmousefd/include/curses.tail 2019-06-26 10:57:05.755049847 +0200
@@ -95,6 +95,7 @@
 extern NCURSES_EXPORT(bool)    has_mouse(void);
+extern NCURSES_EXPORT(int)     getmousefd(void);
 extern NCURSES_EXPORT(int)     getmouse (MEVENT *);
 extern NCURSES_EXPORT(int)     ungetmouse (MEVENT *);
 extern NCURSES_EXPORT(mmask_t) mousemask (mmask_t, mmask_t *);
@@ -105,6 +106,7 @@
 extern NCURSES_EXPORT(bool)    NCURSES_SP_NAME(has_mouse) (SCREEN*);
+extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(getmousefd) (SCREEN*);
 extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(getmouse) (SCREEN*, MEVENT *);
 extern NCURSES_EXPORT(int)     NCURSES_SP_NAME(ungetmouse) (SCREEN*,MEVENT *);
 extern NCURSES_EXPORT(mmask_t) NCURSES_SP_NAME(mousemask) (SCREEN*, mmask_t, mmask_t *);
--- ncurses-6.1/ncurses/base/lib_mouse.c 2017-11-18 23:12:06.000000000 +0100
+++ ncurses-6.1-withmousefd/ncurses/base/lib_mouse.c 2019-06-26 10:56:53.138048893 +0200
@@ -2005,3 +2005,17 @@
+_nc_getmousefd(SCREEN *scr) {
+ return scr->_mouse_fd;
+    return _nc_getmousefd(CURRENT_SCREEN);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]