This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-14
Channels
- # announcements (1)
- # asami (3)
- # aws (1)
- # babashka (22)
- # beginners (39)
- # calva (21)
- # clj-kondo (10)
- # cljdoc (22)
- # cljs-dev (17)
- # clojure (93)
- # clojure-australia (3)
- # clojure-europe (39)
- # clojure-italy (3)
- # clojure-losangeles (17)
- # clojure-nl (14)
- # clojure-russia (2)
- # clojure-uk (5)
- # clojurescript (35)
- # community-development (7)
- # conjure (2)
- # cursive (13)
- # data-science (1)
- # datomic (25)
- # emacs (5)
- # events (4)
- # figwheel-main (2)
- # fulcro (12)
- # graphql (7)
- # gratitude (2)
- # inf-clojure (6)
- # leiningen (6)
- # lsp (49)
- # malli (13)
- # membrane (30)
- # minecraft (1)
- # pathom (3)
- # pedestal (26)
- # polylith (13)
- # portal (2)
- # quil (3)
- # random (1)
- # re-frame (13)
- # reagent (43)
- # reitit (6)
- # releases (1)
- # reveal (2)
- # ring (3)
- # shadow-cljs (30)
- # specter (5)
- # sql (8)
- # tools-build (1)
- # tools-deps (13)
- # videos (1)
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.
Which backend are you using? membrane.skia
?
yes. skia/run
The test code might be helpful
(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)))))
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}}}
: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.
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
From https://www.glfw.org/docs/latest/input_guide.html#input_keyboard:
key-pressed
maps to glfwSetCharCallback
and key-event
maps to glfwSetKeyCallback
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?
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.
What's the string key you're getting? It should only pass a keyword if the input key isn't printable (eg. :return
)
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.
:event {262 {:press 3, :unknown 3}, 263 {:press 3, :unknown 3}},
I'm getting 262 instead of :rightI 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.
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.
# 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
Thanks for the info! I created an issue https://github.com/phronmophobic/membrane/issues/24.