From 35681082f89783ca07e35182b1fe2434593354d2 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Fri, 5 Aug 2016 16:30:53 -0700 Subject: [PATCH] x11/x11base.scm (key-event): Free buffers. Handle null translation. Do not c-peek-bytes when nbytes is zero. --- src/x11/x11base.scm | 52 ++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/x11/x11base.scm b/src/x11/x11base.scm index 84c0739ca..ad657e405 100644 --- a/src/x11/x11base.scm +++ b/src/x11/x11base.scm @@ -261,28 +261,36 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. (C-enum "LockMask")))) (let* ((nbytes (C-call "x_lookup_string" event buffer buffer-size keysym-buffer)) - (keysym (C-> keysym-buffer "KeySym"))) - (and (not (= keysym (C-enum "NoSymbol"))) - (not (= (C-enum "True") (C-call "IsModifierKey" keysym))) - (vector type - window - ;; If the BackSpace keysym is received, and - ;; XLookupString has translated it into ASCII - ;; backspace, substitute ASCII DEL instead. - (if (and (= keysym (C-enum "XK_BackSpace")) - (= nbytes 1) - (= (C-> buffer "char") (char->ascii #\b))) - (char->string #\Delete) - (let ((string (make-string nbytes))) - (c-peek-bytes buffer 0 nbytes string 0) - string)) - ;; Create Scheme bucky bits (kept independent of - ;; the character). X has already controlified, so - ;; Scheme may choose to ignore the control bucky - ;; bit. - (C-call "x_modifier_mask_to_bucky_bits" state window) - keysym - (C-> event "XKeyEvent time"))))))) + (keysym (C-> keysym-buffer "KeySym")) + (event (and (not (= keysym (C-enum "NoSymbol"))) + (not (= (C-enum "True") + (C-call "IsModifierKey" keysym))) + (vector type + window + ;; If the BackSpace keysym is received, and + ;; XLookupString has translated it into ASCII + ;; backspace, substitute ASCII DEL instead. + (cond ((and (= keysym (C-enum "XK_BackSpace")) + (= nbytes 1) + (= (C-> buffer "char") + (char->ascii #\b))) + (char->string #\Delete)) + ((> nbytes 0) + (let ((s (make-string nbytes))) + (c-peek-bytes buffer 0 nbytes s 0) + s)) + (else "")) + ;; Create Scheme bucky bits (kept independent + ;; of the character). X has already + ;; controlified, so Scheme may choose to + ;; ignore the control bucky bit. + (C-call "x_modifier_mask_to_bucky_bits" + state window) + keysym + (C-> event "XKeyEvent time"))))) + (free keysym-buffer) + (free buffer) + event)))) (define key-event-state-mask (+ (C-enum "ShiftMask") -- 2.25.1