From c260ae425475597120a65ad413d4341f7698a469 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 28 Jun 2019 22:07:00 +0200 Subject: Events.c: refactor nxagentHandleKeypress --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index d8bf4df60..666302606 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -2225,8 +2225,6 @@ FIXME: Don't enqueue the KeyRelease event if the key was int nxagentHandleKeyPress(XEvent *X, enum HandleEventResult *result) { - xEvent x; - if (nxagentXkbState.Initialized == 0) { if (X -> xkey.keycode == nxagentCapsLockKeycode) @@ -2258,15 +2256,15 @@ int nxagentHandleKeyPress(XEvent *X, enum HandleEventResult *result) nxagentXkbState.Num = (~nxagentXkbState.Num & 1); } + nxagentLastServerTime = X -> xkey.time; + nxagentLastEventTime = nxagentLastKeyPressTime = GetTimeInMillis(); - - memset(&x, 0, sizeof(xEvent)); + + xEvent x = {0}; x.u.u.type = KeyPress; x.u.u.detail = nxagentConvertKeycode(X -> xkey.keycode); x.u.keyButtonPointer.time = nxagentLastKeyPressTime; - nxagentLastServerTime = X -> xkey.time; - mieqEnqueue(&x); CriticalOutputPending = 1; -- cgit v1.2.3 From b3d41485dea64fb6b3e287356dcf31aa59a56032 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 28 Jun 2019 22:09:23 +0200 Subject: Events.c: add more comments and TEST output --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 666302606..846254e92 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -1113,8 +1113,8 @@ FIXME: If we don't flush the queue here, it could happen /* FIXME: Don't enqueue the KeyRelease event if the key was not already pressed. This workaround avoids a fake - KeyPress is enqueued by the XKEYBOARD extension. - Another solution would be to let the events are + KeyPress being enqueued by the XKEYBOARD extension. + Another solution would be to let the events enqueued and to remove the KeyPress afterwards. */ if (BitIsOn(inputInfo.keyboard -> key -> down, @@ -1153,6 +1153,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was nxagentXkbNumTrap = 0; } + /* Calculate the time elapsed between this and the last event we + received. Add this delta to time we recorded for the last + KeyPress event we passed on to our clients. */ memset(&x, 0, sizeof(xEvent)); x.u.u.type = KeyRelease; x.u.u.detail = nxagentConvertKeycode(X.xkey.keycode); @@ -1168,8 +1171,14 @@ FIXME: Don't enqueue the KeyRelease event if the key was x.u.keyButtonPointer.time = nxagentLastEventTime; } - if (!(nxagentCheckSpecialKeystroke(&X.xkey, &result)) && sendKey == 1) + /* do not send a KeyRelease for a special keystroke since we + also did not send a KeyPress event in that case */ + if (!(nxagentCheckSpecialKeystroke(&X.xkey, &result)) && (sendKey == 1)) { + #ifdef TEST + fprintf(stderr, "%s: passing KeyRelease event to clients\n", __func__); + #endif + mieqEnqueue(&x); CriticalOutputPending = 1; @@ -1181,6 +1190,12 @@ FIXME: Don't enqueue the KeyRelease event if the key was NXShadowEvent(nxagentDisplay, X); } } + else + { + #ifdef TEST + fprintf(stderr, "%s: NOT passing KeyRelease event to clients\n", __func__); + #endif + } break; } @@ -2244,6 +2259,9 @@ int nxagentHandleKeyPress(XEvent *X, enum HandleEventResult *result) if (nxagentCheckSpecialKeystroke(&X -> xkey, result)) { + #ifdef TEST + fprintf(stderr, "%s: NOT passing KeyPress event to clients\n", __func__); + #endif return 1; } @@ -2265,6 +2283,10 @@ int nxagentHandleKeyPress(XEvent *X, enum HandleEventResult *result) x.u.u.detail = nxagentConvertKeycode(X -> xkey.keycode); x.u.keyButtonPointer.time = nxagentLastKeyPressTime; + #ifdef TEST + fprintf(stderr, "%s: passing KeyPress event to clients\n", __func__); + #endif + mieqEnqueue(&x); CriticalOutputPending = 1; -- cgit v1.2.3 From ceeb53f0c591b2a0b69343208282cfc2c7872509 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 28 Jun 2019 22:10:23 +0200 Subject: Keystroke.c: fix wrong return code The effect of this was that special keystrokes where detected and passed to the nxagent. E.g. pressing ctrl-alt-f for Fullscreen also produced an "f" in the current input window inside the nxagent. --- nx-X11/programs/Xserver/hw/nxagent/Keystroke.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c index 662da6b04..966b4f842 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c @@ -480,6 +480,9 @@ static enum nxagentSpecialKeystroke find_keystroke(XKeyEvent *X) return ret; } +/* + * returns True if a special keystroke has been pressed. *result will contain the action. + */ Bool nxagentCheckSpecialKeystroke(XKeyEvent *X, enum HandleEventResult *result) { enum nxagentSpecialKeystroke stroke = find_keystroke(X); @@ -629,5 +632,5 @@ Bool nxagentCheckSpecialKeystroke(XKeyEvent *X, enum HandleEventResult *result) case KEYSTROKE_MAX: break; } - return (*result == doNothing); + return (*result != doNothing); } -- cgit v1.2.3