Skip to content

Commit

Permalink
Don't pass KeyRelease events to XwcLookupString().
Browse files Browse the repository at this point in the history
Check the numerical status code of `XwcLookupString()` as well as its return value.

Should resolve Issue #74. Thanks @tsesani and @scaramacai!



git-svn-id: file:///home/dev/agar/trunk@11248 86a84d31-9702-0410-8f1e-a60cab7bd424
  • Loading branch information
JulNadeauCA committed Apr 10, 2024
1 parent 32b0acb commit 8a1ca67
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
54 changes: 42 additions & 12 deletions gui/drv_glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,49 @@ GLX_GetNextEvent(void *_Nullable drvCaller, AG_DriverEvent *_Nonnull dev)
AG_MutexUnlock(&agDisplayLock);
return (0);
}
if (XLookupString(&xev.xkey, xkbBuf, sizeof(xkbBuf), NULL, &xkbCompStatus) >= 1) {
ch = (AG_Char)xkbBuf[0];
} else {
ch = 0;
}
if (!LookupKeyCode(xev.xkey.keycode, &ks)) {
AG_SetError("KeyRelease: Unknown keycode: %d", (int)xev.xkey.keycode);
AG_MutexUnlock(&agDisplayLock);
return (-1);
}
AG_MutexUnlock(&agDisplayLock);
/* FALLTHROUGH */

if ((win = LookupWindowByID(xev.xkey.window)) == NULL) {
return (-1);
}
#ifdef DEBUG_XEVENTS
Debug(win, "KeyRelease(%u)\n", (Uint)xev.xkey.keycode);
#endif
AG_KeyboardUpdate(WIDGET(win)->drv->kbd, AG_KEY_RELEASED, ks);

dev->type = AG_DRIVER_KEY_UP;
dev->win = win;
dev->key.ks = ks;
dev->key.ucs = ch;
break;
case KeyPress:
AG_MutexLock(&agDisplayLock);
#ifdef AG_UNICODE
if (agXIC) {
XwcLookupString(agXIC, &xev.xkey,
(wchar_t *)&ch, 1,
NULL, NULL);
wchar_t wch;
Status status;

if (XwcLookupString(agXIC, &xev.xkey, &wch, 1,
NULL, &status) == 0) {
ch = (AG_Char)xkbBuf[0];
} else {
if (status != XBufferOverflow &&
status != XLookupNone) {
ch = (AG_Char)wch;
} else {
ch = (AG_Char)xkbBuf[0];
}
}
} else
#endif /* AG_UNICODE */
{
Expand All @@ -693,8 +727,7 @@ GLX_GetNextEvent(void *_Nullable drvCaller, AG_DriverEvent *_Nonnull dev)
}

if (!LookupKeyCode(xev.xkey.keycode, &ks)) {
AG_SetError(_("Keyboard event: Unknown keycode: %d"),
(int)xev.xkey.keycode);
AG_SetError("KeyPress: Unknown keycode: %d", (int)xev.xkey.keycode);
AG_MutexUnlock(&agDisplayLock);
return (-1);
}
Expand All @@ -704,14 +737,11 @@ GLX_GetNextEvent(void *_Nullable drvCaller, AG_DriverEvent *_Nonnull dev)
return (-1);
}
#ifdef DEBUG_XEVENTS
Debug(win, "Key%s(%u)\n", (xev.type == KeyPress) ? "Press" : "Release", (Uint)xev.xkey.keycode);
Debug(win, "KeyPress(%u)\n", (Uint)xev.xkey.keycode);
#endif
AG_KeyboardUpdate(WIDGET(win)->drv->kbd,
(xev.type == KeyPress) ? AG_KEY_PRESSED : AG_KEY_RELEASED,
ks);
AG_KeyboardUpdate(WIDGET(win)->drv->kbd, AG_KEY_PRESSED, ks);

dev->type = (xev.type == KeyPress) ? AG_DRIVER_KEY_DOWN :
AG_DRIVER_KEY_UP;
dev->type = AG_DRIVER_KEY_DOWN;
dev->win = win;
dev->key.ks = ks;
dev->key.ucs = ch;
Expand Down
14 changes: 3 additions & 11 deletions mk/build.lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,10 @@ lib${LIB}.so: ${SRCS_GENERATED} _lib_objs ${OBJS}
echo "${CXX} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} -Wl,-rpath,${LIBDIR} ${LDFLAGS} $$_objs"; \
${CXX} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} -Wl,-rpath ${LIBDIR} ${LDFLAGS} $$_objs; \
;; \
*-linux*) \
*) \
echo "${CXX} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} ${LDFLAGS} $$_objs ${LIBS}"; \
${CXX} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} ${LDFLAGS} $$_objs ${LIBS}; \
;; \
*) \
echo "${CXX} -shared -o $$_libout -Wl,-rpath,${LIBDIR} ${LDFLAGS} $$_objs"; \
${CXX} -shared -o $$_libout -Wl,-rpath ${LIBDIR} ${LDFLAGS} $$_objs; \
;; \
esac; \
else \
case "${HOST}" in \
Expand All @@ -452,14 +448,10 @@ lib${LIB}.so: ${SRCS_GENERATED} _lib_objs ${OBJS}
echo "${CC} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} -Wl,-rpath,${LIBDIR} ${LDFLAGS} $$_objs"; \
${CC} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} -Wl,-rpath ${LIBDIR} ${LDFLAGS} $$_objs; \
;; \
*-linux*) \
*) \
echo "${CC} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} ${LDFLAGS} $$_objs ${LIBS}"; \
${CC} -shared -o $$_libout -Wl,-soname,lib${LIB}.so.${LIB_CURRENT} ${LDFLAGS} $$_objs ${LIBS}; \
;; \
*) \
echo "${CC} -shared -o $$_libout -Wl,-rpath,${LIBDIR} ${LDFLAGS} $$_objs"; \
${CC} -shared -o $$_libout -Wl,-rpath ${LIBDIR} ${LDFLAGS} $$_objs; \
;; \
esac; \
fi; \
\
Expand Down Expand Up @@ -882,7 +874,7 @@ install-lib: check-libtool
done; \
fi
@case "${HOST}" in \
*-linux*) \
*-linux* | *-haiku*) \
if [ "${EUID}" = "0" -o "${USER}" = "root" ]; then \
if [ -x "/sbin/ldconfig" ]; then \
echo "/sbin/ldconfig"; \
Expand Down

0 comments on commit 8a1ca67

Please sign in to comment.