Fork me on GitHub
#membrane
<
2021-10-14
>
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 (https://developer.apple.com/library/archive/documentation/mac/pdf/MacintoshToolboxEssentials.pdf) 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.

phronmophobic22:10:27

Which backend are you using? membrane.skia?

Dan Maltbie22:10:02

yes. skia/run

phronmophobic22:10:28

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)))]
    (on
     :key-event   (fn [key scancode action mods]
                    (update-counter [:event key action])
                    nil)
     :key-pressed (fn [key]
                    (update-counter [:pressed key])
                    nil)
     :mouse-down  (fn [_]
                    (update-counter [:mouse :down])
                    nil)
     :mouse-up    (fn [_]
                    (update-counter [:mouse :up])
                    nil)
     (horizontal-layout
      (spacer 5 0)
      (ui/label item-name)))))

Dan Maltbie22:10:18

results ttngui.ttngui> @*counts

{:event
 {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}}}

phronmophobic22:10:40

I'm trying it now. one sec

🙏 1
phronmophobic23:10:05

:key-pressed should be :key-press

phronmophobic23:10:00

and then I start seeing those events:

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

phronmophobic23:10:34

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).

phronmophobic23:10:12

hmmm, I'm getting both on mac.

phronmophobic23:10:25

I wonder if there's a difference on linux

Dan Maltbie23:10:32

I restarted repl and am now getting both.

👍 1
phronmophobic23:10:13

From https://www.glfw.org/docs/latest/input_guide.html#input_keyboard: 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}}

phronmophobic23:10:15

yea, it seems like :unknown should be :release

phronmophobic23:10:28

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

phronmophobic23:10:22

I should double check key-action-map on linux

phronmophobic23:10:54

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 https://github.com/phronmophobic/membrane/blob/master/docs/tutorial.md#key-event says it reports the :grave_accent, but probably makes better sense to report the key value as it does now.

phronmophobic23:10:51

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

phronmophobic23:10:39

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
phronmophobic23:10:34

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

phronmophobic23:10:19

Fixing the docs right now!

phronmophobic03:10:18

@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