Fork me on GitHub
Dan Maltbie22:10:10

I've been investigating UI frameworks for about six months now and came across your library. I found your approach a refreshing change (actually it blew my mind but that may be a little over the top) and hope to use it. I have started trying some examples but ran into a basic problem that may be my misunderstanding. I set up a simple test for keyboard and mouse events. I can reliably detect mouse up and down events as expected but the keyboard events don't seem right. In particular, for :key-event the arrow keys (left, right, up, down) are being reported as string values representing the Apple Virtual Keycodes ( and not the :grave_accent keywords. And I get no reports for :key-pressed. I am running on Ubuntu 20.04 as a virtual machine in MacOS Parallels. I can share my test code if it would be helpful.


Which backend are you using? membrane.skia?

Dan Maltbie22:10:02

yes. skia/run


The test code might be helpful

Dan Maltbie22:10:03

(def *counts (atom {}))

(defui item-row [ {:keys [item-name]}]
  (let [update-counter (fn [counter]
                         (if (nil? (get-in @*counts counter))
                           (swap! *counts assoc-in counter 1)
                           (swap! *counts update-in counter inc)))]
     :key-event   (fn [key scancode action mods]
                    (update-counter [:event key action])
     :key-pressed (fn [key]
                    (update-counter [:pressed key])
     :mouse-down  (fn [_]
                    (update-counter [:mouse :down])
     :mouse-up    (fn [_]
                    (update-counter [:mouse :up])
      (spacer 5 0)
      (ui/label item-name)))))

Dan Maltbie22:10:18

results ttngui.ttngui> @*counts

 {262 {:press 1, :unknown 1},
  263 {:press 1, :unknown 1},
  264 {:press 1, :unknown 1},
  265 {:press 1, :unknown 1},
  257 {:press 1, :unknown 1}}}


I'm trying it now. one sec

🙏 1

:key-pressed should be :key-press


and then I start seeing those events:

:pressed {:right 4, :up 2, :left 4, :down 1, :left_super 1}


The values for values key, scancode, action , and mods come from glfw.

Dan Maltbie23:10:42

yep. that works. sorry for such a boneheaded question. does only one of the two events get reported (either :key-press or :key-event but not both? that's what I'm seeing).


hmmm, I'm getting both on mac.


I wonder if there's a difference on linux

Dan Maltbie23:10:32

I restarted repl and am now getting both.

👍 1

From key-pressed maps to glfwSetCharCallback and key-event maps to glfwSetKeyCallback

Dan Maltbie23:10:50

thanks for the reference, it's good to know. here is my result. Shouldn't key-event have :press and :release?

{:mouse {:down 4, :up 4},
 :event {262 {:press 3, :unknown 3}, 263 {:press 3, :unknown 3}},
 :pressed {:right 3, :left 3}}


yea, it seems like :unknown should be :release


(def key-action-map
  {1 :press
   2 :repeat
   0 :release})
action (get key-action-map action :unknown)


I should double check key-action-map on linux


I was previously using Virtualbox to test linux, but that doesn't work on the M1 macs the last time I checked. How do you like Parallels?

Dan Maltbie23:10:31

Also, event reports string key value instead of :grave_accent. The says it reports the :grave_accent, but probably makes better sense to report the key value as it does now.


What's the string key you're getting? It should only pass a keyword if the input key isn't printable (eg. :return)

Dan Maltbie23:10:57

Parallels is decent. Yes, it costs money but I have had no significant problems and it is really easy to use. I like snapshots and linked clones a lot. I used Virtual Box for years but it is kind of clunky compared to Parallels.

👍 1
Dan Maltbie23:10:21

:event {262 {:press 3, :unknown 3}, 263 {:press 3, :unknown 3}},
I'm getting 262 instead of :right


I think that's a misprint in the tutorial. key-event is a lower level type event that really just tells you what key was pressed and doesn't try to interpret it as opposed to key-press which will try to use the OS settings to interpret the key.

👍 1

so key-event should give 65 instead of a and it will be the same number regardless of whether caps lock or shift is pressed


Fixing the docs right now!


@U01AGMXNQ3X, I tried to reproduce the :unknown action issue using my virtual box setup and it was correctly showing :release. Not sure which part of my setup I need to change to reproduce the bug. Do you have the versions of the OS, architecture, java version, and Parallels handy? Hopefully, I can at least log the info to try and look into it further.

Dan Maltbie08:10:05

# java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal
# uname -a
Linux parallels 5.11.0-37-generic #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
# Parallels
17.0.1 Pro Edition

👍 1