aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/interface-curses
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2022-06-22 15:00:38 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2022-06-22 15:10:36 +0200
commit147e53b63cb9f3e00c340bd32980eb2a51e972f0 (patch)
treecd70c9f53fa760fafbed382090ccaa0738b06be7 /src/interface-curses
parent51cdc29c9e716beff1b8c6851688db9b10cf1694 (diff)
downloadsciteco-147e53b63cb9f3e00c340bd32980eb2a51e972f0.tar.gz
PDCursesMod/WinGUI now uses the polling fallback again with a temporary workaround
* The keyboard hook required polling as well and was actually much less performant than the generic getch() polling fallback. Furthemore it did at least not work on Wine. * We instead now release the WinGUI-internal mutex and yield the thread giving it some time to process new key presses. * This workaround is temporary and will probably be part of the the next PDCursesMod-release (v4.3.4). We still want to support the latest MSYS/MinGW version though which is currently at v4.3.2. The fix will also currently only work when statically linking in libpdcurses_wingui.a. This is what we do for nightly builds. See also https://github.com/Bill-Gray/PDCursesMod/issues/197 * Once the fix is released upstream and into MSYS, we should probably bump our minimal required PDCursesMod version. The color-table workaround (cf9ffc0cec0d2e55930238d1752209bca659c96d) can then also be removed. * We should also consider dropping official support for the classic PDCurses and support only PDCursesMod - this will allow us to simplify interfaces-curses/interface.c a bit. Support for classic PDCurses is probably broken by now anyway and trying to support it is just too much.
Diffstat (limited to 'src/interface-curses')
-rw-r--r--src/interface-curses/interface.c90
1 files changed, 14 insertions, 76 deletions
diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c
index 186525f..5503d11 100644
--- a/src/interface-curses/interface.c
+++ b/src/interface-curses/interface.c
@@ -128,55 +128,6 @@ teco_console_ctrl_handler(DWORD type)
#endif
-#if defined(PDCURSES_GUI) && defined(G_OS_WIN32)
-
-/**
- * Hooks into the key processing to catch CTRL+C.
- *
- * FIXME: This might be used as the default way to catch CTRL+C on
- * all Windows ports, even including Gtk+.
- */
-static LRESULT CALLBACK
-teco_keyboard_hook(int nCode, WPARAM wParam, LPARAM lParam)
-{
- PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;
- static gboolean ctrl_pressed = FALSE;
-
- if (nCode == HC_ACTION) {
- switch (wParam) {
- case WM_KEYDOWN:
- switch (p->vkCode) {
- case VK_LCONTROL:
- case VK_RCONTROL:
- case VK_CONTROL:
- ctrl_pressed = TRUE;
- break;
- case 0x43: /* C */
- if (ctrl_pressed) {
- teco_sigint_occurred = TRUE;
- return 1;
- }
- break;
- }
- break;
-
- case WM_KEYUP:
- switch (p->vkCode) {
- case VK_LCONTROL:
- case VK_RCONTROL:
- case VK_CONTROL:
- ctrl_pressed = FALSE;
- break;
- }
- break;
- }
- }
-
- return CallNextHookEx(NULL, nCode, wParam, lParam);
-}
-
-#endif
-
static gint teco_xterm_version(void) G_GNUC_UNUSED;
#define UNNAMED_FILE "(Unnamed)"
@@ -415,7 +366,7 @@ teco_interface_init(void)
{
for (guint i = 0; i < G_N_ELEMENTS(teco_interface.color_table); i++)
teco_interface.color_table[i] = -1;
-#ifdef PDCURSES_GUI
+#if defined(__PDCURSESMOD__) && defined(PDCURSES_GUI)
/* NOTE: Fixed and no longer necessary in PDCursesMod v4.3.3. */
teco_interface.color_table[8] = 0x808080;
#endif
@@ -1510,21 +1461,7 @@ teco_interface_is_interrupted(void)
return teco_sigint_occurred != FALSE;
}
-#elif defined(PDCURSES_GUI) && defined(G_OS_WIN32)
-
-gboolean
-teco_interface_is_interrupted(void)
-{
- /*
- * NOTE: The teco_keyboard_hook() is only called from event loops.
- */
- MSG msg;
- PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE);
-
- return teco_sigint_occurred != FALSE;
-}
-
-#else /* !CURSES_TTY && !PDCURSES_WINCON && !NCURSES_WIN32 && (!PDCURSES_GUI || !G_OS_WIN32) */
+#else /* !CURSES_TTY && !PDCURSES_WINCON && !NCURSES_WIN32 */
/*
* This function is called repeatedly, so we can poll the keyboard input queue,
@@ -1539,6 +1476,18 @@ teco_interface_is_interrupted(void)
gint key;
/*
+ * This is a workaround for PDCursesMod/WinGUI that will
+ * likely be fixed in versions newer than v4.3.3.
+ * See also https://github.com/Bill-Gray/PDCursesMod/issues/197
+ */
+#if defined(HAVE_PDC_CS) && PDC_BUILD <= 4303
+ extern CRITICAL_SECTION PDC_cs;
+ LeaveCriticalSection(&PDC_cs);
+ SwitchToThread();
+ EnterCriticalSection(&PDC_cs);
+#endif
+
+ /*
* NOTE: getch() is configured to be nonblocking.
*/
while ((key = wgetch(teco_interface.cmdline_window)) != ERR) {
@@ -1557,13 +1506,6 @@ teco_interface_is_interrupted(void)
static gint
teco_interface_blocking_getch(void)
{
-#if defined(PDCURSES_GUI) && defined(G_OS_WIN32)
- static HHOOK keyboard_hook = NULL;
-
- if (G_LIKELY(keyboard_hook != NULL))
- UnhookWindowsHookEx(keyboard_hook);
-#endif
-
/*
* Setting function key processing is important
* on Unix Curses, as ESCAPE is handled as the beginning
@@ -1598,10 +1540,6 @@ teco_interface_blocking_getch(void)
cbreak();
#endif
-#if defined(PDCURSES_GUI) && defined(G_OS_WIN32)
- keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, teco_keyboard_hook, NULL, 0);
-#endif
-
return key;
}