membrane

Quest 2022-05-22T17:36:13.737739Z

Is there a Membrane way to do a popup/take UI focus from the desktop background? I've made a global keypress handler (via JNativeInput), but I need to bring my program to the forefront of the desktop. In the CljFx/Java2D code, I use (.requestFocus node) on an https://githubhot.com/repo/cljfx/cljfx/issues/94 & just toggle the visibility on/off. I note that (.setVisible (:membrane.java2d/frame x) false) works to change visibility using the Swing API. I think I can get this working if I wrap Swing & https://www.b4x.com/android/forum/threads/solved-how-to-set-the-focus-to-a-non-java-application-in-windows.99253/#post-624929, but would anyone recommend a different approach?

phronmophobic 2022-05-22T17:45:42.533669Z

That approach sounds reasonable to me. For Swing, this stackoverflow answer also looks like you might be able to avoid OS specific code, https://stackoverflow.com/a/64220284. I haven't tried it though.

👀 1
Quest 2022-05-22T17:50:15.434879Z

I'll take a look, nice to avoid OS custom impls. Is stuff like supporting toplevel "visibility" in-scope for Membrane to eventually support, or is this fundamentally not something the library should tackle? (I think the idea is excellent & might be able to add some PRs eventually)

phronmophobic 2022-05-22T17:52:09.438439Z

Yea, that sounds great! If there's a way to abstract it across backends, we can make a common API. If there's not, it's totally fine to just have implementations that support individual backends/OS's

👍 1
Quest 2022-05-22T17:55:13.287499Z

Good to know! If I can get my app off the ground then I'll need to support multiple platforms, so I'll be thinking about how to PR this as I code. Thanks for the advice & hope you're having a good weekend 👋☀️

😄 1
phronmophobic 2022-05-22T17:55:59.036039Z

I had a repl open, so I just tried out the stackoverflow code. Seems to work on Mac OSX

(ns focus
  (:require [membrane.java2d :as backend]
            [membrane.ui :as ui]))

(def window-info (backend/run #(ui/label "ui")))
(def frame (::backend/frame window-info))

;; manually minimize or send window to bottom

;; bring window to front
(javax.swing.SwingUtilities/invokeLater
 (fn []
   (.requestFocusInWindow frame)
   (.setVisible frame true)))

phronmophobic 2022-05-22T17:56:45.803579Z

Also, thanks for trying membrane. I would love to hear your feedback (including the good, bad, or ugly).

👍 1
🤔 1
Quest 2022-05-22T18:49:52.790699Z

I'm just getting into Membrane. So far, I find the stricter decoupling of the events & UI makes the code easier to grok than CljFx. While there's less references to Google, I'm used to diving into library code & am interested in leveraging the benefits (hierarchical UI composability, multiplatform views)

zimablue 2022-05-26T13:23:40.052399Z

just to note on this thread this is also the a thing I cooked up to use in electron so it's probably a common requirement, might be useful inbuilt

➕ 1