Closed stacksmith closed 5 years ago
Another bug here: the loop reads the first keyval only!
(for keyval = (mem-aref keyvals :uint )) ; bug: not indexed - default to element 0...
should be
(for keyval = (mem-aref keyvals :uint i )) ; fetch the keyval for this level
I won't bother with a pull request since @crategus never responds, but if anyone cares, here is the fixed version
(defun gdk-keymap-get-entries-for-keycode (keymap hardware-keycode)
#+cl-cffi-gtk-documentation
"@version{2013-6-13}
@argument[keymap]{a @class{gdk-keymap} object}
@argument[hardware-keycode]{a keycode}
@begin{return}
@code{keys} -- list of @class{gdk-keymap-key}, or @code{nil} @br{}
@code{keyvals} --list of keyvals, or @code{nil} @br{}
@end{return}
@begin{short}
Returns the keyvals bound to @arg{hardware-keycode}.
@end{short}
The Nth @class{gdk-keymap-key} in keys is bound to the Nth keyval in keyvals.
When a keycode is pressed by the user, the keyval from this list
of entries is selected by considering the effective keyboard group and
level. See the function @fun{gdk-keymap-translate-keyboard-state}."
(with-foreign-objects ((keys :pointer) (keyvals :pointer) (n-keys :int))
(when (gdk::%gdk-keymap-get-entries-for-keycode keymap
hardware-keycode
keys
keyvals
n-keys)
(let ((keys (mem-ref keys :pointer))
(keyvals (mem-ref keyvals :pointer))
(n-keys (mem-ref n-keys :int)))
(iter:iter (for i from 0 below n-keys)
(for keyval = (mem-aref keyvals :uint i))
(for keymap-key =
(convert-from-foreign
(inc-pointer
keys
(* i (foreign-type-size
'(:struct gdk::gdk-keymap-key-cstruct))))
'(g-boxed-foreign gdk-keymap-key)))
(collect keymap-key into r-keys)
(collect keyval into r-keyvals)
(finally
(gdk::g-free keys)
(gdk::g-free keyvals)
(return (values r-keys r-keyvals))))))))
@Ferada, take note...
Many thanks for your help. I have corrected the code as suggested. I will commit the code soon. Yes, I have some communication problems for my project. I try to do better.
The intent is to return 2 values but because of prog1 only the primary value is returned. The array of keyvals is therefore lost! Edit: see gdk.key-values.lisp