membrane

Dan Maltbie 2021-10-14T22:52:10.084800Z

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.

Dan Maltbie 2021-10-15T08:53:05.106900Z

# 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
phronmophobic 2021-10-15T17:20:09.107900Z

Thanks for the info! I created an issue https://github.com/phronmophobic/membrane/issues/24.

🙌 1
phronmophobic 2021-10-14T22:53:27.084900Z

Which backend are you using? membrane.skia?

Dan Maltbie 2021-10-14T22:54:02.085100Z

yes. skia/run

phronmophobic 2021-10-14T22:54:28.085300Z

The test code might be helpful

Dan Maltbie 2021-10-14T22:55:03.085500Z

(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 Maltbie 2021-10-14T22:55:18.085700Z

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}}}

phronmophobic 2021-10-14T22:57:40.086Z

I'm trying it now. one sec

🙏 1
phronmophobic 2021-10-14T23:00:05.086300Z

:key-pressed should be :key-press

phronmophobic 2021-10-14T23:01:00.086500Z

and then I start seeing those events:

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

phronmophobic 2021-10-14T23:02:34.086700Z

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

Dan Maltbie 2021-10-14T23:02:42.086900Z

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

phronmophobic 2021-10-14T23:05:12.087100Z

hmmm, I'm getting both on mac.

phronmophobic 2021-10-14T23:05:25.087300Z

I wonder if there's a difference on linux

Dan Maltbie 2021-10-14T23:06:32.087500Z

I restarted repl and am now getting both.

👍 1
phronmophobic 2021-10-14T23:07:13.087700Z

From https://www.glfw.org/docs/latest/input_guide.html#input_keyboard: key-pressed maps to glfwSetCharCallback and key-event maps to glfwSetKeyCallback

Dan Maltbie 2021-10-14T23:09:50.088Z

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}}

phronmophobic 2021-10-14T23:12:15.088200Z

yea, it seems like :unknown should be :release

phronmophobic 2021-10-14T23:13:28.088400Z

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

phronmophobic 2021-10-14T23:14:22.088600Z

I should double check key-action-map on linux

phronmophobic 2021-10-14T23:15:54.088800Z

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 Maltbie 2021-10-14T23:17:31.089Z

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.

phronmophobic 2021-10-14T23:19:51.089200Z

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

Dan Maltbie 2021-10-14T23:20:57.089500Z

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 Maltbie 2021-10-14T23:24:21.089800Z

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

phronmophobic 2021-10-14T23:28:39.090Z

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
phronmophobic 2021-10-14T23:29:34.090200Z

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

phronmophobic 2021-10-14T23:31:19.090400Z

Fixing the docs right now!

phronmophobic 2021-10-15T03:32:18.090600Z

@dmaltbie, 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.